Esempio n. 1
0
        public async Task Can_refresh()
        {
            _pool.Start();
            var syncPeer = Substitute.For <ISyncPeer>();

            syncPeer.Node.Returns(new Node(TestItem.PublicKeyA, "127.0.0.1", 30303));
            _pool.AddPeer(syncPeer);
            _pool.Refresh(TestItem.PublicKeyA);
            await Task.Delay(200);

            await syncPeer.Received(2).GetHeadBlockHeader(Arg.Any <Keccak>(), Arg.Any <CancellationToken>());
        }
Esempio n. 2
0
        public void HintBlock(Keccak hash, long number, Node node)
        {
            if (!_pool.TryFind(node.Id, out PeerInfo peerInfo))
            {
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Received a block hint from an unknown {node:c}, ignoring");
                }
                return;
            }

            if (number > _blockTree.BestKnownNumber + 8)
            {
                return;
            }

            if (number > peerInfo.HeadNumber)
            {
                if (_logger.IsTrace)
                {
                    _logger.Trace($"HINT Updating header of {peerInfo} from {peerInfo.HeadNumber} {peerInfo.TotalDifficulty} to {number}");
                }
                peerInfo.HeadNumber = number;
                peerInfo.HeadHash   = hash;

                lock (_recentlySuggested)
                {
                    if (_recentlySuggested.Get(hash) != null)
                    {
                        return;
                    }

                    /* do not add as this is a hint only */
                }

                _pool.Refresh(node.Id);
            }
        }