Page MenuHomePhabricator

walletdb: don't reinitialize desc cache with multiple cache entries
ClosedPublic

Authored by PiRK on Aug 31 2021, 09:15.

Details

Summary

When loading descriptor caches, we would accidentally reinitialize the
descriptor cache when seeing that one already exists. This should have
only been initializing the cache when one does not exist. However this
code itself is unnecessary as the act of looking up the cache to add to
it will initialize it if it didn't already exist.

This issue could be hit by trying to load a wallet that had imported a
multisig descriptor. The wallet would fail to load.

A test has been added to wallet_importdescriptors.py to catch this case.
Another test case has also been added to check that loading a wallet
with only single key descriptors works.

This is a backport of core#19441

Test Plan

ninja all check-all

I confirmed that before the change in walletdb.cpp, the new test fails with an error Error: Unable to expand wallet descriptor from cache (-4). And the change fixes it.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Aug 31 2021, 09:15

Tail of the build log:

2021-08-31T09:21:12.268863Z (mocktime: 2021-08-31T11:21:13Z)       - Connect 1 transactions: 0.21ms (0.214ms/tx, 0.000ms/txin) [0.00s (0.02ms/blk)]
2021-08-31T09:21:12.269503Z (mocktime: 2021-08-31T11:21:13Z)     - Verify 0 txins: 0.90ms (0.000ms/txin) [0.01s (0.04ms/blk)]
Segmentation fault (core dumped)
[389/445] bitcoin: testing scheduler_tests
[390/445] Running utility command for check-bitcoin-bswap_tests
[391/445] bitcoin: testing merkleblock_tests
[392/445] bitcoin: testing bip32_tests
[393/445] bitcoin: testing crypto_tests
[394/445] bitcoin: testing schnorr_tests
[395/445] Running utility command for check-bitcoin-coinselector_tests
[396/445] Running utility command for check-bitcoin-key_tests
[397/445] bitcoin: testing sync_tests
[398/445] Running utility command for check-bitcoin-crypto_tests
[399/445] bitcoin: testing script_tests
[400/445] bitcoin: testing torcontrol_tests
[401/445] bitcoin: testing coins_tests
[402/445] Running utility command for check-bitcoin-bip32_tests
[403/445] Running utility command for check-bitcoin-merkleblock_tests
[404/445] bitcoin: testing serialize_tests
[405/445] bitcoin: testing settings_tests
[406/445] Running utility command for check-bitcoin-blockindex_tests
[407/445] bitcoin: testing streams_tests
[408/445] Running utility command for check-bitcoin-scheduler_tests
[409/445] bitcoin: testing timedata_tests
[410/445] Running utility command for check-bitcoin-schnorr_tests
[411/445] Running utility command for check-bitcoin-config_tests
[412/445] bitcoin: testing validation_flush_tests
[413/445] bitcoin: testing util_tests
[414/445] Running utility command for check-bitcoin-serialize_tests
[415/445] bitcoin: testing compilerbug_tests
[416/445] Running utility command for check-bitcoin-coins_tests
[417/445] bitcoin: testing checkpoints_tests
[418/445] Running utility command for check-bitcoin-validation_flush_tests
[419/445] Running utility command for check-bitcoin-compilerbug_tests
[420/445] bitcoin: testing script_standard_tests
[421/445] bitcoin: testing validationinterface_tests
[422/445] Running utility command for check-bitcoin-timedata_tests
[423/445] Running utility command for check-bitcoin-blockfilter_tests
[424/445] bitcoin: testing blockstatus_tests
[425/445] bitcoin: testing versionbits_tests
[426/445] Running utility command for check-bitcoin-sync_tests
[427/445] Running utility command for check-bitcoin-streams_tests
[428/445] bitcoin: testing cashaddr_tests
[429/445] bitcoin: testing monolith_opcodes_tests
[430/445] Running utility command for check-bitcoin-txvalidationcache_tests
[431/445] Running utility command for check-bitcoin-checkpoints_tests
[432/445] Running utility command for check-bitcoin-monolith_opcodes_tests
[433/445] Running utility command for check-bitcoin-cashaddr_tests
[434/445] Running utility command for check-bitcoin-script_standard_tests
[435/445] Running utility command for check-bitcoin-settings_tests
[436/445] Running utility command for check-bitcoin-radix_tests
[437/445] Running utility command for check-bitcoin-validationinterface_tests
[438/445] Running utility command for check-bitcoin-util_tests
[439/445] Running utility command for check-bitcoin-torcontrol_tests
[440/445] Running utility command for check-bitcoin-blockstatus_tests
[441/445] Running utility command for check-bitcoin-blockcheck_tests
[442/445] Running utility command for check-bitcoin-script_tests
[443/445] Running utility command for check-bitcoin-versionbits_tests
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang-tidy failed with exit code 1

Tail of the build log:

