Skip to content
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

Merged

Conversation

martinezjorge
Copy link
Contributor

@martinezjorge martinezjorge commented Aug 12, 2024

Closes #10219

@martinezjorge
Copy link
Contributor Author

@Rjected Could I get some feedback/direction on this approach?

@shekhirin shekhirin added C-enhancement New feature or request A-blockchain-tree Related to sidechains, reorgs and pending blocks labels Aug 12, 2024
@martinezjorge martinezjorge changed the title WIP: enhancement: Properly bubble up InsertBlockFatalError feat: Properly bubble up InsertBlockFatalError Aug 14, 2024
Copy link
Member

@Rjected Rjected left a 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?

@martinezjorge martinezjorge marked this pull request as ready for review August 17, 2024 06:10
@martinezjorge
Copy link
Contributor Author

@Rjected I switched from bubbling towards main thread using emits to bubbling up in EngineApiTreeHandler until the fn run. I also updated the tests. Please let me know you'd like me to approach the bubble up or the tests differently or if there is a test you'd like me to add.

Copy link
Member

@Rjected Rjected left a 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

Comment on lines 902 to 906
if let Err(fatal) = self.on_backfill_sync_finished(ctrl) {
Err(fatal)
} else {
Ok(())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Err(fatal) = self.on_backfill_sync_finished(ctrl) {
Err(fatal)
} else {
Ok(())
}
self.on_backfill_sync_finished(ctrl)?;

}
}
}
}
}
FromEngine::DownloadedBlocks(blocks) => {
if let Some(event) = self.on_downloaded(blocks) {
FromEngine::DownloadedBlocks(blocks) => match self.on_downloaded(blocks) {
Copy link
Member

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);
    }
}

}

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if let Ok(Some(event)) = self.on_downloaded_block(block) {
if let Some(event) = self.on_downloaded_block(block)? {

@@ -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> {
Copy link
Member

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
}

Copy link
Contributor Author

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.

crates/engine/tree/src/chain.rs Outdated Show resolved Hide resolved
@martinezjorge
Copy link
Contributor Author

Made the requested changes but I'm having a couple unit tests that are hanging

test tree::tests::test_engine_tree_live_sync_transition_eventually_canonical has been running for over 60 seconds
test tree::tests::test_engine_tree_live_sync_transition_required_blocks_requested has been running for over 60 seconds

So investigating, trying to figure out what's going on with those

Copy link
Member

@Rjected Rjected left a 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

@@ -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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem

Comment on lines 523 to 537
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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha


// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!("event received: {:?}", event);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops


let event = test_harness.from_tree_rx.recv().await.unwrap();
println!("event received: {:?}", event);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!("event received: {:?}", event);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops x 2

Copy link
Member

@Rjected Rjected left a 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!

@Rjected Rjected added this pull request to the merge queue Aug 26, 2024
Merged via the queue into paradigmxyz:main with commit 1c427c6 Aug 26, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-blockchain-tree Related to sidechains, reorgs and pending blocks C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly bubble up InsertBlockFatalError
3 participants