You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
consensus: extract block gossiping into its own reactor #2127
Block gossiping is currently a big part of the consensus reactor, but it actually might not be that difficult to refactor it out, so the consensus reactor just has a blockAvailable signaling mechanism (like it has for transactions), and that thing has to be triggered before you can vote on a proposal.
The thing that populates blockAvailable could be another reactor that propagates the block parts however it wants, including having most of it from the mempool.
We should discuss this topic, possibly synchronously.
I agree that block propagation should be a component by itself, maybe a new reactor, although this is not a requirement. This enables, in particular, some optimizations for consensus heights with multiple rounds (currently we drop the block from the previous round once a new round is started, even thought the same block can be re-proposed).
This component that handles block propagation should be informed, in some way, by consensus about the blocks it has to retrieve. One of the problems of a "blind" block propagation component is that it can be flooded with an arbitrary and possibly invalid number of blocks.
We also have the problem of persisting the blocks we accept (or propose). This is necessary, as otherwise, a node recovering from a crash will likely misbehave, since it does not "remember" actions taken before crashing.
So I've got to agree with you, I guess that it fits at all possible it's probably good to source what a block is directly from the proposer. However if we look at CAT, maybe there's a solution here.
The proposer could reference the transaction hashes and I think we might be able to reduce bandwidth quite a bit. Overall I'm still of the opinion that we are unlikely to be able to comprehensively fix the mempool, but....
I would like to be wrong about this because I do actually like having it and the other changes that are necessary will in my opinion require a great deal of work from infrastructure operators just to get into production.
Copying over what I just wrote in #1776, which really belongs here.
The block gossip is currently an integral part of the consensus reactor, but its really orthogonal to the core logic. In principle it could be separated out, even into its own reactor. This would clean up the consensus reactor and allow it to align even further with the core consensus specification, which would be nice.
However, there's a few complications to consider in the interface between the consensus reactor and such a new block gossip reactor.
First, as discussed, we need to ensure its still possible to sync up securely through the consensus reactor. This means the Proposal will need to contain some kind of commitment to the block gossip mechanism, whatever it might be (this was the motivation behind this issue in the first place!). Since removing the PartSetHeader from the Block already requires us to add it to the Proposal, we could go ahead and call it "BlockGossipHeader" for generality sake, and have the type be dependent on the actual block gossip mechanism used. I'm not sure it should literally be a generic type, it could just be []byte that are interpreted as necessary by the block gossip (this would mean a bit of extra encoding, but probably a pretty minor thing).
Second, we need to synchronize the round state and the peer states between the two reactors. Block gossiping logic depends heavily on our own consensus state (height, round, proposal) and on that of our peers. Since this information is communicated/stored in the consensus reactor, it would be ideal if it could be reused in the block gossip reactor (without having to be gossiped independenlty). But this will either require some way to share state, which could get messy, or to have regular communication between the two. Basically every time we update our own RoundState or a PeerState, we'd have to notify the BlockGossipReactor as well. This way it would know what to be downloading, and what to be sending to peers.
Third, we need to figure out how proposals will work. Currently the consensus calls CreateProposal from the state package, which calls into the mempool to fetch txs to assemble into a block and then calls PrepareProposal. This could stay in the consensus, but once the block is assembled, we'd need to send it to the BlockGossipReactor to start gossiping. Alternatively this could be done in the BlockGossipReactor, but then the block hash and BlockGossipHeader needs to be sent back to the consensus reactor so it can form the proposal. This would probably be the more natural separation of concerns. That way the consensus doesn't actually need to know anything about blocks, since it would just operate on the block hash and an opaque BlockGossipHeader. And the BlockGossipReactor can start putting together its proposals whenever it wants (eg. in advance of actually becoming the proposer). Taking this further we could even imagine the BlockGossipReactor subsuming the mempool completely.
Finally, we need a way for the BlockGossipReactor to communicate back to the consensus reactor that it received a complete block. This should be straight forward.
So there's quite a bit to work out, but it definetely seems doable and like it would be a huge unlock, simplifying the consensus package and allowing for much easier experimentation with new block gossip mechanisms.
Second, we need to synchronize the round state and the peer states between the two reactors. Block gossiping logic depends heavily on our own consensus state (height, round, proposal) and on that of our peers. Since this information is communicated/stored in the consensus reactor, it would be ideal if it could be reused in the block gossip reactor (without having to be gossiped independenlty).
Notice that we only need to know which block our peers are looking for. If the same block is proposed in multiple rounds, we don't need to propagate it multiple times (currently we need). I agree we need the height information.
A general comment here is that consensus still needs to inform this block gossip component which blocks it needs. For instance, when accepting a Proposal, the included PartSetHeader must be passed to the block gossip component.
The same applies to when we realize that a block, which is not the Proposal block, becomes valid. This situation is actually an argument against removing the PartSetHeader from vote messages.
Currently the consensus calls CreateProposal from the state package, which calls into the mempool to fetch txs to assemble into a block and then calls PrepareProposal. This could stay in the consensus, but once the block is assembled, we'd need to send it to the BlockGossipReactor to start gossiping.
This requires more thinking, but I would keep the building of a block part of consensus. Consensus needs, in any way, to know the full proposed block, not only its ID.
It is on the Proposal. It is part of the BlockID currently, although we have proposals to remove it from votes: tendermint/spec#78
Yes by "remove PartSetHeader from the Block" I mean remove it from the BlockID which means it would need to be separately added to the Proposal. I think ideally the PartSetHeader would only show up in the Proposal and no where else.
A general comment here is that consensus still needs to inform this block gossip component which blocks it needs. For instance, when accepting a Proposal, the included PartSetHeader must be passed to the block gossip component.
The same applies to when we realize that a block, which is not the Proposal block, becomes valid. This situation is actually an argument against removing the PartSetHeader from vote messages.
Yep I was proposing the Proposal generalize over commitments to part sets so that the consensus doesnt need to be aware of how blocks will be gossiped, just that there will be some opaque commitment to a gossip protocol in the proposal.
Good point re another block becoming valid though, just another thing to consider re communication from consensus reactor to blockgossip reactor
This requires more thinking, but I would keep the building of a block part of consensus. Consensus needs, in any way, to know the full proposed block, not only its ID.
Can you say more here? I would think consensus really only needs to know the block id, and nothing else. Obviously it needs to know the block is available, and it needs to be able to get the block to pass it to the state for execution once the block is committed, but it can otherwise stay oblivious to it.
And since the mempool is already concerned with gossiping most of the content of what will ultimately make up the block, it makes sense to potentially consolidate the mempool, block gossip, and block creation functions.
Can you say more here? I would think consensus really only needs to know the block id, and nothing else.
Ideally, yes. Although even in the pseudo-code we round this valid(v) method to check whether a proposed value is valid, from the application (which can be seen as the blockchain) point of view. It is true, and this is a design we consider in Malachite, that consensus only need the output of valid(v), not to "call" this method. Consensus would receive, in this case, the information of a valid block with a given ID was received. Far enough.
But in terms of the existing implementation, is consensus that commits a block, call the application, persists the block, etc., etc. So, for all effects, it currently needs the full block.
Another point here: consensus needs to ensure that both ValidBlock and LockedBlock are available as well. So, at some extent, consensus needs to say to this propagation module that it must keep some blocks, not GC them.
A first step towards this is to remove this logic from the consensus logic implementation (state.go), while still using the same consensus reactor. In particular because we still need the full block in consensus. But I would start this de-coupling from that.
Activity
cason commentedon Jan 25, 2024
Related to #14
cason commentedon Jan 25, 2024
We should discuss this topic, possibly synchronously.
I agree that block propagation should be a component by itself, maybe a new reactor, although this is not a requirement. This enables, in particular, some optimizations for consensus heights with multiple rounds (currently we drop the block from the previous round once a new round is started, even thought the same block can be re-proposed).
This component that handles block propagation should be informed, in some way, by consensus about the blocks it has to retrieve. One of the problems of a "blind" block propagation component is that it can be flooded with an arbitrary and possibly invalid number of blocks.
We also have the problem of persisting the blocks we accept (or propose). This is necessary, as otherwise, a node recovering from a crash will likely misbehave, since it does not "remember" actions taken before crashing.
faddat commentedon Jan 25, 2024
@cason
So I've got to agree with you, I guess that it fits at all possible it's probably good to source what a block is directly from the proposer. However if we look at CAT, maybe there's a solution here.
The proposer could reference the transaction hashes and I think we might be able to reduce bandwidth quite a bit. Overall I'm still of the opinion that we are unlikely to be able to comprehensively fix the mempool, but....
I would like to be wrong about this because I do actually like having it and the other changes that are necessary will in my opinion require a great deal of work from infrastructure operators just to get into production.
ebuchman commentedon Jan 28, 2024
Copying over what I just wrote in #1776, which really belongs here.
The block gossip is currently an integral part of the consensus reactor, but its really orthogonal to the core logic. In principle it could be separated out, even into its own reactor. This would clean up the consensus reactor and allow it to align even further with the core consensus specification, which would be nice.
However, there's a few complications to consider in the interface between the consensus reactor and such a new block gossip reactor.
First, as discussed, we need to ensure its still possible to sync up securely through the consensus reactor. This means the Proposal will need to contain some kind of commitment to the block gossip mechanism, whatever it might be (this was the motivation behind this issue in the first place!). Since removing the PartSetHeader from the Block already requires us to add it to the Proposal, we could go ahead and call it "BlockGossipHeader" for generality sake, and have the type be dependent on the actual block gossip mechanism used. I'm not sure it should literally be a generic type, it could just be []byte that are interpreted as necessary by the block gossip (this would mean a bit of extra encoding, but probably a pretty minor thing).
Second, we need to synchronize the round state and the peer states between the two reactors. Block gossiping logic depends heavily on our own consensus state (height, round, proposal) and on that of our peers. Since this information is communicated/stored in the consensus reactor, it would be ideal if it could be reused in the block gossip reactor (without having to be gossiped independenlty). But this will either require some way to share state, which could get messy, or to have regular communication between the two. Basically every time we update our own RoundState or a PeerState, we'd have to notify the BlockGossipReactor as well. This way it would know what to be downloading, and what to be sending to peers.
Third, we need to figure out how proposals will work. Currently the consensus calls CreateProposal from the state package, which calls into the mempool to fetch txs to assemble into a block and then calls PrepareProposal. This could stay in the consensus, but once the block is assembled, we'd need to send it to the BlockGossipReactor to start gossiping. Alternatively this could be done in the BlockGossipReactor, but then the block hash and BlockGossipHeader needs to be sent back to the consensus reactor so it can form the proposal. This would probably be the more natural separation of concerns. That way the consensus doesn't actually need to know anything about blocks, since it would just operate on the block hash and an opaque BlockGossipHeader. And the BlockGossipReactor can start putting together its proposals whenever it wants (eg. in advance of actually becoming the proposer). Taking this further we could even imagine the BlockGossipReactor subsuming the mempool completely.
Finally, we need a way for the BlockGossipReactor to communicate back to the consensus reactor that it received a complete block. This should be straight forward.
So there's quite a bit to work out, but it definetely seems doable and like it would be a huge unlock, simplifying the consensus package and allowing for much easier experimentation with new block gossip mechanisms.
ebuchman commentedon Jan 28, 2024
Oh, as for possible block gossip mechanisms, there's an old issue here tendermint/tendermint#7932 with some ideas
cason commentedon Jan 29, 2024
Notice that we only need to know which block our peers are looking for. If the same block is proposed in multiple rounds, we don't need to propagate it multiple times (currently we need). I agree we need the height information.
cason commentedon Jan 29, 2024
It is on the
Proposal. It is part of theBlockIDcurrently, although we have proposals to remove it from votes: tendermint/spec#78cason commentedon Jan 29, 2024
A general comment here is that consensus still needs to inform this block gossip component which blocks it needs. For instance, when accepting a
Proposal, the includedPartSetHeadermust be passed to the block gossip component.The same applies to when we realize that a block, which is not the
Proposalblock, becomes valid. This situation is actually an argument against removing thePartSetHeaderfrom vote messages.cason commentedon Jan 29, 2024
This requires more thinking, but I would keep the building of a block part of consensus. Consensus needs, in any way, to know the full proposed block, not only its ID.
faddat commentedon Jan 29, 2024
Is there consensus on moving as much of P2P as possible to libp2p?
ebuchman commentedon Jan 29, 2024
Yes by "remove PartSetHeader from the Block" I mean remove it from the BlockID which means it would need to be separately added to the Proposal. I think ideally the PartSetHeader would only show up in the Proposal and no where else.
Yep I was proposing the Proposal generalize over commitments to part sets so that the consensus doesnt need to be aware of how blocks will be gossiped, just that there will be some opaque commitment to a gossip protocol in the proposal.
Good point re another block becoming valid though, just another thing to consider re communication from consensus reactor to blockgossip reactor
Can you say more here? I would think consensus really only needs to know the block id, and nothing else. Obviously it needs to know the block is available, and it needs to be able to get the block to pass it to the state for execution once the block is committed, but it can otherwise stay oblivious to it.
And since the mempool is already concerned with gossiping most of the content of what will ultimately make up the block, it makes sense to potentially consolidate the mempool, block gossip, and block creation functions.
cason commentedon Feb 1, 2024
Ideally, yes. Although even in the pseudo-code we round this
valid(v)method to check whether a proposed value is valid, from the application (which can be seen as the blockchain) point of view. It is true, and this is a design we consider in Malachite, that consensus only need the output ofvalid(v), not to "call" this method. Consensus would receive, in this case, the information of a valid block with a given ID was received. Far enough.But in terms of the existing implementation, is consensus that commits a block, call the application, persists the block, etc., etc. So, for all effects, it currently needs the full block.
cason commentedon Feb 1, 2024
Another point here: consensus needs to ensure that both
ValidBlockandLockedBlockare available as well. So, at some extent, consensus needs to say to this propagation module that it must keep some blocks, not GC them.cason commentedon Jul 12, 2024
A first step towards this is to remove this logic from the consensus logic implementation (
state.go), while still using the same consensus reactor. In particular because we still need the full block in consensus. But I would start this de-coupling from that.