Skip to content

Commit 2bcb2d6

Browse files
committed
Fixed zero-offset protection for PBFT (where it can be normal)
1 parent fbcfb95 commit 2bcb2d6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

explorer/adapter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,14 @@ class Adapter : public Node::IObserver, public IAdapter {
471471

472472
if (bForceReset)
473473
{
474-
if (!lst.empty() && (lst.back().second.m_TotalOffset == sd.m_Extra0.m_TotalOffset))
474+
// Historically explorer node could corrupt itself, it usually manifests in consecutive blocks having the same State Extra, in particular same Total Offset.
475+
// Here we try to detect this.
476+
// One situation which could be legit: it's a network running on PBFT consensus algorithm. Completely empty blocks are normal.
477+
// But, due to cannibalization, this can happen only to the last block.
478+
//
479+
// hence we check that our backtravel list has at least 2 previous entries
480+
481+
if ((lst.size() >= 2) && (lst.back().second.m_TotalOffset == sd.m_Extra0.m_TotalOffset))
475482
{
476483
CorruptionException exc;
477484
exc.m_sErr = "zero offset detected. Full Reset is required to recover";

node/processor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,12 @@ bool NodeProcessor::HandleBlockInternal(const HeightHash& id, const Block::Syste
31473147

31483148
if (bFirstTime)
31493149
{
3150-
if (block.m_Offset.m_Value == Zero)
3150+
// Protect against blocks with invalid offset (historically happened in explorer node)
3151+
3152+
// Block with zero offset can be created in PBFT consensus algorithm, empty blocks are normal.
3153+
// However only the last block can be empty (due to cannibalization).
3154+
// Hence it's not applicable to Fast-Sync case.
3155+
if ((s.m_Number.v <= m_SyncData.m_TxoLo.v) && (block.m_Offset.m_Value == Zero))
31513156
{
31523157
BEAM_LOG_WARNING() << id << " has zero offset";
31533158
return false;

0 commit comments

Comments
 (0)