-
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: Properly bubble up InsertBlockFatalError
#10276
feat: Properly bubble up InsertBlockFatalError
#10276
Conversation
…oll, and emitting events
@Rjected Could I get some feedback/direction on this approach? |
InsertBlockFatalError
InsertBlockFatalError
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.
instead of using emit_event
, let's ensure that the methods which call on_insert_block_error
return a Result
so we can do
self.on_insert_block_error(err)?;
I like this direction as opposed to using events to bubble the error, because the events contain more "actual" information we want the engine to handle, and the result Err
variant seems like a better fit for fatal errors.
does that make sense?
@Rjected I switched from bubbling towards main thread using emits to bubbling up in |
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.
nice! some comments on result handling and the run
signature
crates/engine/tree/src/tree/mod.rs
Outdated
if let Err(fatal) = self.on_backfill_sync_finished(ctrl) { | ||
Err(fatal) | ||
} else { | ||
Ok(()) | ||
} |
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.
if let Err(fatal) = self.on_backfill_sync_finished(ctrl) { | |
Err(fatal) | |
} else { | |
Ok(()) | |
} | |
self.on_backfill_sync_finished(ctrl)?; |
crates/engine/tree/src/tree/mod.rs
Outdated
} | ||
} | ||
} | ||
} | ||
} | ||
FromEngine::DownloadedBlocks(blocks) => { | ||
if let Some(event) = self.on_downloaded(blocks) { | ||
FromEngine::DownloadedBlocks(blocks) => match self.on_downloaded(blocks) { |
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 can be
FromEngine::DownloadedBlocks(blocks) => {
if let Some(event) = self.on_downloaded(blocks)? {
self.on_tree_event(event);
}
}
crates/engine/tree/src/tree/mod.rs
Outdated
} | ||
|
||
trace!(target: "engine", block_count = %blocks.len(), "received downloaded blocks"); | ||
let batch = self.config.max_execute_block_batch_size().min(blocks.len()); | ||
for block in blocks.drain(..batch) { | ||
if let Some(event) = self.on_downloaded_block(block) { | ||
if let Ok(Some(event)) = self.on_downloaded_block(block) { |
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.
if let Ok(Some(event)) = self.on_downloaded_block(block) { | |
if let Some(event) = self.on_downloaded_block(block)? { |
crates/engine/tree/src/tree/mod.rs
Outdated
@@ -500,24 +500,23 @@ where | |||
/// Run the engine API handler. | |||
/// | |||
/// This will block the current thread and process incoming messages. | |||
pub fn run(mut self) { | |||
pub fn run(mut self) -> Result<(), InsertBlockFatalError> { |
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.
in this method I would prefer that the signature remain as run(mut self)
, and instead we handle the on_engine_message
like this:
if let Err(err) = self.on_engine_message(msg) {
// some error! message
return
}
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.
Okay no problem, I was not sure about this detail. Thank you for clarifying.
…ng clone attribute macro to HandlerEvent<T>
Made the requested changes but I'm having a couple unit tests that are hanging
So investigating, trying to figure out what's going on with those |
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.
Nice! I have some small nitpicks but this seems good otherwise
crates/engine/tree/src/tree/mod.rs
Outdated
@@ -169,7 +169,7 @@ impl TreeState { | |||
current_hash = self.canonical_block_hash(); | |||
while let Some(current_block) = self.block_by_hash(current_hash) { | |||
if current_block.hash() == target_hash { | |||
return false | |||
return false; |
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.
one nit: let's remove the added semicolons
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.
no problem
crates/engine/tree/src/tree/mod.rs
Outdated
break; | ||
} | ||
} | ||
Ok(None) => { | ||
debug!(target: "engine", "received no engine message for some time, while waiting for persistence task to complete"); | ||
} | ||
Err(_err) => { | ||
error!(target: "engine", "Engine channel disconnected"); | ||
return | ||
return; | ||
} | ||
} | ||
|
||
if let Err(err) = self.advance_persistence() { | ||
error!(target: "engine", %err, "Advancing persistence failed"); | ||
break | ||
break; |
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 return
here, they should be equivalent but this is just to stay consistent
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.
gotcha
crates/engine/tree/src/tree/mod.rs
Outdated
|
||
// send fcu to the tip of main | ||
test_harness.fcu_to(main_chain_last_hash, ForkchoiceStatus::Syncing).await; | ||
|
||
let event = test_harness.from_tree_rx.recv().await.unwrap(); | ||
println!("event received: {:?}", event); |
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.
println!("event received: {:?}", event); |
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.
whoops
crates/engine/tree/src/tree/mod.rs
Outdated
|
||
let event = test_harness.from_tree_rx.recv().await.unwrap(); | ||
println!("event received: {:?}", event); |
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.
println!("event received: {:?}", event); |
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.
whoops x 2
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 looks good to me, thanks!
Closes #10219