コード例 #1
0
        protected override TxPool.TxPool CreateTxPool(PersistentTxStorage txStorage)
        {
            // This has to be different object than the _processingReadOnlyTransactionProcessorSource as this is in separate thread
            var txPoolReadOnlyTransactionProcessorSource = CreateReadOnlyTransactionProcessorSource();

            var(txPriorityContract, localDataSource) = TxFilterBuilders.CreateTxPrioritySources(_auraConfig, _api, txPoolReadOnlyTransactionProcessorSource !);

            ReportTxPriorityRules(txPriorityContract, localDataSource);

            var minGasPricesContractDataStore = TxFilterBuilders.CreateMinGasPricesDataStore(_api, txPriorityContract, localDataSource);

            ITxFilter txPoolFilter = TxFilterBuilders.CreateAuRaTxFilter(
                NethermindApi.Config <IMiningConfig>(),
                _api,
                txPoolReadOnlyTransactionProcessorSource,
                minGasPricesContractDataStore);

            return(new FilteredTxPool(
                       txStorage,
                       _api.EthereumEcdsa,
                       new ChainHeadSpecProvider(_api.SpecProvider, _api.BlockTree),
                       NethermindApi.Config <ITxPoolConfig>(),
                       _api.ChainHeadStateProvider,
                       _api.TxValidator,
                       _api.LogManager,
                       CreateTxPoolTxComparer(txPriorityContract, localDataSource),
                       new TxFilterAdapter(_api.BlockTree, txPoolFilter)));
        }
コード例 #2
0
        protected override TxPoolTxSource CreateTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, IReadOnlyTxProcessorSource readOnlyTxProcessorSource)
        {
            // We need special one for TxPriority as its following Head separately with events and we want rules from Head, not produced block
            IReadOnlyTxProcessorSource readOnlyTxProcessorSourceForTxPriority =
                new ReadOnlyTxProcessingEnv(_api.DbProvider, _api.ReadOnlyTrieStore, _api.BlockTree, _api.SpecProvider, _api.LogManager);

            (_txPriorityContract, _localDataSource) = TxFilterBuilders.CreateTxPrioritySources(_auraConfig, _api, readOnlyTxProcessorSourceForTxPriority);

            if (_txPriorityContract != null || _localDataSource != null)
            {
                _minGasPricesContractDataStore = TxFilterBuilders.CreateMinGasPricesDataStore(_api, _txPriorityContract, _localDataSource) !;
                _api.DisposeStack.Push(_minGasPricesContractDataStore);

                ContractDataStore <Address> whitelistContractDataStore = new ContractDataStoreWithLocalData <Address>(
                    new HashSetContractDataStoreCollection <Address>(),
                    _txPriorityContract?.SendersWhitelist,
                    _api.BlockTree,
                    _api.ReceiptFinder,
                    _api.LogManager,
                    _localDataSource?.GetWhitelistLocalDataSource() ?? new EmptyLocalDataSource <IEnumerable <Address> >());

                DictionaryContractDataStore <TxPriorityContract.Destination> prioritiesContractDataStore =
                    new DictionaryContractDataStore <TxPriorityContract.Destination>(
                        new TxPriorityContract.DestinationSortedListContractDataStoreCollection(),
                        _txPriorityContract?.Priorities,
                        _api.BlockTree,
                        _api.ReceiptFinder,
                        _api.LogManager,
                        _localDataSource?.GetPrioritiesLocalDataSource());

                _api.DisposeStack.Push(whitelistContractDataStore);
                _api.DisposeStack.Push(prioritiesContractDataStore);


                return(new TxPriorityTxSource(
                           _api.TxPool,
                           processingEnv.StateReader,
                           _api.LogManager,
                           CreateTxSourceFilter(processingEnv, readOnlyTxProcessorSource),
                           whitelistContractDataStore,
                           prioritiesContractDataStore));
            }
            else
            {
                return(base.CreateTxPoolTxSource(processingEnv, readOnlyTxProcessorSource));
            }
        }
コード例 #3
0
        protected override BlockProcessor CreateBlockProcessor()
        {
            if (_api.SpecProvider == null) throw new StepDependencyException(nameof(_api.SpecProvider));
            if (_api.ChainHeadStateProvider == null) throw new StepDependencyException(nameof(_api.ChainHeadStateProvider));
            if (_api.BlockValidator == null) throw new StepDependencyException(nameof(_api.BlockValidator));
            if (_api.RewardCalculatorSource == null) throw new StepDependencyException(nameof(_api.RewardCalculatorSource));
            if (_api.TransactionProcessor == null) throw new StepDependencyException(nameof(_api.TransactionProcessor));
            if (_api.DbProvider == null) throw new StepDependencyException(nameof(_api.DbProvider));
            if (_api.StateProvider == null) throw new StepDependencyException(nameof(_api.StateProvider));
            if (_api.StorageProvider == null) throw new StepDependencyException(nameof(_api.StorageProvider));
            if (_api.TxPool == null) throw new StepDependencyException(nameof(_api.TxPool));
            if (_api.ReceiptStorage == null) throw new StepDependencyException(nameof(_api.ReceiptStorage));
       
            var processingReadOnlyTransactionProcessorSource = CreateReadOnlyTransactionProcessorSource();
            var txPermissionFilterOnlyTxProcessorSource = CreateReadOnlyTransactionProcessorSource();
            ITxFilter? txPermissionFilter = TxFilterBuilders.CreateTxPermissionFilter(_api, txPermissionFilterOnlyTxProcessorSource);
            
            var processor = new AuRaBlockProcessor(
                _api.SpecProvider,
                _api.BlockValidator,
                _api.RewardCalculatorSource.Get(_api.TransactionProcessor),
                _api.TransactionProcessor,
                _api.StateProvider,
                _api.StorageProvider,
                _api.TxPool,
                _api.ReceiptStorage,
                _api.LogManager,
                _api.BlockTree,
                txPermissionFilter,
                GetGasLimitCalculator());
            
            var auRaValidator = CreateAuRaValidator(processor, processingReadOnlyTransactionProcessorSource);
            processor.AuRaValidator = auRaValidator;
            var reportingValidator = auRaValidator.GetReportingValidator();
            _api.ReportingValidator = reportingValidator;
            if (_sealValidator != null)
            {
                _sealValidator.ReportingValidator = reportingValidator;
            }

            return processor;
        }
