Commit Graph

1460 Commits

Author SHA1 Message Date
Oliver Gugger
5bd3e91750
rpcwallet: pass prev output fetcher into ComputeInputScript
This commit fixes signing of Taproot inputs when some of the other
inputs of the transaction are not known to the wallet (such as a Pool
account for example).
If we want to sign for a Taproot (change) input when depositing into a
Pool account the wallet won't know the Pool account input. So we need to
make sure we pass it along inside the PrevOutputFetcher (which contains
the UTXO information extracted from the PSBT).
2022-11-11 10:20:09 +01:00
Oliver Gugger
ed2e542515
rpcwallet: don't re-use sign desc in loop
This commit fixes an issue with signing for mixed inputs in a remote
signing setup where the re-use of the sign descriptor would lead to the
sign method not being reset correctly if a p2wkh input is following a
p2tr input.
2022-11-11 10:20:09 +01:00
habibitcoin
0b1e881d18
scripted-diff: replace ⛰ emoji with $ [skip ci]
-BEGIN VERIFY SCRIPT-
sed -i 's/⛰/$/g' $(git grep -l '⛰')
-END VERIFY SCRIPT-
2022-10-28 12:06:49 -04:00
Joost Jager
28256b7ea8
htlcswitch: keep final htlc outcome 2022-10-27 16:42:36 +02:00
Oliver Gugger
d2d3cf3408
Merge pull request #6956 from ellemouton/configureChanReserve
multi: configurable remote chan reserve
2022-10-13 15:39:40 +02:00
Eng Zer Jun
c70e39cd21
multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:46:54 +08:00
Olaoluwa Osuntokun
30eb6770e5
lnwallet/chancloser: fix loop variable shadowing in TestMaxFeeBailOut 2022-10-10 14:50:51 -07:00
Olaoluwa Osuntokun
2482de9cab
lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.

To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.

We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.

The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.

Fixes #6953
2022-10-10 14:50:45 -07:00
Elle Mouton
10f0eddd51
multi: verify channel constraints on funding request
In this commit, the sanity checks in the CommitConstraints method is
moved out into a helper function called VerifyConstraints. This is done
so that the sanity checks can be performed more easily else where in the
code base. The new helper method is then called in the
handleInitFundingMsg method of the funding manager before the
OpenChannelMessage is sent.
2022-10-07 14:57:05 +02:00
Oliver Gugger
0d6e791042
lntest+lnwallet: add ImportTaprootScript to wallet interface 2022-08-25 09:20:23 +02:00
Eng Zer Jun
9acd53a5de
lnwallet: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 09:03:05 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
priyanshiiit
99e4728eb7 lnwallet: adds list addresses method 2022-08-18 07:58:24 +05:30
Slyghtning
b2e624cd52 psbt: Indicate which psbt inputs were signed 2022-08-16 19:31:06 -04:00
Olaoluwa Osuntokun
42549519ca
lnwallet/chanfunding: assumes all change outputs are P2TR 2022-08-11 17:26:23 -07:00
Olaoluwa Osuntokun
322937a67e
lnwallet: use P2TR addresses for change outputs for funding coin select 2022-08-11 17:26:21 -07:00
Olaoluwa Osuntokun
a61b6c25b3
lnwallet/chanclose: update ProcessCloseMsg to check co-op close addrs
We only want to allow p2wkh, p2tr, and p2wsh addresses, so we'll utilize
the newly public wallet function to restrict this.
2022-08-10 18:44:31 -07:00
Olaoluwa Osuntokun
c79ffc07ce
lnwallet: export ValidateUpfrontShutdown and restrict allowed addrs
In this commit, we catch up our logic with the latest version of the
spec that removed support for normal p2kh and p2sh addresses for co-op
closes, in order to make dust calculations more uniform.
2022-08-10 18:44:29 -07:00
Olaoluwa Osuntokun
9eb1e8721a
lnwallet/chancloser: add tests for the new max fee behavior 2022-07-26 17:23:11 -07:00
Olaoluwa Osuntokun
106912b015
lnwallet/chancloser: remove raw state machine pointer, add channel interface
In this commit, we remove the raw channel state machine pointer from the
chan closer and instead replace that with an interface that captures
*just* the methods we need in order to do the co-op close dance.

This is a preparatory refactoring for some upcoming unit tests.
2022-07-26 17:23:08 -07:00
Olaoluwa Osuntokun
4a997bfdd2
lnwallet: add new AbsoluteThawHeight method
This lets callers get the thaw height without needing to first obtain a
snapshot of the channel state.
2022-07-26 17:23:05 -07:00
Olaoluwa Osuntokun
c140da8f49 lnwallet/chancloser: remove the commit fee clamp, introduce max fee
In this commit, we stop clamping the ideal fee rate to the commitment
fee of the channel. This catches us up to this PR of the spec:
https://github.com/lightning/bolts/pull/847.

We also do away with the old 3x ideal fee "max fee", and replace that
with an explicit max fee. This new max fee will either be the default
multiplier of the ideal fee, or a new user specified max fee value.
2022-07-26 17:20:23 -07:00
Oliver Gugger
e6b25309bd
Merge pull request #6731 from guggero/linter-upgrade
tools: upgrade linter version to v1.46.2
2022-07-15 11:25:25 +02:00
ErikEk
b5af0ce327
signrpc: add schnorr sig to sign and validate msg 2022-07-14 10:29:29 +02:00
Oliver Gugger
850330a34e
multi: fix linter issues
Fix some issues found by the new nonamedreturn rule and rename some
nolint comment to the new rule name.
2022-07-14 09:30:53 +02:00
Oliver Gugger
9fd9234d86
lnwallet: don't create BIP044 key scope by default
With a change in #6379 we made sure that all default scopes are added to
the the wallet. Unfortunately this included the BIP044 key scope that
our wallet doesn't really use. This breaks the remote signing setup
because we don't export the account of the BIP044 scope and therefore
run into an issue on the watch-only side when attempting to create the
wallet.
2022-07-08 14:32:03 +02:00
eugene
21c83b0744
lnwallet: extend Reservation with alias chan-type, feature-bit flags
This extends the Reservation arguments to include whether a pending
channel open has negotiated the zero-conf channel type, the scid-alias
channel type, and/or the scid-alias feature bit. The result of those
negotiates are stored in the OpenChannel's ChanType. The arguments to
NewChannelReservation have also been simplified.
2022-07-07 17:10:27 -04:00
Oliver Gugger
63ec849605
lnwallet: fix bug in SignPsbt with np2wkh addresses
Fixes #6626.
If either of the two fields FinalScriptSig or FinalScriptWitness is set
on an input of a PSBT then that results in most of the fields of that
input not to be serialized in the packet anymore, since the input is
considered to be complete.
But because a signer isn't supposed to set any of the Final* fields,
this was wrong from the beginning. Only the finalizer will set those
fields.
2022-06-30 10:27:39 +02:00
priyanshiiit
150c0b5de8 lnwallet: adds RequiredReserve method 2022-06-28 23:31:51 +05:30
priyanshiiit
fce7fb43ba lnwallet: exports fields related to AnchorChans 2022-06-28 23:31:51 +05:30
priyanshiiit
61493a5f29 lnwallet: add previous_outpoints to ListTransactionDetails 2022-06-27 15:57:57 +05:30
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Oliver Gugger
427702dbe6
rpcwallet: use PSBT prev out fetcher 2022-06-10 22:03:45 +02:00
Oliver Gugger
70103a1838
multi: return more information in list of leased outputs
With this commit we return the additional information the wallet now
provides about locked/leased outputs.
2022-05-12 10:24:40 +02:00
Oliver Gugger
9f4f0e94f5
multi: avoid direct use of dcrec/secp256k1 library
Because the original dcrec secp256k1 library that is used for the
Schnorr signature primitives uses different hash algorithms than the
btcd secp256k1 library. Therefore pulling in the wrong library can lead
to weird and unexpected errors. We try to make it harder to make the
mistake by not using the library directly in lnd in the first place.
Note that it is still indirectly needed by the btcd secp256k1 library,
therefore the module dependency is still expected to be there, just
moved to the indirect section.
2022-05-11 10:07:52 +02:00
Oliver Gugger
d1a151010a
lntest+rpcwallet: support remote p2tr script spend signing 2022-05-11 10:07:51 +02:00
Oliver Gugger
7f4e977073
lntest+rpcwallet: support remote p2tr key spend signing 2022-05-11 10:07:50 +02:00
Oliver Gugger
35dd2d25ea
btcwallet: support taproot script signing in PSBT 2022-05-11 10:07:50 +02:00
Oliver Gugger
0f32a4456d
btcwallet: support taproot key spend signing in PSBT 2022-05-11 10:07:50 +02:00
Oliver Gugger
e4aa32fdf7
btcwallet: prepare for supporting new signing methods 2022-05-11 10:07:49 +02:00
Olaoluwa Osuntokun
630fc36dcf
multi: introduce and use new TapTweak and SignMethod fields
In this commit, we add a new field `TapTweak` to be used for key path
spends. Before this commit, we'd overload the existing `WitnessScript`
field to pass this information to the signing context. This was
confusing as for tapscript spends, this was the leaf script, which
mirrors the other script based spending types.

With this new filed, users need to set this to the script root for
keypath spends where the output key commits to a real merkle root, and
nothing when bip 86 spending is being used.

To make the signing even more explicit, we also add a new field called
sign_method with an enum type that differentiates between the different
segwit v0 and v1 signing methods.

Fixes https://github.com/lightningnetwork/lnd/issues/6446.
2022-05-11 10:07:49 +02:00
Oliver Gugger
5395a0fe6b
rpcwallet: attempt to locate UTXO information in prev output fetcher
Since we might now be given a whole list of UTXOs in the PrevOutputs
field of the SignOutputRaw RPC, the previous output fetcher might
contain the information we require for the remote signing case. So
instead of failing if our wallet doesn't know each input that's being
spent, we fall back to the UTXO information contained in the previous
outputs.
2022-05-11 10:07:48 +02:00
Elle Mouton
f766268e8c
lnwallet/test: test against bitcoind-rpc-polling backend 2022-05-11 09:02:13 +02:00
Elle Mouton
5a08788a05
multi: update btcwallet to v0.15.0
Update go.mod to point to latest btcwallet version.
2022-05-11 08:45:06 +02:00
Oliver Gugger
18cf06ddd1
chanfunding: fix sighash type for p2tr inputs
This commit fixes the default sighash type for p2tr channel funding
transaction inputs.
2022-05-10 18:13:00 +02:00
Oliver Gugger
631b2af818
btcwallet: support p2tr input info type detection 2022-05-10 18:03:29 +02:00
Oliver Gugger
8980471d57
chanfunding: support p2tr input fee calculation
With this commit we support fee calculation in coin selection for p2tr
inputs. We assume that coins in our UTXO selection are only BIP0086
coins. Any other input types with different spend paths won't be
selected by the wallet assembler.
2022-05-10 18:01:14 +02:00
Olaoluwa Osuntokun
0ec88b5346
Merge pull request #6347 from yyforyongyu/5388-rm-revc-log
lnwallet+channeldb: store minimal info in revocation log bucket
2022-05-05 15:52:59 -07:00
Oliver Gugger
bdd1c5c4e1
Merge pull request #6423 from tvolk131/fix_typos
Typo fixes and code cleanup
2022-05-05 09:42:39 +02:00
Oliver Gugger
7e11f64650
rpcwallet: only shut down on RPC error 2022-05-04 19:23:58 +02:00
Oliver Gugger
95ff670c0e
multi: add MuSig2Cleanup method to MuSig2 signer 2022-05-04 19:23:58 +02:00
Tommy Volk
5ae2ce984e multi: typo fixes [skip ci] 2022-05-03 20:55:40 +00:00
Oliver Gugger
e31aab5af6
multi: fix inclusion proof size
The inclusion proof field in the TapscriptPartialReveal function was
incorrect. An inclusion proof can be zero or more elements of 32-byte
slices. So an empty inclusion proof can be valid too for a tree that
only consists of a single leaf.
2022-04-29 11:41:09 +02:00
Oliver Gugger
f7275c7fc4
multi: implement MuSig2 RPCs and remote signing 2022-04-29 11:41:09 +02:00
Oliver Gugger
8fc99fba00
input+btcwallet: add MuSig2 signing operations
With this commit we add the high-level MuSig2 signing methods to the
btcwallet which will later be exposed through an RPC interface.
2022-04-29 11:41:08 +02:00
eugene
d881679de0
peer+chancloser: allow restarting coop close process
On startup, we'll check whether we have the coop close chan status
and have already broadcasted a coop close txn, and then make a
decision on whether to restart the process based on that.
2022-04-26 12:52:48 -04:00
yyforyongyu
22d98ca6d5
multi: use new revocation log when creating breach retribution
This commit changes the `NewBreachRetribution` to use the new revocation
log format, while maintaining the compatibilty to use an older
revocation log format. Unit tests have been added to make sure a breach
retribution can be created in both log formats.

