paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.72k stars 620 forks source link

Consider removing GrandPa commit messages gossiping #4120

Open tomaka opened 4 months ago

tomaka commented 4 months ago

Right now, nodes "sometimes" (as an implementation detail) gossip GrandPa commit messages to each other.

Light clients rely on these commit messages in order to know which block has been finalized. In practice, however, since the gossip messages aren't always gossiped, there is sometimes a delay between the chain's finalized block and the light client's finalized block. Since UIs on top of light clients are supposed to rely only on finalized blocks and that anything non-finalized can't 100% be trusted, this is not great. See https://github.com/smol-dot/smoldot/issues/1754

It seems to me that it would be a better idea to make light clients explicitly download the justification of a block once it has learned (through a neighbor packet) that it has been finalized.

As far as I understand (correct me if I'm wrong), at the time when GrandPa was created, we would only store justifications of epoch change blocks. Since we've implemented warp syncing, however, we also store the latest finalized block justification.

Since, if I'm not mistaken, we only store the latest finalized block's justification, that gives 6 seconds for the full node to send a neighbor packet to light clients and for light clients to ask for the justification in return. This should be more than enough. If the block time was to be reduced, however, we would have to store the justifications of a few recent blocks rather than just the one most recent block.

Let me know if that all makes sense.

cc @andresilva

andresilva commented 4 months ago

I wonder why the light client doesn't get the commit messages gossiped to it regularly. Is it connected to a low number of peers?

Either way, your suggestion for requesting the justification explicitly should work since we always have the latest justification available. IIRC we are currently only sending neighbor packets to light clients when the authority set changes, so we'll need to change this to everytime a new block is finalized (or basically when the round finishes, same as full nodes).

burdges commented 4 months ago

Yes, we could switch light clients from gandpa to beefy, not sure the current beefy lag, but..

We could do beefy BLS signatures every block, even ETH relayers do not create the web3sum proof of the beefy aggregate public key every block.

A polkadot light client who knows the validators BLS public keys could simply read the bitfield identifying the signers, add up those public keys, and do the pairing check of the aggregate BLS public key. We ingnore the web3sum proof entirely, because that's just an optimization for ETH's fucked up cost model.

At least on kusama, this should already be faster than checking over 600 signatures, assuming we're building ed25519 verification into wasm now. If otoh the light client uses the webcrypto APIs for native verification code, then maybe sticking with unaggregated ed25519 remains faster.

tomaka commented 4 months ago

I wonder why the light client doesn't get the commit messages gossiped to it regularly. Is it connected to a low number of peers?

It's normally connected to 3 full nodes, but it can be fewer than that because smoldot can only ever connect to nodes through WebSocket, which significantly limits the possible selection.

tomaka commented 4 months ago

Having to explicitly query justifications (as opposed to passively receiving commit messages) has a few advantages: