-
Notifications
You must be signed in to change notification settings - Fork 65
apollo_l1_provider: add test for low latest L1 block number #10345
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
apollo_l1_provider: add test for low latest L1 block number #10345
Conversation
86cea3b to
fe01db9
Compare
976c083 to
7b71af3
Compare
7b71af3 to
e3bf1a2
Compare
fe01db9 to
0561669
Compare
0561669 to
540158c
Compare
e3bf1a2 to
3593658
Compare
3593658 to
f408e04
Compare
540158c to
76a7ed4
Compare
f408e04 to
7c809c5
Compare
76a7ed4 to
21157d9
Compare
ShahakShama
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.
@ShahakShama reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @guy-starkware)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 159 at r1 (raw file):
#[tokio::test] async fn base_layer_returns_block_number_below_finality() {
Add the expect result to the end of the test (_causes_error)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 163 at r1 (raw file):
const FINALITY: u64 = 10; const INITIAL_L1_BLOCK_NUMBER: u64 = 100; const INITIAL_L1_BLOCK_HASH: L1BlockHash = L1BlockHash([123; 32]);
This is in-fact the hash of all l1 blocks in this test. Either fix it so that you'll have different hash for INITIAL_L1_BLOCK_NUMBER and WRONG_L1_BLOCK_NUMBER or rename this to reflect that it's for all blocks
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 188 at r1 (raw file):
// Test. assert_eq!(scraper.send_events_to_l1_provider().await, Ok(()));
use unwrap instead
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
assert_matches!( scraper.send_events_to_l1_provider().await, Err(L1ScraperError::FinalityTooHigh { .. })
Why is that the expected outcome? IIUC this means that if I got block x then got block x-95 then you return finality too high to the provider, but shouldn't you return a reorg error?
guy-starkware
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.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ShahakShama)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 159 at r1 (raw file):
Previously, ShahakShama wrote…
Add the expect result to the end of the test (_causes_error)
I'm not sure what you want me to add where?
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 163 at r1 (raw file):
Previously, ShahakShama wrote…
This is in-fact the hash of all l1 blocks in this test. Either fix it so that you'll have different hash for INITIAL_L1_BLOCK_NUMBER and WRONG_L1_BLOCK_NUMBER or rename this to reflect that it's for all blocks
Done.
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
Previously, ShahakShama wrote…
Why is that the expected outcome? IIUC this means that if I got block x then got block x-95 then you return finality too high to the provider, but shouldn't you return a reorg error?
If x is 100 you should get FinalityTooHigh. If the new height is lower than the old height but still above 10, you should get a reorg.
Here are the list of checks we do each scrape, in order:
- Reorg detection. Assume the same block number, try to get that block again. If the block is missing, or if the hash changed, trigger a reorg. This doesn't check finality. So if the endpoint's latest L1 block number goes down a few blocks, it may still have the block in question, so it may not trigger the reorg error.
- Check if the latest L1 block number from the endpoint is above finality. This guards against what I assume is a but in Infura where sometimes it reports the latest number is zero (I never checked, it could also be reporting 3 or 8, but it doesn't matter). The get block at number function could still work normally, so it doesn't necessarily trigger reorg. In such cases we cannot continue because the latest number - 10 is not valid. This is FinalityTooHigh error.
- If we don't trigger these two errors, and still the endpoint reports a latest number (after subtracting finality) that is lower than the number we already scraped (or equal) we just issue a warning and wait until the next scrape (this happens when switching endpoints and the new one -- usually Infura -- is less updated than the old one).
guy-starkware
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.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ShahakShama)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 188 at r1 (raw file):
Previously, ShahakShama wrote…
use unwrap instead
Done.
21157d9 to
d4fa6a1
Compare
7c809c5 to
67ca8a6
Compare
guy-starkware
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.
Reviewable status: 0 of 1 files reviewed, 4 unresolved discussions (waiting on @ShahakShama)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
Previously, guy-starkware wrote…
If x is 100 you should get FinalityTooHigh. If the new height is lower than the old height but still above 10, you should get a reorg.
Here are the list of checks we do each scrape, in order:
- Reorg detection. Assume the same block number, try to get that block again. If the block is missing, or if the hash changed, trigger a reorg. This doesn't check finality. So if the endpoint's latest L1 block number goes down a few blocks, it may still have the block in question, so it may not trigger the reorg error.
- Check if the latest L1 block number from the endpoint is above finality. This guards against what I assume is a but in Infura where sometimes it reports the latest number is zero (I never checked, it could also be reporting 3 or 8, but it doesn't matter). The get block at number function could still work normally, so it doesn't necessarily trigger reorg. In such cases we cannot continue because the latest number - 10 is not valid. This is FinalityTooHigh error.
- If we don't trigger these two errors, and still the endpoint reports a latest number (after subtracting finality) that is lower than the number we already scraped (or equal) we just issue a warning and wait until the next scrape (this happens when switching endpoints and the new one -- usually Infura -- is less updated than the old one).
Correction: if new height is lower but still above 10 you may get a reorg (if the block you last scraped no longer exists) but you may also just get a warning if the block exists but the (finality-adjusted) latest number is not higher than the last one you scraped.
guy-starkware
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.
Reviewable status: 0 of 1 files reviewed, 4 unresolved discussions (waiting on @ShahakShama)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
Previously, guy-starkware wrote…
If x is 100 you should get FinalityTooHigh. If the new height is lower than the old height but still above 10, you should get a reorg.
Here are the list of checks we do each scrape, in order:
- Reorg detection. Assume the same block number, try to get that block again. If the block is missing, or if the hash changed, trigger a reorg. This doesn't check finality. So if the endpoint's latest L1 block number goes down a few blocks, it may still have the block in question, so it may not trigger the reorg error.
- Check if the latest L1 block number from the endpoint is above finality. This guards against what I assume is a but in Infura where sometimes it reports the latest number is zero (I never checked, it could also be reporting 3 or 8, but it doesn't matter). The get block at number function could still work normally, so it doesn't necessarily trigger reorg. In such cases we cannot continue because the latest number - 10 is not valid. This is FinalityTooHigh error.
- If we don't trigger these two errors, and still the endpoint reports a latest number (after subtracting finality) that is lower than the number we already scraped (or equal) we just issue a warning and wait until the next scrape (this happens when switching endpoints and the new one -- usually Infura -- is less updated than the old one).
Correction: if new height is lower but still above 10 you may get a reorg (if the block you last scraped no longer exists) but you may also just get a warning if the block exists but the (finality-adjusted) latest number is not higher than the last one you scraped.
ShahakShama
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.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @guy-starkware)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 159 at r1 (raw file):
Previously, guy-starkware wrote…
I'm not sure what you want me to add where?
Sorry, I should've been more clear
Rename the test to base_layer_returns_block_number_below_finality_causes_error
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
Previously, guy-starkware wrote…
Correction: if new height is lower but still above 10 you may get a reorg (if the block you last scraped no longer exists) but you may also just get a warning if the block exists but the (finality-adjusted) latest number is not higher than the last one you scraped.
Let's discuss. 2 sounds like it has nothing to do with finality and we arbitrarily decided to use the finality as the threshold to determine if this is an error
guy-starkware
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.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @ShahakShama)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
Previously, ShahakShama wrote…
Let's discuss. 2 sounds like it has nothing to do with finality and we arbitrarily decided to use the finality as the threshold to determine if this is an error
If you prefer that we rename this error LatestBlockNumberTooLow instead, that's fine by me.
ShahakShama
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.
@ShahakShama reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @guy-starkware)
crates/apollo_l1_provider/src/l1_scraper_tests.rs line 196 at r1 (raw file):
Previously, guy-starkware wrote…
If you prefer that we rename this error LatestBlockNumberTooLow instead, that's fine by me.
Yes, in future PR
67ca8a6 to
92e1316
Compare
ShahakShama
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.
@ShahakShama reviewed 1 of 1 files at r3, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @guy-starkware)

No description provided.