listunspent, fundrawtransaction, getwalletinfo locks wallet for any other operation
- Dominant language
- C++
- Stars
- 90.2k
- Forks
- 39.4k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 88
Description
**Actual behavior**
If you run a `listunspent`, `fundrawtransaction`, `getwalletinfo` (maybe other commands) on a big wallet (e.g. with wallet with at least 8000 transactions or more) all other operations conducted in parallel (e.g. `getnewaddress`) will be stuck until that command finishes.
Because of this issue when our wallet is sending transactions using `listunspent` and `fundrawtransactions` there is no way to get a new address via `getnewaddress` RPC call (as bitcoin waits for those calls to finish).
I've got bitcoin's datadir and wallet both on NVME drives, but running `listunspent` and sometimes `getwalletinfo` is painfully slow.
The wallet itself is not that big and was created recently to migrate from bdb to the new descriptors wallet:
```
$ du -sh .bitcoin/desc/
78M .bitcoin/desc/
```
```
~$ ./bitcoin-cli -rpcwallet=desc getwalletinfo
{
"walletname": "desc",
"walletversion": 169900,
"format": "sqlite",
"balance": xxx,
"unconfirmed_balance": xxx,
"immature_balance": 0.00000000,
"txcount": 8482,
"keypoolsize": 4000,
"keypoolsize_hd_internal": 4000,
"paytxfee": 0.00000000,
"private_keys_enabled": true,
"avoid_reuse": false,
"scanning": false,
"descriptors": true,
"external_signer": false
}
```
```
$ time ./bitcoin-cli -rpcwallet=desc listunspent|grep txid|wc -l
224
real 1m15.596s
user 0m0.008s
sys 0m0.000s
```
**Expected behavior**
`listunspent` or `fundrawtransaction` shouldn't lock the wallet at least for getting new address, maybe other operations as well?
**To reproduce**
* create a new descriptors wallet and generate 17K addresses there
* create at least 8K transactions in and out
* try to run `listunspent` or `fundrawtransaction` and in parallel `getnewaddress`
* `getnewaddress` will take 60 seconds or more to return an address until either of `listunspent` or `fundrawtransaction` finishes
**System information**
I've tried latest bitcoin release `v24.0.1`, master branch (built 77a36033b5ecbf8dedb917d680f4116786fd7375 commit) issue reproduces.
Self-built for Ubuntu 18.04 LTS.
I've got bitcoin's datadir and wallet both on NVME drives, but running `listunspent` is painfully slow.
Contributor guide
Research direction
Start by reproducing the contention with the descriptors wallet using listunspent or fundrawtransaction in parallel with getnewaddress, as described in the issue. Trace the wallet locking used by these RPC entry points and verify that address generation can complete concurrently; done means the long-running calls no longer block getnewaddress on a large wallet.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, sqlite
- Domain
- backend-api-design, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100