Beispiel #1
0
        public void returns_correct_validator_type(AuRaParameters.ValidatorType validatorType, Type expectedType)
        {
            var stateDb = Substitute.For <IDb>();

            stateDb[Arg.Any <byte[]>()].Returns((byte[])null);

            var factory = new AuRaValidatorFactory(Substitute.For <IStateProvider>(),
                                                   Substitute.For <IAbiEncoder>(),
                                                   Substitute.For <ITransactionProcessor>(),
                                                   Substitute.For <IReadOnlyTransactionProcessorSource>(),
                                                   Substitute.For <IBlockTree>(),
                                                   Substitute.For <IReceiptStorage>(),
                                                   Substitute.For <IValidatorStore>(),
                                                   Substitute.For <IBlockFinalizationManager>(),
                                                   LimboLogs.Instance);

            var validator = new AuRaParameters.Validator()
            {
                ValidatorType = validatorType,
                Addresses     = new[] { Address.Zero },
                Validators    = new Dictionary <long, AuRaParameters.Validator>()
                {
                    {
                        0, new AuRaParameters.Validator()
                        {
                            ValidatorType = AuRaParameters.ValidatorType.List, Addresses = new[] { Address.SystemUser }
                        }
                    }
                }
            };

            var result = factory.CreateValidatorProcessor(validator);

            result.Should().BeOfType(expectedType);
        }
        protected override BlockProcessor CreateBlockProcessor(
            ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv,
            ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource,
            IReadOnlyDbProvider readOnlyDbProvider)
        {
            if (_context.RewardCalculatorSource == null)
            {
                throw new StepDependencyException(nameof(_context.RewardCalculatorSource));
            }
            if (_context.ValidatorStore == null)
            {
                throw new StepDependencyException(nameof(_context.ValidatorStore));
            }
            if (_context.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_context.ChainSpec));
            }
            if (_context.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_context.BlockTree));
            }

            var validator = new AuRaValidatorFactory(
                readOnlyTxProcessingEnv.StateProvider,
                _context.AbiEncoder,
                readOnlyTxProcessingEnv.TransactionProcessor,
                readOnlyTransactionProcessorSource,
                readOnlyTxProcessingEnv.BlockTree,
                _context.ReceiptStorage,
                _context.ValidatorStore,
                _context.FinalizationManager,
                _context.LogManager,
                true)
                            .CreateValidatorProcessor(_context.ChainSpec.AuRa.Validators, _context.BlockTree.Head?.Header);

            if (validator is IDisposable disposableValidator)
            {
                _context.DisposeStack.Push(disposableValidator);
            }

            return(new AuRaBlockProcessor(
                       _context.SpecProvider,
                       _context.BlockValidator,
                       _context.RewardCalculatorSource.Get(readOnlyTxProcessingEnv.TransactionProcessor),
                       readOnlyTxProcessingEnv.TransactionProcessor,
                       readOnlyDbProvider.StateDb,
                       readOnlyDbProvider.CodeDb,
                       readOnlyTxProcessingEnv.StateProvider,
                       readOnlyTxProcessingEnv.StorageProvider,
                       _context.TxPool,
                       _context.ReceiptStorage,
                       _context.LogManager,
                       readOnlyTxProcessingEnv.BlockTree,
                       GetTxPermissionFilter(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource, readOnlyTxProcessingEnv.StateProvider),
                       GetGasLimitOverride(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource, readOnlyTxProcessingEnv.StateProvider))
            {
                AuRaValidator = validator
            });
        }
