Skip to content

Conversation

@Sjors
Copy link
Member

@Sjors Sjors commented Nov 10, 2023

Extracted from #28616, this adds a (very) basic wallet test for assume utxo. It checks some circumstances where a backup can and can't be loaded.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 10, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK theStack, maflcko, achow101
Concept ACK BrandonOdiwuor
Stale ACK pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28616 (Show transactions as not fully confirmed during background validation by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot DrahtBot added the Tests label Nov 10, 2023
for n in self.nodes:
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)

w.backupwallet("/tmp/abc.dat")
Copy link
Member

Choose a reason for hiding this comment

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

My diff was a hack, obviously. I don't think it makes sense to escape the datadir "sandbox" and potentially overwrite user data when running a test.


## Possible test improvements

- TODO: the "assumed" field for a confirmed wallet transaction should be
Copy link
Member

Choose a reason for hiding this comment

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

Seems odd to add a TODO to add a test based on a feature that doesn't even exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

Dropped


self.sync_blocks()

n0.createwallet('test',blank=True, disable_private_keys=True, descriptors=True)
Copy link
Member

Choose a reason for hiding this comment

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

nit: blank may not be needed? Also, could run a python formatter on this file to fix the whitespace?

Copy link
Member Author

@Sjors Sjors Nov 13, 2023

Choose a reason for hiding this comment

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

Might indeed just give the wallet some keys, so later tests can have transactions and rescans.

Which formatter? Ah PEP-8 https://github.com/bitcoin/bitcoin/tree/master/test/functional#style-guidelines

@Sjors Sjors force-pushed the 2023/11/test-wallet-assume branch from 0b81433 to f4f3a0c Compare November 13, 2023 06:43
@Sjors
Copy link
Member Author

Sjors commented Nov 13, 2023

Pushed some cleanups.

Copy link
Member

Choose a reason for hiding this comment

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

Could add a comment why this is needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not. Replaced with a TODO comment to add wallet test for a pruned node.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem like this was pushed?

Copy link
Member Author

@Sjors Sjors Nov 13, 2023

Choose a reason for hiding this comment

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

Also dropping this import since the wallet is no longer watch-only. I added a TODO instead to test scenarios like when you import a descriptor with existing transactions while background sync is in progress.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem like this was pushed?

Co-Authored-By: MarcoFalke <*~=`'#}+{/-|&$^[email protected]>
Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

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

ACK f4f3a0c910a148a158e1879f8c9e6767575539db

@Sjors, I think you need to fix @maflcko's email on the co-authoring section in the commit body.

@maflcko
Copy link
Member

maflcko commented Nov 27, 2023

lgtm ACK f4f3a0c910a148a158e1879f8c9e6767575539db

@Sjors Sjors force-pushed the 2023/11/test-wallet-assume branch from f4f3a0c to 997b9a7 Compare November 28, 2023 15:23
@Sjors
Copy link
Member Author

Sjors commented Nov 28, 2023

@achow101 good catch, I indeed forgot to push.

@pablomartin4btc I think he likes it this way

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

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

Concept ACK

@theStack
Copy link
Contributor

Concept ACK

Will review in a bit. As a follow-up idea, maybe we could put the AssumeUTXO chain and snapshot creation in a shared module, in order to deduplicate code between feature_assumeutxo.py and wallet_assumeutxo.py? If we ever wanted to change the snapshot chainstate for e.g. more advanced tests, it'd be quite annoying having to touch several files.

glozow added a commit that referenced this pull request Jan 10, 2024
…fter loading

9315754 test: assumeutxo: spend coin from snapshot chainstate after loading (Sebastian Falbesoner)

Pull request description:

  This PR extends the AssumeUTXO functional test by submitting a spending transaction for an UTXO that is only available in a the snapshot chainstate (after loading via `loadtxoutset`), i.e. it hasn't been seen in a block before. With that we can verify that snapshot coins are visible to the mempool.

  Note that we unfortunately can't use MiniWallet here, as the only available UTXO to spend from the snapshot chainstate is at height 200, where a P2PKH created from the test framework's deterministic private key is used (see `TestNode.generate(...)` and the `PRIV_KEYS` array). Coinbase outputs with smaller heights (<= 199) would be part of the pre-generated chain and hence not qualify for the "UTXO is only in snapshot chainstate and has never been seen in a block" scenario, coinbase outputs with larger heights (>= 201) can't be spent due to immaturity, as the snapshot chainstate block height is 299.

  One could of course mine a different chain with outputs that MiniWallet supports (e.g. taproot anyone-can-spend), but this would change the hardcoded AssumeUTXO hash, colliding with other PRs like #28838, so I wanted to avoid that.

ACKs for top commit:
  maflcko:
    lgtm ACK 9315754
  jamesob:
    ACK 9315754

Tree-SHA512: 0665868e1e91fe74f408d0a239cc264bbbc11a6b55bcc0e86cc8b4b2ec1f44977884b817dbe9065a7c768332cab464636656858bc8b9c8e7d7810498e0a17d78
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Code-review ACK 997b9a7

Also ran the test locally.

Comment on lines +81 to +82
assert_equal(n.getblockchaininfo()[
"headers"], SNAPSHOT_BASE_HEIGHT)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: looks like an unintended newline here?

Suggested change
assert_equal(n.getblockchaininfo()[
"headers"], SNAPSHOT_BASE_HEIGHT)
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)

@DrahtBot DrahtBot requested review from BrandonOdiwuor, maflcko and pablomartin4btc and removed request for BrandonOdiwuor January 10, 2024 17:51
@maflcko
Copy link
Member

maflcko commented Jan 11, 2024

lgtm ACK 997b9a7

@DrahtBot DrahtBot requested review from BrandonOdiwuor and removed request for BrandonOdiwuor and maflcko January 11, 2024 10:16
@achow101
Copy link
Member

ACK 997b9a7

@DrahtBot DrahtBot removed the request for review from BrandonOdiwuor January 11, 2024 16:23
@achow101 achow101 merged commit 4e104e2 into bitcoin:master Jan 11, 2024
@jamesob
Copy link
Contributor

jamesob commented Jan 11, 2024

Posthumous ACK 997b9a7

Was just in the middle of reviewing this and figuring out how to add some balance checks. May file a followup.

@maflcko
Copy link
Member

maflcko commented Jan 11, 2024

https://github.com/bitcoin/bitcoin/actions/runs/7491713362/job/20393561752?pr=29218#step:27:7881

                                   test_framework.authproxy.JSONRPCException: remove_all: The process cannot access the file because it is being used by another process.: "D:\a\_temp\test_runner_?_??_20240111_163825\wallet_assumeutxo_47\node1\regtest\w" (-1)

assert_equal(n.getblockchaininfo()[
"headers"], SNAPSHOT_BASE_HEIGHT)

w.backupwallet("backup_w.dat")
Copy link
Member Author

Choose a reason for hiding this comment

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

@jamesob I think you can just close the wallet after this call?

Copy link
Member Author

Choose a reason for hiding this comment

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

From reading the test again (it's a been a while) I don't think we care about this loaded wallet w anymore.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the problem is that the original wallet is open. The error is the path for the restored wallet on node1, not the original on node0.

Copy link
Member Author

@Sjors Sjors Jan 12, 2024

Choose a reason for hiding this comment

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

I see (just saw the log in #29234).

Sounds like the node that made the backup holds on to it after writing? Maybe restart the node (n0)? Or copy the backup file?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like the node that made the backup holds on to it after writing? Maybe restart the node? Or copy the backup file?

We don't remove the backup. The failure is in cleaning up the restored wallet after it fails to restore. The backup file is copied to a new path, and that is what remove_all is trying to remove.

I think it's more likely that the database isn't fully closed yet even though the CWallet should be destructed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so it has nothing to do with what n0 did. I'm surprised none of the other wallet backup & restore tests have this issue. But I guess it's a different failure condition.

Copy link
Member

@achow101 achow101 Jan 12, 2024

Choose a reason for hiding this comment

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

It looks like we don't have any other tests that have a failure in CWallet::Create, which I don't think is that surprising since generally the wallet needs to be corrupted for that to happen.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's more likely that the database isn't fully closed yet even though the CWallet should be destructed.

Maybe it's because of -unsafesqlitesync, going to try turning that off for the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder why it's called unsafe :-)

@bitcoin bitcoin locked and limited conversation to collaborators Jan 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants