Merge bitcoin/bitcoin#27920: wallet: bugfix, always use apostrophe for spkm descriptor ID

5df988b534 test: add coverage for descriptor ID (furszy)
6a9510d2da wallet: bugfix, always use apostrophe for spkm descriptor ID (furszy)
97a965d98f refactor: extract descriptor ID calculation from spkm GetID() (furszy)
1d207e3931 wallet: do not allow loading descriptor with an invalid ID (furszy)

Pull request description:

  Aiming to fix #27915.

  As we re-write the descriptor's db record every time that
  the wallet is loaded (at `TopUp` time), if the spkm ID differs
  from the one in db, the wallet will enter in an unrecoverable
  corruption state (due to the storage of a descriptor with an ID
  that is not linked to any other descriptor record in DB), and
  no soft version will be able to open it anymore.

  Because we cannot change the past, to stay compatible between
  releases, we need to always use the apostrophe version for the
  spkm IDs.

ACKs for top commit:
  achow101:
    ACK 5df988b534
  Sjors:
    tACK 5df988b534

Tree-SHA512: f63fc4aac7d21a4e515657471758d28857575e751865bfa359298f8b89b2568970029ca487a873c1786a5716325f453f06cd417ed193f3366417f6e8c2987332
This commit is contained in:
Andrew Chow
2023-07-03 21:30:38 -04:00
6 changed files with 135 additions and 72 deletions

View File

@@ -803,6 +803,12 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
}
pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
// Prior to doing anything with this spkm, verify ID compatibility
if (id != pwallet->GetDescriptorScriptPubKeyMan(desc)->GetID()) {
strErr = "The descriptor ID calculated by the wallet differs from the one in DB";
return DBErrors::CORRUPT;
}
DescriptorCache cache;
// Get key cache for this descriptor