8000 feat: do not panic when block validation fails by jeluard · Pull Request #259 · pragma-org/amaru · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: do not panic when block validation fails #259

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

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to 8000
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/amaru/src/stages/consensus/forward_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl gasket::framework::Worker<ForwardChainStage> for Worker {
target: EVENT_TARGET,
parent: span,
slot = ?point.slot_or_default(),
hash = %Hash::<32>::from(point),
hash = ?Hash::<32>::from(point),
"block_validation_failed"
);

Expand Down
33 changes: 15 additions & 18 deletions crates/amaru/src/stages/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ impl<S: Store + Send, HS: HistoricalStores + Send> ValidateBlockStage<S, HS> {
let protocol_version = block.header.header_body.protocol_version;
match rules::validate_block(&mut context, self.state.protocol_parameters(), &block) {
BlockValidation::Err(err) => return Err(err),
BlockValidation::Invalid(err) => {
error!("Block invalid: {:?}", err);
return Ok(Some(err));
}
BlockValidation::Invalid(err) => Ok(Some(err)),
BlockValidation::Valid(()) => {
let state: VolatileState = context.into();
let issuer = Hasher::<224>::hash(&block.header.header_body.issuer_vkey[..]);
Expand Down Expand Up @@ -175,20 +172,20 @@ impl<S: Store + Send, HS: HistoricalStores + Send>
stage: &mut ValidateBlockStage<S, HS>,
) -> Result<(), WorkerError> {
let result = match unit {
ValidateBlockEvent::Validated { point, block, span } => stage
.roll_forward(point.clone(), block.to_vec())
.map(|res| match res {
None => BlockValidationResult::BlockValidated {
point: point.clone(),
block: block.to_vec(),
span: restore_span(span),
},
Some(_err) => BlockValidationResult::BlockValidationFailed {
point: point.clone(),
span: restore_span(span),
},
})
.or_panic()?,
ValidateBlockEvent::Validated { point, block, span } => {
let point = point.clone();
let block = block.to_vec();
let span = restore_span(span);

match stage.roll_forward(point.clone(), block.clone()) {
Ok(None) => BlockValidationResult::BlockValidated { point, block, span },
Ok(Some(_)) => BlockValidationResult::BlockValidationFailed { point, span },
Err(err) => {
error!(?err, "Failed to validate block");
BlockValidationResult::BlockValidationFailed { point, span }
}
}
}
ValidateBlockEvent::Rollback {
rollback_point,
span,
Expand Down
Loading
0