From 473a1132419d05911933ac0095b207c4e2fc59f3 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Wed, 4 Apr 2018 01:28:57 +0100 Subject: [PATCH] Don't increase banscore if the transaction only just expired. Author: Jack Grigg --- qa/rpc-tests/p2p_txexpiry_dos.py | 15 ++++++++++++++- src/main.cpp | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/p2p_txexpiry_dos.py b/qa/rpc-tests/p2p_txexpiry_dos.py index 477fc5c01..44838beff 100755 --- a/qa/rpc-tests/p2p_txexpiry_dos.py +++ b/qa/rpc-tests/p2p_txexpiry_dos.py @@ -97,7 +97,7 @@ class TxExpiryDoSTest(BitcoinTestFramework): # Mininodes send transaction to zcashd node. def setExpiryHeight(tx): - tx.nExpiryHeight = 1 + tx.nExpiryHeight = 101 spendtx = self.create_transaction(self.nodes[0], self.coinbase_blocks[0], @@ -114,6 +114,19 @@ class TxExpiryDoSTest(BitcoinTestFramework): assert_equal(1, versions.count(OVERWINTER_PROTO_VERSION)) assert_equal(0, peerinfo[0]["banscore"]) + # Mine a block and resend the transaction + self.nodes[0].generate(1) + test_node.send_message(msg_tx(spendtx)) + + time.sleep(3) + + # Verify test mininode has not been dropped + # but has a banscore of 10. + peerinfo = self.nodes[0].getpeerinfo() + versions = [x["version"] for x in peerinfo] + assert_equal(1, versions.count(OVERWINTER_PROTO_VERSION)) + assert_equal(10, peerinfo[0]["banscore"]) + [ c.disconnect_node() for c in connections ] if __name__ == '__main__': diff --git a/src/main.cpp b/src/main.cpp index 975aed2f6..e1b49a62b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -897,7 +897,9 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, // Check that all transactions are unexpired if (IsExpiredTx(tx, nHeight)) { - return state.DoS(0, error("ContextualCheckTransaction(): transaction is expired"), REJECT_INVALID, "tx-overwinter-expired"); + // Don't increase banscore if the transaction only just expired + int expiredDosLevel = IsExpiredTx(tx, nHeight - 1) ? dosLevel : 0; + return state.DoS(expiredDosLevel, error("ContextualCheckTransaction(): transaction is expired"), REJECT_INVALID, "tx-overwinter-expired"); } }