Skip to content

Follow consensus-specs sync protocol more closely#840

Merged
yrong merged 10 commits intovincent/improve-ancestry-proofsfrom
ron/improve-ancestry-proofs
May 23, 2023
Merged

Follow consensus-specs sync protocol more closely#840
yrong merged 10 commits intovincent/improve-ancestry-proofsfrom
ron/improve-ancestry-proofs

Conversation

@yrong
Copy link
Copy Markdown
Contributor

@yrong yrong commented May 22, 2023

For SNO-446

strict follows ALC spec only apply_light_client_update after successfully validate_light_client_update

@yrong yrong force-pushed the ron/improve-ancestry-proofs branch from 61fc13b to a948332 Compare May 22, 2023 13:59
@yrong
Copy link
Copy Markdown
Contributor Author

yrong commented May 22, 2023

More checks added per spec required as following:

ensure!(
update.signature_slot > update.attested_header.slot &&
update.attested_header.slot >= update.finalized_header.slot,
Error::<T>::InvalidUpdateSlot
);

if update_attested_period == store_period && <NextSyncCommittee<T>>::exists() {
let next_committee_root = <NextSyncCommittee<T>>::get().sync_committee_root;
ensure!(
sync_committee_root == next_committee_root,
Error::<T>::InvalidSyncCommitteeUpdate
);
}

if !<NextSyncCommittee<T>>::exists() {
ensure!(
update_finalized_period == store_period,
<Error<T>>::InvalidSyncCommitteeUpdate
);
<NextSyncCommittee<T>>::set(sync_committee_prepared);

@yrong yrong requested a review from vgeddes May 22, 2023 14:18
Copy link
Copy Markdown
Collaborator

@vgeddes vgeddes left a comment

Choose a reason for hiding this comment

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

Thanks Ron, this is also a good improvement.

Just wanted to say, we don't have to strictly follow the design in ALC consensus-specs. We can also improve on it, and change the algorithm if it makes sense.

@vgeddes vgeddes changed the title Strict follows ALC specification Follow consensus-specs sync protocol more closely May 22, 2023
@yrong
Copy link
Copy Markdown
Contributor Author

yrong commented May 23, 2023

Just wanted to say, we don't have to strictly follow the design in ALC consensus-specs. We can also improve on it, and change the algorithm if it makes sense.

IMHO we first follow spec closely which make it easy to find missing checks as above, also make audit/review a bit easier. Then we do optimization based on that and yes we can definitely change as required.

(update.next_sync_committee_update.is_some() &&
update_attested_period == store_period);
ensure!(
update.attested_header.slot > store_period || update_has_next_sync_committee,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

bug fix here. should be update.attested_header.slot > latest_finalized_state.slot

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.

Nice catch!

.try_into()
.map_err(|_| <Error<T>>::BLSPreparePublicKeysFailed)?;
<CurrentSyncCommittee<T>>::set(sync_committee_prepared);
<NextSyncCommittee<T>>::kill();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kill NextSyncCommittee here.

return fmt.Errorf("get initial sync: %w", err)
}
initialSync := initialSyncScale.ToJSON()
err = writeJSONToFile(initialSync, fmt.Sprintf("initial-checkpoint.%s.json", activeSpec.ToString()))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As mentioned before, we can not use initialSync generated in same command together with other updates.

Copy link
Copy Markdown
Collaborator

@vgeddes vgeddes May 23, 2023

Choose a reason for hiding this comment

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

How can we improve the command so that it generates all the updates, without having to run it twice? Surely this possible to implement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 7fda5f4

@vgeddes
Copy link
Copy Markdown
Collaborator

vgeddes commented May 23, 2023

See this comment here #839 (comment). I don't want to prune FinalizedBeaconState right now, because it depends on FinalizedCheckpoints/FinalizedHeaderSlotsCache. I want to remove that storage item.

@yrong yrong force-pushed the ron/improve-ancestry-proofs branch from 4606b52 to 495d724 Compare May 23, 2023 06:57
log.Info("downloading beacon state, this can take a few minutes...")
syncCommitteePeriod := s.ComputeSyncPeriodAtSlot(initialSyncHeaderSlot)
// wait for 5 blocks
time.Sleep(6 * time.Second * 5)
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.

Is the block time 6s in our E2E stack? Curious if we configured this explicitly somewhere

You should probably make it wait some more time in case the 5th block hasn't been produced yet.

Copy link
Copy Markdown
Contributor Author

@yrong yrong May 23, 2023

Choose a reason for hiding this comment

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

Yes, it's 6s for minimal spec and we did not hack it for this test. Waiting for 5 blocks is just a decent value to make sure FinalizedUpdate change and SyncPeriod does not change in that period. This is requied by recently added check in our light client here.
There is chance at some time we run command but fail to get data meet requirements, in that case we just fail with error as following and rerun it at another time.

if initialSyncPeriod != finalizedUpdatePeriod {
return fmt.Errorf("initialSyncPeriod %d should be consistent with finalizedUpdatePeriod %d", initialSyncPeriod, finalizedUpdatePeriod)
}
if finalizedUpdate.AttestedHeader.Slot <= initialSyncHeaderSlot {
return fmt.Errorf("AttestedHeader slot %d should be greater than initialSyncHeaderSlot %d", finalizedUpdate.AttestedHeader.Slot, initialSyncHeaderSlot)
}


log.Info("downloading beacon state, this can take a few minutes...")
syncCommitteePeriod := s.ComputeSyncPeriodAtSlot(initialSyncHeaderSlot)
// wait for 5 blocks
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.

Is 5 special number here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

@vgeddes vgeddes left a comment

Choose a reason for hiding this comment

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

+1

@yrong yrong merged commit 2156d17 into vincent/improve-ancestry-proofs May 23, 2023
@yrong yrong deleted the ron/improve-ancestry-proofs branch May 23, 2023 14:26
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.

2 participants