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

[Epoch Sync] Add a Nayduck test for Epoch Sync. #12237

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

robin-near
Copy link
Contributor

Most of the complexity here is changes to the StoreValidator:

  • Do not check that previous block exists, if it's older than the epoch sync boundary.
  • Do not check that if BlockInfo exists the header also exists, because this is also not true for some blocks before the epoch sync boundary.
  • (This one was pre-existing before epoch sync) Be lenient when checking chunk body's existence, because we don't seem to download these for the extra blocks needed by state sync. I couldn't figure out a good way to check this rigorously, so I included a heuristic to skip checking if the block in question is <= tail height. I don't think it's correct, but it works for now.
    • The reason why this does not trigger state sync nayduck test failures is because the utils.poll_blocks function doesn't trigger store validations, but utils.wait_for_blocks does 🙄

@robin-near robin-near requested a review from a team as a code owner October 16, 2024 18:39
@robin-near robin-near linked an issue Oct 16, 2024 that may be closed by this pull request
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 32.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 71.62%. Comparing base (3cb74c2) to head (dfaf49c).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
chain/chain/src/store_validator/validate.rs 25.00% 12 Missing ⚠️
chain/chain/src/store_validator.rs 57.14% 1 Missing and 2 partials ⚠️
chain/client/src/sync/epoch.rs 0.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12237      +/-   ##
==========================================
- Coverage   71.72%   71.62%   -0.11%     
==========================================
  Files         833      837       +4     
  Lines      166700   167141     +441     
  Branches   166700   167141     +441     
==========================================
+ Hits       119573   119718     +145     
- Misses      41902    42198     +296     
  Partials     5225     5225              
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.25% <0.00%> (-0.01%) ⬇️
integration-tests 38.86% <0.00%> (+0.13%) ⬆️
linux 71.23% <32.00%> (-0.18%) ⬇️
linux-nightly 71.20% <32.00%> (-0.12%) ⬇️
macos 54.32% <32.00%> (+<0.01%) ⬆️
pytests 1.57% <0.00%> (-0.01%) ⬇️
sanity-checks 1.37% <0.00%> (-0.01%) ⬇️
unittests 65.42% <32.00%> (-0.13%) ⬇️
upgradability 0.21% <0.00%> (-0.01%) ⬇️

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.

Copy link
Contributor

@wacban wacban 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 97 to 98
let epoch_sync_boundary = if let Ok(Some(epoch_sync_proof)) =
store.get_ser::<EpochSyncProof>(DBCol::EpochSyncProof, &[])
Copy link
Contributor

Choose a reason for hiding this comment

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

sanity check: Is it ok to ignore errors here?

mini nit: not sure if any better but you can consider .ok().flatten().map() and splitting into multiple lines to improve readability.

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 should .expect instead, indeed.

@@ -436,6 +436,8 @@ impl EpochSync {
.choose(&mut rand::thread_rng())
.ok_or_else(|| Error::Other("No peers to request epoch sync from".to_string()))?;

tracing::info!(peer_id=?peer.peer_info.id, "Bootstrapping node via epoch sync");
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

Comment on lines 55 to 57
for height, block_hash in utils.poll_blocks(node0,
timeout=SYNC_FROM_BLOCK * 2,
poll_interval=0.1):
Copy link
Contributor

Choose a reason for hiding this comment

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

mini nit: If you add a trailing comma after the last arg the formatting will be a bit nicer - imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh, it leaves a dangling ): on its own line. I feel the existing way is better.

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine but you can consider using unitttest like so:
https://github.com/near/nearcore/blob/master/pytest/README.md#creating-new-tests

poll_interval=0.1):
if height >= SYNC_FROM_BLOCK:
break
ctx.send_moar_txs(block_hash, 1, False)
Copy link
Contributor

Choose a reason for hiding this comment

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

makes me chuckle every time

{x: node_config for x in range(3)})

node0 = spin_up_node(config, near_root, node_dirs[0], 0)
node1 = spin_up_node(config, near_root, node_dirs[1], 1, boot_node=node0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought node1 wouldn't be started until after the delay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh, so I had to use two nodes because the TxContext class needs that and I have no idea why 🤷‍♂️

break
ctx.send_moar_txs(block_hash, 1, False)

node1 = spin_up_node(config, near_root, node_dirs[2], 2, boot_node=node0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I think it's the third node that does the state sync? Can you rename to node2 and update the comment at the beginning of the file please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, thanks for catching that.

utils.wait_for_blocks(node1, target=CATCHUP_BLOCK, timeout=(CATCHUP_BLOCK - SYNC_FROM_BLOCK) * 2)

# Verify that we did bootstrap using epoch sync (rather than header sync).
tracker.check('Bootstrapped from epoch sync')
Copy link
Contributor

Choose a reason for hiding this comment

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

nifty

@wacban
Copy link
Contributor

wacban commented Oct 17, 2024

You should also add your new test to nayduck by adding it to one of the config files (sanity.txt or similar).

@robin-near
Copy link
Contributor Author

You should also add your new test to nayduck by adding it to one of the config files (sanity.txt or similar).

Oh right, of course!

@robin-near robin-near added this pull request to the merge queue Oct 17, 2024
Merged via the queue into near:master with commit ba6c707 Oct 17, 2024
27 of 30 checks passed
@robin-near robin-near deleted the esync10 branch October 17, 2024 18:20
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.

[Epoch Sync] Add end to end test for epoch sync
2 participants