Skip to content

Commit 478fb28

Browse files
committed
WIP test
1 parent ac547ea commit 478fb28

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,8 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
14001400
std::optional<int> snapshot_height{m_chainman.GetSnapshotBaseHeight()};
14011401
if (state->pindexLastCommonBlock == nullptr ||
14021402
(snapshot_height.has_value() && state->pindexLastCommonBlock->nHeight < snapshot_height.value())) {
1403+
// TODO: REMOVE DEBUG MESSAGE
1404+
LogPrintf("HERE\n");
14031405
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
14041406
// Guessing wrong in either direction is not a problem.
14051407
// Also applies after loading a snapshot, when we want to prioritise loading the snapshot chain and therefore need to skip ahead.

test/functional/feature_assumeutxo.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434
"""
3535
from shutil import rmtree
3636

37-
from test_framework.messages import tx_from_hex
37+
from test_framework.messages import (
38+
CBlock,
39+
from_hex,
40+
msg_block,
41+
msg_headers,
42+
tx_from_hex,
43+
)
44+
from test_framework.p2p import P2PDataStore
3845
from test_framework.test_framework import BitcoinTestFramework
3946
from test_framework.util import (
4047
assert_equal,
@@ -304,19 +311,56 @@ def run_test(self):
304311
self.log.info("-- Testing all indexes + reindex")
305312
assert_equal(n2.getblockcount(), START_HEIGHT)
306313

314+
# Connect a peer and start syncing the IBD chain before the snapshot
315+
# is loaded.
316+
peer = n2.add_outbound_p2p_connection(P2PDataStore(), p2p_idx=0, connection_type="outbound-full-relay")
317+
# Sending an IBD block before loading the dump so that the peer has a
318+
# last common block set.
319+
block_hash = n0.getblockhash(START_HEIGHT + 1)
320+
block_hex = n0.getblock(blockhash=block_hash, verbosity=0)
321+
block = from_hex(CBlock(), block_hex)
322+
323+
# TODO: REMOVE DEBUG MESSAGE CHECK
324+
with n2.assert_debug_log(expected_msgs=["[FindNextBlocksToDownload] HERE"]):
325+
peer.send_and_ping(msg_headers([block]))
326+
peer.wait_until(lambda: int(block_hash, 16) in peer.getdata_requests)
327+
peer.send_and_ping(msg_block(block))
328+
307329
self.log.info(f"Loading snapshot into third node from {dump_output['path']}")
308330
loaded = n2.loadtxoutset(dump_output['path'])
309331
assert_equal(loaded['coins_loaded'], SNAPSHOT_BASE_HEIGHT)
310332
assert_equal(loaded['base_height'], SNAPSHOT_BASE_HEIGHT)
311333

312334
normal, snapshot = n2.getchainstates()['chainstates']
313-
assert_equal(normal['blocks'], START_HEIGHT)
335+
assert_equal(normal['blocks'], START_HEIGHT + 1)
314336
assert_equal(normal.get('snapshot_blockhash'), None)
315337
assert_equal(normal['validated'], True)
316338
assert_equal(snapshot['blocks'], SNAPSHOT_BASE_HEIGHT)
317339
assert_equal(snapshot['snapshot_blockhash'], dump_output['base_hash'])
318340
assert_equal(snapshot['validated'], False)
319341

342+
# Send all available headers to node 2 to trigger another getdata
343+
# request
344+
blocks = []
345+
for i in range(START_HEIGHT, FINAL_HEIGHT):
346+
block_hash = n0.getblockhash(i)
347+
block_hex = n0.getblock(blockhash=block_hash, verbosity=0)
348+
block = from_hex(CBlock(), block_hex)
349+
blocks.append(block)
350+
351+
# TODO: REMOVE DEBUG MESSAGE CHECK
352+
with n2.assert_debug_log(expected_msgs=["[FindNextBlocksToDownload] HERE"]):
353+
peer.send_and_ping(msg_headers(blocks))
354+
355+
# Node 2 should request the blocks following the snapshot next. It
356+
# should not ask for blocks below the snapshot (IBD blocks).
357+
assert int(n0.getblockhash(SNAPSHOT_BASE_HEIGHT + 1), 16) in peer.getdata_requests
358+
assert int(n0.getblockhash(START_HEIGHT + 2), 16) not in peer.getdata_requests
359+
assert int(n0.getblockhash(SNAPSHOT_BASE_HEIGHT - 1), 16) not in peer.getdata_requests
360+
361+
# Disconnect to not interfere with the rest of the test
362+
peer.peer_disconnect()
363+
320364
self.connect_nodes(0, 2)
321365
self.wait_until(lambda: n2.getchainstates()['chainstates'][-1]['blocks'] == FINAL_HEIGHT)
322366
self.sync_blocks()

0 commit comments

Comments
 (0)