68 Commits

Author SHA1 Message Date
jp1ac4
bf1e90e0fa
sqlite: merge two migration tests 2024-08-02 10:49:33 +01:00
Antoine Poinsot
e8836757c7
sqlite: add a unit test for migration between v4 and v5 2024-08-02 10:49:32 +01:00
jp1ac4
a86d12d629
commands: get wallet transactions from db 2024-08-02 10:49:31 +01:00
jp1ac4
afa6a51601
poller: save transactions in database
This includes changes from darosior's commits:
3e7d968508a71ffa740576d6bf9432611e78f4a5
e2225a5110ca981c340eef329182e702b375b55f
2024-08-02 09:41:16 +01:00
Antoine Poinsot
ba4c819918
sqlite: separate DB migration from constructor
This is a slightly modified version of darosior's commit:
d826f9fa6336de6eb293a85af044c2c95550cfb5
2024-08-02 09:39:31 +01:00
jp1ac4
f9bae9cc08
database: add migration from db version 3 to 4 2024-03-25 11:49:48 +00:00
jp1ac4
3a7c151674
database: allow for coinbase transactions to change addresses
`is_change` is `true` for a coin if its address is derived
from our change descriptor and could in principle be used for a
coinbase transaction.

The functional test was provided by darosior in a PR comment:
https://github.com/wizardsardine/liana/pull/1001#pullrequestreview-1948564150
2024-03-20 18:29:37 +00:00
jp1ac4
fa39e2ced4
database: convert CoinStatus to listcoins argument string 2024-03-08 08:16:04 +00:00
pythcoiner
79177945ad add timestamp field to getinfo 2024-01-19 13:06:32 +01:00
Antoine Poinsot
0e99136404
Clippification
Bump clippy in CI to latest stable.
2024-01-11 10:45:41 +01:00
Antoine Poinsot
ce026a62e6
Update rust-bitcoin and rust-miniscript
The most notable change is rust-bitcoin's change in the serialization of
transaction with no input. It now accounts for the segwit marker even
for those. The base tx weight in coin selection had to be adapted to
handle this.

See https://gnusha.org/bitcoin-rust/2024-01-04.log for details.
2024-01-11 10:45:36 +01:00
Antoine Poinsot
f78e831c39
db: make it possible to mark coins back as unspent 2023-11-17 13:52:59 +01:00
jp1ac4
79c5f92d9c
db: check for change using address strings only
Comparing the address itself includes the network, but an
unchecked signet address will have its network set as testnet
by `assume_checked` and so change addresses will not be
matched.
2023-11-15 11:27:17 +00: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
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