Example #1
0
            public SyncingContext(SynchronizerType synchronizerType)
            {
                _logger = _logManager.GetClassLogger();
                ISyncConfig syncConfig = new SyncConfig();

                syncConfig.FastSync = synchronizerType == SynchronizerType.Fast;
                ISnapshotableDb stateDb = new StateDb();
                ISnapshotableDb codeDb  = new StateDb();

                BlockTree = new BlockTree(new MemDb(), new MemDb(), new MemDb(), new SingleReleaseSpecProvider(Constantinople.Instance, 1), NullTxPool.Instance, _logManager);
                var stats = new NodeStatsManager(new StatsConfig(), _logManager);

                SyncPeerPool = new EthSyncPeerPool(BlockTree, stats, syncConfig, _logManager);

                NodeDataFeed       feed = new NodeDataFeed(codeDb, stateDb, _logManager);
                NodeDataDownloader nodeDataDownloader = new NodeDataDownloader(SyncPeerPool, feed, _logManager);

                Synchronizer = new Synchronizer(BlockTree,
                                                TestBlockValidator.AlwaysValid,
                                                TestSealValidator.AlwaysValid,
                                                SyncPeerPool, syncConfig, nodeDataDownloader, _logManager);

                SyncServer = new SyncServer(stateDb, codeDb, BlockTree, NullReceiptStorage.Instance, TestSealValidator.AlwaysValid, SyncPeerPool, Synchronizer, _logManager);
                SyncPeerPool.Start();

                Synchronizer.Start();
                Synchronizer.SyncEvent += SynchronizerOnSyncEvent;

                AllInstances.Add(this);
            }
        private NodeDataDownloader PrepareDownloader(ISyncPeer syncPeer)
        {
            DbContext dbContext = new DbContext(_logger);
            BlockTree blockTree = Build.A.BlockTree().OfChainLength((int)BlockTree.BestSuggestedHeader.Number).TestObject;

            _pool = new EthSyncPeerPool(blockTree, new NodeStatsManager(new StatsConfig(), LimboLogs.Instance), 25, LimboLogs.Instance);
            _pool.Start();
            _pool.AddPeer(syncPeer);

            NodeDataFeed       feed       = new NodeDataFeed(dbContext.LocalCodeDb, dbContext.LocalStateDb, _logManager);
            NodeDataDownloader downloader = new NodeDataDownloader(_pool, feed, NullDataConsumer.Instance, _logManager);

            return(downloader);
        }
Example #3
0
        private Task StartSync()
        {
            if (!_initConfig.SynchronizationEnabled)
            {
                if (_logger.IsWarn)
                {
                    _logger.Warn($"Skipping blockchain synchronization init due to ({nameof(IInitConfig.SynchronizationEnabled)} set to false)");
                }
                return(Task.CompletedTask);
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Starting synchronization from block {_blockTree.Head.ToString(BlockHeader.Format.Short)}.");
            }

            _syncPeerPool.Start();
            _synchronizer.Start();
            return(Task.CompletedTask);
        }
        public async Task Cannot_remove_when_stopped()
        {
            _pool.Start();
            ISyncPeer[] syncPeers = new ISyncPeer[3];
            for (int i = 0; i < 3; i++)
            {
                syncPeers[i] = new SimpleSyncPeerMock(TestItem.PublicKeys[i]);
                _pool.AddPeer(syncPeers[i]);
            }

            await _pool.StopAsync();

            for (int i = 3; i > 0; i--)
            {
                Assert.AreEqual(3, _pool.PeerCount, $"Remove {i}");
                _pool.RemovePeer(syncPeers[i - 1]);
            }
        }
        public void Retrieves_missing_blocks_in_batches()
        {
            _remoteBlockTree = Build.A.BlockTree(_genesisBlock).OfChainLength(SyncBatchSize.Max * 2).TestObject;
            ISyncPeer peer = new SyncPeerMock(_remoteBlockTree);

            ManualResetEvent resetEvent = new ManualResetEvent(false);

            _synchronizer.SyncEvent += (sender, args) =>
            {
                if (args.SyncEvent == SyncEvent.Completed || args.SyncEvent == SyncEvent.Failed)
                {
                    resetEvent.Set();
                }
            };
            _pool.Start();
            _synchronizer.Start();
            _pool.AddPeer(peer);

            resetEvent.WaitOne(_standardTimeoutUnit);
            Assert.AreEqual(SyncBatchSize.Max * 2 - 1, (int)_blockTree.BestSuggested.Number);
        }