segfault from importmulti #17911

issue bitcoinhodler opened this issue on January 12, 2020
  1. bitcoinhodler commented at 4:36 AM on January 12, 2020: contributor

    Importing a 1-of-2 multisig p2sh address into 0.19.0.1 testnet, the following script dies with a segfault:

    #!/bin/bash
    
    echo running createwallet
    ./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet createwallet "whynokeys"
    #sleep 4
    
    echo running importprivkey 1
    ./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys importprivkey "cQkx6d2rpRJgrsAUT6sfctTbxSPD1CaTQ5Q6XMQojjZXK1ntjCvo" "addr1" false
    #sleep 4
    
    echo running importprivkey 2
    ./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys importprivkey "cPaQ8eEdhYbtSLX6t86eoWePqZcKB7ibAqH8zhqnA936k8ML8F1H" "addr2" false
    #sleep 4
    
    echo running importmulti
    ./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys importmulti \
        '[
          {
            "scriptPubKey": { "address": "2NBeG2myyAwSUCv1L21kTHAA3SdMELxdspi" },
            "timestamp":1578787441,
            "redeemscript":"512103b7e7e3dacb0ad6f1e2bee28a7a5e8842152a8232f36be55bba66243aee77b95c21039dd05437b699bf98ea32ed3217d0aeb5a5a5fd76a343bebeec6e56968aa9bf0d52ae"
          }]'
    #sleep 4
    
    echo running listunspent
    ./bitcoin-0.19.0.1/bin/bitcoin-cli -testnet -rpcwallet=whynokeys listunspent
    
    echo all done
    

    Results:

    user@host:~$ ./badimport.sh 
    running createwallet
    {
      "name": "whynokeys",
      "warning": ""
    }
    running importprivkey 1
    running importprivkey 2
    running importmulti
    error: Could not connect to the server 127.0.0.1:18332 (error code 1 - "EOF reached")
    
    Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
    running listunspent
    error: Could not connect to the server 127.0.0.1:18332
    
    Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
    all done
    [1]+  Segmentation fault      ./bitcoin-0.19.0.1/bin/bitcoin-qt -server
    
    

    Though sometimes the importmulti completes and the segfault doesn't occur until the listunspent.

    If you uncomment all the sleep 4 lines, this works every time without segfault, however the importmulti gives a bogus warning:

    running createwallet
    {
      "name": "whynokeys",
      "warning": ""
    }
    running importprivkey 1
    running importprivkey 2
    running importmulti
    [
      {
        "success": true,
        "warnings": [
          "Some private keys are missing, outputs will be considered watchonly. If this is intentional, specify the watchonly flag."
        ]
      }
    ]
    running listunspent
    [
      {
        "txid": "d322f58c03fab2526d9cd32baa3ab5e1719a6841a59b92494aa58d2fd2447be1",
        "vout": 1,
        "address": "2NBeG2myyAwSUCv1L21kTHAA3SdMELxdspi",
        "label": "",
        "redeemScript": "512103b7e7e3dacb0ad6f1e2bee28a7a5e8842152a8232f36be55bba66243aee77b95c21039dd05437b699bf98ea32ed3217d0aeb5a5a5fd76a343bebeec6e56968aa9bf0d52ae",
        "scriptPubKey": "a914c9cd895fba08d0cfb13510fd8a4c6be8ad70bd6c87",
        "amount": 0.02100000,
        "confirmations": 80,
        "spendable": true,
        "solvable": true,
        "desc": "sh(multi(1,[c9d3ec21]03b7e7e3dacb0ad6f1e2bee28a7a5e8842152a8232f36be55bba66243aee77b95c,[5e88ca09]039dd05437b699bf98ea32ed3217d0aeb5a5a5fd76a343bebeec6e56968aa9bf0d))#z2pgdmn0",
        "safe": true
      }
    ]
    all done
    

    I doublechecked that the two privkeys imported do match the pubkeys in the redeem script. Also notice that listunspent claims they are spendable and solvable, as expected. Therefore the warning about missing private keys is bogus.

    Expected behavior

    • No segfault
    • No warning from importmulti

    Actual behavior

    • Segfault
    • (after adding delays to script) bogus warning from importmulti

    To reproduce

    See above script. Segfault is not 100% reliable but probably 90%. The bogus warning is 100% reproducible.

    System information

    Running Bitcoin Core 0.19.0.1 on Whonix 14. First noticed on my own build of 0.19.0.1, also reproduced on official download of bitcoin-0.19.0.1-x86_64-linux-gnu.tar.gz.

    Debug log from (successful, non-segfaulting) importmulti:

    2020-01-12T04:24:07Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
    2020-01-12T04:24:07Z Using wallet /home/user/.bitcoin/testnet3/whynokeys
    2020-01-12T04:24:07Z BerkeleyEnvironment::Open: LogDir=/home/user/.bitcoin/testnet3/whynokeys/database ErrorFile=
    /home/user/.bitcoin/testnet3/whynokeys/db.log
    2020-01-12T04:24:07Z init message: Loading wallet...
    2020-01-12T04:24:07Z BerkeleyEnvironment::Open: LogDir=/home/user/.bitcoin/testnet3/whynokeys/database ErrorFile=/home/user/.bitcoin/testnet3/whynokeys/db.log
    2020-01-12T04:24:07Z [whynokeys] Wallet File Version = 10500
    2020-01-12T04:24:07Z [whynokeys] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0
    2020-01-12T04:24:07Z [whynokeys] Performing wallet upgrade to 169900
    2020-01-12T04:24:08Z [whynokeys] keypool added 2000 keys (1000 internal), size=2000 (1000 internal)
    2020-01-12T04:24:08Z [whynokeys] Wallet completed loading in            1476ms
    2020-01-12T04:24:08Z [whynokeys] setKeyPool.size() = 2000
    2020-01-12T04:24:08Z [whynokeys] mapWallet.size() = 0
    2020-01-12T04:24:08Z [whynokeys] mapAddressBook.size() = 0
    2020-01-12T04:24:08Z New outbound peer connected: version: 70015, blocks=1659728, peer=7 (full-relay)
    2020-01-12T04:24:09Z New outbound peer connected: version: 70015, blocks=1659728, peer=8 (full-relay)
    2020-01-12T04:24:09Z P2P peers available. Skipped DNS seeding.
    2020-01-12T04:24:09Z dnsseed thread exit
    2020-01-12T04:24:12Z [whynokeys] Already have script 0014c9d3ec21d7a7667dd8317255d9b604ca0a3b73d5, skipping
    2020-01-12T04:24:16Z [whynokeys] Already have script 00145e88ca0914a704056bc79b25a958d2d543900ef2, skipping
    2020-01-12T04:24:20Z [whynokeys] RescanFromTime: Rescanning last 140 blocks
    2020-01-12T04:24:20Z [whynokeys] Rescan started from block 00000000000007d256a92bfb67e59ecda20fc5728ce36f7404a2bc7c34853378...
    2020-01-12T04:24:20Z [whynokeys] AddToWallet d322f58c03fab2526d9cd32baa3ab5e1719a6841a59b92494aa58d2fd2447be1  new
    2020-01-12T04:24:20Z [whynokeys] Rescan completed in              32ms
    
  2. bitcoinhodler added the label Bug on Jan 12, 2020
  3. bitcoinhodler commented at 7:42 AM on January 12, 2020: contributor

    I think I've just realized that the warning is because I didn't provide the keys directly in the importmulti. Perhaps the warning isn't bogus after all.

  4. elichai commented at 4:24 PM on February 3, 2020: contributor

    Couldn't recreate it. even without your sleeps I don't get any segfault.

    Any chance you can provide a backtrace? (ie run in gbd/lldb and after the segfault write bt)

  5. bitcoinhodler renamed this:
    segfault and bogus warning from importmulti
    segfault from importmulti
    on Feb 3, 2020
  6. bitcoinhodler commented at 7:40 PM on February 3, 2020: contributor

    I rebuilt 0.19.0.1 with --enable-debug:

    user@host:~$ gdb --args bitcoin-qt -server
    GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
    Copyright (C) 2016 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from bitcoin-qt...done.
    (gdb) run
    Starting program: /home/user/bitcoin/src/qt/bitcoin-qt -server
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    [New Thread 0x7ffff57c7700 (LWP 5986)]
    [New Thread 0x7fffeffff700 (LWP 5987)]
    [New Thread 0x7fffeee55700 (LWP 5993)]
    [New Thread 0x7fffe7fff700 (LWP 5994)]
    [New Thread 0x7fffe77fe700 (LWP 5995)]
    [New Thread 0x7fffe6ffd700 (LWP 5996)]
    [New Thread 0x7fffe67fc700 (LWP 5997)]
    [New Thread 0x7fffe5ffb700 (LWP 5998)]
    [New Thread 0x7fffe57fa700 (LWP 5999)]
    [New Thread 0x7fffe4ff9700 (LWP 6000)]
    [New Thread 0x7fffc3fff700 (LWP 6001)]
    [New Thread 0x7fffc37fe700 (LWP 6002)]
    [New Thread 0x7fffb33da700 (LWP 6003)]
    [New Thread 0x7fff4a84e700 (LWP 6004)]
    [New Thread 0x7fff4a04d700 (LWP 6005)]
    [Thread 0x7fff4a84e700 (LWP 6004) exited]
    [New Thread 0x7fff4984c700 (LWP 6008)]
    [New Thread 0x7fff4904b700 (LWP 6009)]
    [New Thread 0x7fff4884a700 (LWP 6010)]
    [New Thread 0x7fff3bfff700 (LWP 6011)]
    [New Thread 0x7fff3b7fe700 (LWP 6012)]
    [New Thread 0x7fff3affd700 (LWP 6013)]
    [New Thread 0x7fff3a7fc700 (LWP 6014)]
    [New Thread 0x7fff39ffb700 (LWP 6015)]
    [Thread 0x7fff4904b700 (LWP 6009) exited]
    
    Thread 1 "bitcoin-qt" received signal SIGSEGV, Segmentation fault.
    0x0000555556687c60 in QProgressDialog::wasCanceled() const ()
    (gdb) bt
    [#0](/bitcoin-bitcoin/0/)  0x0000555556687c60 in QProgressDialog::wasCanceled() const ()
    [#1](/bitcoin-bitcoin/1/)  0x000055555572989f in WalletView::showProgress (this=0x5555577d7a70, 
        title=..., nProgress=1) at qt/walletview.cpp:322
    [#2](/bitcoin-bitcoin/2/)  0x0000555556296354 in QMetaObject::activate(QObject*, int, int, void**) ()
    [#3](/bitcoin-bitcoin/3/)  0x00005555557360e4 in WalletModel::showProgress (_t2=<optimized out>, 
        _t1=..., this=0x7fffc5839400) at qt/moc_walletmodel.cpp:312
    [#4](/bitcoin-bitcoin/4/)  WalletModel::qt_static_metacall (_o=0x7fffc5839400, _c=<optimized out>, 
        _id=<optimized out>, _a=0x7fffb4001550) at qt/moc_walletmodel.cpp:148
    [#5](/bitcoin-bitcoin/5/)  0x0000555556297361 in QObject::event(QEvent*) ()
    [#6](/bitcoin-bitcoin/6/)  0x00005555564fe53c in QApplicationPrivate::notify_helper(QObject*, QEvent*)
        ()
    [#7](/bitcoin-bitcoin/7/)  0x00005555565055a0 in QApplication::notify(QObject*, QEvent*) ()
    [#8](/bitcoin-bitcoin/8/)  0x0000555556267110 in QCoreApplication::notifyInternal2(QObject*, QEvent*)
        ()
    [#9](/bitcoin-bitcoin/9/)  0x000055555626a3ad in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
    [#10](/bitcoin-bitcoin/10/) 0x00005555562b8cd4 in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
    [#11](/bitcoin-bitcoin/11/) 0x0000555555d993ad in QUnixEventDispatcherQPA::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
    [#12](/bitcoin-bitcoin/12/) 0x0000555556265585 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
    [#13](/bitcoin-bitcoin/13/) 0x000055555626e768 in QCoreApplication::exec() ()
    [#14](/bitcoin-bitcoin/14/) 0x000055555569eab5 in GuiMain (argc=<optimized out>, argv=<optimized out>) at qt/bitcoin.cpp:588
    [#15](/bitcoin-bitcoin/15/) 0x00007ffff647f2e1 in __libc_start_main (main=0x5555556881b0 <main(int, char**)>, argc=2, argv=0x7fffffffd548, init=<optimized out>, 
        fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd538) at ../csu/libc-start.c:291
    [#16](/bitcoin-bitcoin/16/) 0x0000555555698dea in _start ()
    (gdb) 
    
  7. promag commented at 8:08 PM on February 3, 2020: member

    @bitcoinhodler do you think you can test the above PR?

  8. bitcoinhodler commented at 2:30 AM on February 4, 2020: contributor

    I cherry-picked your commit onto 0.19.0.1 and the good news: no more bitcoin-qt core dumps!

    I ran probably 10 times, each time exiting bitcoin-qt, deleting the whynokeys wallet dir, and restarting bitcoin-qt.

    Strange thing, though: the first time, the importmulti popped up a GUI progress bar. The remaining nine times, even though importmulti still took a while to run, no GUI popup appeared.

  9. promag commented at 2:50 PM on February 4, 2020: member

    @bitcoinhodler that's due to concurrency - from the RPC thread signals are emitted and enqueued in the GUI thread and when the GUI thread processes them it might open and close the dialog in the same loop and so you don't see it.

    And thanks for testing!

  10. MarcoFalke added the label GUI on Feb 5, 2020
  11. fanquake closed this on Feb 6, 2020

  12. DrahtBot locked this on Feb 15, 2022
  13. Munkybooty referenced this in commit 4871b78eee on Sep 23, 2022
  14. Munkybooty referenced this in commit e8f4e57c39 on Oct 3, 2022
  15. Munkybooty referenced this in commit 32483d351c on Oct 13, 2022
  16. Munkybooty referenced this in commit fdfd3062fe on Oct 13, 2022
  17. PastaPastaPasta referenced this in commit 2447425762 on Oct 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me