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

Test fixture for sepolia #1097

Merged
merged 12 commits into from
Jan 8, 2024
Merged

Test fixture for sepolia #1097

merged 12 commits into from
Jan 8, 2024

Conversation

yrong
Copy link
Contributor

@yrong yrong commented Jan 4, 2024

  • Test fixture from Sepolia testnet
  • Revamp conditional compile with all-features enabled and improve CI to cover the checks.

Comment on lines 126 to 130
// 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)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allow SyncCommiteeUpdate without blockRootsProof

Copy link
Contributor

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.

Copy link
Contributor Author

@yrong yrong Jan 8, 2024

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

// 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

Comment on lines 421 to 432
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
);
}
Copy link
Contributor Author

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)

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (17f7ad0) 58.37% compared to head (87ba289) 80.57%.
Report is 1 commits behind head on main.

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               
Flag Coverage Δ
rust 80.55% <100.00%> (+27.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yrong yrong marked this pull request as ready for review January 7, 2024 09:33
@yrong
Copy link
Contributor Author

yrong commented Jan 8, 2024

@claravanstaden
In this PR I've also revamped the condition compile a bit to enable all features which is what Parity does for polkadot-sdk in their CI, the main difference with paritytech/polkadot-sdk#2792 is that when running test with the two conflicting features fast-runtime and runtime-benchmarks enabled at the same time, the minimal spec will get applied and benchmark for beacon client will be ignored. IMO it will make the conditional compile code a bit cleaner.

Please let me know what you think and if anything important missing.

Copy link
Contributor

@claravanstaden claravanstaden left a 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.

Comment on lines 421 to 432
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
);
}
Copy link
Contributor

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.

parachain/pallets/ethereum-beacon-client/src/lib.rs Outdated Show resolved Hide resolved
parachain/pallets/ethereum-beacon-client/src/mock.rs Outdated Show resolved Hide resolved
// 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...")
Copy link
Contributor

Choose a reason for hiding this comment

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

🍵 🙃

log.Info("created next sync committee update file")
}

// Generate benchmark fixture for mainnet spec only
Copy link
Contributor

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? 🤔

Copy link
Contributor Author

@yrong yrong Jan 8, 2024

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.

63a1bcd

Comment on lines 126 to 130
// 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)
}
Copy link
Contributor

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.

Copy link
Contributor

@alistair-singh alistair-singh left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 120 to 127
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)
Copy link
Contributor

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?

Copy link
Contributor Author

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

parachain/pallets/ethereum-beacon-client/src/lib.rs Outdated Show resolved Hide resolved
Copy link
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.

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.

Copy link
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.

Ignore my previous, seems we no longer need to conditionally compile add_benchmarks.

Approved!

@yrong yrong merged commit 513fb46 into main Jan 8, 2024
7 checks passed
@yrong yrong deleted the ron/test-fixture-for-sepolia branch January 8, 2024 12:02
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.

4 participants