Beispiel #1
0
            protected override BlockProcessor CreateBlockProcessor()
            {
                var blockGasLimitContractTransition = ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
                var gasLimitContract = new BlockGasLimitContract(new AbiEncoder(), blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key,
                                                                 new ReadOnlyTxProcessorSource(DbProvider, BlockTree, SpecProvider, LimboLogs.Instance));

                GasLimitOverrideCache = new AuRaContractGasLimitOverride.Cache();
                GasLimitCalculator    = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, FollowOtherMiners.Instance, LimboLogs.Instance);

                return(new AuRaBlockProcessor(
                           SpecProvider,
                           Always.Valid,
                           new RewardCalculator(SpecProvider),
                           TxProcessor,
                           StateDb,
                           CodeDb,
                           State,
                           Storage,
                           TxPool,
                           ReceiptStorage,
                           LimboLogs.Instance,
                           BlockTree,
                           null,
                           GasLimitCalculator as AuRaContractGasLimitOverride));
            }
        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);
        }
        private AuRaContractGasLimitOverride?GetGasLimitCalculator()
        {
            if (_api.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_api.ChainSpec));
            }
            var blockGasLimitContractTransitions = _api.ChainSpec.AuRa.BlockGasLimitContractTransitions;

            if (blockGasLimitContractTransitions?.Any() == true)
            {
                _api.GasLimitCalculatorCache = new AuRaContractGasLimitOverride.Cache();

                AuRaContractGasLimitOverride gasLimitCalculator = new AuRaContractGasLimitOverride(
                    blockGasLimitContractTransitions.Select(blockGasLimitContractTransition =>
                                                            new BlockGasLimitContract(
                                                                _api.AbiEncoder,
                                                                blockGasLimitContractTransition.Value,
                                                                blockGasLimitContractTransition.Key,
                                                                CreateReadOnlyTransactionProcessorSource()))
                    .ToArray <IBlockGasLimitContract>(),
                    _api.GasLimitCalculatorCache,
                    _auraConfig.Minimum2MlnGasPerBlockWhenUsingBlockGasLimitContract,
                    new TargetAdjustedGasLimitCalculator(_api.SpecProvider, NethermindApi.Config <IMiningConfig>()),
                    _api.LogManager);

                return(gasLimitCalculator);
            }

            // do not return target gas limit calculator here - this is used for validation to check if the override should have been used
            return(null);
        }
        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);
        }
        public void GetGasLimit(bool minimum2MlnGasPerBlockWhenUsingBlockGasLimit, long blockNumber, long?expected)
        {
            var blockGasLimitContract1 = Substitute.For <IBlockGasLimitContract>();

            blockGasLimitContract1.ActivationBlock.Returns(3);
            blockGasLimitContract1.Activation.Returns(3);
            blockGasLimitContract1.BlockGasLimit(Arg.Any <BlockHeader>()).Returns(1000u);
            var blockGasLimitContract2 = Substitute.For <IBlockGasLimitContract>();

            blockGasLimitContract2.ActivationBlock.Returns(5);
            blockGasLimitContract2.Activation.Returns(5);
            blockGasLimitContract2.BlockGasLimit(Arg.Any <BlockHeader>()).Returns(3000000u);
            var blockGasLimitContract3 = Substitute.For <IBlockGasLimitContract>();

            blockGasLimitContract3.ActivationBlock.Returns(10);
            blockGasLimitContract3.Activation.Returns(10);
            blockGasLimitContract3.BlockGasLimit(Arg.Any <BlockHeader>()).Throws(new AbiException(string.Empty));

            var config = new MiningConfig {
                TargetBlockGasLimit = 4000000
            };
            var gasLimitOverride = new AuRaContractGasLimitOverride(
                new List <IBlockGasLimitContract> {
                blockGasLimitContract1, blockGasLimitContract2, blockGasLimitContract3
            },
                new AuRaContractGasLimitOverride.Cache(),
                minimum2MlnGasPerBlockWhenUsingBlockGasLimit,
                new TargetAdjustedGasLimitCalculator(MainnetSpecProvider.Instance, config),
                LimboLogs.Instance);

            var header = Build.A.BlockHeader.WithGasLimit(3999999).WithNumber(blockNumber - 1).TestObject;

            gasLimitOverride.GetGasLimit(header).Should().Be(expected);
        }
            protected override BlockProcessor CreateBlockProcessor()
            {
                KeyValuePair <long, Address> blockGasLimitContractTransition = ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
                BlockGasLimitContract        gasLimitContract = new(AbiEncoder.Instance, blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key,
                                                                    new ReadOnlyTxProcessingEnv(
                                                                        DbProvider,
                                                                        new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly(),
                                                                        BlockTree, SpecProvider, LimboLogs.Instance));

                GasLimitOverrideCache = new AuRaContractGasLimitOverride.Cache();
                GasLimitCalculator    = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, new FollowOtherMiners(SpecProvider), LimboLogs.Instance);

                return(new AuRaBlockProcessor(
                           SpecProvider,
                           Always.Valid,
                           new RewardCalculator(SpecProvider),
                           new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State),
                           State,
                           Storage,
                           ReceiptStorage,
                           LimboLogs.Instance,
                           BlockTree,
                           null,
                           GasLimitCalculator as AuRaContractGasLimitOverride));
            }
Beispiel #7
0
            protected override BlockProcessor CreateBlockProcessor()
            {
                var validator = new AuRaParameters.Validator()
                {
                    Addresses     = TestItem.Addresses,
                    ValidatorType = AuRaParameters.ValidatorType.List
                };

                var blockGasLimitContractTransition = this.ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
                var gasLimitContract = new BlockGasLimitContract(new AbiEncoder(), blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key,
                                                                 new ReadOnlyTransactionProcessorSource(DbProvider, BlockTree, SpecProvider, LimboLogs.Instance));

                GasLimitOverrideCache = new IGasLimitOverride.Cache();
                GasLimitOverride      = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, LimboLogs.Instance);

                return(new AuRaBlockProcessor(
                           SpecProvider,
                           Always.Valid,
                           new RewardCalculator(SpecProvider),
                           TxProcessor,
                           StateDb,
                           CodeDb,
                           State,
                           Storage,
                           TxPool,
                           ReceiptStorage,
                           LimboLogs.Instance,
                           BlockTree,
                           null,
                           GasLimitOverride));
            }
Beispiel #8
0
        private IGasLimitOverride?GetGasLimitOverride()
        {
            if (_context.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_context.ChainSpec));
            }
            var blockGasLimitContractTransitions = _context.ChainSpec.AuRa.BlockGasLimitContractTransitions;

            if (blockGasLimitContractTransitions?.Any() == true)
            {
                _context.GasLimitOverrideCache = new IGasLimitOverride.Cache();

                var gasLimitOverride = new AuRaContractGasLimitOverride(
                    blockGasLimitContractTransitions.Select(blockGasLimitContractTransition =>
                                                            new BlockGasLimitContract(
                                                                _context.AbiEncoder,
                                                                blockGasLimitContractTransition.Value,
                                                                blockGasLimitContractTransition.Key,
                                                                GetReadOnlyTransactionProcessorSource()))
                    .ToArray <IBlockGasLimitContract>(),
                    _context.GasLimitOverrideCache,
                    _context.Config <IAuraConfig>().Minimum2MlnGasPerBlockWhenUsingBlockGasLimitContract,
                    _context.LogManager);

                return(gasLimitOverride);
            }

            return(null);
        }