private void SetupBeamProcessor()
        {
            MemDbProvider memDbProvider = new MemDbProvider();

            _ = new BeamBlockchainProcessor(
                new ReadOnlyDbProvider(memDbProvider, false),
                _blockTree,
                MainNetSpecProvider.Instance,
                LimboLogs.Instance,
                _validator,
                NullRecoveryStep.Instance,
                new InstanceRewardCalculatorSource(NoBlockRewards.Instance),
                _blockchainProcessor
                );
        }
        private async Task SetupBeamProcessor(ISyncModeSelector syncModeSelector = null)
        {
            IDbProvider memDbProvider = await TestMemDbProvider.InitAsync();

            _beamBlockchainProcessor = new BeamBlockchainProcessor(
                new ReadOnlyDbProvider(memDbProvider, false),
                _blockTree,
                MainnetSpecProvider.Instance,
                LimboLogs.Instance,
                _validator,
                NullRecoveryStep.Instance,
                NoBlockRewards.Instance,
                _blockchainProcessingQueue,
                syncModeSelector ?? new StaticSelector(SyncMode.Beam)
                );
        }
Beispiel #3
0
        private void SetupBeamProcessor(ISyncModeSelector syncModeSelector = null)
        {
            MemDbProvider memDbProvider = new MemDbProvider();

            _beamBlockchainProcessor = new BeamBlockchainProcessor(
                new ReadOnlyDbProvider(memDbProvider, false),
                _blockTree,
                MainnetSpecProvider.Instance,
                LimboLogs.Instance,
                _validator,
                NullRecoveryStep.Instance,
                new InstanceRewardCalculatorSource(NoBlockRewards.Instance),
                _blockchainProcessingQueue,
                _blockchainProcessor,
                syncModeSelector ?? new StaticSelector(SyncMode.Beam)
                );
        }
        private Task InitBlockchain()
        {
            if (_context.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_context.ChainSpec));
            }
            if (_context.DbProvider == null)
            {
                throw new StepDependencyException(nameof(_context.DbProvider));
            }
            if (_context.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_context.SpecProvider));
            }

            ILogger     logger     = _context.LogManager.GetClassLogger();
            IInitConfig initConfig = _context.Config <IInitConfig>();
            ISyncConfig syncConfig = _context.Config <ISyncConfig>();

            if (syncConfig.DownloadReceiptsInFastSync && !syncConfig.DownloadBodiesInFastSync)
            {
                logger.Warn($"{nameof(syncConfig.DownloadReceiptsInFastSync)} is selected but {nameof(syncConfig.DownloadBodiesInFastSync)} - enabling bodies to support receipts download.");
                syncConfig.DownloadBodiesInFastSync = true;
            }

            if (syncConfig.BeamSync)
            {
                logger.Warn("Welcome to the alpha version of the Nethermind Goerli Beam Sync. I will start by downloading the pivot block header and then will continue to download all the headers from the pivot upwards. After that I will be beam synchronizing the new blocks. Many things can fail - appreciated if you report issues via GitHub or Gitter.");
            }

            Account.AccountStartNonce = _context.ChainSpec.Parameters.AccountStartNonce;

            _context.StateProvider = new StateProvider(
                _context.DbProvider.StateDb,
                _context.DbProvider.CodeDb,
                _context.LogManager);

            _context.EthereumEcdsa = new EthereumEcdsa(_context.SpecProvider, _context.LogManager);
            _context.TxPool        = new TxPool.TxPool(
                new PersistentTxStorage(_context.DbProvider.PendingTxsDb, _context.SpecProvider),
                Timestamper.Default,
                _context.EthereumEcdsa,
                _context.SpecProvider,
                _context.Config <ITxPoolConfig>(),
                _context.StateProvider,
                _context.LogManager);

            _context.ReceiptStorage = new PersistentReceiptStorage(_context.DbProvider.ReceiptsDb, _context.SpecProvider, _context.LogManager);

            var bloomConfig = _context.Config <IBloomConfig>();

            _context.BloomStorage = bloomConfig.Index
                ? new BloomStorage(bloomConfig, _context.DbProvider.BloomDb, new FixedSizeFileStoreFactory(Path.Combine(initConfig.BaseDbPath, DbNames.Bloom), DbNames.Bloom, Bloom.ByteLength))
                : (IBloomStorage)NullBloomStorage.Instance;

            _context.DisposeStack.Push(_context.BloomStorage);

            _context.ChainLevelInfoRepository = new ChainLevelInfoRepository(_context.DbProvider.BlockInfosDb);

            _context.BlockTree = new BlockTree(
                _context.DbProvider.BlocksDb,
                _context.DbProvider.HeadersDb,
                _context.DbProvider.BlockInfosDb,
                _context.ChainLevelInfoRepository,
                _context.SpecProvider,
                _context.TxPool,
                _context.BloomStorage,
                _context.Config <ISyncConfig>(),
                _context.LogManager);

            // Init state if we need system calls before actual processing starts
            if (_context.BlockTree.Head != null)
            {
                _context.StateProvider.StateRoot = _context.BlockTree.Head.StateRoot;
            }

            _context.RecoveryStep = new TxSignaturesRecoveryStep(_context.EthereumEcdsa, _context.TxPool, _context.LogManager);

            _context.StorageProvider = new StorageProvider(
                _context.DbProvider.StateDb,
                _context.StateProvider,
                _context.LogManager);

            // blockchain processing
            BlockhashProvider blockhashProvider = new BlockhashProvider(
                _context.BlockTree, _context.LogManager);

            VirtualMachine virtualMachine = new VirtualMachine(
                _context.StateProvider,
                _context.StorageProvider,
                blockhashProvider,
                _context.SpecProvider,
                _context.LogManager);

            _context.TransactionProcessor = new TransactionProcessor(
                _context.SpecProvider,
                _context.StateProvider,
                _context.StorageProvider,
                virtualMachine,
                _context.LogManager);

            InitSealEngine();
            if (_context.SealValidator == null)
            {
                throw new StepDependencyException(nameof(_context.SealValidator));
            }

            /* validation */
            _context.HeaderValidator = new HeaderValidator(
                _context.BlockTree,
                _context.SealValidator,
                _context.SpecProvider,
                _context.LogManager);

            OmmersValidator ommersValidator = new OmmersValidator(
                _context.BlockTree,
                _context.HeaderValidator,
                _context.LogManager);

            TxValidator txValidator = new TxValidator(_context.SpecProvider.ChainId);

            _context.BlockValidator = new BlockValidator(
                txValidator,
                _context.HeaderValidator,
                ommersValidator,
                _context.SpecProvider,
                _context.LogManager);

            _context.TxPoolInfoProvider = new TxPoolInfoProvider(_context.StateProvider, _context.TxPool);

            _context.MainBlockProcessor = CreateBlockProcessor();

            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(
                _context.BlockTree,
                _context.MainBlockProcessor,
                _context.RecoveryStep,
                _context.LogManager,
                initConfig.StoreReceipts,
                !syncConfig.BeamSync);

            _context.BlockProcessingQueue = blockchainProcessor;
            _context.BlockchainProcessor  = blockchainProcessor;

            if (syncConfig.BeamSync)
            {
                _ = new BeamBlockchainProcessor(
                    new ReadOnlyDbProvider(_context.DbProvider, false),
                    _context.BlockTree,
                    _context.SpecProvider,
                    _context.LogManager,
                    _context.BlockValidator,
                    _context.RecoveryStep,
                    _context.RewardCalculatorSource,
                    _context.BlockProcessingQueue);
            }

            return(Task.CompletedTask);
        }