This also means the watch tower needs to pass the relevant commit tx at
its backup height when creating the breach retribution during backing
up. This is achieved by recording the current remote commitment state
before advancing the remote commitment chain.
2022-04-20 01:18:14 +08:00
yyforyongyu
953767961e
multi: use txid instead of tx in BreachRetribution
This commit replaces the field `BreachTransaction` with `BreachTxHash`
as there's no need to pass that large raw transaction.
2022-04-20 01:18:14 +08:00
yyforyongyu
37b11c4503
channeldb+lnwallet: store revocation log using the new format
This commit removes the usage of the old revocation log bucket and
starts to perform db operations using the new sub-bucket.
2022-04-20 01:18:14 +08:00
yyforyongyu
df810114cf
lnwallet: add method to compute output indexes
This commit adds a new method, findOutputIndexesFromRemote to compute
the our/their output indexes. As we will see in the following commit,
saving these two fields(4+4=8 bytes) will end up saving us some disk
space.
2022-04-20 01:18:13 +08:00
yyforyongyu
22f8f6ed4a
channeldb+lnwallet: save initial balances during channel opening 2022-04-20 01:18:12 +08:00
yyforyongyu
9a4589d54e
lnwallet: remove unused field PendingHTLCs 2022-04-20 01:18:12 +08:00
yyforyongyu
acde626ac9
lnwallet+htlcswitch: remove the redundant param in OweCommitment
This commit removes the bool param found in OweCommitment, which we
only ever use `true`.
2022-04-20 01:18:12 +08:00
yyforyongyu
fcb314bf2c
channeldb: add more verbose docs 2022-04-20 01:18:11 +08:00
Oliver Gugger
485d8f043d
btcwallet: always make sure default scopes exist
If new default scopes are added to the underlying btcwallet
implementation, then they aren't automatically created for _existing_
wallets, only for new ones. So on startup we need to make sure all
scopes are present.
2022-03-30 12:50:16 +02:00
Oliver Gugger
ef98f2df8a
multi: add p2tr tapscript key path signing capabilities 2022-03-24 18:02:39 +01:00
Oliver Gugger
78db46be7e
multi: add p2tr tapscript signing capabilities 2022-03-24 18:02:39 +01:00
Oliver Gugger
108f49f23b
input+signer: test wallet script import 2022-03-24 18:02:38 +01:00
Oliver Gugger
c73cf03a55
multi: add p2tr keyspend wallet support 2022-03-24 18:02:38 +01:00
Oliver Gugger
f130eddb92
multi: use prev output fetcher where possible 2022-03-24 18:02:37 +01:00
Oliver Gugger
72c9582b85
multi: bump btcd to taproot aware version 2022-03-24 15:00:25 +01:00
Oliver Gugger
0dcaa511a2
Merge pull request #6341 from guggero/remote-signer-signoutputraw
remote signer: fix SignOutputRaw RPC for incomplete key info, fix healthcheck connection leak
2022-03-24 14:59:38 +01:00
Oliver Gugger
8c44da225a
rpcwallet: fix RPC wallet health check connection leak
Fixes #6329.
This commit fixes a connection leak in the RPC wallet's health check. By
not closing the test connection the watch-only node would slowly stack
up connections and eventually hit the ulimit.
2022-03-24 14:13:06 +01:00
Oliver Gugger
42b0aa9a8e
rpcwallet+itest: fix incomplete key info problem
Fixes an issue with SignOutputRaw in remote signing mode where we
weren't able to sign on the remote signer if we only provided the public
key or only the family/index (and not both).

Fixes part of an issue detected in lightninglabs/loop#457.
2022-03-24 14:13:05 +01:00
Oliver Gugger
5bf9b710fc
config_builder+rpcwallet: add full net params
As a preparation for parsing addresses, we need the full network
parameters and not just the coin type in the RPC wallet.
2022-03-24 14:13:05 +01:00
Oliver Gugger
efa36ce8f2
lntest+lnwallet: add AddressInfo to WalletController
We need to be able to query the watch-only wallet about a public key
when trying to sign with a key that we don't know the family or index
of. The easiest way to do that is to leverage the wallet's address index
to query the derivation path for a public key.
To give the RPC wallet access to that functionality, we need to expose
the method on the WalletController interface.
2022-03-24 14:13:05 +01:00
yyforyongyu
13ade7e9ce
htlcswitch+lnwallet: add trace logs for tickers 2022-03-24 10:01:41 +08:00
Bjarne Magnussen
052bb9d711
lnwallet: remove DestAddresses from lnwallet
With `OutputDetail` now containing the destination addresses, the `DestAddresses` field can be removed from the `lnwallet.TransactionDetail`. It is already populated when needed for backwards compatibility to `lnrpc.TransactionDetail` via `OutputDetail.Addresses`.
2022-03-23 11:29:09 +01:00
Bjarne Magnussen
d43cdcf9a0
btcwallet: populate data to DestOutput field
Adds the output script and amount to the `DestOutput` field of `TransactionDetails`, as well as sets the flag `isOurAddress` if the output is controlled by the node's wallet.
2022-03-23 11:28:18 +01:00
Bjarne Magnussen
cbf6bd9aca
lnwallet: add new DestOutputs field to TransactionDetail
A new `DestOutputs` field contains additional information on destinations of a transaction described with the `TransactionDetail` structure.

The additional information inside `DestOuputs` denote the output script and amount, as well as a flag `IsOurAddress` if the address is controlled by the node's wallet.
2022-03-23 11:28:18 +01:00
Olaoluwa Osuntokun
e1e9de24df
sweep: remove all unconfirmed descendant transactions when a sweep conflicts
Before this commit, we we were trying to sweep an anchor output, and
that output was spent by someone else (not the sweeper), then we would
report this back to the original resolver (allowing it to be cleaned
up), and also remove the set of inputs spent by that transaction from
the set we need to sweep.

However, it's possible that if a user is spending unconfirmed outputs,
then the wallet is holding onto an invalid transaction, as the outputs
that were used as inputs have been double spent elsewhere.

