(self)
| 48 | self.skip_if_no_wallet() |
| 49 | |
| 50 | def run_test(self): |
| 51 | # Before we connect anything, we first set the time on the node |
| 52 | # to be in the past, otherwise things break because the CNode |
| 53 | # time counters can't be reset backward after initialization |
| 54 | old_time = int(time.time() - 2*60*60*24*7) |
| 55 | self.nodes[0].setmocktime(old_time) |
| 56 | |
| 57 | # Generate some old blocks |
| 58 | self.generate(self.nodes[0], 130) |
| 59 | |
| 60 | # p2p_conns[0] will only request old blocks |
| 61 | # p2p_conns[1] will only request new blocks |
| 62 | # p2p_conns[2] will test resetting the counters |
| 63 | p2p_conns = [] |
| 64 | |
| 65 | for _ in range(3): |
| 66 | p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn())) |
| 67 | |
| 68 | # Now mine a big block |
| 69 | mine_large_block(self, self.nodes[0], self.utxo_cache) |
| 70 | |
| 71 | # Store the hash; we'll request this later |
| 72 | big_old_block = self.nodes[0].getbestblockhash() |
| 73 | old_block_size = self.nodes[0].getblock(big_old_block, True)['size'] |
| 74 | big_old_block = int(big_old_block, 16) |
| 75 | |
| 76 | # Advance to two days ago |
| 77 | self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24) |
| 78 | |
| 79 | # Mine one more block, so that the prior block looks old |
| 80 | mine_large_block(self, self.nodes[0], self.utxo_cache) |
| 81 | |
| 82 | # We'll be requesting this new block too |
| 83 | big_new_block = self.nodes[0].getbestblockhash() |
| 84 | big_new_block = int(big_new_block, 16) |
| 85 | |
| 86 | # p2p_conns[0] will test what happens if we just keep requesting the |
| 87 | # the same big old block too many times (expect: disconnect) |
| 88 | |
| 89 | getdata_request = msg_getdata() |
| 90 | getdata_request.inv.append(CInv(MSG_BLOCK, big_old_block)) |
| 91 | |
| 92 | max_bytes_per_day = 800*1024*1024 |
| 93 | daily_buffer = 144 * 4000000 |
| 94 | max_bytes_available = max_bytes_per_day - daily_buffer |
| 95 | success_count = max_bytes_available // old_block_size |
| 96 | |
| 97 | # 576MB will be reserved for relaying new blocks, so expect this to |
| 98 | # succeed for ~235 tries. |
| 99 | for i in range(success_count): |
| 100 | p2p_conns[0].send_and_ping(getdata_request) |
| 101 | assert_equal(p2p_conns[0].block_receive_map[big_old_block], i+1) |
| 102 | |
| 103 | assert_equal(len(self.nodes[0].getpeerinfo()), 3) |
| 104 | # At most a couple more tries should succeed (depending on how long |
| 105 | # the test has been running so far). |
| 106 | for _ in range(3): |
| 107 | p2p_conns[0].send_message(getdata_request) |
nothing calls this directly
no test coverage detected