Commit Graph
54 Commits
Author SHA1 Message Date
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
edouard 7338e6f988 Add labels to lianad 2023-08-28 13:14:21 +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 6b82894614 bitcoin: track maturity of coinbase deposits
We detect and store immature deposits (cause otherwise we won't go
through them again with listsinceblock), but mark them as such and
unconfirmed.
We only mark them as confirmed once they've matured. It's a bit clumsy
but it's not as if most of our users had coinbase deposits.
2023-07-20 13:42:35 +02:00
Antoine Poinsot 26add29b19 database: record whether a coin comes from an immature coinbase
We need to keep track of such coins to:
	- Track their maturation
	- Avoid using them (for instance in coin selection)

Reorg handling for coinbase deposits that become immature is not
implemented (yet). That's reasonable because:
1. It would be very unlikely that we'd move back, so it's most likely
   gonna be mature again immediately.
2. If there's a reorg of more than 100 blocks we've got bigger problems.
2023-07-20 13:42:30 +02:00
Antoine Poinsot e28010915f lianad: update rust-miniscript (and rust-bitcoin) dependencies
Rust-bitcoin, that we use through rust-miniscript, has seen plenty of
breaking changes in the latest version. I've tried to keep the necessary
changes here minimal, still it had to be a single commit to keep it
hygienic. But i'll try to summarize the main things here. Tobin also
wrote a guide about the release at
https://rust-bitcoin.org/blog/release-0.30.0/.

The most verbose change in this commit is probably due to the `Address`
type overhaul. It's overengineered if you ask me but hey here we are. I
tried to keep network validation in commands, and otherwise passing
around unchecked addresses (to avoid having to pass around a global
state between our various components).

Another non-obvious change was changes in hash types upstream and the
removal of `ToHex`, forcing us to get the hex representation of a txid
through its `Display` implementation. It is however displayed backward
in this case ("little-endian" if you will), and we need a regular hex
encoding for some queries to the database. We needed to make sure we
didn't implement any silent bug here.

The rest (Script type changes, PSBT serialization updates, ..) is
probably self-explanatory.
2023-07-13 09:56:09 +02:00
Antoine Poinsot c20c05cee7 ci: upgrade lianad clippy to 1.70 2023-06-28 10:23:15 +02:00
Antoine Poinsot 039b82d9b3 sqlite: prevent races when updating the next derivation index 2023-05-12 12:08:55 +02:00
Antoine Poinsot 104c6e1a09 commands: add an 'updated_at' field to listspendtxs entries 2023-04-05 12:41:03 +02:00
Antoine Poinsot 6b666e75c0 db: unit test the migration from v0 to v1 2023-04-05 12:41:03 +02:00
Antoine Poinsot 29ae0a4a5e db: add a new 'updated_at' column to Spend transactions
Since this is our first modification to the database schema since the
first release of the software this also introduces migration logic for
existing databases.
2023-04-05 12:41:02 +02:00
jp1ac4 b519c8d185 lib: rename and use existing structs (Db)SpendBlock 2023-04-04 09:27:03 +01:00
jp1ac4 4cb6d2dc69 lib: couple block height and time 2023-04-03 10:47:04 +01:00
Antoine Poinsot 8d1c6de5dd descriptors: rename MultipathDescriptor into LianaDescriptor 2023-03-23 19:15:53 +01:00
Antoine Poinsot ed156543c9 database: permit to remove coins from DB 2023-02-03 12:57:44 +01:00
Antoine Poinsot 1cd61c9236 descriptors: require that an origin be set for the keys.
It would be possible for users to create a descriptor with xpubs without
an origin set. In fact, not many are used to origins and it's a very
likely mistake. Signers need this information in order to be able to
sign. So they could potentially create a wallet and potentially never be
able to sign for one or multiple keys.

Fix this by requiring an origin for all keys in the descriptor.
2023-02-01 13:54:18 +01:00
Antoine Poinsot d3b89add9a daemon: apply clippy 1.66.0 fixes 2022-12-16 11:01:23 +01:00
Antoine Poinsot 54410cd9c4 database: allow to query coins by their spending status 2022-12-09 12:19:01 +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 3cd709697b Add listconfirmed command 2022-11-22 19:31:02 +01:00
Antoine Poinsot 968a7d17a0 daemon: rename Minisafe to Liana 2022-11-17 17:10:22 +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 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 d9f905a19a db: track the next unused derivation index for change, too 2022-10-24 15:00:17 +02:00
Antoine Poinsot 58a0e57c59 db: record whether a coin was received on a change address
So we know what descriptor to use when spending it.
2022-10-24 15:00:16 +02:00
Antoine Poinsot 9b04a55147 db: store derivation index also for addresses from the change desc
This doubles the storage required but there is no way around it if we
want the poller to detect those coins without grinding.
2022-10-24 15:00:16 +02:00
Antoine Poinsot ca3d7c1f33 descriptors: introduce a newtype for the multipath descriptor
The multipath descriptor has very different properties than the receive
and change ones. Use a newtype to assist us in differentiating those.
2022-10-24 15:00:15 +02:00
Antoine Poinsot 1320ee30ba daemon: use multipath descriptors
In config, expect to be given a multipath descriptor that contains a
derivation path for both receive and change addresses, but only for
those.

