Skip to content

feat(consensus): proposer locks part set until all parts are added - #4009

Merged
cason merged 19 commits into
mainfrom
cason/1742-proposed-block-parts
Sep 10, 2024
Merged

cason merged 19 commits into
mainfrom
cason/1742-proposed-block-parts

Conversation

@cason

@cason cason commented Sep 5, 2024

Copy link
Copy Markdown

Addresses #1742.

When a validator is the round proposer, it produces a Proposal and a number of block Parts that it then delivers to itself (code). When a Proposal is accepted, the validator initializes a types.PartSet instance from the proposed BlockID (code). Then, when each of the block Parts are delivered, they are added to this part set. Once a Part is added to the cs.ProposalBlockParts part set, it becomes available to the consensus reactor, that sends them to peers.

The issue reported in #1742 is that we add the block parts in order to cs.ProposalBlockParts, and one by one, even when the we are the proposer. When we are the proposer we know all the block parts and could produce cs.ProposalBlockParts immediately, instead of processing all Parts, one by one, as they were received from the network. This would have as a consequence that the consensus reactor will only start sending block Parts to peers once all of them are available. Since we randomly choose the next part to send to a peer, we are less likely to send to all peers the same part. That is what currently happens, as reported in #1742.

The solution proposed here is relatively simple and non-intrusive. To the types.PartSet type we add a boolean locked value. Once the proposer receives its own Proposal, it creates and locks its cs.ProposalBlockParts, which is unlocked when all the expected parts are received and processed.

The consensus reactor, in turn, only send blocks Parts to peers when cs.ProposalBlockParts is unlocked. When the node is not the proposed of the round, it is always unlocked. When the node is the current round proposer, it is unlocked once all the parts it should contain are added, likely fixing the issue reported in #1742.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@cason
cason requested a review from a team as a code owner September 5, 2024 12:08
@cason
cason requested a review from a team September 5, 2024 12:08
@cason cason self-assigned this Sep 5, 2024
@cason
cason requested a review from ebuchman September 5, 2024 12:08
@cason cason added consensus enhancement New feature or request labels Sep 5, 2024
@cason cason changed the title consensus: proposer locks part set until all parts are added feat(consensus): proposer locks part set until all parts are added Sep 5, 2024
@cason

cason commented Sep 5, 2024

Copy link
Copy Markdown
Author

Some my internal comments:

  1. Why we need to protect the added field with a lock? I am not sure, some methods use a lock, others don't. For safety, I adopted locks.
  2. Since it is a single boolean, why not use an atomic boolean? It should probably work as well, but probably requires some initialization.

@melekes melekes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread internal/consensus/state.go Resolved
Comment thread internal/consensus/state.go Resolved
Comment thread types/part_set.go Resolved
Comment thread types/part_set_test.go Resolved

@sergio-mena sergio-mena left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this

Comment thread internal/consensus/state.go Outdated

// If we are the proposer, lock the PartSet until we load all
// the block parts, that should come just after this Proposal.
if bytes.Equal(proposerPubKey.Bytes(), cs.privValidatorPubKey.Bytes()) {

@sergio-mena sergio-mena Sep 6, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if bytes.Equal(proposerPubKey.Bytes(), cs.privValidatorPubKey.Bytes()) {
if cs.isProposer(cs.privValidatorPubKey.Address()) {

More readable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have accepted it then reverted it.

We have to test if the Proposal has been signed by us.

@cason
cason enabled auto-merge September 9, 2024 15:05
@cason
cason added this pull request to the merge queue Sep 10, 2024
Merged via the queue into main with commit 18454e6 Sep 10, 2024
@cason
cason deleted the cason/1742-proposed-block-parts branch September 10, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consensus enhancement New feature or request

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants