From f679530219f426cea309506634871c5229681bc1 Mon Sep 17 00:00:00 2001 From: Lukasz Rozmej Date: Wed, 24 Jun 2020 00:23:47 +0200 Subject: [PATCH] For AuRa FullSync can't be in parallel with FastBlocks (#2047) --- .../Synchronization/ISyncConfig.cs | 3 +++ .../Synchronization/SyncConfig.cs | 3 ++- .../Steps/InitializeBlockchainAuRa.cs | 2 ++ .../MultiSyncModeSelectorTests.cs | 23 ++++++++++++++++++- .../ParallelSync/MultiSyncModeSelector.cs | 7 ++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs index bc6ee8b5e4e..2a0ed48144e 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs @@ -75,5 +75,8 @@ public interface ISyncConfig : IConfig [ConfigItem(Description = "Should use beam sync to fix corrupted state DB (dev use).", DefaultValue = "false")] public bool BeamSyncFixMode { get; set; } + + [ConfigItem(Description = "If FullSync can be run in parallel with FastBlocks. It is false for AuRa chains.", DefaultValue = "true")] + public bool AllowFullSyncParallelToFastBlocks { get; set; } } } diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs index 570c936ffa4..32a9808e613 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs @@ -41,5 +41,6 @@ public class SyncConfig : ISyncConfig public int BeamSyncContextTimeout { get; set; } = 4; public int BeamSyncPreProcessorTimeout { get; set; } = 15; public bool BeamSyncFixMode { get; set; } = false; + public bool AllowFullSyncParallelToFastBlocks { get; set; } = true; } -} \ No newline at end of file +} diff --git a/src/Nethermind/Nethermind.Runner/Ethereum/Steps/InitializeBlockchainAuRa.cs b/src/Nethermind/Nethermind.Runner/Ethereum/Steps/InitializeBlockchainAuRa.cs index b009478a508..903c1abed24 100644 --- a/src/Nethermind/Nethermind.Runner/Ethereum/Steps/InitializeBlockchainAuRa.cs +++ b/src/Nethermind/Nethermind.Runner/Ethereum/Steps/InitializeBlockchainAuRa.cs @@ -17,6 +17,7 @@ using System; using System.Linq; using Nethermind.Blockchain.Processing; +using Nethermind.Blockchain.Synchronization; using Nethermind.Blockchain.Validators; using Nethermind.Consensus.AuRa; using Nethermind.Consensus.AuRa.Config; @@ -40,6 +41,7 @@ public class InitializeBlockchainAuRa : InitializeBlockchain public InitializeBlockchainAuRa(AuRaEthereumRunnerContext context) : base(context) { _context = context; + _context.Config().AllowFullSyncParallelToFastBlocks = false; } protected override BlockProcessor CreateBlockProcessor() diff --git a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.cs index fc225f4fae0..ca30f624869 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/MultiSyncModeSelectorTests.cs @@ -666,6 +666,16 @@ void Test() } } } + + public ScenarioBuilder WhenAuRa() + { + _overwrites.Add(() => + { + SyncConfig.AllowFullSyncParallelToFastBlocks = false; + }); + + return this; + } } public static ScenarioBuilder GoesLikeThis() @@ -888,6 +898,17 @@ public void Just_after_finishing_state_sync_but_not_fast_blocks() .WhenBeamSyncIsConfigured() .TheSyncModeShouldBe(SyncMode.Full | SyncMode.FastBlocks); } + + [Test] + public void Just_after_finishing_state_sync_but_not_fast_blocks_on_AuRa() + { + Scenario.GoesLikeThis() + .IfThisNodeFinishedStateSyncButNotFastBlocks() + .AndGoodPeersAreKnown() + .WhenBeamSyncIsConfigured() + .WhenAuRa() + .TheSyncModeShouldBe(SyncMode.FastBlocks); + } [Test] public void When_finished_fast_sync_and_pre_pivot_block_appears() @@ -1089,4 +1110,4 @@ public void When_long_range_state_catch_up_is_needed() .TheSyncModeShouldBe(SyncMode.StateNodes | SyncMode.Beam); } } -} \ No newline at end of file +} diff --git a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs index c2e46cd4ad6..5263ca4c93b 100644 --- a/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs +++ b/src/Nethermind/Nethermind.Synchronization/ParallelSync/MultiSyncModeSelector.cs @@ -274,6 +274,7 @@ private bool ShouldBeInFullSyncMode(Snapshot best) bool notInBeamSync = !best.IsInBeamSync; bool notInFastSync = !best.IsInFastSync; bool notInStateSync = !best.IsInStateSync; + bool notInConflictWithFastBlocks = _syncConfig.AllowFullSyncParallelToFastBlocks || !best.IsInFastBlocks; if (_logger.IsTrace) { @@ -284,6 +285,7 @@ private bool ShouldBeInFullSyncMode(Snapshot best) _logger.Trace("notInBeamSync " + notInBeamSync); _logger.Trace("notInFastSync " + notInFastSync); _logger.Trace("notInStateSync " + notInStateSync); + _logger.Trace("notInConflictWithFastBlocks " + notInConflictWithFastBlocks); } return desiredPeerKnown && @@ -291,7 +293,8 @@ private bool ShouldBeInFullSyncMode(Snapshot best) hasFastSyncBeenActive && notInBeamSync && notInFastSync && - notInStateSync; + notInStateSync && + notInConflictWithFastBlocks; } private bool ShouldBeInFastBlocksMode(Snapshot best) @@ -488,4 +491,4 @@ public Snapshot(long processed, long state, long block, long header, long peerBl public UInt256 PeerDifficulty { get; } } } -} \ No newline at end of file +}