Instead of 'xpub/*', start using 'xpub/0/*' and 'xpub/1/*'.

When creating the watchonly wallet on bitcoind import both the receive
and change descriptors.

When polling, check for coins on both descriptors.
2022-10-24 15:00:14 +02:00
Antoine Poinsot caaca1fd1a descriptors: rename derive into derive_received
We'll be able to derive change addresses too
2022-10-24 15:00:12 +02:00
Antoine Poinsot a4bdb1efb7 tree wide: upgrade to Miniscript 8.0.0
This also updates the indirect rust-bitcoin dependency to 0.29.

Major changes are in the descriptors management:
	- The rust-miniscript descriptors don't support raw hashes
	  within the pk_h() fragments, so we don't need all the boutique
	  management for this.
	- The key translator API changed.
	- We now take a u16 for the timelock instead of our previous
	  checks. This was inspired by the new rust-bitcoin Sequence
	  type.
	- We now take a path instead of just a derivation index in
	  DerivedKey. We might use paths after all...

As for rust-bitcoin it's just a few nits:
	- No more 'global' field on PSBTs (yay)
	- Couple more trait derivation on types
	- Some APIs were renamed.
2022-10-20 17:53:26 +02:00
Antoine Poinsot 92f7ef1225 commands: make listcoins return all coins by default
We'll add some parameters to filter by status and/or outpoints later on.
But for now also list coins that were spent or are being spent.
2022-10-17 11:47:41 +02:00
Antoine Poinsot e9e4acd69d db: database interface to rollback to a previous best block 2022-10-17 11:47:40 +02:00
Antoine Poinsot 972c8dac86 db: require the spend block height from the DB interface
Hence add a 'spend_block_height' field to the 'coin' column in the
SQLite implementation. This also contains a couple cleanups, as well as
a fix (we were still checking if the blockheight was > 1).
2022-10-17 10:44:38 +02:00
Antoine Poinsot 6038843d33 database: rename coins' spent_at in spend_block_time 2022-10-17 10:27:03 +02:00
Antoine Poinsot 8b4866158b daemon: clippification
That's a minimal API break because of some error variants that were
Box'd.
2022-10-13 14:24:24 +02:00
Antoine Poinsot c9b6c6dedb db: re-rename list_unspent_coins into unspent_coins 2022-10-12 17:19:27 +02:00
edouard 3cf6bcbb98 add spent_coins to bitcoind poller 2022-10-05 17:41:16 +02:00
edouard 94ee94edbd Add blocktime and spent_at to coins table
Spent coins are coins where spent_txid and spent_at
are both not null.
2022-10-05 17:41:16 +02:00
Antoine Poinsot c73e8a42dd commands: add a new 'delspendtx' command 2022-10-01 14:05:27 +02:00
Antoine Poinsot c6e004806a commands: add a 'list_spend' command (and 'listspendtxs' RPC) 2022-10-01 13:33:08 +02:00
Antoine Poinsot bafcadf398 db: interface to upsert a Spend PSBT and query it by txid
I initially wanted to have a bridge table between the 'coins' and
'spend_transactions' table as we do in revaultd. But let's not optimize
to early, we'll see if/when we need it.
2022-09-15 11:41:33 +02:00
Antoine Poinsot 46320d5fc0 db: an interface to query coins by their outpoints 2022-09-15 11:41:29 +02:00
Antoine Poinsot 0fd57db8a8 Use the descriptor newtype instead of the raw miniscript Descriptor type 2022-08-18 12:02:27 +02:00
Antoine Poinsot 99a9cbf0f8 poller: query derivation index by address from DB 2022-08-18 12:01:26 +02:00
Antoine Poinsot 3f17e9f0c3 database: change interface from update_der_index to increment_der_index
And take care of updating the (addr->index) mapping in the SQLite implementation.
2022-08-18 12:01:26 +02:00
Antoine Poinsot e74ea4c2d3 sqlite: a table for a mapping from address to derivation index. 2022-08-18 12:01:25 +02:00
Antoine Poinsot 05b3af1b5a database: interface and implementation for coins storage and update 2022-08-18 12:01:24 +02:00
Antoine Poinsot 726209cc0a jsonrpc: add a 'stop' command
This also implements a simple JSONRPC server sanity check

And introduces a new tmp_dir() test utility, that i didn't have the courage to split from this commit
2022-08-17 19:39:57 +02:00