public void MarkInvalidTransaction_Test() { var host = "127.0.0.1"; bool markResult; _peerInvalidTransactionProvider.TryRemoveInvalidRecord(host).ShouldBe(false); for (var i = 0; i < 5; i++) { var txId = HashHelper.ComputeFrom(i.ToString()); markResult = _peerInvalidTransactionProvider.TryMarkInvalidTransaction(host, txId); markResult.ShouldBeTrue(); } markResult = _peerInvalidTransactionProvider.TryMarkInvalidTransaction(host, HashHelper.ComputeFrom("0")); markResult.ShouldBeTrue(); markResult = _peerInvalidTransactionProvider.TryMarkInvalidTransaction(host, HashHelper.ComputeFrom("5")); markResult.ShouldBeFalse(); markResult = _peerInvalidTransactionProvider.TryMarkInvalidTransaction("192.168.1.1", HashHelper.ComputeFrom("0")); markResult.ShouldBeTrue(); _peerInvalidTransactionProvider.TryRemoveInvalidRecord(host).ShouldBe(true); markResult = _peerInvalidTransactionProvider.TryMarkInvalidTransaction(host, HashHelper.ComputeFrom("0")); markResult.ShouldBeTrue(); }
public async Task ProcessPeerInvalidTransactionAsync(Hash transactionId) { var knowsTransactionPeers = _peerPool.GetPeers().Where(p => p.KnowsTransaction(transactionId)).ToList(); var toRemovePeerPubkey = new List <string>(); foreach (var knowsTransactionPeer in knowsTransactionPeers) { var host = knowsTransactionPeer.RemoteEndpoint.Host; if (_peerInvalidTransactionProvider.TryMarkInvalidTransaction(host, transactionId)) { continue; } var peers = _peerPool.GetPeersByHost(host); toRemovePeerPubkey.AddRange(peers.Select(p => p.Info.Pubkey)); _peerInvalidTransactionProvider.TryRemoveInvalidRecord(host); } foreach (var pubkey in toRemovePeerPubkey) { await _networkService.RemovePeerByPubkeyAsync(pubkey); } }