-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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(engine): proof fetching on state update for StateRootTask #12458
base: main
Are you sure you want to change the base?
Conversation
d0f48d5
to
fdb55e9
Compare
14ca9a0
to
da06971
Compare
c38de83
to
a8e0cf2
Compare
fdb55e9
to
5d2048f
Compare
a8e0cf2
to
6e0e20e
Compare
6e0e20e
to
3b04efb
Compare
@@ -237,6 +241,7 @@ impl From<ParallelStateRootError> for ProviderError { | |||
ParallelStateRootError::StorageRoot(StorageRootError::Database(error)) => { | |||
Self::Database(error) | |||
} | |||
ParallelStateRootError::Other(other) => Self::Database(DatabaseError::Other(other)), |
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 should not be casted to database error. out of scope for this PR, but we have to fix this at some point ^^
52e1366
to
2ffe7c8
Compare
|
||
pending_proofs.push_back(rx); | ||
|
||
state.extend(hashed_state_update); |
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 extends the state immediately and that's what is used to perform state root updates, but this might result in invalid cached trie nodes. not sure yet, but worth double checking @fgimenez
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.
left a few questions
crates/engine/tree/src/tree/root.rs
Outdated
// try to receive state updates without blocking | ||
match self.state_stream.rx.try_recv() { |
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 now a busy loop, right?
ideally we can use just recv here because then this can yield
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.
yep, if we recv
here we would be blocking until all the state updates are received, ie. until the block is executed, and the benefits of the task would be diminished? the proof calculation for each state root change would be triggered, but we would not trigger the state root calculation from proofs.
crates/engine/tree/src/tree/root.rs
Outdated
rayon::spawn(move || { | ||
let result = calculate_state_root_from_proofs( | ||
view, | ||
&input_nodes_sorted, | ||
&input_state_sorted, | ||
multiproof, | ||
state, | ||
); | ||
let _ = tx.send(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 spawns a new rayon job that then also branches out via par_iter
all of this looks very IO heavy
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.
yep, that's the case
crates/engine/tree/src/tree/root.rs
Outdated
} | ||
|
||
fn run(mut self) -> StateRootResult { | ||
let mut task_state = StateRootTaskState::Idle(MultiProof::default(), B256::default()); |
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.
not super easy to follow how state management is done here
looks like we're sending a few things around and need to await things from different event variants from different sources, hence the try_recv to not block indefinitely on one kind of receiver?
I assume we can make this work with only one channel if we unify the message variants into one single enum?
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.
looks like we're sending a few things around and need to await things from different event variants from different sources, hence the try_recv to not block indefinitely on one kind of receiver?
yes, exactly
I assume we can make this work with only one channel if we unify the message variants into one single enum?
yep sounds good, will prepare changes for this
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.
ok done, the main changes are:
- we have now a
StateRootMessage
enum with all the message variants for state change inside the task. - the task creates an internal channel for sending and receive messages of type
StateRootMessage
- the task also creates a background thread that just receives items from the input state stream, wraps them into the correspondent
StateRootMessage
variant and forwards them to the internalStateRootMessage
channel. It callsrecv
in the external channel receiver, so that it yields run
now callsrecv
in the internalStateRootMessage
receiver (yielding) and processes each message- there's a separate
ProofSequencer
type to manage proofs in order.
@mattsse ptal, still not tested on the mainnet machine, but local checks are looking good
8e7f598
to
e734d3f
Compare
… ongoing proof calculations received
…e_root_from_proofs
Co-authored-by: Roman Krasiuk <[email protected]>
f982fa2
to
1665120
Compare
Towards #12053
Requires #12378 #12467 #12510