ethresearch / sharding-p2p-poc

Proof of Concept of Ethereum Serenity Peer-to-Peer Layer on libp2p PubSub System
40 stars 19 forks source link

Message implementation #63

Closed ChihChengLiang closed 5 years ago

ChihChengLiang commented 5 years ago

What is wrong?

A beacon chain client sends and receives multiple types of messages, such as blocks and attestationRecords. It would be tedious if implementing a new type of message requires modifications in several places in both Python and Go codebase.

For example, if a message foo is introduced, it is likely that we need to:

How can it be fixed?

Make Go codebase agnostic to message type, whenever it receives a new message, pass the raw byte to the Python host. The Python host deserializes the raw byte and determine it's validity and return to the Go.

The proposed solution requires only adding a generic message, rpc server, and event notifier in both Go and Python codebase. When introducing a new message foo, the extra modification is reduced to:

This also comes a downside that the invalid messages can't be pre-filtered in Go side by the content but by the size. This could be an attacking vector but might be tolerable in the prototyping stage.

mhchia commented 5 years ago

Totally agree with you. It makes a lot of sense. When we simplify the RPC call to notfiy(topic, bytes) and send(topic, bytes), it will be a lot easier to replace it with PIPE. Just for fun, I drew a flowchart for notify from Go to Python. Hope it will be useful.

ChihChengLiang commented 5 years ago

Addressed