Skip to content

Instantly share code, notes, and snippets.

@rooprob
Last active October 14, 2021 06:30
Show Gist options
  • Save rooprob/91d78358b920b8f8b7df78af8b2ce99c to your computer and use it in GitHub Desktop.
Save rooprob/91d78358b920b8f8b7df78af8b2ce99c to your computer and use it in GitHub Desktop.
# https://github.com/bitcoin/bitcoin/issues/21605
## debug.log
2021-10-14T03:33:13Z UpdateTip: new best=000000000000000000107efa2f66b85ab41eefec8ce9863610a94fafe9320608 height=493831 version=0x20000000 log2_work=87.444241 tx=270055468 date='2017-11-09T22:27:45Z' progress=0.400284 cache=59.9MiB(446394txo)
2021-10-14T03:33:13Z UpdateTip: new best=0000000000000000006747f674b86424f1f03f66f8cd6fd7e24db5eed7002567 height=493832 version=0x20000000 log2_work=87.444284 tx=270057701 date='2017-11-09T22:40:04Z' progress=0.400287 cache=60.5MiB(451081txo)
2021-10-14T03:33:14Z UpdateTip: new best=00000000000000000023ac583bf812c9679a9849545734685cfd96f9694bb62b height=493833 version=0x20000000 log2_work=87.444327 tx=270060535 date='2017-11-09T22:48:26Z' progress=0.400292 cache=61.1MiB(456009txo)
2021-10-14T03:33:15Z UpdateTip: new best=0000000000000000000fc44ef26463d0b2d0849c9ffe7450ecdbad3966434ad4 height=493834 version=0x20000000 log2_work=87.444370 tx=270063119 date='2017-11-09T22:50:15Z' progress=0.400295 cache=61.6MiB(460268txo)
## gdb
Thread 9 "b-scheduler" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffed7fa640 (LWP 168421)]
LegacyScriptPubKeyMan::MarkUnusedAddresses (this=0x555556443560, script=...) at wallet/scriptpubkeyman.cpp:378
378 bool internal = (meta.key_origin.path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
(gdb) backtrace
#0 LegacyScriptPubKeyMan::MarkUnusedAddresses (this=0x555556443560, script=...) at wallet/scriptpubkeyman.cpp:378
#1 0x0000555555c92052 in CWallet::AddToWalletIfInvolvingMe (this=0x5555606dc190,
ptx=std::shared_ptr<const CTransaction> (use count 1, weak count 0) = {...}, confirm=..., fUpdate=true)
at wallet/wallet.cpp:1057
#2 0x0000555555c92f56 in CWallet::SyncTransaction (this=0x5555606dc190,
ptx=std::shared_ptr<const CTransaction> (use count 1, weak count 0) = {...}, confirm=..., update_tx=true)
at wallet/wallet.cpp:1194
#3 0x0000555555c934f6 in CWallet::blockConnected (this=0x5555606dc190, block=..., height=493831) at wallet/wallet.cpp:1258
#4 0x0000555555739865 in node::(anonymous namespace)::NotificationsProxy::BlockConnected (this=0x55556214f700, block=
std::shared_ptr<const CBlock> (use count 2, weak count 0) = {...}, index=0x55555721d8e0) at node/interfaces.cpp:356
#5 0x0000555555a4f508 in operator() (__closure=0x7fffed7f95e0, callbacks=...) at validationinterface.cpp:222
#6 0x0000555555a51eff in MainSignalsInstance::Iterate<CMainSignals::BlockConnected(const std::shared_ptr<const CBlock>&, const CBlockIndex*)::<lambda()>::<lambda(CValidationInterface&)> >(struct {...} &&) (this=0x5555563ec340, f=...)
at validationinterface.cpp:83
#7 0x0000555555a4f571 in operator() (__closure=0x7fff29e388b0) at validationinterface.cpp:222
#8 0x0000555555a4f726 in operator() (__closure=0x7fff29e38890) at validationinterface.cpp:224
#9 0x0000555555a55ddd in std::__invoke_impl<void, CMainSignals::BlockConnected(const std::shared_ptr<const CBlock>&, const CBlockIndex*)::<lambda()>&>(std::__invoke_other, struct {...} &) (__f=...) at /usr/include/c++/10/bits/invoke.h:60
#10 0x0000555555a54d87 in std::__invoke_r<void, CMainSignals::BlockConnected(const std::shared_ptr<const CBlock>&, const CBlockIndex*)::<lambda()>&>(struct {...} &) (__fn=...) at /usr/include/c++/10/bits/invoke.h:110
#11 0x0000555555a53d58 in std::_Function_handler<void(), CMainSignals::BlockConnected(const std::shared_ptr<const CBlock>&, const CBlockIndex*)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...) at /usr/include/c++/10/bits/std_function.h:291
#12 0x00005555557a085b in std::function<void ()>::operator()() const (this=0x7fffed7f97d0)
at /usr/include/c++/10/bits/std_function.h:622```
# Investigation
## Wrap the offending code with a length check,
diff --color -r bitcoin-22.0.orig/src/wallet/scriptpubkeyman.cpp bitcoin-22.0/src/wallet/scriptpubkeyman.cpp
378,379d377
< bool internal = (meta.key_origin.path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
< int64_t index = meta.key_origin.path[2] & ~BIP32_HARDENED_KEY_LIMIT;
381,382c379,390
< if (!TopUpInactiveHDChain(meta.hd_seed_id, index, internal)) {
< WalletLogPrintf("%s: Adding inactive seed keys failed\n", __func__);
---
> if (meta.key_origin.path.size() > 0){
> WalletLogPrintf("Debug: meta.key_origin.path was %d, has_key_origin=%s\n", meta.key_origin.path.size(), meta.has_key_origin);
> WalletLogPrintf("Debug: meta.key_origin.path[1] %s:\n", meta.key_origin.path[1]);
>
> bool internal = (meta.key_origin.path[1] & ~BIP32_HARDENED_KEY_LIMIT) != 0;
> int64_t index = meta.key_origin.path[2] & ~BIP32_HARDENED_KEY_LIMIT;
>
> if (!TopUpInactiveHDChain(meta.hd_seed_id, index, internal)) {
> WalletLogPrintf("%s: Adding inactive seed keys failed\n", __func__);
> }
> } else {
> WalletLogPrintf("Debug: meta.key_origin.path was %d, has_key_origin=%s\n", meta.key_origin.path.size(), meta.has_key_origin);
## Successfully passed the offending block,
debug.log
000000 log2_work=87.444241 tx=270055468 date='2017-11-09T22:27:45Z' progress=0.400281 cache=59.9MiB(446394txo)
2021-10-14T04:06:43Z UpdateTip: new best=0000000000000000006747f674b86424f1f03f66f8cd6fd7e24db5eed7002567 height=493832 version=0x20000000 log2_work=87.444284 tx=270057701 date='2017-11-09T22:40:04Z' progress=0.400284 cache=60.5MiB(451081txo)
2021-10-14T04:06:44Z UpdateTip: new best=00000000000000000023ac583bf812c9679a9849545734685cfd96f9694bb62b height=493833 version=0x20000000 log2_work=87.444327 tx=270060535 date='2017-11-09T22:48:26Z' progress=0.400289 cache=61.1MiB(456009txo)
2021-10-14T04:06:45Z UpdateTip: new best=0000000000000000000fc44ef26463d0b2d0849c9ffe7450ecdbad3966434ad4 height=493834 version=0x20000000 log2_work=87.444370 tx=270063119 date='2017-11-09T22:50:15Z' progress=0.400292 cache=61.6MiB(460268txo)
2021-10-14T04:06:45Z [default wallet] Debug: meta.key_origin.path was 0, has_key_origin=false
2021-10-14T04:06:45Z [default wallet] AddToWallet 9ab6586b9763d7c278cbaf7c1098445a6c8d674b10204e01c5100e2d75dd3ff1 update
2021-10-14T04:06:45Z UpdateTip: new best=0000000000000000002dd12aab8fa0c2b6b370de52c3f17d9c5a8a4ad4275a88 height=493835 version=0x20000002 log2_work=87.444412 tx=270065357 date='2017-11-09T23:10:10Z' progress=0.400296 cache=61.9MiB(462871txo)
2021-10-14T04:06:46Z UpdateTip: new best=00000000000000000057a65b54e2530cc5f4ff4a66ad4074d87c3956295839eb height=493836 version=0x20000000 log2_work=87.444455 tx=270067476 date='2017-11-09T23:16:16Z' progress=0.400299 cache=62.5MiB(467178txo)
2021-10-14T04:06:48Z UpdateTip: new best=000000000000000000022b0cf2a9b1d65e2228aa4e4b2080de463e8e81d272cc height=493837 version=0x20000000 log2_work=87.444498 tx=270070102 date='2017-11-09T23:19:57Z' progress=0.400303 cache=63.1MiB(472106txo)
2021-10-14T04:06:48Z UpdateTip: new best=0000000000000000001546a8d11a6860cf403e3c63fc720a47f0ec2c3c0a76f4 height=493838 version=0x20000000 log2_work=87.444541 tx=270072402 date='2017-11-09T23:28:16Z' progress=0.400306 cache=63.6MiB(476156txo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment