Skip to content

Commit

Permalink
Fix non-consencutive block validator loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jmederosalvarado committed Oct 26, 2022
1 parent 60dee2a commit 36bada2
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ public override void OnBlockProcessingStart(Block block, ProcessingOptions optio
bool isProducingBlock = options.ContainsFlag(ProcessingOptions.ProducingBlock);
bool isMainChainProcessing = !ForSealing && !isProducingBlock;
bool isInProcessedRange = _lastProcessedBlockNumber is not null && block.Number - 1 <= _lastProcessedBlockNumber;
bool isConsecutiveBlock = _lastProcessedBlockHash is not null && block.ParentHash == _lastProcessedBlockHash;

if (Validators == null || !isInProcessedRange || isProducingBlock)
// this condition is probably redundant because whenever Validators is null, isConsecutiveBlock will be false
// but let's leave it here just in case, it does not harm
if (Validators is null || !isConsecutiveBlock)
{
var parentHeader = BlockTree.FindParentHeader(block.Header, BlockTreeLookupOptions.None);
Validators = isInitBlock || !isInProcessedRange ? LoadValidatorsFromContract(parentHeader) : ValidatorStore.GetValidators(block.Number);
Expand Down Expand Up @@ -133,7 +136,7 @@ public override void OnBlockProcessingStart(Block block, ProcessingOptions optio
// We need to initialize pending validators from db on each block being produced.
_currentPendingValidators = ValidatorStore.PendingValidators;
}
else if (_lastProcessedBlockHash is null || block.ParentHash != _lastProcessedBlockHash) // either reorg or blocks skipped (like fast sync)
else if (!isConsecutiveBlock) // either reorg or blocks skipped (like fast sync)
_currentPendingValidators = ValidatorStore.PendingValidators = TryGetInitChangeFromPastBlocks(block.ParentHash);
}

Expand Down

0 comments on commit 36bada2

Please sign in to comment.