public void PreProcess(Block block, ProcessingOptions options = ProcessingOptions.None) { bool isProducingBlock = options.IsProducingBlock(); long previousBlockNumber = block.Number - 1; bool isNotConsecutive = previousBlockNumber != _lastProcessedBlock; if (isProducingBlock || isNotConsecutive) { if (TryGetLastValidator(previousBlockNumber, out var validatorInfo)) { if (validatorInfo.Value.ValidatorType.CanChangeImmediately()) { SetCurrentValidator(validatorInfo); } else if (!isProducingBlock) { bool canSetValidatorAsCurrent = !TryGetLastValidator(validatorInfo.Key - 1, out var previousValidatorInfo); long?finalizedAtBlockNumber = null; if (!canSetValidatorAsCurrent) { SetCurrentValidator(previousValidatorInfo); finalizedAtBlockNumber = _blockFinalizationManager.GetFinalizedLevel(validatorInfo.Key); canSetValidatorAsCurrent = finalizedAtBlockNumber != null; } if (canSetValidatorAsCurrent) { SetCurrentValidator(finalizedAtBlockNumber ?? validatorInfo.Key, validatorInfo.Value); } } } } _currentValidator?.PreProcess(block, options); }
public void OnBlockProcessingStart(Block block, ProcessingOptions options = ProcessingOptions.None) { if (!block.IsGenesis) { bool ValidatorWasAlreadyFinalized(KeyValuePair <long, AuRaParameters.Validator> validatorInfo) => _blockFinalizationManager.LastFinalizedBlockLevel >= validatorInfo.Key; bool isProducingBlock = options.IsProducingBlock(); long previousBlockNumber = block.Number - 1; bool isNotConsecutive = previousBlockNumber != _lastProcessedBlock; if (isProducingBlock || isNotConsecutive) { if (TryGetLastValidator(previousBlockNumber, out var validatorInfo)) { var parentHeader = _blockTree.FindParentHeader(block.Header, BlockTreeLookupOptions.None); if (validatorInfo.Value.ValidatorType.CanChangeImmediately() || ValidatorWasAlreadyFinalized(validatorInfo)) { SetCurrentValidator(validatorInfo, parentHeader); } else if (!isProducingBlock) { bool canSetValidatorAsCurrent = !TryGetLastValidator(validatorInfo.Key - 1, out var previousValidatorInfo); long?finalizedAtBlockNumber = null; if (!canSetValidatorAsCurrent) { SetCurrentValidator(previousValidatorInfo, parentHeader); finalizedAtBlockNumber = _blockFinalizationManager.GetFinalizedLevel(validatorInfo.Key); canSetValidatorAsCurrent = finalizedAtBlockNumber != null; } if (canSetValidatorAsCurrent) { SetCurrentValidator(finalizedAtBlockNumber ?? validatorInfo.Key, validatorInfo.Value, parentHeader); } } } } } _currentValidator?.OnBlockProcessingStart(block, options); }