private IGasLimitCalculator CreateGasLimitCalculator(IReadOnlyTxProcessorSource 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);
        }
Example #2
0
        public void Test(long current, long target, long expected)
        {
            MiningConfig miningConfig = new MiningConfig();

            miningConfig.TargetBlockGasLimit = target;

            TargetAdjustedGasLimitCalculator targetAdjustedGasLimitCalculator = new TargetAdjustedGasLimitCalculator(
                MainnetSpecProvider.Instance, miningConfig);

            BlockHeader header = Build.A.BlockHeader.WithGasLimit(current).TestObject;

            targetAdjustedGasLimitCalculator.GetGasLimit(header).Should().Be(expected);
        }
Example #3
0
        public Task InitBlockProducer()
        {
            if (_nethermindApi !.SealEngineType != SealEngineType.Clique)
            {
                return(Task.CompletedTask);
            }

            var(getFromApi, setInApi) = _nethermindApi !.ForProducer;

            _miningConfig = getFromApi.Config <IMiningConfig>();
            if (!_miningConfig.Enabled)
            {
                throw new InvalidOperationException("Request to start block producer while mining disabled.");
            }

            setInApi.Sealer = new CliqueSealer(
                getFromApi.EngineSigner !,
                _cliqueConfig !,
                _snapshotManager !,
                getFromApi.LogManager);

            ReadOnlyDbProvider readOnlyDbProvider = getFromApi.DbProvider.AsReadOnly(false);
            ReadOnlyBlockTree  readOnlyBlockTree  = getFromApi.BlockTree.AsReadOnly();

            ReadOnlyTxProcessingEnv producerEnv = new ReadOnlyTxProcessingEnv(
                readOnlyDbProvider,
                getFromApi.ReadOnlyTrieStore,
                readOnlyBlockTree,
                getFromApi.SpecProvider,
                getFromApi.LogManager);

            BlockProcessor producerProcessor = new BlockProcessor(
                getFromApi !.SpecProvider,
                getFromApi !.BlockValidator,
                NoBlockRewards.Instance,
                producerEnv.TransactionProcessor,
                producerEnv.StateProvider,
                producerEnv.StorageProvider,
                NullTxPool.Instance, // do not remove transactions from the pool when preprocessing
                NullReceiptStorage.Instance,
                NullWitnessCollector.Instance,
                getFromApi.LogManager);

            IBlockchainProcessor producerChainProcessor = new BlockchainProcessor(
                readOnlyBlockTree,
                producerProcessor,
                getFromApi.BlockPreprocessor,
                getFromApi.LogManager,
                BlockchainProcessor.Options.NoReceipts);

            OneTimeChainProcessor chainProcessor = new OneTimeChainProcessor(
                readOnlyDbProvider,
                producerChainProcessor);

            ITxFilter txFilter = new MinGasPriceTxFilter(_miningConfig !.MinGasPrice);
            ITxSource txSource = new TxPoolTxSource(
                getFromApi.TxPool,
                getFromApi.StateReader,
                getFromApi.LogManager,
                txFilter);

            var gasLimitCalculator = new TargetAdjustedGasLimitCalculator(getFromApi.SpecProvider, _miningConfig);

            setInApi.BlockProducer = new CliqueBlockProducer(
                txSource,
                chainProcessor,
                producerEnv.StateProvider,
                getFromApi.BlockTree !,
                getFromApi.Timestamper,
                getFromApi.CryptoRandom,
                _snapshotManager !,
                getFromApi.Sealer !,
                gasLimitCalculator,
                getFromApi.SpecProvider,
                _cliqueConfig !,
                getFromApi.LogManager);

            return(Task.CompletedTask);
        }