Beispiel #3
0
        private IAuRaValidator CreateAuRaValidator(IBlockProcessor processor, IReadOnlyTxProcessorSource readOnlyTxProcessorSource)
        {
            if (_api.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_api.ChainSpec));
            }
            if (_api.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_api.BlockTree));
            }
            if (_api.EngineSigner == null)
            {
                throw new StepDependencyException(nameof(_api.EngineSigner));
            }
            if (_api.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_api.SpecProvider));
            }

            var chainSpecAuRa = _api.ChainSpec.AuRa;

            _api.FinalizationManager = new AuRaBlockFinalizationManager(
                _api.BlockTree,
                _api.ChainLevelInfoRepository,
                processor,
                _api.ValidatorStore,
                new ValidSealerStrategy(),
                _api.LogManager,
                chainSpecAuRa.TwoThirdsMajorityTransition);

            IAuRaValidator validator = new AuRaValidatorFactory(
                _api.StateProvider,
                _api.AbiEncoder,
                _api.TransactionProcessor,
                readOnlyTxProcessorSource,
                _api.BlockTree,
                _api.ReceiptStorage,
                _api.ValidatorStore,
                _api.FinalizationManager,
                new TxPoolSender(_api.TxPool, new NonceReservingTxSealer(_api.EngineSigner, _api.Timestamper, _api.TxPool)),
                _api.TxPool,
                NethermindApi.Config <IMiningConfig>(),
                _api.LogManager,
                _api.EngineSigner,
                _api.SpecProvider,
                _api.ReportingContractValidatorCache,
                chainSpecAuRa.PosdaoTransition,
                false)
                                       .CreateValidatorProcessor(chainSpecAuRa.Validators, _api.BlockTree.Head?.Header);

            if (validator is IDisposable disposableValidator)
            {
                _api.DisposeStack.Push(disposableValidator);
            }

            return(validator);
        }
Beispiel #4
0
        private IAuRaValidator CreateAuRaValidator(IBlockProcessor processor)
        {
            if (_context.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_context.ChainSpec));
            }
            if (_context.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_context.BlockTree));
            }
            if (_context.Signer == null)
            {
                throw new StepDependencyException(nameof(_context.Signer));
            }

            var chainSpecAuRa = _context.ChainSpec.AuRa;

            _context.FinalizationManager = new AuRaBlockFinalizationManager(
                _context.BlockTree,
                _context.ChainLevelInfoRepository,
                processor,
                _context.ValidatorStore,
                new ValidSealerStrategy(),
                _context.LogManager,
                chainSpecAuRa.TwoThirdsMajorityTransition);

            IAuRaValidator validator = new AuRaValidatorFactory(
                _context.StateProvider,
                _context.AbiEncoder,
                _context.TransactionProcessor,
                GetReadOnlyTransactionProcessorSource(),
                _context.BlockTree,
                _context.ReceiptStorage,
                _context.ValidatorStore,
                _context.FinalizationManager,
                new TxPoolSender(_context.TxPool, new TxNonceTxPoolReserveSealer(_context.Signer, _context.Timestamper, _context.TxPool)),
                _context.TxPool,
                _context.LogManager,
                _context.Signer,
                _context.ReportingContractValidatorCache,
                chainSpecAuRa.PosdaoTransition,
                false)
                                       .CreateValidatorProcessor(chainSpecAuRa.Validators, _context.BlockTree.Head?.Header);

            if (validator is IDisposable disposableValidator)
            {
                _context.DisposeStack.Push(disposableValidator);
            }

            return(validator);
        }
Beispiel #5
0
        private IAuRaValidator CreateAuRaValidator(IBlockProcessor processor)
        {
            if (_context.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_context.ChainSpec));
            }
            if (_context.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_context.BlockTree));
            }

            _context.FinalizationManager = new AuRaBlockFinalizationManager(
                _context.BlockTree,
                _context.ChainLevelInfoRepository,
                processor,
                _context.ValidatorStore,
                new ValidSealerStrategy(),
                _context.LogManager,
                _context.ChainSpec.AuRa.TwoThirdsMajorityTransition);

            IAuRaValidator validator = new AuRaValidatorFactory(
                _context.StateProvider,
                _context.AbiEncoder,
                _context.TransactionProcessor,
                GetReadOnlyTransactionProcessorSource(),
                _context.BlockTree,
                _context.ReceiptStorage,
                _context.ValidatorStore,
                _context.FinalizationManager,
                _context.LogManager,
                false)
                                       .CreateValidatorProcessor(_context.ChainSpec.AuRa.Validators, _context.BlockTree.Head?.Header);

            if (validator is IDisposable disposableValidator)
            {
                _context.DisposeStack.Push(disposableValidator);
            }

            return(validator);
        }