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

Engine switching with committee rotation #531

Merged
merged 18 commits into from
Nov 29, 2023

Conversation

jonastheis
Copy link
Contributor

@jonastheis jonastheis commented Nov 20, 2023

This PR addresses several problems around engine switching with committee rotation across epoch boundaries:

  1. AttestationManager: Use the committee of the slot of the attestation in contrast to the slot that we're committing. This is because at the time the attestation was created, the committee might have been different from the current one (due to rotation at epoch boundary).
  2. CommitmentVerifier: Update validatorAccountsData if fork happened across epoch boundaries. We try to use the latest accounts data (at lastCommonSlotBeforeFork) for the current epoch. This is necessary because the committee might have rotated at the epoch boundary and different validators might be part of it. In case anything goes wrong we keep using previously known accounts data (initially set to the accounts data of the validators for the epoch of the last common commitment before the fork). It could be, that we don't know about a validator when we verify the attestations: we then simply ignore this attestation (just like with public key changes) and weight of the chain will build up slower.
  3. Fixes some problems with race conditions with force accepting and confirmation/finalization that lead to wrong commitments for a node syncing up with warp sync as weight was not fully propagated when the slot was force committed.
  4. Implements test for scenario where a node is separated into a partition and due to no finalization reuses the committee while the majority partition goes on to select a new committee due to finalization. After the partition is merged the node of the minority partition successfully joins the majority partition.
  5. Some minor fixes here and there and improving readability of some code

Fixes #210, #266, #255

…asier understandable at which slot certain conditions apply
…d thus prevented weight/ratifier propagation
…didates that were decided before the target slot instead of after
…re committing in attestation manager. This is because at the time the attestation was created, the committee might have been different from the current one (due to rotation at epoch boundary).
… instead of always relying on accountsData of committee before forking point (important when fork persists over epoch boundary with rotating committee)
…ed throughout the slot where blocks are issued. If that is not the case, some blocks might already commit to a more recent commitment (which became committable because of issuing). This, however, makes the issuance non-deterministic and assertions of e.g. attestations impossible
@jonastheis jonastheis force-pushed the feat/engine-switching-committee-rotation-test branch from aab424b to b31645c Compare November 23, 2023 05:08
@jonastheis jonastheis marked this pull request as ready for review November 23, 2023 05:18
@jonastheis jonastheis requested a review from alexsporn November 23, 2023 05:20
Copy link
Contributor

@karimodm karimodm left a comment

Choose a reason for hiding this comment

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

I have to really remark the very high quality of this PR: clean code, well commented and well designed. VERY GOOD JOB!!!! 👍 👍 👍 👍

if exists {
validatorAccounts, err := committee.Accounts()
if err == nil {
validatorAccountsData, err := c.engine.Ledger.PastAccounts(validatorAccounts.IDs(), c.lastCommonSlotBeforeFork)
Copy link
Contributor

Choose a reason for hiding this comment

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

So if you have a committee for the new epoch you take those accounts with the data at the last common slot before the fork. If instead you don't have a committee for the new epoch you are going to keep using the previous (or initial) validatorAccountsData; you are therefore assuming that the committee should be re-used and it was not rotated.
If I reed the following code correctly, in either case you would need accurate account data at lastCommonSlotBeforeFork ONLY in terms of signing keys: to verify attestations' signatures.

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 exactly

// Determine the rewards root.
{
targetRewardsEpoch := currentEpoch
if slot == currentEpochEndSlot {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would we calculate the rewards for the next epoch? I don't get this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was asking myself the same question. I just refactored that code to be easier understandable what is happening at which time because before it was basically impossible to read

}

if err := p.rollbackCommitteesCandidates(targetEpoch, pruningRange[0]-1); err != nil {
if err := p.rollbackCommitteesCandidates(targetEpoch, startPruneRange); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You removed the original -1 from the startPruneRange. Was it intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed a bug in the condition as it was candidacySlot < targetSlot which lead to the wrong slots being deleted.

And yes, it was intended because I changed it to be inclusive candidacySlot >= deletionStartSlot. So we delete everything starting and including deletionStartSlot

pkg/testsuite/testsuite.go Show resolved Hide resolved
@jonastheis jonastheis enabled auto-merge November 29, 2023 12:20
@jonastheis jonastheis merged commit 6a455be into develop Nov 29, 2023
4 checks passed
@jonastheis jonastheis deleted the feat/engine-switching-committee-rotation-test branch November 29, 2023 12:31
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.

Test engine switching over epoch boundaries with rotating committee
2 participants