Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Test new header sync behavior in loadtxoutset #29478

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 24 additions & 15 deletions test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def expected_error(log_msg="", rpc_details=""):
f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27, got {wrong_hash}")

def test_headers_not_synced(self, valid_snapshot_path):
for node in self.nodes[1:]:
assert_raises_rpc_error(-32603, "The base block header (3bb7ce5eba0be48939b7a521ac1ba9316afee2c7bada3a0cca24188e6d7d96c0) must appear in the headers chain. Make sure all headers are syncing, and call this RPC again.",
node.loadtxoutset,
valid_snapshot_path)

def test_invalid_chainstate_scenarios(self):
self.log.info("Test different scenarios of invalid snapshot chainstate in datadir")

Expand Down Expand Up @@ -166,26 +172,12 @@ def run_test(self):
for n in self.nodes:
n.setmocktime(n.getblockheader(n.getbestblockhash())['time'])

self.sync_blocks()

fjahr marked this conversation as resolved.
Show resolved Hide resolved
# Generate a series of blocks that `n0` will have in the snapshot,
# but that n1 doesn't yet see. In order for the snapshot to activate,
# though, we have to ferry over the new headers to n1 so that it
# isn't waiting forever to see the header of the snapshot's base block
# while disconnected from n0.
# but that n1 and n2 don't yet see.
for i in range(100):
if i % 3 == 0:
self.mini_wallet.send_self_transfer(from_node=n0)
self.generate(n0, nblocks=1, sync_fun=self.no_op)
newblock = n0.getblock(n0.getbestblockhash(), 0)

# make n1 aware of the new header, but don't give it the block.
n1.submitheader(newblock)
n2.submitheader(newblock)

# Ensure everyone is seeing the same headers.
for n in self.nodes:
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)

self.log.info("-- Testing assumeutxo + some indexes + pruning")

Expand All @@ -195,6 +187,23 @@ def run_test(self):
self.log.info(f"Creating a UTXO snapshot at height {SNAPSHOT_BASE_HEIGHT}")
dump_output = n0.dumptxoutset('utxos.dat')

self.log.info("Test loading snapshot when headers are not synced")
self.test_headers_not_synced(dump_output['path'])

# In order for the snapshot to activate, we have to ferry over the new
# headers to n1 and n2 so that they see the header of the snapshot's
# base block while disconnected from n0.
for i in range(1, 300):
block = n0.getblock(n0.getblockhash(i), 0)
# make n1 and n2 aware of the new header, but don't give them the
# block.
n1.submitheader(block)
n2.submitheader(block)
Comment on lines +197 to +201
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: only fetching the headers rather than the full blocks seems to be sufficient here:

Suggested change
block = n0.getblock(n0.getblockhash(i), 0)
# make n1 and n2 aware of the new header, but don't give them the
# block.
n1.submitheader(block)
n2.submitheader(block)
block_header = n0.getblockheader(n0.getblockhash(i), verbose=False)
# make n1 and n2 aware of the new header, but don't give them the
# block.
n1.submitheader(block_header)
n2.submitheader(block_header)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is already the case. Afaict getblock with verbosity 0 returns the same result as getblockheader with false. Inspired me to suggest this: #29646.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into this as a follow-up, potentially improving getblockheader too since it's confusing that this works


# Ensure everyone is seeing the same headers.
for n in self.nodes:
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)

assert_equal(
dump_output['txoutset_hash'],
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")
Expand Down
2 changes: 0 additions & 2 deletions test/functional/wallet_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def run_test(self):
for n in self.nodes:
n.setmocktime(n.getblockheader(n.getbestblockhash())['time'])

self.sync_blocks()

n0.createwallet('w')
w = n0.get_wallet_rpc("w")

Expand Down