Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lr/variable stake table #3893

Merged
merged 51 commits into from
Dec 12, 2024
Merged

Lr/variable stake table #3893

merged 51 commits into from
Dec 12, 2024

Conversation

lukaszrzasik
Copy link
Contributor

@lukaszrzasik lukaszrzasik commented Nov 15, 2024

Closes #<ISSUE_NUMBER>

This PR:

  • Adds a new NodeType called TestTwoStakeTablesTypes which uses a new Membership
  • Adds the new Membership called TwoStaticCommittees. The membership is used to test the basic scenarios where we have two different stake tables. It works in the following way: takes the nodes created in the test suite and splits the in half based on the even/odd node id. The even id nodes are added to the stake table used for even epochs and the odd id nodes are added to the stake table used for odd epochs.
  • Adds epoch fields to the data types (e.g. QuorumData2, DaData, etc.) and to the proposals (e.g. QuorumProposal2, DaProposal) and also to the Leaf and ViewInner. The epoch fields are used to validate the messages against the proper stake table.
  • Add a concept of "being in the epoch transition" which occurs when a node's high QC is for the last block in an epoch. This is used to optimistically:
    • accept votes even if we are not the leader because we expect the broadcast final votes for eQC
    • start gathering the dependencies to make a proposal assuming we successfully transition into the new epoch in which we are the leader. If the transition does not happen, the proposal will be dropped.
  • Uses the new data and proposal types that include the epoch field on the wire. That means it breaks backward compatibility and we need to gate it somehow.
  • Changes the commit calculation of the types that now include the epoch field to include the epoch field in the commit. It breaks the commit compatibility between the old and new types. It might not be what we want at the moment but the epoch field needs to be signed eventually so that it cannot be spoofed.

This PR does not:

  • Does not yet add the double quorums

Key places to review:

@lukaszrzasik lukaszrzasik marked this pull request as ready for review November 21, 2024 22:13
Copy link
Contributor

@ss-es ss-es left a comment

Choose a reason for hiding this comment

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

I think this looks good to me overall, I don't know if anyone else wants to take a look

crates/task-impls/src/consensus/mod.rs Show resolved Hide resolved
crates/task-impls/src/quorum_proposal/handlers.rs Outdated Show resolved Hide resolved
Comment on lines 156 to 169
let proposal_block_number = proposal.data.block_header.block_number();
let proposal_epoch = TYPES::Epoch::new(epoch_from_block_number(
proposal_block_number,
validation_info.epoch_height,
));
let justify_qc_epoch = if validation_info.epoch_height != 0
&& proposal_block_number % validation_info.epoch_height == 1
{
// if the proposal is for the first block in an epoch, the justify QC must be from the previous epoch
proposal_epoch - 1
} else {
// otherwise justify QC is from the same epoch
proposal_epoch
};
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth making this a helper function? i.e. take a proposal and the previous block header and return the proposal's epoch number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I can make it into a helper function but I didn't fully understand what you mean. This piece of code calculates the proposed block's epoch and the justify QC block's epoch. Do you want the function to return both?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I meant:

  • the proposed block's epoch is already epoch_from_block_number(proposal.data.block_header.block_number()) (straightforward)
  • the preceding block's epoch is the check based on the block height modulo the epoch height, but we could make a function like preceding_block_epoch(proposal, epoch_height)

(maybe these could even be generic in a HasBlockNumber trait or something)

it's not that important though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! yeah, these are good ideas. Can we agree to make it a separate PR? I don't think this exact code is repeated anywhere else so it's not that it's non-DRY at the moment. I've already created a trait called HasEpoch so we may extend this one if it makes sense. I also think it'll be nice to clean the whole epoch-related code up after everything is more or less finished. I would of course take care of that.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I agree -- I think it's fine to merge as-is!

@ss-es ss-es mentioned this pull request Dec 5, 2024
Copy link
Contributor Author

@lukaszrzasik lukaszrzasik left a comment

Choose a reason for hiding this comment

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

Just a few comments. We might want to discuss outside GH.

crates/task-impls/src/da.rs Show resolved Hide resolved
crates/task-impls/src/network.rs Outdated Show resolved Hide resolved
crates/task-impls/src/quorum_proposal_recv/handlers.rs Outdated Show resolved Hide resolved
crates/task-impls/src/transactions.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@lukaszrzasik lukaszrzasik left a comment

Choose a reason for hiding this comment

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

Just two optional changes. I cannot approve the PR because I'm the author.

crates/task-impls/src/da.rs Show resolved Hide resolved
crates/types/src/data.rs Outdated Show resolved Hide resolved
crates/types/src/simple_vote.rs Show resolved Hide resolved
@ss-es ss-es merged commit 43263a5 into main Dec 12, 2024
17 checks passed
@ss-es ss-es deleted the lr/variable-stake-table branch December 12, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants