aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-06-17 09:05:48 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-06-17 09:05:52 +0200
commitdd24567a243fd71ab2fe991b431f805bcc3f7b3e (patch)
tree0c6fb1b6b6d43d60e466396197409015be7281fb /test/functional
parentd50302625e115da2bd4bcaf14c90c8b0e4872bc7 (diff)
parent754e802274e9373ad7e1dccb710acf74ded6e7fb (diff)
downloadbitcoin-dd24567a243fd71ab2fe991b431f805bcc3f7b3e.tar.xz
Merge bitcoin/bitcoin#22120: test: p2p_invalid_block: Check that a block rejected due to too-new tim…
754e802274e9373ad7e1dccb710acf74ded6e7fb test: check rejected future block later accepted (Luke Dashjr) Pull request description: (Luke) was unsure if the code sufficiently avoided caching a time-too-new rejection, so wrote this test to check it. It looks like despite only exempting BLOCK_MUTATED, it is still okay because header failures never cache block invalidity. This test will help ensure that if this ever changes, BLOCK_TIME_FUTURE gets excluded at the same time. This PR re-opens https://github.com/bitcoin/bitcoin/pull/17872 which went stale and addresses the nits raised by reviewers there. ACKs for top commit: MarcoFalke: review ACK 754e802274e9373ad7e1dccb710acf74ded6e7fb Tree-SHA512: a2bbc8fffb523cf2831e1ecb05f20868e30106a38cc2e369e4973fa549cca06675a668df16f76c49cc4ce3a22925404255e5c53c4232d63ba1b9fca878509aa0
Diffstat (limited to 'test/functional')
-rwxr-xr-xtest/functional/p2p_invalid_block.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/functional/p2p_invalid_block.py b/test/functional/p2p_invalid_block.py
index 483f25f48c..91666d0f08 100755
--- a/test/functional/p2p_invalid_block.py
+++ b/test/functional/p2p_invalid_block.py
@@ -9,8 +9,11 @@ In this test we connect to one node over p2p, and test block requests:
2) Invalid block with duplicated transaction should be re-requested.
3) Invalid block with bad coinbase value should be rejected and not
re-requested.
+4) Invalid block due to future timestamp is later accepted when that timestamp
+becomes valid.
"""
import copy
+import time
from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
from test_framework.messages import COIN
@@ -18,6 +21,9 @@ from test_framework.p2p import P2PDataStore
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
+MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
+
+
class InvalidBlockRequestTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
@@ -133,5 +139,18 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
self.log.info("Test inflation by duplicating input")
peer.send_blocks_and_test([block4], node, success=False, reject_reason='bad-txns-inputs-duplicate')
+ self.log.info("Test accepting identical block after rejecting it due to a future timestamp.")
+ t = int(time.time())
+ node.setmocktime(t)
+ # Set block time +1 second past max future validity
+ block = create_block(tip, create_coinbase(height), t + MAX_FUTURE_BLOCK_TIME + 1)
+ block.hashMerkleRoot = block.calc_merkle_root()
+ block.solve()
+ # Need force_send because the block will get rejected without a getdata otherwise
+ peer.send_blocks_and_test([block], node, force_send=True, success=False, reject_reason='time-too-new')
+ node.setmocktime(t + 1)
+ peer.send_blocks_and_test([block], node, success=True)
+
+
if __name__ == '__main__':
InvalidBlockRequestTest().main()