Beispiel #5
0
        private Task InitBlockchain()
        {
            if (_context.ChainSpec == null)
            {
                throw new StepDependencyException(nameof(_context.ChainSpec));
            }
            if (_context.DbProvider == null)
            {
                throw new StepDependencyException(nameof(_context.DbProvider));
            }
            if (_context.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_context.SpecProvider));
            }

            ILogger     logger     = _context.LogManager.GetClassLogger();
            IInitConfig initConfig = _context.Config <IInitConfig>();
            ISyncConfig syncConfig = _context.Config <ISyncConfig>();

            if (syncConfig.DownloadReceiptsInFastSync && !syncConfig.DownloadBodiesInFastSync)
            {
                logger.Warn($"{nameof(syncConfig.DownloadReceiptsInFastSync)} is selected but {nameof(syncConfig.DownloadBodiesInFastSync)} - enabling bodies to support receipts download.");
                syncConfig.DownloadBodiesInFastSync = true;
            }

            Account.AccountStartNonce = _context.ChainSpec.Parameters.AccountStartNonce;

            _context.Signer = new Signer(_context.SpecProvider.ChainId, _context.OriginalSignerKey);

            _context.StateProvider = new StateProvider(
                _context.DbProvider.StateDb,
                _context.DbProvider.CodeDb,
                _context.LogManager);

            _context.EthereumEcdsa = new EthereumEcdsa(_context.SpecProvider.ChainId, _context.LogManager);
            _context.TxPool        = new TxPool.TxPool(
                new PersistentTxStorage(_context.DbProvider.PendingTxsDb),
                Timestamper.Default,
                _context.EthereumEcdsa,
                _context.SpecProvider,
                _context.Config <ITxPoolConfig>(),
                _context.StateProvider,
                _context.LogManager);

            var bloomConfig = _context.Config <IBloomConfig>();

            var fileStoreFactory = initConfig.DiagnosticMode == DiagnosticMode.MemDb
                ? (IFileStoreFactory) new InMemoryDictionaryFileStoreFactory()
                : new FixedSizeFileStoreFactory(Path.Combine(initConfig.BaseDbPath, DbNames.Bloom), DbNames.Bloom, Bloom.ByteLength);

            _context.BloomStorage = bloomConfig.Index
                ? new BloomStorage(bloomConfig, _context.DbProvider.BloomDb, fileStoreFactory)
                : (IBloomStorage)NullBloomStorage.Instance;

            _context.DisposeStack.Push(_context.BloomStorage);

            _context.ChainLevelInfoRepository = new ChainLevelInfoRepository(_context.DbProvider.BlockInfosDb);

            _context.BlockTree = new BlockTree(
                _context.DbProvider.BlocksDb,
                _context.DbProvider.HeadersDb,
                _context.DbProvider.BlockInfosDb,
                _context.ChainLevelInfoRepository,
                _context.SpecProvider,
                _context.TxPool,
                _context.BloomStorage,
                _context.Config <ISyncConfig>(),
                _context.LogManager);

            // Init state if we need system calls before actual processing starts
            if (_context.BlockTree.Head != null)
            {
                _context.StateProvider.StateRoot = _context.BlockTree.Head.StateRoot;
            }

            _context.ReceiptStorage = initConfig.StoreReceipts ? (IReceiptStorage?)new PersistentReceiptStorage(_context.DbProvider.ReceiptsDb, _context.SpecProvider, new ReceiptsRecovery()) : NullReceiptStorage.Instance;
            _context.ReceiptFinder  = new FullInfoReceiptFinder(_context.ReceiptStorage, new ReceiptsRecovery(), _context.BlockTree);

            _context.RecoveryStep = new TxSignaturesRecoveryStep(_context.EthereumEcdsa, _context.TxPool, _context.LogManager);

            _context.StorageProvider = new StorageProvider(
                _context.DbProvider.StateDb,
                _context.StateProvider,
                _context.LogManager);

            // blockchain processing
            BlockhashProvider blockhashProvider = new BlockhashProvider(
                _context.BlockTree, _context.LogManager);

            VirtualMachine virtualMachine = new VirtualMachine(
                _context.StateProvider,
                _context.StorageProvider,
                blockhashProvider,
                _context.SpecProvider,
                _context.LogManager);

            _context.TransactionProcessor = new TransactionProcessor(
                _context.SpecProvider,
                _context.StateProvider,
                _context.StorageProvider,
                virtualMachine,
                _context.LogManager);

            InitSealEngine();
            if (_context.SealValidator == null)
            {
                throw new StepDependencyException(nameof(_context.SealValidator));
            }

            /* validation */
            _context.HeaderValidator = CreateHeaderValidator();

            OmmersValidator ommersValidator = new OmmersValidator(
                _context.BlockTree,
                _context.HeaderValidator,
                _context.LogManager);

            TxValidator txValidator = new TxValidator(_context.SpecProvider.ChainId);

            _context.BlockValidator = new BlockValidator(
                txValidator,
                _context.HeaderValidator,
                ommersValidator,
                _context.SpecProvider,
                _context.LogManager);

            ReadOnlyDbProvider readOnly    = new ReadOnlyDbProvider(_context.DbProvider, false);
            StateReader        stateReader = new StateReader(readOnly.StateDb, readOnly.CodeDb, _context.LogManager);

            _context.TxPoolInfoProvider = new TxPoolInfoProvider(stateReader, _context.TxPool);

            _context.MainBlockProcessor = CreateBlockProcessor();

            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(
                _context.BlockTree,
                _context.MainBlockProcessor,
                _context.RecoveryStep,
                _context.LogManager,
                new BlockchainProcessor.Options
            {
                AutoProcess            = !syncConfig.BeamSync,
                StoreReceiptsByDefault = initConfig.StoreReceipts,
                RunGethTracer          = initConfig.DiagnosticMode == DiagnosticMode.GethTrace,
                RunParityTracer        = initConfig.DiagnosticMode == DiagnosticMode.ParityTrace,
            });

            _context.BlockProcessingQueue = blockchainProcessor;
            _context.BlockchainProcessor  = blockchainProcessor;

            if (syncConfig.BeamSync)
            {
                BeamBlockchainProcessor beamBlockchainProcessor = new BeamBlockchainProcessor(
                    new ReadOnlyDbProvider(_context.DbProvider, false),
                    _context.BlockTree,
                    _context.SpecProvider,
                    _context.LogManager,
                    _context.BlockValidator,
                    _context.RecoveryStep,
                    _context.RewardCalculatorSource,
                    _context.BlockProcessingQueue,
                    _context.BlockchainProcessor,
                    _context.SyncModeSelector);

                _context.DisposeStack.Push(beamBlockchainProcessor);
            }

            ThisNodeInfo.AddInfo("Mem est trie :", $"{LruCache<Keccak, byte[]>.CalculateMemorySize(52 + 320, Trie.MemoryAllowance.TrieNodeCacheSize) / 1024 / 1024}MB".PadLeft(8));

            return(Task.CompletedTask);
        }