-
Notifications
You must be signed in to change notification settings - Fork 144
test(l1): add FCU test for StateNotReachable case #5628
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
base: main
Are you sure you want to change the base?
test(l1): add FCU test for StateNotReachable case #5628
Conversation
Add a unit test that verifies apply_fork_choice returns StateNotReachable when attempting to fork choice to a block whose state root is not available in the trie. Closes lambdaclass#5603
crates/blockchain/smoke_test.rs
Outdated
| let result = apply_fork_choice(&store, block_hash, genesis_hash, genesis_hash).await; | ||
|
|
||
| assert!( | ||
| matches!(result, Err(InvalidForkChoice::StateNotReachable)), | ||
| "Expected StateNotReachable, got {:?}", | ||
| result | ||
| ); |
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.
This case isn't that useful. On normal operation, if we have the state for a block, and we receive a child, we'll only insert the header into the database if we executed the block (we have the state), so this can't happen.
The issue refers to cases where we have a reorg, and the nearest chain link is beyond our pruning range (128 blocks, currently).
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.
understood, rewrote the test to cover the actual reorg scenario you described. builds 130 blocks on canonical, forks early, then simulates the pruning by clearing the trie cache before attempting the reorg.
Had to add a test helper (clear_trie_cache_for_testing) to Store since the InMemory backend threshold is 10k and won't prune naturally in tests.
The previous test created an artificial scenario (fake state_root) that can't occur in production. The new test simulates the actual case: - Build canonical chain beyond 128-block pruning threshold - Create fork early in chain - Common ancestor's state gets pruned - Reorg to fork fails with StateNotReachable Added clear_trie_cache_for_testing() helper to Store.
Peponks9
left a 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.
hey @madisoncarter1234 looks like the lint check failing causes the other two tests to fail.
Peponks9
left a 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.
is this being blocked by another task?
just waiting on approvals, ready for review |
Summary
StateNotReachableerror inapply_fork_choicecovering the real-world pruning scenarioStateNotReachableclear_trie_cache_for_testing()helper to Store for simulating pruning in tests (InMemory backend uses 10k threshold)Test plan
cargo test -p ethrex-blockchain test_state_not_reachable_on_reorg_beyond_pruning_rangeCloses #5603