protected override TxPool.TxPool CreateTxPool(PersistentTxStorage txStorage) { // This has to be different object than the _processingReadOnlyTransactionProcessorSource as this is in separate thread var txPoolReadOnlyTransactionProcessorSource = new ReadOnlyTxProcessorSource(_api.DbProvider, _api.BlockTree, _api.SpecProvider, _api.LogManager); 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, _api.SpecProvider, NethermindApi.Config <ITxPoolConfig>(), _api.ChainHeadStateProvider, _api.LogManager, CreateTxPoolTxComparer(txPriorityContract, localDataSource), new TxFilterAdapter(_api.BlockTree, txPoolFilter))); }
private ITxFilter?GetTxPermissionFilter( ReadOnlyTxProcessingEnv environment, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { if (_api.ChainSpec == null) { throw new StepDependencyException(nameof(_api.ChainSpec)); } if (_api.ChainSpec.Parameters.TransactionPermissionContract != null) { var txPermissionFilter = new PermissionBasedTxFilter( new VersionedTransactionPermissionContract(_api.AbiEncoder, _api.ChainSpec.Parameters.TransactionPermissionContract, _api.ChainSpec.Parameters.TransactionPermissionContractTransition ?? 0, readOnlyTxProcessorSource, _api.TransactionPermissionContractVersions), _api.TxFilterCache, environment.StateProvider, _api.LogManager); return(txPermissionFilter); } return(null); }
private IGasLimitCalculator CreateGasLimitCalculator(ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { if (_api.ChainSpec == null) { throw new StepDependencyException(nameof(_api.ChainSpec)); } var blockGasLimitContractTransitions = _api.ChainSpec.AuRa.BlockGasLimitContractTransitions; IGasLimitCalculator gasLimitCalculator = new TargetAdjustedGasLimitCalculator(_api.SpecProvider, NethermindApi.Config <IMiningConfig>()); if (blockGasLimitContractTransitions?.Any() == true) { AuRaContractGasLimitOverride auRaContractGasLimitOverride = new AuRaContractGasLimitOverride( blockGasLimitContractTransitions.Select(blockGasLimitContractTransition => new BlockGasLimitContract( _api.AbiEncoder, blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key, readOnlyTxProcessorSource)) .ToArray <IBlockGasLimitContract>(), _api.GasLimitCalculatorCache, _auraConfig?.Minimum2MlnGasPerBlockWhenUsingBlockGasLimitContract == true, gasLimitCalculator, _api.LogManager); gasLimitCalculator = auRaContractGasLimitOverride; } return(gasLimitCalculator); }
protected virtual ITxSource CreateTxSourceForProducer( ReadOnlyTxProcessingEnv processingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { ITxSource innerSource = new TxPoolTxSource(_api.TxPool, processingEnv.StateReader, _api.LogManager); return(new FilteredTxSource(innerSource, CreateGasPriceTxFilter(readOnlyTxProcessorSource))); }
private IAuRaValidator CreateAuRaValidator(IBlockProcessor processor, ReadOnlyTxProcessorSource 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)); } 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.ReportingContractValidatorCache, chainSpecAuRa.PosdaoTransition, false) .CreateValidatorProcessor(chainSpecAuRa.Validators, _api.BlockTree.Head?.Header); if (validator is IDisposable disposableValidator) { _api.DisposeStack.Push(disposableValidator); } return(validator); }
protected override ITxFilter CreateGasPriceTxFilter(ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { ITxFilter gasPriceTxFilter = base.CreateGasPriceTxFilter(readOnlyTxProcessorSource); 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); }
protected override TxPoolTxSource CreateTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { // We need special one for TxPriority as its following Head separately with events and we want rules from Head, not produced block ReadOnlyTxProcessorSource readOnlyTxProcessorSourceForTxPriority = new ReadOnlyTxProcessorSource(_api.DbProvider, _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, IContractDataStoreCollection <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, TxPriorityContract.DestinationSortedListContractDataStoreCollection> prioritiesContractDataStore = new DictionaryContractDataStore <TxPriorityContract.Destination, TxPriorityContract.DestinationSortedListContractDataStoreCollection>( 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)); } }
protected BlockProducerContext GetProducerChain() { BlockProducerContext Create() { ReadOnlyDbProvider dbProvider = new ReadOnlyDbProvider(_api.DbProvider, false); ReadOnlyBlockTree blockTree = new ReadOnlyBlockTree(_api.BlockTree); ReadOnlyTxProcessingEnv txProcessingEnv = new ReadOnlyTxProcessingEnv(dbProvider, blockTree, _api.SpecProvider, _api.LogManager); ReadOnlyTxProcessorSource txProcessorSource = new ReadOnlyTxProcessorSource(txProcessingEnv); BlockProcessor blockProcessor = CreateBlockProcessor(txProcessingEnv, txProcessorSource, dbProvider); IBlockchainProcessor blockchainProcessor = new BlockchainProcessor( blockTree, blockProcessor, _api.RecoveryStep, _api.LogManager, BlockchainProcessor.Options.NoReceipts); OneTimeChainProcessor chainProcessor = new OneTimeChainProcessor( dbProvider, blockchainProcessor); return(new BlockProducerContext { ChainProcessor = chainProcessor, ReadOnlyStateProvider = txProcessingEnv.StateProvider, TxSource = CreateTxSourceForProducer(txProcessingEnv, txProcessorSource), ReadOnlyTxProcessingEnv = txProcessingEnv, ReadOnlyTxProcessorSource = txProcessorSource }); } return(_blockProducerContext ??= Create()); }
protected virtual BlockProcessor CreateBlockProcessor( ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource, IReadOnlyDbProvider readOnlyDbProvider) { if (_api.SpecProvider == null) { throw new StepDependencyException(nameof(_api.SpecProvider)); } if (_api.BlockValidator == null) { throw new StepDependencyException(nameof(_api.BlockValidator)); } if (_api.RewardCalculatorSource == null) { throw new StepDependencyException(nameof(_api.RewardCalculatorSource)); } if (_api.ReceiptStorage == null) { throw new StepDependencyException(nameof(_api.ReceiptStorage)); } if (_api.TxPool == null) { throw new StepDependencyException(nameof(_api.TxPool)); } return(new BlockProcessor( _api.SpecProvider, _api.BlockValidator, _api.RewardCalculatorSource.Get(readOnlyTxProcessingEnv.TransactionProcessor), readOnlyTxProcessingEnv.TransactionProcessor, readOnlyDbProvider.StateDb, readOnlyDbProvider.CodeDb, readOnlyTxProcessingEnv.StateProvider, readOnlyTxProcessingEnv.StorageProvider, _api.TxPool, _api.ReceiptStorage, _api.LogManager)); }
protected override BlockProcessor CreateBlockProcessor() { AbiEncoder abiEncoder = new AbiEncoder(); ReadOnlyTxProcessorSource readOnlyTransactionProcessorSource = new ReadOnlyTxProcessorSource(DbProvider, BlockTree, SpecProvider, LimboLogs.Instance); CertifierContract = new CertifierContract( abiEncoder, new RegisterContract(abiEncoder, ChainSpec.Parameters.Registrar, readOnlyTransactionProcessorSource), readOnlyTransactionProcessorSource); return(new AuRaBlockProcessor( SpecProvider, Always.Valid, new RewardCalculator(SpecProvider), TxProcessor, StateDb, CodeDb, State, Storage, TxPool, ReceiptStorage, LimboLogs.Instance, BlockTree)); }
protected override BlockProcessor CreateBlockProcessor( ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTxProcessorSource 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, readOnlyDbProvider.StateDb, readOnlyDbProvider.CodeDb, readOnlyTxProcessingEnv.StateProvider, readOnlyTxProcessingEnv.StorageProvider, NullTxPool.Instance, _api.ReceiptStorage, _api.LogManager, readOnlyTxProcessingEnv.BlockTree, _txPermissionFilter, CreateGasLimitCalculator(readOnlyTxProcessorSource) as AuRaContractGasLimitOverride) { AuRaValidator = _validator }); }
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 = new ReadOnlyTxProcessorSource(_api.DbProvider, _api.BlockTree, _api.SpecProvider, _api.LogManager); var txPermissionFilterOnlyTxProcessorSource = new ReadOnlyTxProcessorSource(_api.DbProvider, _api.BlockTree, _api.SpecProvider, _api.LogManager); ITxFilter?txPermissionFilter = TxFilterBuilders.CreateTxPermissionFilter(_api, txPermissionFilterOnlyTxProcessorSource); var processor = new AuRaBlockProcessor( _api.SpecProvider, _api.BlockValidator, _api.RewardCalculatorSource.Get(_api.TransactionProcessor), _api.TransactionProcessor, _api.DbProvider.StateDb, _api.DbProvider.CodeDb, _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); }
protected override ITxFilter CreateTxSourceFilter(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) => TxFilterBuilders.CreateAuRaTxFilter( NethermindApi.Config <IMiningConfig>(), _api, readOnlyTxProcessorSource, _minGasPricesContractDataStore);
protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv processingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { bool CheckAddPosdaoTransactions(IList <ITxSource> list, long auRaPosdaoTransition) { if (auRaPosdaoTransition < AuRaParameters.TransitionDisabled && _validator is ITxSource validatorSource) { list.Insert(0, validatorSource); return(true); } return(false); } bool CheckAddRandomnessTransactions(IList <ITxSource> list, IDictionary <long, Address> randomnessContractAddress, ISigner signer) { IList <IRandomContract> GetRandomContracts( IDictionary <long, Address> randomnessContractAddressPerBlock, IAbiEncoder abiEncoder, IReadOnlyTransactionProcessorSource txProcessorSource, ISigner signer) => randomnessContractAddressPerBlock .Select(kvp => new RandomContract( abiEncoder, kvp.Value, txProcessorSource, kvp.Key, signer)) .ToArray <IRandomContract>(); if (randomnessContractAddress?.Any() == true) { var randomContractTxSource = new RandomContractTxSource( GetRandomContracts(randomnessContractAddress, _api.AbiEncoder, readOnlyTxProcessorSource, signer), new EciesCipher(_api.CryptoRandom), _api.NodeKey, _api.CryptoRandom, _api.LogManager); list.Insert(0, randomContractTxSource); return(true); } return(false); } 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)); } IList <ITxSource> txSources = new List <ITxSource> { base.CreateTxSourceForProducer(processingEnv, readOnlyTxProcessorSource) }; bool needSigner = false; needSigner |= CheckAddPosdaoTransactions(txSources, _api.ChainSpec.AuRa.PosdaoTransition); needSigner |= CheckAddRandomnessTransactions(txSources, _api.ChainSpec.AuRa.RandomnessContractAddress, _api.EngineSigner); ITxSource txSource = txSources.Count > 1 ? new CompositeTxSource(txSources.ToArray()) : txSources[0]; if (needSigner) { TxSealer transactionSealer = new TxSealer(_api.EngineSigner, _api.Timestamper); txSource = new GeneratedTxSource(txSource, transactionSealer, processingEnv.StateReader, _api.LogManager); } if (_txPermissionFilter != null) { // we now only need to filter generated transactions here, as regular ones are filtered on TxPoolTxSource filter based on CreateTxSourceFilter method txSource = new FilteredTxSource <GeneratedTransaction>(txSource, _txPermissionFilter); } return(txSource); }
protected virtual ITxFilter CreateGasPriceTxFilter(ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { UInt256 minGasPrice = _api.Config <IMiningConfig>().MinGasPrice; return(new MinGasPriceTxFilter(minGasPrice)); }
protected override ITxSource CreateTxSourceForProducer( ReadOnlyTxProcessingEnv processingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) => new SinglePendingTxSelector(base.CreateTxSourceForProducer(processingEnv, readOnlyTxProcessorSource));
protected virtual ITxFilter CreateTxSourceFilter(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) => TxFilterBuilders.CreateStandardTxFilter(_api.Config <IMiningConfig>());
protected virtual TxPoolTxSource CreateTxPoolTxSource(ReadOnlyTxProcessingEnv processingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) { ITxFilter txSourceFilter = CreateTxSourceFilter(processingEnv, readOnlyTxProcessorSource); return(new TxPoolTxSource(_api.TxPool, processingEnv.StateReader, _api.LogManager, txSourceFilter)); }
protected virtual ITxSource CreateTxSourceForProducer( ReadOnlyTxProcessingEnv processingEnv, ReadOnlyTxProcessorSource readOnlyTxProcessorSource) => CreateTxPoolTxSource(processingEnv, readOnlyTxProcessorSource);