-
Notifications
You must be signed in to change notification settings - Fork 107
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
Test fixture for sepolia #1097
Test fixture for sepolia #1097
Conversation
// It's possible that beaconState is not available when GetSyncCommitteePeriodUpdate, in this case | ||
// there is no blockRootsProof and just ignore it in beacon client | ||
if err != nil && err != ErrBeaconStateAvailableYet { | ||
return scale.Update{}, fmt.Errorf("fetch block roots: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow SyncCommiteeUpdate without blockRootsProof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this change is a good one. Does it even make sense to send the finalized header update without an ancestry proof? That's the main reason we send beacon header updates in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an edge case that I run generateBeaconTestFixture
for the SyncCommitteePeriodUpdate
from sepolia and beaconState is not available at that moment. Code in
snowbridge/relayer/cmd/generate_beacon_data.go
Lines 189 to 193 in faacc1e
// generate SyncCommitteeUpdate for filling the missing NextSyncCommittee in initial checkpoint | |
syncCommitteeUpdateScale, err := s.GetSyncCommitteePeriodUpdate(initialSyncPeriod) | |
if err != nil { | |
return fmt.Errorf("get sync committee update: %w", err) | |
} |
But it's possible to switch to another time to generate the test fixture so it's not a strong reason to relax the check just for that. Also as you mentioned it could lead to some unexpected behavior so I reverted in ab9ee6f
if !update.block_roots_branch.is_empty() { | ||
ensure!( | ||
verify_merkle_branch( | ||
update.block_roots_root, | ||
&update.block_roots_branch, | ||
config::BLOCK_ROOTS_SUBTREE_INDEX, | ||
config::BLOCK_ROOTS_DEPTH, | ||
update.finalized_header.state_root | ||
), | ||
Error::<T>::InvalidBlockRootsRootMerkleProof | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the reason mentioned in #1097 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm but how can this merkle proof be conditional? Could it not lead to unexpected behaviour? As an example, this check allows finalized header verification without providing the block roots proof. What could happen is we keep processing these beacon headers without the necessary ancestry proofs (needed for the execution header imports). Then, our execution header imports could fail because there are no ancestry proofs to verify the execution header against a beacon header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1097 +/- ##
===========================================
+ Coverage 58.37% 80.57% +22.20%
===========================================
Files 55 55
Lines 2167 2209 +42
Branches 72 72
===========================================
+ Hits 1265 1780 +515
+ Misses 885 412 -473
Partials 17 17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@claravanstaden Please let me know what you think and if anything important missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @yrong! Thanks for these changes. I think resolving the all-features problem in paritytech/polkadot-sdk#2792 in the PR is better than the fixes I attempted. I'm not sure we will be able to convince Parity of the conditional add_benchmarks
in the Rococo runtime, we'll have to see.
I am not comfortable with allowing beacon header updates without ancestry proofs. But perhaps I am missing something in my understanding, please let me know.
if !update.block_roots_branch.is_empty() { | ||
ensure!( | ||
verify_merkle_branch( | ||
update.block_roots_root, | ||
&update.block_roots_branch, | ||
config::BLOCK_ROOTS_SUBTREE_INDEX, | ||
config::BLOCK_ROOTS_DEPTH, | ||
update.finalized_header.state_root | ||
), | ||
Error::<T>::InvalidBlockRootsRootMerkleProof | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm but how can this merkle proof be conditional? Could it not lead to unexpected behaviour? As an example, this check allows finalized header verification without providing the block roots proof. What could happen is we keep processing these beacon headers without the necessary ancestry proofs (needed for the execution header imports). Then, our execution header imports could fail because there are no ancestry proofs to verify the execution header against a beacon header.
// generate FinalizedUpdate for next epoch | ||
log.Info("waiting for a new finalized_update in next epoch and in current sync period,several seconds required...") | ||
log.Info("waiting finalized_update in next epoch(6.4 minutes later), be patient and drink a cup of tea...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍵 🙃
relayer/cmd/generate_beacon_data.go
Outdated
log.Info("created next sync committee update file") | ||
} | ||
|
||
// Generate benchmark fixture for mainnet spec only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would we regenerate the minimal spec test fixture data? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use snowbridge-relay generate-beacon-data --spec "minimal"
for that.
Btw: I think it's fine to also generate benchmark fixtures for minimal spec which we ignore before, then we can avoid the conditional add_benchmarks hack in the Rococo runtime.
// It's possible that beaconState is not available when GetSyncCommitteePeriodUpdate, in this case | ||
// there is no blockRootsProof and just ignore it in beacon client | ||
if err != nil && err != ErrBeaconStateAvailableYet { | ||
return scale.Update{}, fmt.Errorf("fetch block roots: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this change is a good one. Does it even make sense to send the finalized header update without an ancestry proof? That's the main reason we send beacon header updates in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
finalizedHeaderBlockRoot, err := finalizedHeader.ToSSZ().HashTreeRoot() | ||
if err != nil { | ||
return scale.Update{}, fmt.Errorf("fetch block roots: %w", err) | ||
return scale.Update{}, fmt.Errorf("beacon header hash tree root: %w", err) | ||
} | ||
|
||
finalizedHeaderBlockRoot, err := finalizedHeader.ToSSZ().HashTreeRoot() | ||
blockRootsProof, err := s.GetBlockRoots(uint64(finalizedHeader.Slot)) | ||
if err != nil { | ||
return scale.Update{}, fmt.Errorf("beacon header hash tree root: %w", err) | ||
return scale.Update{}, fmt.Errorf("fetch block roots: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this reordering necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary and reverted in 87ba289
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great Ron.
However the conditional add_benchmarks
in the Rococo runtime is problematic. I'm sure Parity will reject it.
As you suggest, lets also generate minimal fixtures for benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore my previous, seems we no longer need to conditionally compile add_benchmarks
.
Approved!
all-features
enabled and improve CI to cover the checks.