|
9 | 9 | 2) Invalid block with duplicated transaction should be re-requested.
|
10 | 10 | 3) Invalid block with bad coinbase value should be rejected and not
|
11 | 11 | re-requested.
|
| 12 | +4) Invalid block due to future timestamp is later accepted when that timestamp |
| 13 | +becomes valid. |
12 | 14 | """
|
13 | 15 | import copy
|
| 16 | +import time |
14 | 17 |
|
15 | 18 | from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
|
16 | 19 | from test_framework.messages import COIN
|
17 | 20 | from test_framework.p2p import P2PDataStore
|
18 | 21 | from test_framework.test_framework import BitcoinTestFramework
|
19 | 22 | from test_framework.util import assert_equal
|
20 | 23 |
|
| 24 | +MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60 |
| 25 | + |
| 26 | + |
21 | 27 | class InvalidBlockRequestTest(BitcoinTestFramework):
|
22 | 28 | def set_test_params(self):
|
23 | 29 | self.num_nodes = 1
|
@@ -133,5 +139,18 @@ def run_test(self):
|
133 | 139 | self.log.info("Test inflation by duplicating input")
|
134 | 140 | peer.send_blocks_and_test([block4], node, success=False, reject_reason='bad-txns-inputs-duplicate')
|
135 | 141 |
|
| 142 | + self.log.info("Test accepting identical block after rejecting it due to a future timestamp.") |
| 143 | + t = int(time.time()) |
| 144 | + node.setmocktime(t) |
| 145 | + # Set block time +1 second past max future validity |
| 146 | + block = create_block(tip, create_coinbase(height), t + MAX_FUTURE_BLOCK_TIME + 1) |
| 147 | + block.hashMerkleRoot = block.calc_merkle_root() |
| 148 | + block.solve() |
| 149 | + # Need force_send because the block will get rejected without a getdata otherwise |
| 150 | + peer.send_blocks_and_test([block], node, force_send=True, success=False, reject_reason='time-too-new') |
| 151 | + node.setmocktime(t + 1) |
| 152 | + peer.send_blocks_and_test([block], node, success=True) |
| 153 | + |
| 154 | + |
136 | 155 | if __name__ == '__main__':
|
137 | 156 | InvalidBlockRequestTest().main()
|
0 commit comments