Skip to content

Commit

Permalink
Fix sepolia invalid block (#4694)
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Oct 10, 2022
1 parent ca2c4b6 commit 8f28e4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.

Expand Down Expand Up @@ -141,6 +141,31 @@ public void Is_fast_block_finished_returns_true_when_no_fast_block_sync_is_used(
Assert.True(syncProgressResolver.IsFastBlocksReceiptsFinished());
}

[Test]
public void Best_state_is_zero_if_snap_sync_range_is_not_complete()
{
IBlockTree blockTree = Substitute.For<IBlockTree>();
IReceiptStorage receiptStorage = Substitute.For<IReceiptStorage>();
IDb stateDb = Substitute.For<IDb>();
SyncConfig syncConfig = new();
syncConfig.PivotNumber = "1";
syncConfig.SnapSync = true;

ProgressTracker progressTracker = new(blockTree, stateDb, LimboLogs.Instance);
progressTracker.MoreAccountsToRight = true;

SyncProgressResolver syncProgressResolver = new(blockTree, receiptStorage, stateDb, NullTrieNodeResolver.Instance, progressTracker, syncConfig, LimboLogs.Instance);
var head = Build.A.Block.WithHeader(Build.A.BlockHeader.WithNumber(5).WithStateRoot(TestItem.KeccakA).TestObject).TestObject;
var suggested = Build.A.BlockHeader.WithNumber(6).WithStateRoot(TestItem.KeccakB).TestObject;
blockTree.Head.Returns(head);
blockTree.BestSuggestedHeader.Returns(suggested);
blockTree.FindHeader(Arg.Any<Keccak>(), BlockTreeLookupOptions.TotalDifficultyNotNeeded).Returns(head.Header);
stateDb.Get(head.StateRoot).Returns(new byte[] { 1 });
stateDb.Get(suggested.StateRoot).Returns(new byte[] { 1 });

Assert.AreEqual(0, syncProgressResolver.FindBestFullState());
}

[Test]
public void Is_fast_block_headers_finished_returns_false_when_headers_not_downloaded()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ public long FindBestFullState()
BlockHeader initialBestSuggested = _blockTree.BestSuggestedHeader; // just storing here for debugging sake
BlockHeader bestSuggested = initialBestSuggested;

// On a small network snap sync's address range request may complete very quickly meaning it will recalculate
// and store a valid state root. However, codes and storage may not be downloaded yet, so we need this check.
if (_syncConfig.SnapSync && !_progressTracker.IsSnapGetRangesFinished())
{
return 0;
}

long bestFullState = 0;
if (head != null)
{
Expand Down

0 comments on commit 8f28e4a

Please sign in to comment.