Example #1
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");
            }
        }
        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");
            }
        }