Example #1
0
        public MultiValidator(
            AuRaParameters.Validator validator,
            IAuRaValidatorFactory validatorFactory,
            IBlockTree blockTree,
            IValidatorStore validatorStore,
            IBlockFinalizationManager finalizationManager,
            BlockHeader parentHeader,
            ILogManager logManager,
            bool forSealing = false)
        {
            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }
            if (validator.ValidatorType != AuRaParameters.ValidatorType.Multi)
            {
                throw new ArgumentException("Wrong validator type.", nameof(validator));
            }
            _validatorFactory = validatorFactory ?? throw new ArgumentNullException(nameof(validatorFactory));
            _blockTree        = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _validatorStore   = validatorStore ?? throw new ArgumentNullException(nameof(validatorStore));
            _forSealing       = forSealing;
            _logger           = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

            _validators = validator.Validators?.Count > 0
                ? validator.Validators
                : throw new ArgumentException("Multi validator cannot be empty.", nameof(validator.Validators));

            SetFinalizationManager(finalizationManager, parentHeader);
        }
Example #2
0
 public ContractBasedValidator(
     AuRaParameters.Validator validator,
     IStateProvider stateProvider,
     IAbiEncoder abiEncoder,
     ITransactionProcessor transactionProcessor,
     IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource,
     IBlockTree blockTree,
     IReceiptFinder receiptFinder,
     IValidatorStore validatorStore,
     IValidSealerStrategy validSealerStrategy,
     IBlockFinalizationManager finalizationManager,
     BlockHeader parentHeader,
     ILogManager logManager,
     long startBlockNumber,
     bool forSealing = false) : base(validator, validSealerStrategy, validatorStore, logManager, startBlockNumber, forSealing)
 {
     _blockTree            = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
     ContractAddress       = validator.Addresses?.FirstOrDefault() ?? throw new ArgumentException("Missing contract address for AuRa validator.", nameof(validator.Addresses));
     _stateProvider        = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
     _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
     _readOnlyReadOnlyTransactionProcessorSource = readOnlyTransactionProcessorSource ?? throw new ArgumentNullException(nameof(readOnlyTransactionProcessorSource));
     _receiptFinder = receiptFinder ?? throw new ArgumentNullException(nameof(receiptFinder));
     _logger        = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     AbiEncoder     = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
     SetPendingValidators(LoadPendingValidators());
     SetFinalizationManager(finalizationManager, parentHeader ?? _blockTree.Head?.Header);
 }
Example #3
0
 public AuRaValidatorFactory(IStateProvider stateProvider,
                             IAbiEncoder abiEncoder,
                             ITransactionProcessor transactionProcessor,
                             IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource,
                             IBlockTree blockTree,
                             IReceiptFinder receiptFinder,
                             IValidatorStore validatorStore,
                             IBlockFinalizationManager finalizationManager,
                             ITxSender txSender,
                             ITxPool txPool,
                             ILogManager logManager,
                             ISigner signer,
                             ReportingContractBasedValidator.Cache reportingValidatorCache,
                             long posdaoTransition,
                             bool forSealing = false)
 {
     _stateProvider        = stateProvider;
     _abiEncoder           = abiEncoder;
     _transactionProcessor = transactionProcessor;
     _readOnlyTransactionProcessorSource = readOnlyTransactionProcessorSource;
     _blockTree           = blockTree;
     _receiptFinder       = receiptFinder;
     _validatorStore      = validatorStore;
     _finalizationManager = finalizationManager;
     _txSender            = txSender;
     _txPool     = txPool;
     _logManager = logManager;
     _signer     = signer;
     _reportingValidatorCache = reportingValidatorCache;
     _posdaoTransition        = posdaoTransition;
     _forSealing = forSealing;
 }
        public void SetUp()
        {
            _db = Substitute.For <IDb>();
            _db[ContractValidator.PendingValidatorsKey.Bytes].Returns((byte[])null);
            _stateProvider            = Substitute.For <IStateProvider>();
            _abiEncoder               = Substitute.For <IAbiEncoder>();
            _logManager               = Substitute.For <ILogManager>();
            _blockTree                = Substitute.For <IBlockTree>();
            _blockFinalizationManager = Substitute.For <IBlockFinalizationManager>();
            _receiptsStorage          = Substitute.For <IReceiptStorage>();
            _validator                = new AuRaParameters.Validator()
            {
                Addresses     = new[] { _contractAddress },
                ValidatorType = AuRaParameters.ValidatorType.Contract
            };

            _block = new Block(Prepare.A.BlockHeader().WithNumber(1).WithAura(1, Bytes.Empty).TestObject, new BlockBody());

            _transactionProcessor = Substitute.For <ITransactionProcessor>();

            _abiEncoder
            .Encode(AbiEncodingStyle.IncludeSignature, Arg.Is <AbiSignature>(s => s.Name == "getValidators"), Arg.Any <object[]>())
            .Returns(_getValidatorsData);

            _abiEncoder
            .Encode(AbiEncodingStyle.IncludeSignature, Arg.Is <AbiSignature>(s => s.Name == "finalizeChange"), Arg.Any <object[]>())
            .Returns(_finalizeChangeData);
        }
