public async Task Execute(CancellationToken _)
        {
            IMiningConfig miningConfig = _api.Config <IMiningConfig>();

            if (miningConfig.Enabled)
            {
                _api.BlockProducer = await BuildProducer();

                if (_api.BlockProducer == null)
                {
                    throw new StepDependencyException(nameof(_api.BlockProducer));
                }
                if (_api.BlockTree == null)
                {
                    throw new StepDependencyException(nameof(_api.BlockTree));
                }

                ILogger logger = _api.LogManager.GetClassLogger();
                if (logger.IsWarn)
                {
                    logger.Warn($"Starting {_api.SealEngineType} block producer & sealer");
                }
                ProducedBlockSuggester suggester = new(_api.BlockTree, _api.BlockProducer);
                _api.DisposeStack.Push(suggester);
                _api.BlockProducer.Start();
            }
        }
Beispiel #2
0
        public async Task Execute(CancellationToken _)
        {
            IMiningConfig miningConfig = _api.Config <IMiningConfig>();

            if (miningConfig.Enabled)
            {
                _api.BlockProducer = await BuildProducer();
            }
        }
 public Task Execute(CancellationToken cancellationToken)
 {
     if (_api.Config <IInitConfig>().ProcessingEnabled)
     {
         return(RunBlockTreeInitTasks(cancellationToken));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }
Beispiel #4
0
        protected virtual async Task <IBlockProducer> BuildProducer()
        {
            _api.BlockProducerEnvFactory = new BlockProducerEnvFactory(_api.DbProvider !,
                                                                       _api.BlockTree !,
                                                                       _api.ReadOnlyTrieStore !,
                                                                       _api.SpecProvider !,
                                                                       _api.BlockValidator !,
                                                                       _api.RewardCalculatorSource !,
                                                                       _api.ReceiptStorage !,
                                                                       _api.BlockPreprocessor,
                                                                       _api.TxPool !,
                                                                       _api.TransactionComparerProvider !,
                                                                       _api.Config <IMiningConfig>(),
                                                                       _api.LogManager);

            if (_api.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_api.ChainSpec));
            }
            IConsensusPlugin?consensusPlugin = _api.GetConsensusPlugin();

            if (consensusPlugin is not null)
            {
                foreach (IConsensusWrapperPlugin wrapperPlugin in _api.GetConsensusWrapperPlugins())
                {
                    return(await wrapperPlugin.InitBlockProducer(consensusPlugin));
                }

                return(await consensusPlugin.InitBlockProducer());
            }
            else
            {
                throw new NotSupportedException($"Mining in {_api.ChainSpec.SealEngineType} mode is not supported");
            }
        }
Beispiel #5
0
        public async Task Execute(CancellationToken _)
        {
            _initConfig = _api.Config <IInitConfig>();
            Keccak?expectedGenesisHash = string.IsNullOrWhiteSpace(_initConfig.GenesisHash) ? null : new Keccak(_initConfig.GenesisHash);

            if (_api.BlockTree == null)
            {
                throw new StepDependencyException();
            }

            // if we already have a database with blocks then we do not need to load genesis from spec
            if (_api.BlockTree.Genesis == null)
            {
                Load();
            }

            ValidateGenesisHash(expectedGenesisHash);

            if (!_initConfig.ProcessingEnabled)
            {
                if (_logger.IsWarn)
                {
                    _logger.Warn($"Shutting down the blockchain processor due to {nameof(InitConfig)}.{nameof(InitConfig.ProcessingEnabled)} set to false");
                }
                await(_api.BlockchainProcessor?.StopAsync() ?? Task.CompletedTask);
            }
        }
Beispiel #6
0
        public Task Execute(CancellationToken cancellationToken)
        {
            if (_api.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_api.DbProvider));
            }

            if (_api.Config <IInitConfig>().ProcessingEnabled)
            {
                return(RunBlockTreeInitTasks(cancellationToken));
            }
            else
            {
                return(Task.CompletedTask);
            }
        }
        public Task Execute(CancellationToken _)
        {
            IMiningConfig miningConfig = _api.Config <IMiningConfig>();

            if (miningConfig.Enabled)
            {
                BuildProducer();
                if (_api.BlockProducer == null)
                {
                    throw new StepDependencyException(nameof(_api.BlockProducer));
                }

                ILogger logger = _api.LogManager.GetClassLogger();
                if (logger.IsWarn)
                {
                    logger.Warn($"Starting {_api.SealEngineType} block producer & sealer");
                }
                _api.BlockProducer.Start();
            }

            return(Task.CompletedTask);
        }
        protected virtual async Task <IBlockProducer> BuildProducer()
        {
            _api.BlockProducerEnvFactory = new BlockProducerEnvFactory(_api.DbProvider !,
                                                                       _api.BlockTree !,
                                                                       _api.ReadOnlyTrieStore !,
                                                                       _api.SpecProvider !,
                                                                       _api.BlockValidator !,
                                                                       _api.RewardCalculatorSource !,
                                                                       _api.ReceiptStorage !,
                                                                       _api.BlockPreprocessor,
                                                                       _api.TxPool !,
                                                                       _api.TransactionComparerProvider !,
                                                                       _api.Config <IMiningConfig>(),
                                                                       _api.LogManager);

            if (_api.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_api.ChainSpec));
            }
            IConsensusPlugin?consensusPlugin = _api.GetConsensusPlugin();

            if (consensusPlugin is not null)
            {
                // TODO: need to wrap preMerge producer inside theMerge first, then need to wrap all of it with MEV
                // I am pretty sure that MEV can be done better than this way
                foreach (IConsensusWrapperPlugin wrapperPlugin in _api.GetConsensusWrapperPlugins())
                {
                    // TODO: foreach returns the first one now
                    return(await wrapperPlugin.InitBlockProducer(consensusPlugin));
                }

                return(await consensusPlugin.InitBlockProducer());
            }
            else
            {
                throw new NotSupportedException($"Mining in {_api.ChainSpec.SealEngineType} mode is not supported");
            }
        }