Skip to content

Conversation

brunoerg
Copy link
Contributor

@brunoerg brunoerg commented Mar 21, 2024

This PR adds a fuzz target for ScriptPubKeyMan migration. It creates a LegacyDataSPKM which can have some keys/scripts/etc, and then migrate it to descriptor. I tried to keep it as compatible as possible with future legacy wallet removal.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 21, 2024

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/29694.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28710 (Remove the legacy wallet and BDB dependency by achow101)

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.

@brunoerg
Copy link
Contributor Author

cc: @achow101

@brunoerg brunoerg marked this pull request as draft June 25, 2024 20:37
@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from d0c3ca9 to 2e7ac47 Compare September 9, 2024 19:02
@brunoerg brunoerg marked this pull request as ready for review September 10, 2024 11:28
@achow101 achow101 self-requested a review October 15, 2024 15:53
@brunoerg
Copy link
Contributor Author

Inputs for this are available at: brunoerg/qa-assets#2

@maflcko
Copy link
Member

maflcko commented Oct 23, 2024

@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from 2e7ac47 to 77c31c8 Compare November 11, 2024 16:56
@brunoerg
Copy link
Contributor Author

@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from 77c31c8 to ed1a16b Compare November 26, 2024 19:33
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Would be good to ensure that #31374 can be replicated here.

@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from ed1a16b to cdc9458 Compare November 26, 2024 19:48
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Debug: https://github.com/bitcoin/bitcoin/runs/33561912794

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@brunoerg
Copy link
Contributor Author

Force-pushed addressing #29694 (comment)

@brunoerg
Copy link
Contributor Author

brunoerg commented Nov 26, 2024

Would be good to ensure that #31374 can be replicated here.

Since this target is only for spkm migration, I don't think it can be replicated here.

Edit: I can add ApplyMigrationData here and reproduce the crash from #31374. I'm going to move this to draft while working on it.

@brunoerg brunoerg marked this pull request as draft November 27, 2024 13:13
@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch 2 times, most recently from 1421097 to 9750b3f Compare December 2, 2024 12:27
@brunoerg
Copy link
Contributor Author

Force-pushed adding SeedRandomStateForTest and SetMockTime for better stability.

@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from 5e2e916 to 457f1d4 Compare January 27, 2025 18:53
@brunoerg
Copy link
Contributor Author

Rebased

@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch 2 times, most recently from a7749a9 to cbffd66 Compare January 27, 2025 21:47
@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 3, 2025

https://cirrus-ci.com/task/5046981191532544?logs=ci#L1799

[22:03:02.859]  test  2025-01-27T22:03:01.984000Z TestFramework (ERROR): Assertion failed 
[22:03:02.859]                                    Traceback (most recent call last):
[22:03:02.859]                                      File "/ci_container_base/test/functional/test_framework/test_framework.py", line 135, in main
[22:03:02.859]                                        self.run_test()
[22:03:02.859]                                      File "/ci_container_base/ci/scratch/build-x86_64-pc-linux-gnu/test/functional/wallet_migration.py", line 1098, in run_test
[22:03:02.859]                                        self.test_failed_migration_cleanup()
[22:03:02.859]                                      File "/ci_container_base/ci/scratch/build-x86_64-pc-linux-gnu/test/functional/wallet_migration.py", line 899, in test_failed_migration_cleanup
[22:03:02.859]                                        assert all(wallet not in self.master_node.listwallets() for wallet in ["failed", "failed_watchonly", "failed_solvables"])
[22:03:02.859]                                    AssertionError

@brunoerg brunoerg marked this pull request as draft February 3, 2025 16:41
@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from cbffd66 to 0c0e79d Compare February 5, 2025 13:09
@DrahtBot DrahtBot removed the CI failed label Feb 5, 2025
@brunoerg brunoerg marked this pull request as ready for review February 5, 2025 16:58
@brunoerg
Copy link
Contributor Author

brunoerg commented Feb 5, 2025

Just fixed CI, ready for review!

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.

You are skipping the backup restore in commit: "wallet: skip backup restoration when using in-memory dbs"; shouldn't the backup itself be skipped too when in_memory?

@@ -4551,11 +4552,14 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
success = reload_wallet(res.solvables_wallet);
}
}
if (!success) {
if (!success && !in_memory) {
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 if you add the condition there, there are other stuff that's missing and I think they need to be done which are:

  • the for after // Unload the wallets;
  • the lines after // Verify that there is no dangling wallet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? the for after // Unload the wallets are basically playing with created_wallets which is used only if the db is not in memory. Same for the lines after // Verify that there is no dangling wallet which needs ptr_wallet.

Copy link
Member

Choose a reason for hiding this comment

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

the for after // Unload the wallets...

There's the removal of the wallet from the context (if (!RemoveWallet(context, w, /*load_on_start=*/false)) {) using created_wallets - that was done when the wallet was loaded (in LoadWalletInternal-> AddWallet(context, wallet); ).

the lines after // Verify that there is no dangling wallet which needs ptr_wallet.

At the end of the condition is returning an error (return util::Error{error};)

Be aware that if you remove the commit wallet: skip backup restoration when using in-memory dbs altogether you need to add a conditional to avoid the restore section.

At some point I think we need to refactor the wallet and extract the wallet migration behaviour into a new/ few object/ s.

For in-memory SQLite databases, exclusive locking is generally not
necessary because in-memory dbs are private to the connection that
created them.
By using in-memory databases, we do not have dbs file to delete
and restore.
@brunoerg brunoerg force-pushed the 2024-03-fuzz-spkm-migration branch from 0c0e79d to c2bbe12 Compare April 28, 2025 16:49
@DrahtBot
Copy link
Contributor

DrahtBot commented May 7, 2025

🐙 This pull request conflicts with the target branch and needs rebase.

@brunoerg
Copy link
Contributor Author

brunoerg commented May 8, 2025

I'm reworking this target, will draft it.

@brunoerg
Copy link
Contributor Author

Closing in favor of #32624.

@brunoerg brunoerg closed this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants