Skip to content

Commit

Permalink
Placed header state distance in config
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-orzechowski committed Dec 14, 2024
1 parent 5be45a3 commit c08476c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,7 @@ public interface ISyncConfig : IConfig

[ConfigItem(Description = "_Technical._ Run explicit GC after state sync finished.", DefaultValue = "true", HiddenFromDocs = true)]
bool GCOnFeedFinished { get; set; }

[ConfigItem(Description = "_Technical._ Max distance between best suggested header and available state to assume state is synced.", DefaultValue = "0", HiddenFromDocs = true)]
int HeaderStateDistance { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public string? PivotHash
public int StateMinDistanceFromHead { get; set; } = 32;
public bool GCOnFeedFinished { get; set; } = true;

/// Additional delay in blocks between best suggested header and synced state to allow faster state switching for PoW chains
/// with higher block processing frequency. Effectively this is the max allowed difference between best header (used as sync
/// pivot) and synced state block, to assume that state is synced and node can start processing blocks
public int HeaderStateDistance { get; set; } = 0;

public override string ToString()
{
return
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.Runner/configs/linea-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"SnapSync": true,
"PivotNumber": 13020000,
"PivotHash": "0x3dbc1fab314e5877280d5d192f0e55ae349500198121b67099c00af378369102",
"PivotTotalDifficulty": "26040001"
"PivotTotalDifficulty": "26040001",
"HeaderStateDistance": 6
},
"JsonRpc": {
"Enabled": true,
"Port": 8545
}
}
}
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.Runner/configs/linea-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"SnapSync": true,
"PivotNumber": 6830000,
"PivotHash": "0x75e380ff226a8b160cdef9c479327c98df28576a4388c90373d2b2931e3e852a",
"PivotTotalDifficulty": "13660001"
"PivotTotalDifficulty": "13660001",
"HeaderStateDistance": 6
},
"JsonRpc": {
"Enabled": true,
"Port": 8545
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class MultiSyncModeSelector : ISyncModeSelector
/// Number of blocks before the best peer's head when we switch from fast sync to full sync
/// </summary>
public const int FastSyncLag = 32;
public const int FastChainLag = 6;

/// <summary>
/// How many blocks can fast sync stay behind while state nodes is still syncing
Expand Down Expand Up @@ -400,7 +399,7 @@ private bool ShouldBeInFastSyncMode(Snapshot best)
// and we need to sync away from it.
// Note: its ok if target block height is not accurate as long as long full sync downloader does not stop
// earlier than this condition below which would cause a hang.
bool notReachedFullSyncTransition = best.Header < best.TargetBlock - FastSyncLag - FastChainLag;
bool notReachedFullSyncTransition = best.Header < best.TargetBlock - FastSyncLag - _syncConfig.HeaderStateDistance;

bool notInAStickyFullSync = !IsInAStickyFullSyncMode(best);
bool notHasJustStartedFullSync = !HasJustStartedFullSync(best);
Expand Down Expand Up @@ -590,8 +589,8 @@ private bool ShouldBeInStateSyncMode(Snapshot best)
bool notInFastSync = !best.IsInFastSync;
bool notNeedToWaitForHeaders = NotNeedToWaitForHeaders;
bool stickyStateNodes = best.TargetBlock - best.Header < (FastSyncLag + StickyStateNodesDelta);
bool stateNotDownloadedYet = (best.TargetBlock - best.State > (FastSyncLag + FastChainLag) ||
best.Header > (best.State + FastChainLag) && best.Header > best.Block);
bool stateNotDownloadedYet = (best.TargetBlock - best.State > (FastSyncLag + _syncConfig.HeaderStateDistance) ||
best.Header > (best.State + _syncConfig.HeaderStateDistance) && best.Header > best.Block);
bool notInAStickyFullSync = !IsInAStickyFullSyncMode(best);
bool notHasJustStartedFullSync = !HasJustStartedFullSync(best);

Expand Down Expand Up @@ -645,7 +644,7 @@ private bool ShouldBeInStateNodesMode(Snapshot best)
private bool ShouldBeInSnapRangesPhase(Snapshot best)
{
bool isInStateSync = best.IsInStateSync;
bool isCloseToHead = best.TargetBlock >= best.Header && (best.TargetBlock - best.Header) <= FastSyncLag + FastChainLag;
bool isCloseToHead = best.TargetBlock >= best.Header && (best.TargetBlock - best.Header) <= FastSyncLag + _syncConfig.HeaderStateDistance;
bool snapNotFinished = !_syncProgressResolver.IsSnapGetRangesFinished();

if (_logger.IsTrace)
Expand Down

0 comments on commit c08476c

Please sign in to comment.