144 Commits

Author SHA1 Message Date
Antoine Poinsot
a78f46fa2f
[refactoring] jsonrpc: sort command names alphabetically 2022-12-09 12:27:48 +01:00
Antoine Poinsot
c09ae3f87b
commands, jsonrpc: add a new 'createrecovery' command
This is a new command dedicated to the recovery usecase. For now it's
dead simple: sweep all coins that are available through the recovery
path to a given address.
2022-12-09 12:27:47 +01:00
Antoine Poinsot
3d5d0134b4
commands: fix the capacity of input vectors in create_spend
They were based on the expected size of the outputs vector...
2022-12-09 12:20:39 +01:00
Antoine Poinsot
f2312593da
commands: check for dust outputs in the PSBT sanity checks 2022-12-09 12:19:02 +01:00
Antoine Poinsot
9f23161a53
commands: correct the max feerate value
We should have a functional test for this...
2022-12-09 12:19:02 +01:00
Antoine Poinsot
54410cd9c4
database: allow to query coins by their spending status 2022-12-09 12:19:01 +01:00
Antoine Poinsot
07e5ea3fd2
commands: fill non_witness_utxo field in PSBT inputs for createspend
We are still in segwit v0, so signers need it!!
2022-12-09 10:49:49 +01:00
Antoine Poinsot
f03b617490
Merge #176: Friendlier bitcoind startup error handling
0306773cdca15009d3bf2c6eb0c3ebd8e7fb7989 daemon: log and exit 1 on startup error, don't panic (Antoine Poinsot)
13b2b8eef4dd5deafe04b2330b469067afd0b12c bitcoind: immediately set the default retry limit (Antoine Poinsot)
b0ef121e91209e1c69ddefa0765d7a93d1dfb569 bitcoind: accurate connection sanity checks at startup (Antoine Poinsot)

Pull request description:

  We were not properly treating warming up errors when bitcoind was starting up. Also, better to just log as error and `exit` with `1` instead of panic'ing on a daemon startup error.

  See the commit messages for details.

  Fixes #134
  Fixes #163

ACKs for top commit:
  edouardparis:
    ACK 0306773cdca15009d3bf2c6eb0c3ebd8e7fb7989

Tree-SHA512: e14a72456104682ccff30d88e21303447065d371aed7279461595795eb938ba823578f05cc47704d996dbe570d12f467b91a88d58363511864e6a1f10eb76004
2022-12-08 17:23:11 +01:00
Antoine Poinsot
0306773cdc
daemon: log and exit 1 on startup error, don't panic 2022-12-08 14:59:50 +01:00
Antoine Poinsot
13b2b8eef4
bitcoind: immediately set the default retry limit
We were previously adding it later on to fail early on startup error.
This didn't handle well "warming up" errors.

Now that it was reachable and listening to requests already, we can just
use the real retry limit from the get-go.
2022-12-08 14:59:49 +01:00
Antoine Poinsot
b0ef121e91
bitcoind: accurate connection sanity checks at startup
The current checks were only testing whether a bitcoind was at all
reachable. We need to make sure it is also listening to requests (and
not warming up) in order for the assumptions made later on (we panic on
requests if we retried for too long) to hold.

This makes the startup sanity checks also wait for bitcoind to get out
of warming up mode.
2022-12-08 14:59:49 +01:00
Antoine Poinsot
9cc748cd2a
descriptors: make the satisfaction size helpers part of the multi desc
Otherwise caller would have to call "receive_desc()" or "change_desc()"
before being able to call that which is unnecessary and an awkward API.
2022-12-08 11:57:47 +01:00
Antoine Poinsot
929c79a56a
descriptors: check for duplicates when creating a descriptor 2022-12-08 11:54:23 +01:00
Antoine Poinsot
066994dddb
Merge #161: daemon: update rust-miniscript to 0.9
3224f08ba083e384f55abb690770d8dd09f8ea3d daemon: update rust-miniscript to 0.9 (Antoine Poinsot)

Pull request description:

  This also updates the multipaths descriptor patch to the review PR https://github.com/rust-bitcoin/rust-miniscript/pull/470 (rebased on 0.9)

  Fixes #123.

ACKs for top commit:
  darosior:
    self-ACK 3224f08ba083e384f55abb690770d8dd09f8ea3d -- trivial.

Tree-SHA512: 03c8b181e96df8d73953cefadfbb090049859f01e6c8d03cf8417ad4d46795dc295b097f8df6c0f683fb9da03b78f39e824cb7768376d1d5718bdce177edcb6d
2022-12-08 10:09:50 +01:00
Antoine Poinsot
3224f08ba0
daemon: update rust-miniscript to 0.9
This also updates the multipaths descriptor patch to the review PR https://github.com/rust-bitcoin/rust-miniscript/pull/470 (rebased on 0.9)
2022-12-07 11:58:36 +01:00
Antoine Poinsot
dc61a1c3bd
commands: remove discrepancy between blockheight and block_height 2022-12-07 11:42:17 +01:00
Antoine Poinsot
0c80702f1b
Merge #151: Some tiny cleanups
a4e66566886901f28e383e67f06de2215e3ebc42 daemon: remove / correct some TODOs (Antoine Poinsot)
628ed3d0ed3997a64d8d0d92206842ef5445e2fa descriptors: remove TODO in assertions, explain instead (Antoine Poinsot)
62067f0030795143cbec87dcc1d5db0e5265c5c5 qa: remove needless import in fixtures (Antoine Poinsot)

Pull request description:

  Small things i noticed while working on #148.

ACKs for top commit:
  darosior:
    ACK a4e66566886901f28e383e67f06de2215e3ebc42

Tree-SHA512: 0d6b6b95a99744cd92b9ecd30d9678ff27c7223238a31c3e9093899caa11889d40cfe4c7d855c07c378ca127ca900269980d179aeb02478f04e3eaa1e20e1721
2022-12-06 13:20:33 +01:00
Antoine Poinsot
a4e6656688
daemon: remove / correct some TODOs 2022-12-05 11:17:27 +01:00
Antoine Poinsot
628ed3d0ed
descriptors: remove TODO in assertions, explain instead 2022-12-05 10:05:26 +01:00
Antoine Poinsot
eebc96c4d5
descriptors: add a method to get the size of a spending input
This is useful for the GUI.
2022-12-05 09:58:04 +01:00
Antoine Poinsot
478707df27
bitcoind: detect coins as spent even if they are unconfirmed 2022-11-23 11:51:28 +01:00
Antoine Poinsot
8e7e46a52c
bitcoind: detect spent coins for send-to-self transactions
We weren't specifying include_change therefore those were not part of
listsinceblock result and never detected as spent!
2022-11-23 11:51:27 +01:00
Antoine Poinsot
1f06c4d4dc db: fix the list_txids query
We need to limit the number of *distinct* txids. Limiting the number of
results in the inner queries at all could lead to incorrect results
with regard to ordering too.

See https://github.com/revault/liana/pull/99#discussion_r1029619579.
2022-11-22 19:31:02 +01:00
edouard
774f969594 Add listtransaction command 2022-11-22 19:31:02 +01:00
edouard
3cd709697b Add listconfirmed command 2022-11-22 19:31:02 +01:00
Antoine Poinsot
f5ff0fad36
daemon: 'revaultd' name usage leftovers 2022-11-18 18:33:07 +01:00
Antoine Poinsot
968a7d17a0
daemon: rename Minisafe to Liana 2022-11-17 17:10:22 +01:00
Antoine Poinsot
4bd65213e2
commands: swap the outpoints and destinations arguments to createspend
The outpoints argument could eventually be made optional in order to
introduce some automated coin selection. So it makes more sense for it
to be after a required parameter, the destinations.
2022-11-17 15:15:22 +01:00
Antoine Poinsot
838daa0c93
commands: set the BIP32 derivation in PSBT for change outputs
So the signing devices (or even the GUI) can view them as such.
2022-11-17 15:01:34 +01:00
Antoine Poinsot
dbf17681a4
commands: signal for opt-in RBF in Spend transactions 2022-11-17 14:52:27 +01:00
Antoine Poinsot
b31673de32
poller: update our internal derivation index also from the chain
Fixes #81
2022-11-16 15:46:25 +01:00
Antoine Poinsot
42d2ffeec1
db: more flexible interface for updating our next derivation indexes.
Instead of only incrementing it, allow to be able to set it to any
value. This will be useful for instance to set the derivation to the
latest used onchain, if another wallet is much further down the
derivation tree than we are (or after a rescan).
2022-11-16 15:19:50 +01:00
Antoine Poinsot
32f3bdeb16
bitcoind: check the rescan was successful, retry at most 10 times 2022-11-14 14:35:57 +01:00
Antoine Poinsot
337f422283
bitcoind: add the timestamp to the 'listdescriptors' entry 2022-11-14 14:13:48 +01:00
Antoine Poinsot
3c75e2e944
bitcoind: disable retry logic for noreply requests
Callers that use this client will have to use a custom retry logic.
2022-11-14 14:07:39 +01:00
Antoine Poinsot
96b634b69c
bitcoind: make the rescan starting interface failible
This makes us more robust to races, where we'd crash previously
2022-11-14 09:47:43 +01:00
Antoine Poinsot
85cd261fcd
bitcoin: remove the BitcoinError enum, use String as error instead
It looks like we'd end up only using variants that contain a String, for
little benefit. Cut down on complexity for now.
2022-11-14 09:37:13 +01:00
Antoine Poinsot
9b253e7ea7
bitcoind: rescan with a range, handle spurious error when rescanning
Give the range to 'importdescriptors' when re-importing a descriptor for
rescanning. This is because the range must include the range of the
descriptor being updated.

Secondly, it is possible that the combination of our timeout-to-1s hack
and our retry logic trigger an edge case: we would retry after
successfully triggering a rescan, and therefore panic on a "a rescan is
already ongoing" error. Instead check before starting that we aren't
rescanning already, and assume that such an error after triggering the
rescan is because we succeeded. That's racy but only reasonably so (as
long as we don't crash, which isn't the case here).
2022-11-14 09:26:39 +01:00
Antoine Poinsot
ff753fecca
bitcoind: get more info from 'listdescriptors'
We'll need the range for the rescan, as a descriptor must be reimported with a range larger than the initial descriptor
2022-11-14 09:20:29 +01:00
Antoine Poinsot
4a7fd1af29
commands: check if the Bitcoin backend is already rescanning
This is racy, but good enough for now.
2022-11-14 09:20:29 +01:00
Antoine Poinsot
925df283a6
bitcoin: check for ongoing rescans in the poller
Once the backend is done rescanning, we rollback our state down to the
rescan depth in order to scan for transactions from there.
2022-11-14 09:20:28 +01:00
Antoine Poinsot
073cdd0a89
commands: add a 'rescan_progress' field to 'getinfo'
We make sure to return a value as long as it was not wiped from
database, that's useful in functional tests.
2022-11-14 09:20:27 +01:00
Antoine Poinsot
7866ff46cf
commands: add a new 'startrescan' command 2022-11-14 09:20:27 +01:00
Antoine Poinsot
7e83bfad55
db: the interface to store the state of an ongoing rescan
We'll need to store in persistent storage if a rescan was requested by a
user, and if so from what date.

For the SQLite implementation we introduce a rescan_timestamp to the
wallet table.
2022-11-14 09:20:26 +01:00
Antoine Poinsot
bd4de0b87a
bitcoin: interface for rescanning the chain on the Bitcoin backend
For now we are given a timestamp and use 'importdescriptors'. It might be
better to be passed a height and use 'rescanblockchain' instead.
2022-11-14 09:20:26 +01:00
Antoine Poinsot
c32f714a2e
bitcoind: add a 'noreply' client
The query we are going to use to rescan, 'importdescriptors' will block
until the rescan is finished. Stopping the connection through a timeout
immediately after triggering the rescan is a workaround to make it
asynchronous.

Eventually we should probably use 'rescanblockchain' but then it
wouldn't update the timestamps of the descriptors in the watchonly
wallet...
2022-11-14 09:20:25 +01:00
Antoine Poinsot
45d601282f
bitcoind: only sleep on error if there is >0 retries
Don't sleep if we won't retry.
2022-11-14 09:20:20 +01:00
Antoine Poinsot
51ff7d6734
bitcoind: a utility to find a block height by block timestamp
We are passed a timestamp and we want to know down to what height we
should rescan / roll back. That's helpful for it. It was a bit tricky
although it's a simple binary search.. So to make sure i got it right i
made it a standalone function in a utils/ module to be able to unit test
it.

See the TODO, it's theoretically not precisely entirely correct. But
it's good enough for now.
2022-11-09 15:42:55 +01:00
Antoine Poinsot
6323ae0d0f
bitcoind: add time and MTP to BlockStats 2022-11-09 10:48:09 +01:00
Antoine Poinsot
80803c78a4
bitcoind: handle missing previousblockhash from getblockheader
It seems that internally bitcoind might temporarily not have a pprev
pointer for a block. This will result in the optional
"previousblockhash" field to be null and would previously make us crash.

Handle that gracefully.
2022-11-09 10:22:33 +01:00