Skip to content

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Jul 16, 2025

Since loading a wallet may change some parts of tx records (e.g. adding nOrderPos), we should rewrite the records instead of copying them so that the automatic upgrade does not need to be performed again when the wallet is loaded.

This is useful for future PRs I'm working on where we need to be sure about what data exists in a tx record in descriptor wallets.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 16, 2025

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/32985.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK rkrux

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:

  • #33034 (wallet: Store transactions in a separate sqlite table 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.

Since loading a wallet may change some parts of tx records (e.g. adding
nOrderPos), we should rewrite the records instead of copying them so
that the automatic upgrade does not need to be performed again when the
wallet is loaded.
Copy link
Contributor

@rkrux rkrux left a comment

Choose a reason for hiding this comment

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

lgtm ACK af041c4

This appears to be a preparatory commit for the latter PR #33034 where transaction is written in the SQLite transactions table as well during migration. This appears fine also because during wallet loading, the transaction is rewritten if it needs to be reordered based on an updated nOrderPos.

I don't suppose there is an easy way to test this in the wallet_migration functional test because the wallet is loaded right after migration is done and this subsequent load would also rewrite the transaction if needed. There is an inspect_sqlite_db function in the functional tests that can query the wallet data before the post-migration load but I don't know if it'd be trivial to generate a specific test that causes the transaction data to change after pre-migration load. Thus, not suggesting to add a functional test for this.

@Eunovo
Copy link
Contributor

Eunovo commented Oct 29, 2025

I'm assuming the PR description is referring to the changes ReorderTransactions() makes during LoadWallet(). If this is the case, these changes are persisted during ReorderTransactions(), so copying the records to the SQLite DB when we do MigrateToSQLite should already transfer the changes to the new DB. Why do we need to rewrite the TX records? What in-memory changes are we trying to persist to the new DB?

@achow101
Copy link
Member Author

these changes are persisted during ReorderTransactions()

Not for migration since legacy wallets are only opened with a BerkeleyRODatabase which does not write anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants