tinychainorg / tinychain

The tiniest blockchain implementation in the world
https://www.tinycha.in/
MIT License
56 stars 4 forks source link

Protobufs + gRPC #13

Closed liamzebedee closed 3 months ago

liamzebedee commented 3 months ago

Exploring using protocol buffers and gRPC.

Currently the RPC interface is implemented as a simple HTTP server, with a set of RPC message types that are serialised using JSON, and peers just send messages and some messages have responses.

Some immediate benefit to using protobufs:

Some benefits to using gRPC:

Things I still gotta work out:

moshababo commented 3 months ago

protobuf (de)serialization isn't deterministic, meaning that a given memory layout can have multiple valid serialized representations. This is fine for the node's API RPC & database-related serialization, but less good for p2p networking, and bad for crypto-related serialization (hashing / signing).

It can be turned deterministic by applying a stricter set of rules (example: node/libs/protobuf/src/proto_fmt.rs), but I'm not sure if such implementation is available in Go.

Also, using gRPC for p2p networking can be problematic. Although most things are doable on the the HTTP/2 connection, It's probably better to either go with plain TCP for full control, or use libp2p.

vrypan commented 3 months ago

May be wort reaching out to the Farcaster team. They use gRPC and libp2p and the network size is ~10,000 nodes.

liamzebedee commented 3 months ago

Thanks @moshababo

protobuf (de)serialization isn't deterministic, meaning that a given memory layout can have multiple valid serialized representations. This is fine for the node's API RPC & database-related serialization, but less good for p2p networking, and bad for crypto-related serialization (hashing / signing).

I'm aware of the serialisation aspects, though haven't heard about the impact on networking? I would guess that one aspect of the dynamically sized encoding is that it might impact benchmarks re: networking.

liamzebedee commented 3 months ago

Also, using gRPC for p2p networking can be problematic. Although most things are doable on the the HTTP/2 connection, It's probably better to either go with plain TCP for full control, or use libp2p.

Can you elaborate / link some references? libp2p definitely on my radar, for their TURN/NAT holepunching.

liamzebedee commented 3 months ago

Ugh I have accidentally closed this while deleting some old branches, github UX is a bit shite. Will try fix, still curious on comments above.