-
Notifications
You must be signed in to change notification settings - Fork 832
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
feat(sync): sender recovery stage #181
Conversation
crates/stages/src/stages/senders.rs
Outdated
let max_block = input.previous_stage.map(|(_, num)| num).unwrap_or_default(); | ||
let mut body_cursor = tx.cursor_mut::<tables::BlockBodies>()?; | ||
let mut body_walker = | ||
body_cursor.walk((start_block, start_hash).into())?.take_while(|res| { |
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.
We shoild add a helper method for walkers over range of blocks, maybe even just passing it StageInput
@gakonst Yes, either way is fine for MVP. We can start profiling once we're over that stage as the difference in implementation probably won't differ much, so switching to either one afterwards should be fine. |
OK sounds good - thank you! Let's unblock this and move forward with the current approach then @rkrasiuk |
I plan to add some stage db utils in a follow up PR |
Codecov Report
@@ Coverage Diff @@
## main #181 +/- ##
==========================================
+ Coverage 73.20% 73.54% +0.34%
==========================================
Files 224 225 +1
Lines 20144 20347 +203
==========================================
+ Hits 14746 14964 +218
+ Misses 5398 5383 -15
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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
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. Feel free to merge and add the helpers requested in a follow up PR.
|
||
let start_hash = tx.get::<tables::CanonicalHeaders>(start_block)?.unwrap(); | ||
let mut body_cursor = tx.cursor::<tables::BlockBodies>()?; | ||
let mut body_walker = body_cursor.walk((start_block, start_hash).into())?; |
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.
Let's add get body walker by 1. block hash and 2. Block number helpers
let (_, body) = entry?; | ||
for tx_id in body.base_tx_id..body.base_tx_id + body.tx_amount { | ||
let transaction = tx | ||
.get::<tables::Transactions>(tx_id)? |
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 is a hash right? Normally at least. Are txs are written by number in the test dbs?
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.
that's not a hash, that's encoded tx data TransactionSigned
let tx = db.get_mut(); | ||
|
||
// Look up the hash of the unwind block | ||
if let Some(unwind_hash) = tx.get::<tables::CanonicalHeaders>(input.unwind_to)? { |
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.
Should we log if it's none?
hash: unwind_hash, | ||
})?; | ||
|
||
unwind_table_by_num::<DB, tables::TxSenders>(tx, latest_tx - 1)?; |
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.
We sure this isn't off by one?
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.
consider block 1 with 2 transactions and block 2 with 3 transactions. the transactions would be enumerated 0..4 (inclusive). if we need to unwind to block 1, we'd just need to look up the tx count at unwind block (2 in this case) and turn it into the tx_id of the last transaction
let mut tx_cursor = tx.cursor::<tables::Transactions>()?; | ||
// Walk the transactions from start to end index (exclusive) | ||
let entries = tx_cursor | ||
.walk(start_tx_index)? |
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.
We should have helpers for these "range walkers" cursor.walk_range(range: Range)
linter error unrelated |
Implement sender recovery stage.
closes #180
blocked by #190 and #204