@@ -2595,9 +2595,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2595
2595
for (const auto & tx : block.vtx ) {
2596
2596
for (size_t o = 0 ; o < tx->vout .size (); o++) {
2597
2597
if (view.HaveCoin (COutPoint (tx->GetHash (), o))) {
2598
- LogPrintf (" ERROR: ConnectBlock(): tried to overwrite transaction\n " );
2599
- return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-txns-BIP30" ,
2600
- " tried to overwrite transaction" );
2598
+ state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-txns-BIP30" ,
2599
+ " tried to overwrite transaction" );
2601
2600
}
2602
2601
}
2603
2602
}
@@ -2636,6 +2635,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2636
2635
blockundo.vtxundo .reserve (block.vtx .size () - 1 );
2637
2636
for (unsigned int i = 0 ; i < block.vtx .size (); i++)
2638
2637
{
2638
+ if (!state.IsValid ()) break ;
2639
2639
const CTransaction &tx = *(block.vtx [i]);
2640
2640
2641
2641
nInputs += tx.vin .size ();
@@ -2649,14 +2649,13 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2649
2649
state.Invalid (BlockValidationResult::BLOCK_CONSENSUS,
2650
2650
tx_state.GetRejectReason (),
2651
2651
tx_state.GetDebugMessage () + " in transaction " + tx.GetHash ().ToString ());
2652
- LogError (" %s: Consensus::CheckTxInputs: %s, %s\n " , __func__, tx.GetHash ().ToString (), state.ToString ());
2653
- return false ;
2652
+ break ;
2654
2653
}
2655
2654
nFees += txfee;
2656
2655
if (!MoneyRange (nFees)) {
2657
- LogPrintf ( " ERROR: %s: accumulated fee in the block out of range. \n " , __func__);
2658
- return state. Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-txns- accumulated- fee-outofrange " ,
2659
- " accumulated fee in the block out of range " ) ;
2656
+ state. Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-txns- accumulated- fee-outofrange " ,
2657
+ " accumulated fee in the block out of range " );
2658
+ break ;
2660
2659
}
2661
2660
2662
2661
// Check that transaction is BIP68 final
@@ -2668,9 +2667,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2668
2667
}
2669
2668
2670
2669
if (!SequenceLocks (tx, nLockTimeFlags, prevheights, *pindex)) {
2671
- LogPrintf ( " ERROR: %s: contains a non-BIP68-final transaction \n " , __func__);
2672
- return state. Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-txns-nonfinal " ,
2673
- " contains a non-BIP68-final transaction " + tx. GetHash (). ToString ()) ;
2670
+ state. Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-txns-nonfinal " ,
2671
+ " contains a non-BIP68-final transaction " + tx. GetHash (). ToString ());
2672
+ break ;
2674
2673
}
2675
2674
}
2676
2675
@@ -2680,8 +2679,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2680
2679
// * witness (when witness enabled in flags and excludes coinbase)
2681
2680
nSigOpsCost += GetTransactionSigOpCost (tx, view, flags);
2682
2681
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST) {
2683
- LogPrintf ( " ERROR: ConnectBlock(): too many sigops\n " );
2684
- return state. Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-blk-sigops " , " too many sigops " ) ;
2682
+ state. Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-blk-sigops " , " too many sigops" );
2683
+ break ;
2685
2684
}
2686
2685
2687
2686
if (!tx.IsCoinBase ())
@@ -2693,8 +2692,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2693
2692
// Any transaction validation failure in ConnectBlock is a block consensus failure
2694
2693
state.Invalid (BlockValidationResult::BLOCK_CONSENSUS,
2695
2694
tx_state.GetRejectReason (), tx_state.GetDebugMessage ());
2696
- LogInfo (" Script validation error in block: %s\n " , state.ToString ());
2697
- return false ;
2695
+ break ;
2698
2696
}
2699
2697
control.Add (std::move (vChecks));
2700
2698
}
@@ -2714,16 +2712,17 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2714
2712
Ticks<MillisecondsDouble>(m_chainman.time_connect ) / m_chainman.num_blocks_total );
2715
2713
2716
2714
CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , params.GetConsensus ());
2717
- if (block.vtx [0 ]->GetValueOut () > blockReward) {
2718
- LogPrintf (" ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n " , block.vtx [0 ]->GetValueOut (), blockReward);
2719
- return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cb-amount" ,
2720
- strprintf (" coinbase pays too much (actual=%d vs limit=%d)" , block.vtx [0 ]->GetValueOut (), blockReward));
2715
+ if (block.vtx [0 ]->GetValueOut () > blockReward && state.IsValid ()) {
2716
+ state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cb-amount" ,
2717
+ strprintf (" coinbase pays too much (actual=%d vs limit=%d)" , block.vtx [0 ]->GetValueOut (), blockReward));
2721
2718
}
2722
2719
2723
2720
auto parallel_result = control.Complete ();
2724
- if (parallel_result.has_value ()) {
2721
+ if (parallel_result.has_value () && state. IsValid () ) {
2725
2722
state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, strprintf (" mandatory-script-verify-flag-failed (%s)" , ScriptErrorString (parallel_result->first )), parallel_result->second );
2726
- LogInfo (" Script validation error in block: %s" , state.ToString ());
2723
+ }
2724
+ if (!state.IsValid ()) {
2725
+ LogInfo (" Block validation error: %s" , state.ToString ());
2727
2726
return false ;
2728
2727
}
2729
2728
const auto time_4{SteadyClock::now ()};
@@ -2734,8 +2733,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2734
2733
Ticks<SecondsDouble>(m_chainman.time_verify ),
2735
2734
Ticks<MillisecondsDouble>(m_chainman.time_verify ) / m_chainman.num_blocks_total );
2736
2735
2737
- if (fJustCheck )
2736
+ if (fJustCheck ) {
2738
2737
return true ;
2738
+ }
2739
2739
2740
2740
if (!m_blockman.WriteUndoDataForBlock (blockundo, state, *pindex)) {
2741
2741
return false ;
0 commit comments