예제 #1
0
 private void BlockTreeOnNewBestSuggestedBlock(object sender, BlockEventArgs e)
 {
     lock (_syncToken)
     {
         _cancellationTokenSource?.Cancel();
     }
 }
예제 #2
0
        private void OnNewBestBlock(object sender, BlockEventArgs blockEventArgs)
        {
            if (blockEventArgs.Block == null)
            {
                throw new InvalidOperationException("New best block is null");
            }

            _miningCancellation?.Cancel();
            EnqueueForProcessing(blockEventArgs.Block);
        }
예제 #3
0
        private void OnNewBestBlock(object sender, BlockEventArgs blockEventArgs)
        {
            ProcessingOptions options = ProcessingOptions.None;

            if (_storeReceiptsByDefault)
            {
                options |= ProcessingOptions.StoreReceipts;
            }

            Enqueue(blockEventArgs.Block, options);
        }
        //private void StartActivePeersTimer()
        //{
        //    if (_logger.IsInfoEnabled)
        //    {
        //        _logger.Info("Starting sync timer");
        //    }

        //    _syncTimer = new System.Timers.Timer(_blockchainConfig.SyncTimerInterval) { AutoReset = false };
        //    _syncTimer.Elapsed += (sender, e) =>
        //    {
        //        _syncTimer.Enabled = false;
        //        if (_logger.IsInfoEnabled)
        //        {
        //            _logger.Info($"Running sync timer: current sync peers: {_peers.Count}, unsynced: {_peers.Count(x => !x.Value.IsSynced)}, synced: {_peers.Count(x => x.Value.IsSynced)}");
        //        }
        //        RunSync();
        //        _syncTimer.Enabled = true;
        //    };

        //    _syncTimer.Start();
        //}

        //private void StopActivePeersTimer()
        //{
        //    try
        //    {
        //        if (_logger.IsInfoEnabled)
        //        {
        //            _logger.Info("Stopping sync timer");
        //        }
        //        _syncTimer?.Stop();
        //    }
        //    catch (Exception e)
        //    {
        //        _logger.Error("Error during sync timer stop", e);
        //    }
        //}

        private void OnNewHeadBlock(object sender, BlockEventArgs blockEventArgs)
        {
            if (_isSyncing)
            {
                return;
            }

            Block block = blockEventArgs.Block;

            foreach ((NodeId nodeId, PeerInfo peerInfo) in _peers)
            {
                if (peerInfo.NumberAvailable < block.Number) // TODO: total difficulty instead
                {
                    peerInfo.Peer.SendNewBlock(block);
                }
            }
        }
예제 #5
0
        private void OnNewBestBlock(object sender, BlockEventArgs blockEventArgs)
        {
            _miningCancellation?.Cancel();

            Block block = blockEventArgs.Block;

            if (_logger.IsTrace)
            {
                _logger.Trace($"Enqueuing a new block {block.ToString(Block.Format.Short)} for processing.");
            }

            BlockRef blockRef = _recoveryQueue.Count > MaxRecoveryQueueSize ? new BlockRef(block.Hash) : new BlockRef(block);

            _recoveryQueue.Add(blockRef);

            if (_logger.IsTrace)
            {
                _logger.Trace($"A new block {block.ToString(Block.Format.Short)} enqueued for processing.");
            }
        }
        private void OnNewHeadBlock(object sender, BlockEventArgs blockEventArgs)
        {
            // this is not critical (just beneficial) not to run in parallel with sync so the race condition here is totally acceptable
            lock (_isSyncingLock)
            {
                if (_isSyncing)
                {
                    return;
                }
            }

            Block block = blockEventArgs.Block;

            foreach ((NodeId nodeId, PeerInfo peerInfo) in _peers)
            {
                if (peerInfo.NumberAvailable < block.Number) // TODO: total difficulty instead
                {
                    peerInfo.Peer.SendNewBlock(block);
                }
            }
        }