示例#1
0
        public bool CanSeal(long blockNumber, Keccak parentHash)
        {
            bool StepNotYetProduced(long step) => !_blockTree.Head.AuRaStep.HasValue
                ? throw new InvalidOperationException("Head block doesn't have AuRaStep specified.'")
                : _blockTree.Head.AuRaStep.Value < step;

            bool IsThisNodeTurn(long step) => _validator.IsValidSealer(_nodeAddress, step);

            var currentStep        = _auRaStepCalculator.CurrentStep;
            var stepNotYetProduced = StepNotYetProduced(currentStep);
            var isThisNodeTurn     = IsThisNodeTurn(currentStep);

            if (isThisNodeTurn)
            {
                if (_logger.IsWarn && !stepNotYetProduced)
                {
                    _logger.Warn($"Cannot seal block {blockNumber}: AuRa step {currentStep} already produced.");
                }
                else if (_logger.IsDebug && stepNotYetProduced)
                {
                    _logger.Debug($"Can seal block {blockNumber}: {_nodeAddress} is correct proposer of AuRa step {currentStep}.");
                }
            }
            else if (_logger.IsDebug)
            {
                _logger.Debug($"Skip seal block {blockNumber}: {_nodeAddress} is not proposer of AuRa step {currentStep}.");
            }

            return(stepNotYetProduced && isThisNodeTurn);
        }
示例#2
0
        public long?GetFinalizedLevel_test(int chainLength, int levelToCheck, Address[] beneficiaries, int minForFinalization)
        {
            _auraValidator.MinSealersForFinalization.Returns(minForFinalization);
            _auraValidator.IsValidSealer(Arg.Any <Address>(), Arg.Any <long>()).Returns(c => beneficiaries.GetItemRoundRobin(c.Arg <long>()) == c.Arg <Address>());
            var blockTreeBuilder    = Build.A.BlockTree().OfChainLength(chainLength, 0, 0, beneficiaries);
            var blockTree           = blockTreeBuilder.TestObject;
            var finalizationManager = new AuRaBlockFinalizationManager(blockTree, blockTreeBuilder.ChainLevelInfoRepository, _blockProcessor, _auraValidator, _logManager);

            var result = finalizationManager.GetFinalizedLevel(levelToCheck);

            return(result);
        }
示例#3
0
 public bool can_seal(long auRaStep, bool validSealer)
 {
     _auRaStepCalculator.CurrentStep.Returns(auRaStep);
     _auRaValidator.IsValidSealer(_address, auRaStep).Returns(validSealer);
     return(_auRaSealer.CanSeal(10, _blockTree.Head.Hash));
 }