Skip to content

Commit

Permalink
Make pivot update attempts infinite (#5988)
Browse files Browse the repository at this point in the history
* make pivot update attempts infinite

* remove remaining attempts from logs

* add counting to logs
  • Loading branch information
marcindsobczak authored Aug 9, 2023
1 parent b4a0138 commit dbb8c0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface ISyncConfig : IConfig
[ConfigItem(DisabledForCli = true, HiddenFromDocs = true)]
Keccak? PivotHashParsed => PivotHash is null ? null : new Keccak(Bytes.FromHexString(PivotHash));

[ConfigItem(Description = "Max number of attempts (seconds) to update pivot block basing on Forkchoice message from Consensus Layer. Only for PoS chains.", DefaultValue = "900")]
[ConfigItem(Description = "Max number of attempts (seconds) to update pivot block basing on Forkchoice message from Consensus Layer. Only for PoS chains. Infinite by default.", DefaultValue = "2147483647")]
int MaxAttemptsToUpdatePivot { get; set; }

[ConfigItem(Description = "[EXPERIMENTAL] Defines the earliest body downloaded in fast sync when DownloadBodiesInFastSync is enabled. Actual values used will be Math.Max(1, Math.Min(PivotNumber, AncientBodiesBarrier))", DefaultValue = "0")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public string? PivotHash
get => FastSync || SnapSync ? _pivotHash : null;
set => _pivotHash = value;
}
public int MaxAttemptsToUpdatePivot { get; set; } = 900;
public int MaxAttemptsToUpdatePivot { get; set; } = int.MaxValue;
public bool WitnessProtocolEnabled { get; set; } = false;
public bool SnapSync { get; set; } = false;
public int SnapSyncAccountRangePartitionCount { get; set; } = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class PivotUpdator

private readonly CancellationTokenSource _cancellation = new();

private static int _maxAttempts;
private int _attemptsLeft;
private int _updateInProgress;
private Keccak _alreadyAnnouncedNewPivotHash = Keccak.Zero;
Expand All @@ -55,6 +56,7 @@ public PivotUpdator(IBlockTree blockTree,
_metadataDb = metadataDb ?? throw new ArgumentNullException(nameof(metadataDb));
_logger = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

_maxAttempts = syncConfig.MaxAttemptsToUpdatePivot;
_attemptsLeft = syncConfig.MaxAttemptsToUpdatePivot;

if (!TryUpdateSyncConfigUsingDataFromDb())
Expand Down Expand Up @@ -141,7 +143,7 @@ private async Task<bool> TrySetFreshPivot(CancellationToken cancellationToken)

if (finalizedBlockHash is null || finalizedBlockHash == Keccak.Zero)
{
if (_logger.IsInfo && _attemptsLeft % 10 == 0) _logger.Info($"Waiting for Forkchoice message from Consensus Layer to set fresh pivot block. {_attemptsLeft} attempts left");
if (_logger.IsInfo && (_maxAttempts - _attemptsLeft) % 10 == 0) _logger.Info($"Waiting for Forkchoice message from Consensus Layer to set fresh pivot block [{_maxAttempts - _attemptsLeft}s]");

return null;
}
Expand Down Expand Up @@ -217,7 +219,7 @@ private async Task<bool> TrySetFreshPivot(CancellationToken cancellationToken)
}
}

if (_logger.IsInfo && _attemptsLeft % 10 == 0) _logger.Info($"Potential new pivot block hash: {finalizedBlockHash}. Waiting for pivot block header. {_attemptsLeft} attempts left");
if (_logger.IsInfo && (_maxAttempts - _attemptsLeft) % 10 == 0) _logger.Info($"Potential new pivot block hash: {finalizedBlockHash}. Waiting for pivot block header [{_maxAttempts - _attemptsLeft}s]");
return null;
}

Expand Down

0 comments on commit dbb8c0b

Please sign in to comment.