Skip to content

Commit

Permalink
For AuRa FullSync can't be in parallel with FastBlocks (NethermindEth…
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaszRozmej authored Jun 23, 2020
1 parent 8adf079 commit f679530
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +41,7 @@ public class InitializeBlockchainAuRa : InitializeBlockchain
public InitializeBlockchainAuRa(AuRaEthereumRunnerContext context) : base(context)
{
_context = context;
_context.Config<ISyncConfig>().AllowFullSyncParallelToFastBlocks = false;
}

protected override BlockProcessor CreateBlockProcessor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ void Test()
}
}
}

public ScenarioBuilder WhenAuRa()
{
_overwrites.Add(() =>
{
SyncConfig.AllowFullSyncParallelToFastBlocks = false;
});

return this;
}
}

public static ScenarioBuilder GoesLikeThis()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1089,4 +1110,4 @@ public void When_long_range_state_catch_up_is_needed()
.TheSyncModeShouldBe(SyncMode.StateNodes | SyncMode.Beam);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -284,14 +285,16 @@ private bool ShouldBeInFullSyncMode(Snapshot best)
_logger.Trace("notInBeamSync " + notInBeamSync);
_logger.Trace("notInFastSync " + notInFastSync);
_logger.Trace("notInStateSync " + notInStateSync);
_logger.Trace("notInConflictWithFastBlocks " + notInConflictWithFastBlocks);
}

return desiredPeerKnown &&
postPivotPeerAvailable &&
hasFastSyncBeenActive &&
notInBeamSync &&
notInFastSync &&
notInStateSync;
notInStateSync &&
notInConflictWithFastBlocks;
}

private bool ShouldBeInFastBlocksMode(Snapshot best)
Expand Down Expand Up @@ -488,4 +491,4 @@ public Snapshot(long processed, long state, long block, long header, long peerBl
public UInt256 PeerDifficulty { get; }
}
}
}
}

0 comments on commit f679530

Please sign in to comment.