Example #5
0
        public void SetUp()
        {
            _validator           = GetValidator();
            _innerValidators     = new SortedList <long, IAuRaValidatorProcessor>();
            _factory             = Substitute.For <IAuRaAdditionalBlockProcessorFactory>();
            _logManager          = Substitute.For <ILogManager>();
            _finalizationManager = Substitute.For <IBlockFinalizationManager>();
            _finalizationManager.LastFinalizedBlockLevel.Returns(-1);

            _factory.CreateValidatorProcessor(default, default)
Example #6
0
        public void SetUp()
        {
            _validator           = GetValidator(AuRaParameters.ValidatorType.List);
            _innerValidators     = new SortedList <long, IAuRaValidator>();
            _factory             = Substitute.For <IAuRaValidatorFactory>();
            _logManager          = LimboLogs.Instance;
            _finalizationManager = Substitute.For <IBlockFinalizationManager>();
            _blockTree           = Substitute.For <IBlockTree>();
            _validatorStore      = Substitute.For <IValidatorStore>();
            _finalizationManager.LastFinalizedBlockLevel.Returns(0);

            _factory.CreateValidatorProcessor(default, default, default)
Example #7
0
        private void SetFinalizationManager(IBlockFinalizationManager finalizationManager, BlockHeader parentHeader)
        {
            _blockFinalizationManager = finalizationManager ?? throw new ArgumentNullException(nameof(finalizationManager));

            if (!ForSealing)
            {
                _blockFinalizationManager.BlocksFinalized += OnBlocksFinalized;

                if (parentHeader != null)
                {
                    Validators = LoadValidatorsFromContract(parentHeader);
                    InitValidatorStore();
                }
            }
        }
 public ReportingContractBasedValidator(AuRaParameters.Validator validator,
                                        IStateProvider stateProvider,
                                        IAbiEncoder abiEncoder,
                                        ITransactionProcessor transactionProcessor,
                                        IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource,
                                        IBlockTree blockTree,
                                        IReceiptFinder receiptFinder,
                                        IValidatorStore validatorStore,
                                        IValidSealerStrategy validSealerStrategy,
                                        IBlockFinalizationManager finalizationManager,
                                        BlockHeader parentHeader,
                                        ILogManager logManager,
                                        long startBlockNumber,
                                        bool forSealing = false)
     : base(validator, stateProvider, abiEncoder, transactionProcessor, readOnlyTransactionProcessorSource, blockTree, receiptFinder, validatorStore, validSealerStrategy, finalizationManager, parentHeader, logManager, startBlockNumber, forSealing)
 {
 }
Example #9
0
        void IAuRaValidator.SetFinalizationManager(IBlockFinalizationManager finalizationManager)
        {
            if (_blockFinalizationManager != null)
            {
                _blockFinalizationManager.BlocksFinalized -= OnBlocksFinalized;
            }

            _blockFinalizationManager = finalizationManager;

            if (_blockFinalizationManager != null)
            {
                _blockFinalizationManager.BlocksFinalized += OnBlocksFinalized;
                InitCurrentValidator();
            }

            _currentValidator?.SetFinalizationManager(finalizationManager);
        }
Example #10
0
        void IAuRaValidator.SetFinalizationManager(IBlockFinalizationManager finalizationManager, bool forProducing)
        {
            if (_blockFinalizationManager != null)
            {
                _blockFinalizationManager.BlocksFinalized -= OnBlocksFinalized;
            }

            _blockFinalizationManager = finalizationManager;
            _isProducing = forProducing;

            if (_blockFinalizationManager != null)
            {
                _blockFinalizationManager.BlocksFinalized += OnBlocksFinalized;
                InitCurrentValidator(_blockFinalizationManager.LastFinalizedBlockLevel);
            }

            _currentValidator?.SetFinalizationManager(finalizationManager, forProducing);
        }
 public ContractBasedValidator(
     IValidatorContract validatorContract,
     IBlockTree blockTree,
     IReceiptFinder receiptFinder,
     IValidatorStore validatorStore,
     IValidSealerStrategy validSealerStrategy,
     IBlockFinalizationManager finalizationManager,
     BlockHeader parentHeader,
     ILogManager logManager,
     long startBlockNumber,
     long posdaoTransition = long.MaxValue,
     bool forSealing       = false) : base(validSealerStrategy, validatorStore, logManager, startBlockNumber, forSealing)
 {
     BlockTree         = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
     _receiptFinder    = receiptFinder ?? throw new ArgumentNullException(nameof(receiptFinder));
     _posdaoTransition = posdaoTransition;
     _logger           = logManager?.GetClassLogger <ContractBasedValidator>() ?? throw new ArgumentNullException(nameof(logManager));
     ValidatorContract = validatorContract ?? throw new ArgumentNullException(nameof(validatorContract));
     SetPendingValidators(LoadPendingValidators());
     SetFinalizationManager(finalizationManager, parentHeader ?? BlockTree.Head?.Header);
 }
Example #12
0
 public AuRaValidatorFactory(IStateProvider stateProvider,
                             IAbiEncoder abiEncoder,
                             ITransactionProcessor transactionProcessor,
                             IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource,
                             IBlockTree blockTree,
                             IReceiptFinder receiptFinder,
                             IValidatorStore validatorStore,
                             IBlockFinalizationManager finalizationManager,
                             ILogManager logManager,
                             bool forSealing = false)
 {
     _stateProvider        = stateProvider;
     _abiEncoder           = abiEncoder;
     _transactionProcessor = transactionProcessor;
     _readOnlyReadOnlyTransactionProcessorSource = readOnlyTransactionProcessorSource;
     _blockTree           = blockTree;
     _receiptFinder       = receiptFinder;
     _validatorStore      = validatorStore;
     _finalizationManager = finalizationManager;
     _logManager          = logManager;
     _forSealing          = forSealing;
 }
 public virtual void SetFinalizationManager(IBlockFinalizationManager finalizationManager, in bool forSealing)
Example #14
0
 public override void SetFinalizationManager(IBlockFinalizationManager finalizationManager, in bool forSealing)
Example #15
0
 public void SetFinalizationManager(IBlockFinalizationManager finalizationManager, BlockHeader parentHeader)
 {
     _blockFinalizationManager = finalizationManager ?? throw new ArgumentNullException(nameof(finalizationManager));
     _blockFinalizationManager.BlocksFinalized += OnBlocksFinalized;
     InitCurrentValidator(_blockFinalizationManager.LastFinalizedBlockLevel, parentHeader);
 }
 protected virtual void SetFinalizationManagerInternal(IBlockFinalizationManager finalizationManager, in bool forProducing)
Example #17
0
 void IAuRaValidator.SetFinalizationManager(IBlockFinalizationManager finalizationManager)
 {
 }                                                                                             // ListValidator doesn't change its behaviour/state based on Finalization of blocks, only Multi and Contract validators do.
Example #18
0
 public void SetFinalizationManager(IBlockFinalizationManager finalizationManager, in bool forSealing = false)
 void IAuRaValidator.SetFinalizationManager(IBlockFinalizationManager finalizationManager, bool forProducing)
 {
     SetFinalizationManagerInternal(finalizationManager, forProducing);
 }