Skip to content

Commit

Permalink
chore(engine): remove map insert error (paradigmxyz#7733)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Apr 18, 2024
1 parent 61acd78 commit d5858ad
Showing 1 changed file with 15 additions and 32 deletions.
47 changes: 15 additions & 32 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,21 @@ where
}
Err(error) => {
warn!(target: "consensus::engine", %error, "Error while processing payload");
self.map_insert_error(error)

// If the error was due to an invalid payload, the payload is added to the invalid
// headers cache and `Ok` with [PayloadStatusEnum::Invalid] is returned.
let (block, error) = error.split();
if error.is_invalid_block() {
warn!(target: "consensus::engine", invalid_hash=?block.hash(), invalid_number=?block.number, %error, "Invalid block error on new payload");
let latest_valid_hash =
self.latest_valid_hash_for_invalid_payload(block.parent_hash, Some(&error));
// keep track of the invalid header
self.invalid_headers.insert(block.header);
let status = PayloadStatusEnum::Invalid { validation_error: error.to_string() };
Ok(PayloadStatus::new(status, latest_valid_hash))
} else {
Err(BeaconOnNewPayloadError::Internal(Box::new(error)))
}
}
};

Expand Down Expand Up @@ -1290,37 +1304,6 @@ where
Ok(PayloadStatus::new(status, latest_valid_hash))
}

/// Maps the error, that occurred while inserting a payload into the tree to its corresponding
/// result type.
///
/// If the error was due to an invalid payload, the payload is added to the invalid headers
/// cache and `Ok` with [PayloadStatusEnum::Invalid] is returned.
///
/// This returns an error if the error was internal and assumed not be related to the payload.
fn map_insert_error(
&mut self,
err: InsertBlockError,
) -> Result<PayloadStatus, BeaconOnNewPayloadError> {
let (block, error) = err.split();

if error.is_invalid_block() {
warn!(target: "consensus::engine", invalid_hash=?block.hash(), invalid_number=?block.number, %error, "Invalid block error on new payload");

// all of these occurred if the payload is invalid
let parent_hash = block.parent_hash;

// keep track of the invalid header
self.invalid_headers.insert(block.header);

let latest_valid_hash =
self.latest_valid_hash_for_invalid_payload(parent_hash, Some(&error));
let status = PayloadStatusEnum::Invalid { validation_error: error.to_string() };
Ok(PayloadStatus::new(status, latest_valid_hash))
} else {
Err(BeaconOnNewPayloadError::Internal(Box::new(error)))
}
}

/// Invoked if we successfully downloaded a new block from the network.
///
/// This will attempt to insert the block into the tree.
Expand Down

0 comments on commit d5858ad

Please sign in to comment.