コード例 #4
0
        private static ITxFilter CreateBaseAuRaTxFilter(
            IMiningConfig miningConfig,
            AuRaNethermindApi api,
            IReadOnlyTxProcessorSource readOnlyTxProcessorSource,
            IDictionaryContractDataStore <TxPriorityContract.Destination>?minGasPricesContractDataStore)
        {
            ITxFilter gasPriceTxFilter = TxFilterBuilders.CreateStandardTxFilter(miningConfig);

            if (minGasPricesContractDataStore != null)
            {
                gasPriceTxFilter = new MinGasPriceContractTxFilter(gasPriceTxFilter, minGasPricesContractDataStore);
            }

            Address?registrar = api.ChainSpec?.Parameters.Registrar;

            if (registrar != null)
            {
                RegisterContract  registerContract  = new RegisterContract(api.AbiEncoder, registrar, readOnlyTxProcessorSource);
                CertifierContract certifierContract = new CertifierContract(api.AbiEncoder, registerContract, readOnlyTxProcessorSource);
                return(new TxCertifierFilter(certifierContract, gasPriceTxFilter, api.LogManager));
            }

            return(gasPriceTxFilter);
        }
コード例 #5
0
 protected override ITxFilter CreateTxSourceFilter(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, IReadOnlyTxProcessorSource readOnlyTxProcessorSource) =>
 TxFilterBuilders.CreateAuRaTxFilter(
     NethermindApi.Config <IMiningConfig>(),
     _api,
     readOnlyTxProcessorSource,
     _minGasPricesContractDataStore);
コード例 #6
0
        protected override BlockProcessor CreateBlockProcessor(
            ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv,
            IReadOnlyTxProcessorSource readOnlyTxProcessorSource,
            IReadOnlyDbProvider readOnlyDbProvider)
        {
            if (_api.RewardCalculatorSource == null)
            {
                throw new StepDependencyException(nameof(_api.RewardCalculatorSource));
            }
            if (_api.ValidatorStore == null)
            {
                throw new StepDependencyException(nameof(_api.ValidatorStore));
            }
            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));
            }

            var chainSpecAuRa = _api.ChainSpec.AuRa;

            _txPermissionFilter = TxFilterBuilders.CreateTxPermissionFilter(_api, readOnlyTxProcessorSource);

            _validator = new AuRaValidatorFactory(
                readOnlyTxProcessingEnv.StateProvider,
                _api.AbiEncoder,
                readOnlyTxProcessingEnv.TransactionProcessor,
                readOnlyTxProcessorSource,
                readOnlyTxProcessingEnv.BlockTree,
                _api.ReceiptStorage,
                _api.ValidatorStore,
                _api.FinalizationManager,
                NullTxSender.Instance,
                NullTxPool.Instance,
                NethermindApi.Config <IMiningConfig>(),
                _api.LogManager,
                _api.EngineSigner,
                _api.ReportingContractValidatorCache,
                chainSpecAuRa.PosdaoTransition,
                true)
                         .CreateValidatorProcessor(chainSpecAuRa.Validators, _api.BlockTree.Head?.Header);

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

            return(new AuRaBlockProcessor(
                       _api.SpecProvider,
                       _api.BlockValidator,
                       _api.RewardCalculatorSource.Get(readOnlyTxProcessingEnv.TransactionProcessor),
                       readOnlyTxProcessingEnv.TransactionProcessor,
                       readOnlyTxProcessingEnv.StateProvider,
                       readOnlyTxProcessingEnv.StorageProvider,
                       NullTxPool.Instance,
                       _api.ReceiptStorage,
                       _api.LogManager,
                       readOnlyTxProcessingEnv.BlockTree,
                       _txPermissionFilter,
                       CreateGasLimitCalculator(readOnlyTxProcessorSource) as AuRaContractGasLimitOverride)
            {
                AuRaValidator = _validator
            });
        }
コード例 #7
0
 protected virtual ITxFilter CreateTxSourceFilter(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) =>
 TxFilterBuilders.CreateStandardTxFilter(_api.Config <IMiningConfig>());