296 Commits

Author SHA1 Message Date
Antoine Poinsot
d03e603abb
descriptors: add a helper to prune BIP32 derivation paths
This is to provide the GUI with a workaround to Bitbox only providing a
single signature per input. Most likely other signing devices will have
this behaviour too in the future. See
https://github.com/wizardsardine/liana/pull/706#issuecomment-1744705808
for details.
2023-10-27 16:50:45 +02:00
Antoine Poinsot
17ca01322e
Revert "Merge #722: Only include BIP32 derivations for a single spending path when creating PSBTs"
This reverts commit 71056982636b408485ab24dab6628a555a6e7924, reversing
changes made to 03c37bd378f4f6bf11d90b224ed1db74b3596eaf.

This reverts PR #722. It turns out the Ledger Bitcoin app needs the
BIP32 derivation for all the keys in the Script, not only for the
spending path used. Therefore always create PSBT with all the BIP32
derivations. We'll add a way to prune them for talking to the Bitbox in
a future commit.
2023-10-27 15:46:03 +02:00
Antoine Poinsot
6f5b053ea5
Revert "Merge #742: commands: don't add derivation paths for keys from different path but same signer"
This reverts commit ec0c2426aa5fa6cee2efabd3ee6f175b41c35f64, reversing
changes made to 26d750d09c84734f56c2dc18cb332a232e24fb6d.

This reverts the fixes to the pruning of BIP32 derivation paths when
creating a PSBT, in preparation of reverting the merge of this feature
altogether. This is because always creating PSBT with only the BIP32
derivations for a single path broke the Ledger support.
2023-10-27 15:43:52 +02:00
Antoine Poinsot
42578609e2
Merge #739: signer: Fix a small borrowck-related fixme
e07637c1567dc85f6b21cbc7f07c7205b0c634f4 signer: Fix a small borrowck-related fixme (Steven Roose)

Pull request description:

ACKs for top commit:
  darosior:
    ACK e07637c1567dc85f6b21cbc7f07c7205b0c634f4

Tree-SHA512: ad6233d0791aa8edc005640954dd40835f141e6629b27e7e13313459cc23523da05a668972307c2ddd83d6930b598b9842bb26f5271f9198256c093ff4c34100
2023-10-24 17:08:24 +02:00
Antoine Poinsot
24edaecbdc
commands: don't add der paths for keys from diff path but same signer
When creating a PSBT, we were checking whether the key was for this path
by checking its origin. This check would return false positive for keys
from other paths but same signer (which shares the same fingerprint).

Instead, check the entire origin for each key to make sure it's actually
the one used in the path we are interested about.

Thanks to Edouard Paris for finding this bug.
2023-10-24 15:44:48 +02:00
edouard
7105698263
Merge #722: Only include BIP32 derivations for a single spending path when creating PSBTs
7f3b0b021858cfb2fe914f3ba6b30a39e3ae05ff qa: test a PSBT has only the BIP32 derivations for a single spending path (Antoine Poinsot)
b71bd693d6ea4c1c3567194fc82be43fb70c05bb qa: don't use a static dummy origin for descriptor xpubs (Antoine Poinsot)
a81d39c81a89cdf5e70b9888cbeb3abaf290a365 commands: do not include BIP32 derivations for other spending paths (Antoine Poinsot)

Pull request description:

ACKs for top commit:
  edouardparis:
    ACK 7f3b0b021858cfb2fe914f3ba6b30a39e3ae05ff

Tree-SHA512: f0e132edf8d653c5575f843b1e85d995f155a2435a6e6257564dc945562df70ec2049c29d77f7580858d9e4a58290b0798f298f77c18255415c4cf26ccc07f33
2023-10-24 12:40:43 +02:00
Steven Roose
e07637c156
signer: Fix a small borrowck-related fixme 2023-10-23 22:45:38 +01:00
edouard
01ca960370
Delete empty labels when they are updated
In order to delete a label, client sends in the
request a null value as label value.

Co-Authored-by: Antoine Poinsot <darosior@protonmail.com>
2023-10-21 09:21:02 +02:00
jp1ac4
176859ed92
commands: add weights before converting to vbytes
Converting to vbytes first can lead to a larger result and
therefore a lower feerate, which could fall below 1 and fail the
sanity check.
2023-10-20 10:03:03 +01:00
Antoine Poinsot
4f2ff1abc0
Merge #723: descriptors: prevent using a signer more than once in a single path
730409eb5299724cdbe1a4da06d272098a791621 descriptors: prevent using a signer more than once in a single path (Antoine Poinsot)
0a95266cce618f83782d3d30362cb2d383b659bf qa: don't use a static dummy origin for descriptor xpubs (Antoine Poinsot)

Pull request description:

  This is necessary to support signers which sign for a single key at once. It also doesn't make any sense to reuse a signer within the same spending path, so rule it out before it creates any new edge cases.

  For more about the Bitbox signer support, which motivated this change, see
  https://github.com/wizardsardine/liana/pull/706#issuecomment-1744705808.

ACKs for top commit:
  edouardparis:
    ACK 730409eb5299724cdbe1a4da06d272098a791621

Tree-SHA512: 3fb34f2a85e103ca5f8eeec901c283c649636971f7730743af24b270626a7fdf11f207a8f3535c9ff69ce475f34c69472595219ac97b8cfd5749379c4213a6e5
2023-10-20 10:15:42 +02:00
Antoine Poinsot
6dfa04f6c7
bitcoin: also log the number of verified blocks in the poller 2023-10-19 10:11:12 +02:00
Antoine Poinsot
b84dbc668c
commands: don't return 100% sync progress until we're done syncing 2023-10-19 10:09:35 +02:00
Antoine Poinsot
f687145c1e
bitcoin: make sure we are *completely* synced before starting up
When not in IBD but catching up to the latest tip, our rounding up of
verificationprogress makes us start while bitcoind is still kind of far
from being caught up. Make sure it doesn't happen by not returning until
bitcoind validated all the blocks we've fetched the headers for.
2023-10-18 19:12:33 +02:00
Antoine Poinsot
03fe06fd1f
descriptors: remove trailing debug trace 2023-10-18 19:10:19 +02:00
Antoine Poinsot
e072e896c7
bitcoind: don't set load_on_startup when loading watchonly wallet
This was necessary to transition wallets that were created without this
flag, but since v2 they are always created with it so this is redundant:
it'd unnecessarily try to update the flag over and over again on
bitcoind's side, always with the same value.
2023-10-08 12:31:41 +02:00
Antoine Poinsot
730409eb52
descriptors: prevent using a signer more than once in a single path
This is necessary to support signers which sign for a single key at
once. It also doesn't make any sense to reuse a signer within the same
spending path, so rule it out before it creates any new edge cases.

For more about the Bitbox signer support, which motivated this change,
see
https://github.com/wizardsardine/liana/pull/706#issuecomment-1744705808.
2023-10-08 11:50:59 +02:00
Antoine Poinsot
a81d39c81a
commands: do not include BIP32 derivations for other spending paths
When creating a PSBT, only include the BIP32 derivations in each input
for the spending path this PSBT was created for.

This is to workaround Bitbox only providing a single signature per
input. Most likely other signing devices will have this behaviour too in
the future. See
https://github.com/wizardsardine/liana/pull/706#issuecomment-1744705808.
2023-10-06 18:23:11 +02:00
jp1ac4
36e04edc82
db: update docstring for spend_coins 2023-09-13 08:49:55 +01:00
jp1ac4
c492c51f26
db: use coins() with filter in list_spending_coins() 2023-09-13 08:49:55 +01:00
jp1ac4
eeaf90e522
commands: optionally filter listcoins by status and/or outpoint 2023-09-13 08:49:54 +01:00
Antoine Poinsot
edb2c513a3
Bump lianad version to 2.0 2023-08-31 13:11:37 +02:00
Antoine Poinsot
5680ad27ec
lib: on Windows, migrate the watchonly wallet from bitcoind datadir
We used to store it there, if it's not within our own datadir copy it
from where it would have been stored by Liana v1.

Note we don't conditionally compile this on Windows so the codepath can
be tested with a functional test.
2023-08-30 17:51:53 +02:00
Antoine Poinsot
c9d86f1c75
lib: implement a superior workaround for the watchonly wallet on Windows
See the added comment for the details. No need to store the watchonly
wallet under bitcoind's datadir anymore. 🎉 🎉
2023-08-30 16:04:44 +02:00
Antoine Poinsot
34f3946fc8
lib: windows: don't unload the wo wallet if not loaded 2023-08-29 20:43:53 +02:00
Antoine Poinsot
9255b5ed94
bitcoind: use the node client to make node requests 2023-08-29 17:34:15 +02:00
Antoine Poinsot
a0c8adbfcc
Merge #609: Add more bitcoind-related setup logging
5c87937d4676354f19357e17b36655eb4853dbf9 Add more bitcoind-related setup logging (Antoine Poinsot)

Pull request description:

  At startup it sometimes appear we may be hanging when setting up bitcoind. Add more logging to give more information about what's taking long to setup (for instance, loading the watchonly wallet).

  Related to https://github.com/wizardsardine/liana/issues/475.

ACKs for top commit:
  darosior:
    ACK 5c87937d4676354f19357e17b36655eb4853dbf9

Tree-SHA512: 75c553cabf545d57a5fc2d251e5b4cd880a931a408c6f1b1052067f2ccc8e0728ad779f30de5a88c2566f9e67ac085b713393ee4fa193331e49c3a8e6112ecc8
2023-08-28 16:35:51 +02:00
edouard
bf3eb33900 lianad api: expose coin address 2023-08-28 13:14:21 +02:00
edouard
7338e6f988 Add labels to lianad 2023-08-28 13:14:21 +02:00
Antoine Poinsot
421c1af6cd
bitcoind: fix the detection of unconfirmed RBF spending txs
As we walk through the spend transactions in the wallet, we may return
the txid of the transaction that was replaced instead of the new one.
2023-08-22 16:49:13 +02:00
Antoine Poinsot
77e46d5495
daemon: remove 'help' detection in command line arguments
This is superfluous and prevents using config files with "-h" in their
path.
2023-08-22 16:42:57 +02:00
Antoine Poinsot
05c9b580db
Merge #625: bitcoin: looper: avoid large sleeps when bitcoind is syncing
0d5041ca4a972a946244643db738e6d35b0d114e bitcoin: looper: avoid large sleeps when bitcoind is syncing (Antoine Poinsot)

Pull request description:

  Sleeping for 30 whole seconds impedes the shutdown check. Sleep only .5s but still only do poll bitcoind one every 30s when it's syncing.

  It was reported to make the GUI hang when closing it while syncing.

ACKs for top commit:
  edouardparis:
    utACK 0d5041ca4a972a946244643db738e6d35b0d114e

Tree-SHA512: 48c9121a02abaf8311d7b646ea64cbde4e14fda737c6f78521739bc185e6081642d05b3ca8088d3ce6782ffa00d6e5879e6a6e09da7f05c85f8476ac83b6860b
2023-08-22 16:16:22 +02:00
Antoine Poinsot
0d5041ca4a
bitcoin: looper: avoid large sleeps when bitcoind is syncing
Sleeping for 30 whole seconds impedes the shutdown check. Sleep only .5s
but still only do poll bitcoind one every 30s when it's syncing.
2023-08-22 15:41:26 +02:00
Antoine Poinsot
2a6b775f60
lib: non-blocking daemon shutdown
This makes it possible to trigger the shutdown of the daemon through the
DaemonHandle, without having to block while waiting for the poller
thread to join.

Incidently, this allows to avoid having to move `self` which in turns
allows to fix a GUI bug (see
https://github.com/wizardsardine/liana/issues/622).

Only available as an optional feature since `is_finished` needs rustc
1.61.
2023-08-22 14:55:14 +02:00
jp1ac4
3372a8d461
bitcoind: add stop method
This is required by the GUI for stopping an internal bitcoind when closing Liana.
2023-08-16 09:26:40 +01:00
jp1ac4
60ee667f6c
bitcoind: make BitcoinD public
This is so that it can be used by the GUI for checking connectivity to bitcoind.
2023-08-16 09:24:10 +01:00
Antoine Poinsot
5c87937d46
Add more bitcoind-related setup logging
At startup it sometimes appear we may be hanging when setting up
bitcoind. Add more loading to give more information about what's taking
long to setup (for instance, loading the watchonly wallet).
2023-08-14 10:29:33 +02:00
Antoine Poinsot
0591243abe
Merge #601: lianad: print a more helpful error message on startup failure
d4da2bf6b451de0cd44630c077b83426ed581940 daemon bin: try to detect '--help' or '-h' (Antoine Poinsot)
01ce0f179d8ef059f04e56e8f7c125264e9949b1 daemon bin: more helpful error message on config file parsing error (Antoine Poinsot)
222c8bba810cb20eeb60270e89857ab09324884d daemon bin: a more helpful error message on unknown arguments. (Antoine Poinsot)

Pull request description:

  Specifically, link to a sample configuration file. How are users supposed to know how to write the config file otherwise?

  Fixes #559.

ACKs for top commit:
  darosior:
    self-ACK d4da2bf6b451de0cd44630c077b83426ed581940 -- trivial.

Tree-SHA512: 7ca05aa0e351c390b67051ad36c2e767b019cf6339d8207e1fdbd1ead47a3d79ab6cd9584c412d98ae876aa7e8ea906885c52261565917a7cd1126798806b5d2
2023-08-14 10:04:57 +02:00
Antoine Poinsot
0785bb7f9f
poller: don't filter out coins with already a spend txid when checking for spends
What if the spending transaction gets RBF'd?
2023-08-11 11:52:51 +02:00
Antoine Poinsot
e549510e21
Merge #602: bitcoind: set load_on_startup to true when loading watchonly wallet
23a63f35e1344a0e6c247e564311cac3e965693c bitcoind: override watchonly wallet as to be loaded on startup (Antoine Poinsot)

Pull request description:

  we used to not set 'load_on_startup' when creating a watchonly wallet. This could create some complications when people are using agressive pruning configurations.

  Fix this by overwriting this parameter when loading watchonly wallets. We can always revert this in the future if for some reason a user wants to have it set to false and no be overwritten everytime Liana loads it.

  Fixes #594.

ACKs for top commit:
  darosior:
    self-ACK 23a63f35e1344a0e6c247e564311cac3e965693c -- tested locally

Tree-SHA512: 8310918286a8a0102bfc76e9d5b2ba4a8b50cac3e4ce2fd26bdfae7c153eeba3bf516d70ed6ef6256c5f4bcc3955559c011a7035cbc293cc594b829ea9038a5c
2023-08-11 10:30:30 +02:00
Antoine Poinsot
d4da2bf6b4
daemon bin: try to detect '--help' or '-h'
It should fall into the "number of args isn't equal to 3" category
anyways, but it's a cheap way of trying to be more helpful.
2023-08-11 10:13:47 +02:00
Antoine Poinsot
23a63f35e1
bitcoind: override watchonly wallet as to be loaded on startup
we used to not set 'load_on_startup' when creating a watchonly wallet.
This could create some complications when people are using agressive
pruning configurations.

Fix this by overwriting this parameter when loading watchonly wallets.
We can always revert this in the future if for some reason a user wants
to have it set to false and no be overwritten everytime Liana loads it.
2023-08-10 13:04:40 +02:00
Antoine Poinsot
01ce0f179d
daemon bin: more helpful error message on config file parsing error 2023-08-10 11:46:41 +02:00
Antoine Poinsot
222c8bba81
daemon bin: a more helpful error message on unknown arguments. 2023-08-10 11:43:47 +02:00
Antoine Poinsot
605c3f657e
descriptors: allow the multipath step to be different than '<0;1>'
Ledger and wallet policies disallow having more than 2 depth after the
placeholder, therefore we can't do `@1/0/<0;1>/*`, `@1/1/<0;1>/*`, ..
Instead we have to do `@1/<0;1>/*`, `@1/<2;3>/*`, ..

Why not? Salvatore also says the cost of deriving another depth is
non-trivial on a signing device.

Don't pick a fight with Salvatore, instead just let the GUI (or whatever
creates the desc) use different multipath steps for keys derived from
the same xpubs.
2023-08-10 08:51:17 +02:00
Antoine Poinsot
10acc482e1
descriptors: fix the signatures count analysis
Since https://github.com/wizardsardine/liana/pull/575 we started using
xpubs with an appended derivation path, and the analysis was assuming
there wasn't any.
2023-08-10 08:50:06 +02:00
Antoine Poinsot
7a33040b83
descriptors: make signed_pubkeys a mapping from fingerprint
It's supposed to represent the number of signature per "master" key, i
guess. At the moment it would always be 1 because the origin changes
when we queried more keys from the signing device (because we increased
the account).
2023-08-09 18:49:49 +02:00
Antoine Poinsot
64df2a15a2
db: keep NOT NULL constraint on is_immature in migration
This adds an extraneous DEFAULT compared to the schema in freshly
created databases, but anything else (altering the column in an
SQLite-friendly way after setting all NULL values to 0) would be way too
involved.
2023-08-07 13:24:30 +02:00
Antoine Poinsot
39d576fe83
Merge #578: Fix the tracking of immature coinbase deposits
097d5e71c19c0c5fc53d1e91087d91edfdd218f3 qa: adapt the migration functional test to also support 1.0 (Antoine Poinsot)
289f6581cccefad42afa870b382fc22eb0c5e46c qa: functional test createspend refuses immature outpoints (Antoine Poinsot)
95dd3e52935cf7a2edb1abdee428efe26ccff36c qa: fix and improve the coinbase deposit functional test (Antoine Poinsot)
6b82894614df3351d788451211d864ecff3f3544 bitcoin: track maturity of coinbase deposits (Antoine Poinsot)
6ab6161078af1932dd43bab813963c78887d7672 commands: expose whether a coin is immature in listcoins (Antoine Poinsot)
fd717123be45b73758f1e965659de8f44031fc90 commands: don't create spends with immature coins (Antoine Poinsot)
26add29b197eb6fdf8f5f86ece4c52576700fc6f database: record whether a coin comes from an immature coinbase (Antoine Poinsot)

Pull request description:

  #567 uncovered that we were actually not tracking coinbase deposits correctly. In fact we would most likely miss them all in any real situation. This is because we would filter out immature coinbase deposits from the result of `listsinceblock` and not consider them newly received coins. But they would be confirmed, and as the chain moves forward we'd not scan this range anymore even once they've become mature.

  This PR fixes it by the simplest possible manner: record immature coinbase deposits as unconfirmed and only mark them as confirmed once they've become mature. This is a bit clumsy, but should be fine for the number of users that would receive payouts from coinbase transactions (ie most likely 0). Also, we don't accurately update coinbase coins on reorg. This is unnecessary as it'd be very unlikely that a mature coinbase would become immature and if there is a 100 blocks reorg that would invalidate it altogether we'd have bigger problems.

  Fixes #567.
  ~~Still as draft as i want to go over this one more time before asking for review, as this if pretty intricate and touches core parts of our codebase.~~

ACKs for top commit:
  darosior:
    self-ACK 097d5e71c19c0c5fc53d1e91087d91edfdd218f3. Didn't have the chance to re-review it but getting it in is best at this time. Edouard will still have a look post-merge.

Tree-SHA512: 4a5f0fb7561af1d4c51dcba26bc20ef5e7a8b2c730547f762782f75c1f28c26e2a577573aa514db8927c1eeb601685071e9eb85c11537621de58c75824435b05
2023-08-01 14:49:00 +02:00
Antoine Poinsot
8ae597fec1
bitcoind: create watchonly wallet with load_on_startup = true 2023-07-31 12:40:59 +02:00
Antoine Poinsot
adf9bf8dd8
Merge #575: descriptor: make it possible to reuse xpubs at different derivation paths
28049d4f7cd2001207cc2b204c31b33d9640077d descriptor: make it possible to use the same xpub at different paths (Antoine Poinsot)

Pull request description:

  This is unnecessary to bump a hardened step to get another xpub for the same participant:
  - It's more hurdle when sharing it
  - It's more hurdle when verifying it on the device's screen
  - It's for the same person within the same script anyways

  Fix this by allowing to use the same xpub multiple times in a descriptor as long as the derivation path is different. Then the GUI will be able to use a new unhardened derivation step instead of bumping the BIP48 "accounts". A unit test is introduced that showcases this.

  See also https://github.com/wizardsardine/liana/issues/542.

ACKs for top commit:
  edouardparis:
    ACK 28049d4f7cd2001207cc2b204c31b33d9640077d

Tree-SHA512: e864a8193998667d36b34d96e6e32bfff1c507b3c31faa324b7f264604c41b5d2d4aefeec3b71a1d3edf5b0242966861887baf97d7a410e43e7449f22c3453f4
2023-07-24 18:32:59 +02:00