private IGasLimitOverride?GetGasLimitOverride( ReadOnlyTxProcessingEnv environment, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource, IStateProvider?stateProvider = null) { if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } var blockGasLimitContractTransitions = _context.ChainSpec.AuRa.BlockGasLimitContractTransitions; if (blockGasLimitContractTransitions?.Any() == true) { var gasLimitOverride = new AuRaContractGasLimitOverride( blockGasLimitContractTransitions.Select(blockGasLimitContractTransition => new BlockGasLimitContract( _context.AbiEncoder, blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key, readOnlyTransactionProcessorSource)) .ToArray <IBlockGasLimitContract>(), _context.GasLimitOverrideCache, _auraConfig?.Minimum2MlnGasPerBlockWhenUsingBlockGasLimitContract == true, _context.LogManager); return(gasLimitOverride); } return(null); }
protected override void InitSealEngine() { if (_context.DbProvider == null) { throw new StepDependencyException(nameof(_context.DbProvider)); } if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.EthereumEcdsa == null) { throw new StepDependencyException(nameof(_context.EthereumEcdsa)); } if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } AbiEncoder abiEncoder = new AbiEncoder(); _context.ValidatorStore = new ValidatorStore(_context.DbProvider.BlockInfosDb); IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource = new ReadOnlyTransactionProcessorSource(_context.DbProvider, _context.BlockTree, _context.SpecProvider, _context.LogManager); IAuRaValidatorProcessorExtension validatorProcessorExtension = new AuRaValidatorProcessorFactory(_context.StateProvider, abiEncoder, _context.TransactionProcessor, readOnlyTransactionProcessorSource, _context.BlockTree, _context.ReceiptStorage, _context.ValidatorStore, _context.LogManager) .CreateValidatorProcessor(_context.ChainSpec.AuRa.Validators); AuRaStepCalculator auRaStepCalculator = new AuRaStepCalculator(_context.ChainSpec.AuRa.StepDuration, _context.Timestamper); _context.SealValidator = new AuRaSealValidator(_context.ChainSpec.AuRa, auRaStepCalculator, _context.ValidatorStore, _context.EthereumEcdsa, _context.LogManager); _context.RewardCalculatorSource = AuRaRewardCalculator.GetSource(_context.ChainSpec.AuRa, abiEncoder); _context.Sealer = new AuRaSealer(_context.BlockTree, _context.ValidatorStore, auRaStepCalculator, _context.NodeKey.Address, new BasicWallet(_context.NodeKey), new ValidSealerStrategy(), _context.LogManager); _context.AuRaBlockProcessorExtension = validatorProcessorExtension; }
private ITxPermissionFilter?GetTxPermissionFilter( ReadOnlyTxProcessingEnv environment, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource, IStateProvider?stateProvider = null) { if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.ChainSpec.Parameters.TransactionPermissionContract != null) { var txPermissionFilter = new TxPermissionFilter( new VersionedTransactionPermissionContract(_context.AbiEncoder, _context.ChainSpec.Parameters.TransactionPermissionContract, _context.ChainSpec.Parameters.TransactionPermissionContractTransition ?? 0, readOnlyTransactionProcessorSource, _context.TransactionPermissionContractVersions), _context.TxFilterCache, environment.StateProvider, _context.LogManager); return(txPermissionFilter); } return(null); }
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 }); }
protected virtual BlockProcessor CreateBlockProcessor( ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource, IReadOnlyDbProvider readOnlyDbProvider) { if (_context.SpecProvider == null) { throw new StepDependencyException(nameof(_context.SpecProvider)); } if (_context.BlockValidator == null) { throw new StepDependencyException(nameof(_context.BlockValidator)); } if (_context.RewardCalculatorSource == null) { throw new StepDependencyException(nameof(_context.RewardCalculatorSource)); } if (_context.ReceiptStorage == null) { throw new StepDependencyException(nameof(_context.ReceiptStorage)); } if (_context.TxPool == null) { throw new StepDependencyException(nameof(_context.TxPool)); } return(new BlockProcessor( _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)); }
protected BlockProducerContext GetProducerChain() { BlockProducerContext Create() { ReadOnlyDbProvider readOnlyDbProvider = new ReadOnlyDbProvider(_context.DbProvider, false); ReadOnlyBlockTree readOnlyBlockTree = new ReadOnlyBlockTree(_context.BlockTree); ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = new ReadOnlyTxProcessingEnv(readOnlyDbProvider, readOnlyBlockTree, _context.SpecProvider, _context.LogManager); var readOnlyTransactionProcessorSource = new ReadOnlyTransactionProcessorSource(readOnlyTxProcessingEnv); BlockProcessor blockProcessor = CreateBlockProcessor(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource, readOnlyDbProvider); OneTimeChainProcessor chainProcessor = new OneTimeChainProcessor(readOnlyDbProvider, new BlockchainProcessor(readOnlyBlockTree, blockProcessor, _context.RecoveryStep, _context.LogManager, BlockchainProcessor.Options.NoReceipts)); return(new BlockProducerContext { ChainProcessor = chainProcessor, ReadOnlyStateProvider = readOnlyTxProcessingEnv.StateProvider, TxSource = CreateTxSourceForProducer(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource), ReadOnlyTxProcessingEnv = readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource = readOnlyTransactionProcessorSource }); } return(_blockProducerContext ??= Create()); }
protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource) { 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, _context.AbiEncoder, readOnlyTransactionProcessorSource, signer), new EciesCipher(_context.CryptoRandom), _context.NodeKey, _context.CryptoRandom); list.Insert(0, randomContractTxSource); return(true); } return(false); } 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)); } IList <ITxSource> txSources = new List <ITxSource> { base.CreateTxSourceForProducer(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource) }; bool needSigner = false; needSigner |= CheckAddPosdaoTransactions(txSources, _context.ChainSpec.AuRa.PosdaoTransition); needSigner |= CheckAddRandomnessTransactions(txSources, _context.ChainSpec.AuRa.RandomnessContractAddress, _context.Signer); ITxSource txSource = txSources.Count > 1 ? new CompositeTxSource(txSources.ToArray()) : txSources[0]; if (needSigner) { TxSealer transactionSealer = new TxSealer(_context.Signer, _context.Timestamper); txSource = new GeneratedTxSourceSealer(txSource, transactionSealer, readOnlyTxProcessingEnv.StateReader); } var txPermissionFilter = GetTxPermissionFilter(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource); if (txPermissionFilter != null) { txSource = new TxFilterTxSource(txSource, txPermissionFilter); } return(txSource); }
protected virtual ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource) => new TxPoolTxSource(_context.TxPool, readOnlyTxProcessingEnv.StateReader, _context.LogManager);
protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource) => new SinglePendingTxSelector(base.CreateTxSourceForProducer(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource));
protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource) { IList <RandomContract> GetRandomContracts( IDictionary <long, Address> randomnessContractAddress, ITransactionProcessor transactionProcessor, IAbiEncoder abiEncoder, IReadOnlyTransactionProcessorSource txProcessorSource, Address nodeAddress) => randomnessContractAddress .Select(kvp => new RandomContract(transactionProcessor, abiEncoder, kvp.Value, txProcessorSource, kvp.Key, nodeAddress)) .ToArray(); if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.BlockTree == null) { throw new StepDependencyException(nameof(_context.BlockTree)); } if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } IList <ITxSource> txSources = new List <ITxSource> { base.CreateTxSourceForProducer(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource) }; bool needSigner = false; if (_context.ChainSpec.AuRa.RandomnessContractAddress?.Any() == true) { var randomContractTxSource = new RandomContractTxSource( GetRandomContracts(_context.ChainSpec.AuRa.RandomnessContractAddress, readOnlyTxProcessingEnv.TransactionProcessor, _context.AbiEncoder, readOnlyTransactionProcessorSource, _context.NodeKey.Address), new EciesCipher(_context.CryptoRandom), _context.NodeKey, _context.CryptoRandom); txSources.Insert(0, randomContractTxSource); needSigner = true; } ITxSource txSource = txSources.Count > 1 ? new CompositeTxSource(txSources.ToArray()) : txSources[0]; if (needSigner) { txSource = new GeneratedTxSourceApprover(txSource, new BasicWallet(_context.NodeKey), _context.Timestamper, readOnlyTxProcessingEnv.StateReader, _context.BlockTree.ChainId); } var txPermissionFilter = GetTxPermissionFilter(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource); if (txPermissionFilter != null) { txSource = new TxFilterTxSource(txSource, txPermissionFilter); } return(txSource); }