Skip to content

Commit ece4dac

Browse files
authored
Merge pull request #6580 from jferrant/bugfix/propogate-up-error-in-accept-block
bugfix/propogate up error in accept_block
2 parents a7f4240 + 67ce930 commit ece4dac

File tree

1 file changed

+27
-33
lines changed
  • stackslib/src/chainstate/nakamoto

1 file changed

+27
-33
lines changed

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,28 +2478,23 @@ impl NakamotoChainState {
24782478
reward_set: &RewardSet,
24792479
obtain_method: NakamotoBlockObtainMethod,
24802480
) -> Result<bool, ChainstateError> {
2481-
test_debug!("Consider Nakamoto block {}", &block.block_id());
2481+
let block_id = block.block_id();
2482+
test_debug!("Consider Nakamoto block {block_id}");
24822483
// do nothing if we already have this block
2483-
if Self::get_block_header(headers_conn, &block.header.block_id())?.is_some() {
2484-
debug!("Already have block {}", &block.header.block_id());
2484+
if Self::get_block_header(headers_conn, &block_id)?.is_some() {
2485+
debug!("Already have block {block_id}");
24852486
return Ok(false);
24862487
}
24872488

24882489
// if this is the first tenure block, then make sure it's well-formed
24892490
block.is_wellformed_tenure_start_block().map_err(|_| {
2490-
warn!(
2491-
"Block {} is not a well-formed first tenure block",
2492-
&block.block_id()
2493-
);
2491+
warn!("Block {block_id} is not a well-formed first tenure block");
24942492
ChainstateError::InvalidStacksBlock("Not a well-formed first-tenure block".into())
24952493
})?;
24962494

24972495
// if this is a tenure-extend block, then make sure it's well-formed
24982496
block.is_wellformed_tenure_extend_block().map_err(|_| {
2499-
warn!(
2500-
"Block {} is not a well-formed tenure-extend block",
2501-
&block.block_id()
2502-
);
2497+
warn!("Block {block_id} is not a well-formed tenure-extend block");
25032498
ChainstateError::InvalidStacksBlock("Not a well-formed tenure-extend block".into())
25042499
})?;
25052500

@@ -2510,51 +2505,50 @@ impl NakamotoChainState {
25102505
if block.is_shadow_block() {
25112506
// this block is already present in the staging DB, so just perform some prefunctory
25122507
// validation (since they're constructed a priori to be valid)
2513-
if let Err(e) = Self::validate_shadow_nakamoto_block_burnchain(
2508+
Self::validate_shadow_nakamoto_block_burnchain(
25142509
staging_db_tx.conn(),
25152510
db_handle,
25162511
expected_burn_opt,
25172512
block,
25182513
config.mainnet,
25192514
config.chain_id,
2520-
) {
2515+
)
2516+
.unwrap_or_else(|e| {
25212517
error!("Unacceptable shadow Nakamoto block";
2522-
"stacks_block_id" => %block.block_id(),
2523-
"error" => ?e
2518+
"stacks_block_id" => %block_id,
2519+
"error" => ?e
25242520
);
25252521
panic!("Unacceptable shadow Nakamoto block");
2526-
}
2527-
2522+
});
25282523
return Ok(false);
25292524
}
25302525

25312526
// this block must be consistent with its miner's leader-key and block-commit, and must
25322527
// contain only transactions that are valid in this epoch.
2533-
if let Err(e) = Self::validate_normal_nakamoto_block_burnchain(
2528+
Self::validate_normal_nakamoto_block_burnchain(
25342529
staging_db_tx.conn(),
25352530
db_handle,
25362531
expected_burn_opt,
25372532
block,
25382533
config.mainnet,
25392534
config.chain_id,
2540-
) {
2535+
)
2536+
.inspect_err(|e| {
25412537
warn!("Unacceptable Nakamoto block; will not store";
2542-
"stacks_block_id" => %block.block_id(),
2543-
"error" => ?e
2538+
"stacks_block_id" => %block_id,
2539+
"error" => ?e
25442540
);
2545-
return Ok(false);
2546-
};
2541+
})?;
25472542

2548-
let signing_weight = match block.header.verify_signer_signatures(reward_set) {
2549-
Ok(x) => x,
2550-
Err(e) => {
2543+
let signing_weight = block
2544+
.header
2545+
.verify_signer_signatures(reward_set)
2546+
.inspect_err(|e| {
25512547
warn!("Received block, but the signer signatures are invalid";
2552-
"block_id" => %block.block_id(),
2553-
"error" => ?e,
2548+
"block_id" => %block_id,
2549+
"error" => ?e,
25542550
);
2555-
return Err(e);
2556-
}
2557-
};
2551+
})?;
25582552

25592553
// if we pass all the tests, then along the way, we will have verified (in
25602554
// Self::validate_nakamoto_block_burnchain) that the consensus hash of this block is on the
@@ -2569,9 +2563,9 @@ impl NakamotoChainState {
25692563
obtain_method,
25702564
)?;
25712565
if ret {
2572-
test_debug!("Stored Nakamoto block {}", &block.block_id());
2566+
test_debug!("Stored Nakamoto block {block_id}");
25732567
} else {
2574-
test_debug!("Did NOT store Nakamoto block {}", &block.block_id());
2568+
test_debug!("Did NOT store Nakamoto block {block_id}");
25752569
}
25762570
Ok(ret)
25772571
}

0 commit comments

Comments
 (0)