Browse Source

Don't increase banscore if the transaction only just expired.

Author: Jack Grigg <str4d@z.cash>
pull/4/head
Daira Hopwood 6 years ago
parent
commit
473a113241
  1. 15
      qa/rpc-tests/p2p_txexpiry_dos.py
  2. 4
      src/main.cpp

15
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__':

4
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");
}
}

Loading…
Cancel
Save