@@ -446,21 +446,21 @@ auto State::add_stage(const std::vector<Block>& blocks, const Headerchain& hc) -
446446 stage.append (prepared.value (), batchRegistry);
447447 }
448448 if (stage.total_work () > chainstate.headers ().total_work ()) {
449- auto [status, update] { apply_stage (std::move (transaction)) };
449+ auto r { apply_stage (std::move (transaction)) };
450450
451- if (status.ce .is_error ()) {
451+ if (r. status .ce .is_error ()) {
452452 // Something went wrong on block body level so block header must be also tainted
453453 // as we checked for correct merkleroot already
454454 // => we need to collect data on rogue header
455455 RogueHeaderData rogueHeaderData (
456- status.ce ,
457- stage[status. ce . height ()] ,
458- stage. total_work_at (status. ce . height () ));
459- return { { status }, rogueHeaderData, update };
456+ r. status .ce ,
457+ r. errorHeader . value () ,
458+ r. errorWorksum . value ( ));
459+ return { { r. status }, std::move ( rogueHeaderData), std::move (r. update ) };
460460 } else {
461461 // pass {} as header arg because we can't to block any headers when
462462 // we have a wrong body (EINV_BODY or EMROOT)
463- return { { ce }, {}, update };
463+ return { { ce }, {}, std::move (r. update ) };
464464 }
465465 } else {
466466 // pass {} as header arg because we can't to block any headers when
@@ -549,25 +549,32 @@ auto State::apply_stage(ChainDBTransaction&& t) -> ApplyStageResult
549549
550550 chainserver::ApplyStageTransaction tr { *this , std::move (t) };
551551 tr.consider_rollback (fh - 1 );
552+ std::optional<Worksum> errorWorksum;
553+ std::optional<Header> errorHeader;
552554 auto status { tr.apply_stage_blocks () };
553555 if (status.is_error ()) {
554556 if (config ().localDebug ) {
555557 assert (0 == 1 ); // In local debug mode no errors should occurr (no bad actors)
556558 }
557559 for (auto h { status.height () }; h < stage.length (); ++h)
558560 db.delete_bad_block (stage.hash_at (h));
561+ errorWorksum = stage.total_work_at (status.height ());
562+ errorHeader = stage[status.height ()];
563+ spdlog::warn (" Invalid block at height {}: {}" , status.height ().value (), status.err_name ());
559564 stage.shrink (status.height () - 1 );
560565 if (stage.total_work_at (status.height () - 1 ) <= chainstate.headers ().total_work ()) {
561566 return {
562567 { status },
568+ errorWorksum,
569+ errorHeader,
563570 {},
564571 };
565572 }
566573 }
567574 db.set_consensus_work (stage.total_work ());
568575 auto update { std::move (tr).commit (*this ) };
569576
570- return { { status }, update };
577+ return { { status }, errorWorksum, errorHeader, update };
571578}
572579
573580auto State::apply_signed_snapshot (SignedSnapshot&& ssnew) -> std::optional<StateUpdateWithAPIBlocks>
0 commit comments