Ejemplo n.º 1
0
        public Task InitBlockProducer()
        {
            if (_nethermindApi !.SealEngineType != SealEngineType.NethDev)
            {
                return(Task.CompletedTask);
            }

            var(getFromApi, setInApi) = _nethermindApi !.ForProducer;
            ITxFilter txFilter = new NullTxFilter();
            ITxSource txSource = new TxPoolTxSource(
                getFromApi.TxPool, getFromApi.StateReader, getFromApi.LogManager, txFilter);

            ILogger logger = getFromApi.LogManager.GetClassLogger();

            if (logger.IsWarn)
            {
                logger.Warn("Starting Neth Dev block producer & sealer");
            }

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

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

            BlockProcessor producerProcessor = new BlockProcessor(
                getFromApi !.SpecProvider,
                getFromApi !.BlockValidator,
                NoBlockRewards.Instance,
                producerEnv.TransactionProcessor,
                producerEnv.DbProvider.StateDb,
                producerEnv.DbProvider.CodeDb,
                producerEnv.StateProvider,
                producerEnv.StorageProvider,
                NullTxPool.Instance,
                NullReceiptStorage.Instance,
                getFromApi.LogManager);

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

            setInApi.BlockProducer = new DevBlockProducer(
                txSource,
                producerChainProcessor,
                producerEnv.StateProvider,
                getFromApi.BlockTree,
                getFromApi.BlockProcessingQueue,
                getFromApi.TxPool,
                getFromApi.Timestamper,
                getFromApi.LogManager);

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public Task InitBlockProducer()
        {
            if (_nethermindApi !.SealEngineType != Nethermind.Core.SealEngineType.NethDev)
            {
                return(Task.CompletedTask);
            }

            var(getFromApi, setInApi) = _nethermindApi !.ForProducer;
            ITxFilter txFilter = new NullTxFilter();
            ITxSource txSource = new TxPoolTxSource(
                getFromApi.TxPool, getFromApi.StateReader, getFromApi.LogManager, txFilter);

            ILogger logger = getFromApi.LogManager.GetClassLogger();

            if (logger.IsWarn)
            {
                logger.Warn("Starting Neth Dev block producer & sealer");
            }

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

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

            BlockProcessor producerProcessor = new(
                getFromApi !.SpecProvider,
                getFromApi !.BlockValidator,
                NoBlockRewards.Instance,
                producerEnv.TransactionProcessor,
                producerEnv.StateProvider,
                producerEnv.StorageProvider,
                NullTxPool.Instance,
                NullReceiptStorage.Instance,
                NullWitnessCollector.Instance,
                getFromApi.LogManager);

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

            setInApi.BlockProducer = new DevBlockProducer(
                txSource.ServeTxsOneByOne(),
                producerChainProcessor,
                producerEnv.StateProvider,
                getFromApi.BlockTree,
                getFromApi.BlockProcessingQueue,
                new BuildBlocksRegularly(TimeSpan.FromMilliseconds(200))
                .IfPoolIsNotEmpty(getFromApi.TxPool)
                .Or(getFromApi.ManualBlockProductionTrigger),
                getFromApi.Timestamper,
                getFromApi.SpecProvider,
                getFromApi.Config <IMiningConfig>(),
                getFromApi.LogManager);

            return(Task.CompletedTask);
        }