2021-08-31T09:20:22.789961Z BlockChecked: block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f state=Valid
2021-08-31T09:20:22.790030Z   - Connect total: 0.18ms [0.00s (0.18ms/blk)]
2021-08-31T09:20:22.790069Z   - Flush: 0.04ms [0.00s (0.04ms/blk)]
2021-08-31T09:20:22.790136Z   - Writing chainstate: 0.07ms [0.00s (0.07ms/blk)]
2021-08-31T09:20:22.790282Z UpdateTip: new best=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f height=0 version=0x00000001 log2_work=32.000022 tx=1 date='2009-01-03T18:15:05Z' progress=0.000000 cache=0.0MiB(0txo)
2021-08-31T09:20:22.790322Z   - Connect postprocess: 0.19ms [0.00s (0.19ms/blk)]
2021-08-31T09:20:22.790354Z - Connect block: 0.55ms [0.00s (0.55ms/blk)]
2021-08-31T09:20:22.790402Z Checking mempool with 0 transactions and 0 inputs
2021-08-31T09:20:22.790479Z Enqueuing BlockConnected: block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f block height=0
2021-08-31T09:20:22.790569Z Enqueuing UpdatedBlockTip: new block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f fork block hash=null (in IBD=true)
2021-08-31T09:20:22.791374Z ERROR: DeserializeFileDB: Failed to open file /tmp/test_common_Bitcoin ABC/129e39da6a39595298b05bafaa35cbb4afc66583231fc986cfeb3e174af0f1d9/banlist.dat
2021-08-31T09:20:22.791410Z Invalid or missing banlist.dat; recreating
2021-08-31T09:20:22.791692Z BlockConnected: block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f block height=0
2021-08-31T09:20:22.791800Z UpdatedBlockTip: new block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f fork block hash=null (in IBD=true)
2021-08-31T09:20:22.794458Z Flushed 0 banned node ips/subnets to banlist.dat  3ms
2021-08-31T09:20:22.794906Z net: setting try another outbound peer=false
2021-08-31T09:20:22.794960Z SetNetworkActive: true
2021-08-31T09:20:22.816254Z Seed: Setting random seed for current tests to RANDOM_CTX_SEED=60dff95c1147fbad5ef547da66d420f118b1c8885249106b36cfba827816b670
2021-08-31T09:20:22.816352Z Bitcoin ABC version v0.24.1-109175ab0 (debug build)
2021-08-31T09:20:22.819379Z Checkpoints will be verified.
2021-08-31T09:20:22.819419Z Assuming ancestors of block 00000000000000000628880962d4adfe6e2fb8b303f8a700c4a006985596a719 have valid signatures.
2021-08-31T09:20:22.819453Z Setting nMinimumChainWork=00000000000000000000000000000000000000000155059db5fe1bf27f1ff6d8
2021-08-31T09:20:22.831891Z Using 32 MiB out of 32 requested for signature cache, able to store 1048576 elements
2021-08-31T09:20:22.839255Z Using 32 MiB out of 32 requested for script execution cache, able to store 1048576 elements
2021-08-31T09:20:22.839653Z Opened LevelDB successfully
2021-08-31T09:20:22.839716Z Using obfuscation key for /tmp/test_common_Bitcoin ABC/0f4f7ee8b349b7f648541e468438ba7953f3deffec781c7ca0fd002fab6ec841/blocks/index: 0000000000000000
2021-08-31T09:20:22.839796Z Switching active chainstate to Chainstate [ibd] @ height -1 (null)
2021-08-31T09:20:22.839933Z Opened LevelDB successfully
2021-08-31T09:20:22.840059Z Wrote new obfuscate key for /tmp/test_common_Bitcoin ABC/0f4f7ee8b349b7f648541e468438ba7953f3deffec781c7ca0fd002fab6ec841/chainstate: 4138e350f095b3d2
2021-08-31T09:20:22.840103Z Using obfuscation key for /tmp/test_common_Bitcoin ABC/0f4f7ee8b349b7f648541e468438ba7953f3deffec781c7ca0fd002fab6ec841/chainstate: 4138e350f095b3d2
2021-08-31T09:20:22.840268Z Pre-allocating up to position 0x1000000 in blk00000.dat
2021-08-31T09:20:22.840591Z   - Load block from disk: 0.08ms [0.00s]
2021-08-31T09:20:22.840741Z BlockChecked: block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f state=Valid
2021-08-31T09:20:22.840813Z   - Connect total: 0.22ms [0.00s (0.20ms/blk)]
2021-08-31T09:20:22.840852Z   - Flush: 0.04ms [0.00s (0.04ms/blk)]
2021-08-31T09:20:22.840921Z   - Writing chainstate: 0.07ms [0.00s (0.07ms/blk)]
2021-08-31T09:20:22.841057Z UpdateTip: new best=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f height=0 version=0x00000001 log2_work=32.000022 tx=1 date='2009-01-03T18:15:05Z' progress=0.000000 cache=0.0MiB(0txo)
2021-08-31T09:20:22.841097Z   - Connect postprocess: 0.18ms [0.00s (0.18ms/blk)]
2021-08-31T09:20:22.841131Z - Connect block: 0.58ms [0.00s (0.57ms/blk)]
2021-08-31T09:20:22.841180Z Checking mempool with 0 transactions and 0 inputs
2021-08-31T09:20:22.841259Z Enqueuing BlockConnected: block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f block height=0
2021-08-31T09:20:22.841372Z Enqueuing UpdatedBlockTip: new block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f fork block hash=null (in IBD=true)
2021-08-31T09:20:22.842023Z ERROR: DeserializeFileDB: Failed to open file /tmp/test_common_Bitcoin ABC/0f4f7ee8b349b7f648541e468438ba7953f3deffec781c7ca0fd002fab6ec841/banlist.dat
2021-08-31T09:20:22.842058Z Invalid or missing banlist.dat; recreating
2021-08-31T09:20:22.844555Z Flushed 0 banned node ips/subnets to banlist.dat  2ms
2021-08-31T09:20:22.845011Z net: setting try another outbound peer=false
2021-08-31T09:20:22.845059Z SetNetworkActive: true
MoneyRange(nSum)2021-08-31T09:20:22.859257Z BlockConnected: block hash=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f block height=0
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create
Aborted (core dumped)
[407/453] Running secp256k1 test suite
PASSED: secp256k1 test suite
[427/453] Running pow test suite
PASSED: pow test suite
[446/453] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[450/453] Running utility command for check-bitcoin-coins_tests
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1
This revision is now accepted and ready to land.Aug 31 2021, 12:38