@@ -2595,9 +2595,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
25952595 for (const auto & tx : block.vtx ) {
25962596 for (size_t o = 0 ; o < tx->vout .size (); o++) {
25972597 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" );
26012600 }
26022601 }
26032602 }
@@ -2636,6 +2635,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26362635 blockundo.vtxundo .reserve (block.vtx .size () - 1 );
26372636 for (unsigned int i = 0 ; i < block.vtx .size (); i++)
26382637 {
2638+ if (!state.IsValid ()) break ;
26392639 const CTransaction &tx = *(block.vtx [i]);
26402640
26412641 nInputs += tx.vin .size ();
@@ -2649,14 +2649,13 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26492649 state.Invalid (BlockValidationResult::BLOCK_CONSENSUS,
26502650 tx_state.GetRejectReason (),
26512651 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 ;
26542653 }
26552654 nFees += txfee;
26562655 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 ;
26602659 }
26612660
26622661 // Check that transaction is BIP68 final
@@ -2668,9 +2667,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26682667 }
26692668
26702669 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 ;
26742673 }
26752674 }
26762675
@@ -2680,8 +2679,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26802679 // * witness (when witness enabled in flags and excludes coinbase)
26812680 nSigOpsCost += GetTransactionSigOpCost (tx, view, flags);
26822681 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 ;
26852684 }
26862685
26872686 if (!tx.IsCoinBase ())
@@ -2693,8 +2692,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26932692 // Any transaction validation failure in ConnectBlock is a block consensus failure
26942693 state.Invalid (BlockValidationResult::BLOCK_CONSENSUS,
26952694 tx_state.GetRejectReason (), tx_state.GetDebugMessage ());
2696- LogInfo (" Script validation error in block: %s\n " , state.ToString ());
2697- return false ;
2695+ break ;
26982696 }
26992697 control.Add (std::move (vChecks));
27002698 }
@@ -2714,16 +2712,17 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27142712 Ticks<MillisecondsDouble>(m_chainman.time_connect ) / m_chainman.num_blocks_total );
27152713
27162714 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));
27212718 }
27222719
27232720 auto parallel_result = control.Complete ();
2724- if (parallel_result.has_value ()) {
2721+ if (parallel_result.has_value () && state. IsValid () ) {
27252722 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 ());
27272726 return false ;
27282727 }
27292728 const auto time_4{SteadyClock::now ()};
@@ -2734,8 +2733,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27342733 Ticks<SecondsDouble>(m_chainman.time_verify ),
27352734 Ticks<MillisecondsDouble>(m_chainman.time_verify ) / m_chainman.num_blocks_total );
27362735
2737- if (fJustCheck )
2736+ if (fJustCheck ) {
27382737 return true ;
2738+ }
27392739
27402740 if (!m_blockman.WriteUndoDataForBlock (blockundo, state, *pindex)) {
27412741 return false ;
0 commit comments