In this commit, we fix this issue by recursively removing all descendant
transactions of our past sweeps that have an intersecting input set as
the spending transaction. In cases where a user spent an unconfirmed
output to funding a channel, and that output was a descendant of the now
swept anchor output, the funds will now properly be marked as available.

Fixes #6241
2022-03-17 16:36:47 -07:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
yyforyongyu
1ad6bbfbc2
multi: add logs when subservers are starting
Also unified the log messages.
2022-02-11 21:17:03 +08:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Oliver Gugger
ffee7d1bcf
multi: fix newly detected linter issues 2022-02-10 11:02:02 +01:00
Oliver Gugger
dfdc2bff8b
multi: run gosimports 2022-02-10 11:02:01 +01:00
Oliver Gugger
0bef42e93c
Merge pull request #6233 from guggero/sign-psbt-utxo-error-message
rpcwallet: disallow empty UTXO pk script [skip ci]
2022-02-08 09:39:09 +01:00
Olaoluwa Osuntokun
80e304573c
lnwallet: increase legacy fee limit threshold to 1k sats
In this commit, we increase the legacy fee limit threshold (the amount
below which we'll allow 100% of funds to go to fees for the non-v2 RPC
calls) from 50 sats to 1k sats.
2022-02-03 11:54:01 -08:00
Oliver Gugger
75016a176c
rpcwallet: disallow empty UTXO pk script [skip ci]
If we're signing for an UTXO that isn't known to the wallet, then the
UTXO's pk script _must_ be set in the sign descriptor. Otherwise we run
into a generic PSBT serialization error when running in a remote signing
setup.
2022-02-03 17:34:14 +01:00
Oliver Gugger
bfa1cf17b9
lnwallet: introduce default routing fee calculation 2022-02-02 14:24:52 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Oliver Gugger
bab807a57d
multi: add migrate-wallet-to-watch-only flag
To enable converting an existing wallet with private key material into a
watch-only wallet on first startup with remote signing enabled, we add a
new flag. Since the conversion is a destructive process, this shouldn't
happen automatically just because remote signing is enabled.
2022-01-06 14:35:26 +01:00
Oliver Gugger
afc53d1c52
lnwallet: initialize first 255 accounts
This fixes lightninglabs/loop#437 by adding all accounts that are used
in liquidity products such as Loop or Pool. Since both of these products
use key families below 255, we can get by with that number.
The alternative to creating way too many accounts (which increases the
default wallet size by ~250kB) would be to hard code the exact accounts
used by Loop (99) and Pool (210). But that sounds like a bad idea given
that there could always be more accounts being added to those (or other)
products. By making sure the first 255 accounts exist, we have a lot
more flexibility in those products for choosing key families.
2022-01-06 14:35:26 +01:00
Oliver Gugger
da59c1fa62
multi: add health check for remote signer 2022-01-06 14:35:25 +01:00
Oliver Gugger
9601a9ab84
multi: make remote signer RPC timeout configurable 2022-01-06 14:35:25 +01:00
Oliver Gugger
f3cd383d1f
rpcwallet: add critical log to remote signer errors 2022-01-06 14:35:24 +01:00
Oliver Gugger
3d353a9879
config_builder+rpcwallet: simplify RPC signing
With the remote signing instance now not needing to know anything about
addresses or current derivation indices, we don't need to forward any
such calls to that instance and can simplify the RPCKeyRing
considerably.
2022-01-06 14:35:24 +01:00
Oliver Gugger
d135b638f6
btcwallet: add SignPsbt 2022-01-06 13:24:32 +01:00
Oliver Gugger
c24763b3da
lnd+lnwallet: add logger for btcwallet+rpcwallet 2022-01-06 13:24:32 +01:00
Oliver Gugger
b54279dd87
lnwallet: add derivation and prev TX to UTXO 2022-01-06 13:24:31 +01:00