NeoResearch / libbft

A lightweight and multi-language library for byzantine fault tolerance
MIT License
24 stars 3 forks source link

Cross-language support #2

Open KrishnaPG opened 4 years ago

KrishnaPG commented 4 years ago

This looks good work.

For cross-language support, it would be good to go deep into one language with runtime support, rather than going wide and providing compile-time linking options for many languages.

For example, once C/C++ implementation is done, please:

That would save lot of implementation redundancy, as well as reaches larger target audience (e.g. Python, R what not)

Also, for serialization, please use cbor rather than depending on protobufs. A good design does not force a rebuild of the code whenever there is a change in the wire/serialization format. All modern languages support CBOR and it is extensible.

igormcoelho commented 4 years ago

Hello @KrishnaPG, thanks for the comments, I believe we are aligned in the same direction. @rodoufu do you know CBOR?

provide connectivity options to invoke the API through HTTP/2, WebSockets, RPC etc. so that all other languages, such as JavaScript, GO, Rest etc. all can start using the C/C++ code at runtime.

Regarding this point, we are using gRPC... so, it works over HTTP, although "not pure". Is that the point? I've been looking at zero-MQ as well, specially to build p2p interconnections, but not certain yet. Next step here is to provide better WorldModel supports and active monitoring of processes (to begin heavy testing).

KrishnaPG commented 4 years ago

Thank you @igormcoelho

The gRPC should be good enough to interact from other languages. But it was not directly apparent from the ReadMe how to use that gRPC API. It would be great if you could kindly add an example or two in the ReadMe, or some docs, showcasing how to use the libBFT's gRPC (preferably from JS or some simple language), so that it becomes easy for us to start using/testing it.

For example, I would love to invoke the gRPC API from browser (through JavaScript) and start using this library for sharing some state data across multiple NodeJS and browser instances. (If you can run from a browser, then you are already mobile-ready). JS is the low-hanging fruit. If it can be used from JS, then using it from other languages, such as Go, Rust is pretty straightforward.

For P2P, ZeroMQ is good, but it has some serious restriction of native sockets, which means browser-based clients are out of question. There were some efforts to use ZMQ with WebSockets earlier, but not much progress there. The best option out there currently is libP2P

Monitoring is the easy part. You might be already aware of below, which are the best options out there currently:

The rather difficult part, however, is making the distributed state management easy for programmers.

When you say "WorldModel" I believe you are referring to the app-specific state data that is being shared by nodes. My request would be to make such "app-state" data API robust with cross-language compatibility so that applications from any language can seamlessly use the same data-model across diverse machines / networks (including browser-instances).

A couple of examples that illustrate how to achieve such above tasks easily from simple languages, such as JS could immensely attract many developers to start using this project rapidly.

The Tendermint ABCI is a good model to study for inspiration. It is a consensus engine, and the ABCI spec is good. But its implementation still needs much more refinement. For example, multi-tenancy etc. Here are some of my thoughts https://github.com/tendermint/tendermint/issues/4058

Since libBFT is still in the developments, there is great scope to make it easy for programmers to adopt and get started easily.

rodoufu commented 4 years ago

Hello @KrishnaPG, thanks for the comments, I believe we are aligned in the same direction. @rodoufu do you know CBOR?

I haven't used CBOR yet, but I started to look about it once I read this issue from @KrishnaPG, we are using Protobuf because it's the default for gRPC and it's also well known and has good performance. @KrishnaPG what are the advantages of CBOR over Protobuf?

rodoufu commented 4 years ago

That's a good suggestion @KrishnaPG, I was going to cite libp2p as well. @igormcoelho, libp2p is the one I talked to you about, I saw a good presentation on the Devcon V about it, @shargon and @belane also liked it.

For P2P, ZeroMQ is good, but it has some serious restriction of native sockets, which means browser-based clients are out of question. There were some efforts to use ZMQ with WebSockets earlier, but not much progress there. The best option out there currently is libP2P

KrishnaPG commented 4 years ago

Thank you @rodoufu

what are the advantages of CBOR over Protobuf?

The main distinction between them is the schema-lockin.

Protobuf is schema-driven:

A decade back when everyone was building applications inside an organization, documeting and sharing their interfaces / schemas, protobuf was a super-hit, because you can consume RPC created in one language from another. These were the days XML was a super-hero (and C/C++ guys usually hated XML), so protobuf became a natural alternative.

Fast-forward few years, where web and mobile became standard, and Javascript emerged as one of the main languages (thanks to the Node.Js and full-stack), which completely destroyed the XML reign, with its super simple JSON. (XML namespaces were a nightmare)

CBOR is just a binary packing of JSON. One can think of Protobuf vs CBOR as C++ Templates vs .Net Reflection.

If one looks at the extensibility of CBOR, for example the tags here, one can discover the provision for IPLD, IOT and other emerging technology tags, which are "semantic markups" of data that are very important for Blockchain frameworks such as this.

For example, consider a simple practical scenaro:

in the above scenario, sensor -> analytics server -> decision nodes, no one knows anything about the other servers. While this can be achieved with protobuf, with lot of coordination, it is certainly not the best tool for the job.

Now, one may ask, without knowing the other party's schema how can CBOR be beneficial either? Since at the end of the day, you have to know the fields in the object to make anything useful out of it. There are two aspects to it:

  1. It is true that one has to know the fields in the data to make anything useful out of. But this does not apply for middleware, such as this libBFT, where the exact state / data is not going to affect the functionality (e.g. what is stored inside the block is never our business).
  2. Also, this is where the concepts of Linked Data and multi-formats shine.
KrishnaPG commented 4 years ago

BTW, on the downside, using CBOR requires you to have your own RPC network mechanism.

gRPC was one of the reasons for the success of Protobuf. You get both the RPC framework + serialization (protobuf) nicely working together.

CBOR is a good option only if you already have a separate RPC mechanism, such as ZMQ / DHT-RPC / Websockets or least a HTTP server, such as H2O or SeaStar.