Skip to content

Commit 47ca81f

Browse files
v0.9.15: merge bug fix from defi branch in case of invalid blocks
1 parent 507a7e5 commit 47ca81f

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project( 'Warthog', ['c','cpp'],
2-
version : '0.9.14',
2+
version : '0.9.15',
33
default_options : ['warning_level=3', 'cpp_std=c++20'])
44

55
rtcstatic = []

src/node/chainserver/state/state.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

573580
auto State::apply_signed_snapshot(SignedSnapshot&& ssnew) -> std::optional<StateUpdateWithAPIBlocks>

src/node/chainserver/state/state.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class State {
132132

133133
struct ApplyStageResult {
134134
stage_operation::StageAddStatus status;
135+
std::optional<Worksum> errorWorksum; // has value when status is not 0
136+
std::optional<Header> errorHeader; // has value when status is not 0
135137
std::optional<state_update::StateUpdateWithAPIBlocks> update;
136138
};
137139
[[nodiscard]] auto apply_stage(ChainDBTransaction&& t) -> ApplyStageResult;

0 commit comments

Comments
 (0)