Commit Graph

191 Commits

Author SHA1 Message Date
yyforyongyu
2dc08a2a76
multi: rename NewFundingLocked to NewChannelReady
This commit is created by the following command,

```shell
gofmt -d -w -r 'NewFundingLocked -> NewChannelReady' .
```
2023-03-17 18:21:58 +08:00
yyforyongyu
1b7c56b2ed
multi: rename FundingLocked to ChannelReady
This commit is created by running,

```shell
gofmt -d -w -r 'FundingLocked -> ChannelReady' .

gco master channeldb/migration
```
2023-03-17 18:21:58 +08:00
yyforyongyu
6618ab493a
multi: enhance loggings and fix logging format
Also adds TODO for a possible bug.
2023-02-23 21:56:08 +08:00
yyforyongyu
a012a5e2ff
peer: skip retrying when reenableTimeout is greater than 1 min
This commit makes retrying enabling channels conditional. We now would
only retry sending the enable request when the `ChanActiveTimeout` is no
greater than 1 min.
2023-01-18 03:46:17 +08:00
yyforyongyu
2f9ba1594c
peer: retry enabling channels on ErrEnableInactiveChan
This commit adds a retry logic to the channels that failed with
`ErrEnableInactiveChan` when requesting enabling. We now subscribe the
channel events to decide what to do with the failed channels.
2023-01-18 03:46:16 +08:00
yyforyongyu
a81d4e9c5c
peer: add filterChannelsToEnable to filter channels for enabling 2023-01-18 03:46:16 +08:00
yyforyongyu
f632a58b3b
htlcswitch+peer: notify inactive link event when htlcManager exits 2023-01-18 03:46:16 +08:00
yyforyongyu
716c685f10
discovery+peer: add logs to reveal shutdown flow
Also adds a `TODO` for checking the err chan.
2022-12-08 17:57:01 +08:00
yyforyongyu
2285bfdf9f
contractcourt+brontide: fix typo and inaccurate logging 2022-10-27 01:11:35 +08:00
positiveblue
4d4d8e480c
multi: stop casting peer warning messages as errors
Split the logic for processing `error` and `warning` messages from our
peers.
2022-10-26 08:09:08 -07:00
Joost Jager
a0a50fa844
htlcswitch: auto-fail held htlcs
Make the interceptable switch aware of htlc expiry and fail back htlcs in-time
to prevent the counterparty from force-closing the channel.
2022-10-18 18:06:49 +02:00
Joost Jager
74eeb95e8c
htlcswitch: add error return value to NewInterceptableSwitch
Prepares for parameter validation.
2022-10-18 18:04:34 +02:00
Joost Jager
a6df9567ba
htlcswitch: add dedicated block subscription to interceptable switch
Preparation for making the interceptable switch aware of expiring htlcs.
2022-10-18 18:04:33 +02:00
Joost Jager
4a3e90f4d0
htlcswitch: add InterceptableSwitchConfig
Preparation for adding more config options.
2022-10-18 18:04:33 +02:00
Eng Zer Jun
f8ae8318c6
peer: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:47:03 +08: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
Eng Zer Jun
71185d46fb
peer: 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
Olaoluwa Osuntokun
fffad49ad1
peer: send taproot addrs during co-op close based on new feature bit
If the ShutdownAnySegwitOptional option is active, then we can safely
send these newer addresses.
2022-08-10 18:44:35 -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
1e556aa189
multi: thread through the new max fee field for co-op close
In this commit, we parse the new max fee field, and pass it through the
switch, all the way to the peer where it's ultimately passed into the
chan closer state machine.
2022-07-26 17:23:16 -07:00
eugene
b9ef26061a
server+netann+peer: put peer's alias in Update, proper config for link
This commit modifies the netann subsystem to use the peer's alias
for ChannelUpdates where appropriate (i.e. in case we are sending
the alias to the peer). It also modifies the loadActiveChannels
function in the peer package to handle upgrading a channel when the
scid-alias feature bit is turned on.
2022-07-07 17:10:30 -04:00
Tommy Volk
834756c53c multi: migrate assert.NoError to require.NoError 2022-07-05 16:41:08 +00:00
Oliver Gugger
4cb68e4de3
Merge pull request #6588 from C-Otto/peer-logging
peer: add pubkey to log messages
2022-07-05 09:36:26 +02:00
Olaoluwa Osuntokun
7b56b67f34
Merge pull request #6546 from carlaKC/bolts-950-warningmessage
lnwire/peer: add ability to read + log peer warning messages
2022-06-30 16:56:20 -07:00
Carsten Otto
ffe8b088d3 peer: add pubkey to log messages 2022-06-27 21:04:03 +02:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Carla Kirk-Cohen
99828b8ebb
multi: add ability to read warning messages and log on link level
Warning messages are intended to add "softer" failure modes for peers,
so to start with we simply log the warnings sent to us. While we "may"
disconnect from the peer according to the spec, we start with the least
extreme option (which is also not a change in behavior because
previously we'd just log that we received an unknown odd message).
2022-05-16 13:51:31 -04:00
eugene
5ec6aafce3
peer: make linter happy 2022-04-26 12:52:49 -04: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
eugene
a94466e936
peer: add createChanCloser function to de-dupe NewChanCloser sites 2022-04-26 12:52:46 -04:00
Joost Jager
13dff2fb3e
htlcswitch: interceptor expiry check 2022-04-12 08:27:06 +02:00
yyforyongyu
1c8c0b4fa0
multi: make PendingCommitInterval configurable 2022-03-24 10:01:42 +08:00
Joost Jager
ae314ec794
htlcswitch: add an always on mode to interceptable switch
Co-authored-by: Juan Pablo Civile <elementohb@gmail.com>
2022-03-17 17:39:37 +01: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
eugene
8607e8c28a
multi: reliable hand-off from htlcswitch to contractcourt
This is achieved by changing the 1-way handoff to a 2-way handoff
with a done channel.
2022-02-24 13:35:15 -05:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Oliver Gugger
dfdc2bff8b
multi: run gosimports 2022-02-10 11:02:01 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Olaoluwa Osuntokun
3481286ea0
lnwire+peer: clamp pong bytes, make ping handler more effcieint
This was not properly enforced and would be a spec violation on the
peer's end. Also re-use a pong buffer to save on heap allocations if
there are a lot of peers. The pong buffer is only read from, so this
is concurrent safe.
2022-01-13 15:01:18 -08:00
Olaoluwa Osuntokun
ae16f2b631
peer: always defer clean up of the block epoch client used for ping headers
In this commit, we fix an inadvertent memory leak by ensuring we always
use `defer` to clean up the allocated objects/memory we use to be
notified of new blocks to update what we send within the set of ping
headers.

A further optimization here would be using a single global block epoch
housed within the server, that all peer `pingHandler` goroutines use
directly.

Fixes #6143.
2022-01-13 15:01:13 -08:00
yyforyongyu
46050fc631
multi: enhance logging for debugging peer connection 2021-12-23 15:14:37 +08:00
Wilmer Paulino
8cfb53f64a
lnwallet: support transactions and scripts for new commitment type
This commit modifies the channel state machine to be able to derive the
proper commitment and second-level HTLC output scripts required by the
new script-enforced leased channel commitment type.
2021-10-19 18:30:32 -07:00
carla
990dda4b18
multi: thread bandwidth check amount down to MayAddOutgoingHtlc
Pass htlc amount down to the channel so that we don't need to rely
on minHtlc (and pad it when the channel sets a 0 min htlc). Update
test to just check some sane values since we're no longer relying
on minHtlc amount at all.
2021-10-19 09:50:51 +02:00
Joost Jager
ade50d0b2c
lnrpc: receive custom message 2021-10-15 17:08:55 +02:00
Joost Jager
ae959b16ae
lnrpc: send custom message 2021-10-15 17:08:53 +02:00
Oliver Gugger
e79d59dd4c
multi: use key locator for lnwallet.MessageSigner
To simplify the message signing API even further, we refactor the
lnwallet.MessageSigner interface to use a key locator instead of the
public key to identify which key should be signed with.
2021-10-08 12:06:52 +02:00
Oliver Gugger
8b7c88537c
multi: refactor SignDigestCompact into SignMessageCompact
To make it possible to use a remote lnrpc server as a signer for our
wallet, we need to change our main interface to sign the message instead
of the message's digest. Otherwise we'd need to alter the
lnrpc.SignMessage RPC to accept a digest instead of only the message
which has security implications.
2021-10-08 12:06:52 +02:00
Andras Banki-Horvath
11cf4216e4
multi: move all channelstate operations to ChannelStateDB 2021-09-29 17:00:03 +02:00
Olaoluwa Osuntokun
7bde1662e2
multi: move breach arbiter and utxo nursery into contractcourt package
In this commit, we take an initial step towards converting the existing
breach arbiter and utxo nursery logic into contract resolvers by moving
the files as is, into the `contractcourt` pacakge.

This commit is primarily move only, though we had to massage some
interfaces and config names along the way to make things compile and the
tests run properly.
2021-09-27 19:10:31 -07:00
Olaoluwa Osuntokun
ac5f88bae8
Merge pull request #5618 from Crypt-iQ/coop_switch_sync_08092021
multi: optimistically shutdown link during coop close
2021-09-20 18:09:07 -07:00
Elle Mouton
171d047972
peer: return from pingHandler if error
This commit adds a missing return statement to pingHandler. This
prevents a nil pointer dereference panic from happening if an error is
returned from RegisterBlockEpochNtfn.
2021-09-15 08:43:16 +02:00
eugene
aeaa009e92
peer+chancloser: tryLinkShutdown during cooperative close process
Adds a new Brontide struct method tryLinkShutdown that attempts to
fetch the target link and calls ShutdownIfChannelClean on it. This
allows the coop close process to guarantee atomicity of the underlying
channel state. Also removes the UnregisterChannel method from the
chancloser's config as the link is shut down before the chancloser
is created.
2021-09-13 13:29:51 -04:00
eugene
608d11dcbc
peer: add mockUpdateHandler for use in mockMessageSwitch 2021-09-13 13:29:50 -04:00
Olaoluwa Osuntokun
3e1558b616
peer: re-use buf from bufpool when decoding messages
In this commit, which builds on top of the prior commit, rather than
using the returned buffer outside of the closure (which means it'll be
copied), we instead use it within the `Submit` closure instead. With the
recent changes to the `brontide` package, we won't allocate any new
buffer when we decrypt, as a result, the `rawMsg` byte slice actually
just slices into the passed `buf` slice (obtained from the pool)`.

With this change, we ensure that the buffer pool can release the slice
back to the pool and eliminate any extra allocations along the way.
2021-08-27 16:57:15 -07:00
Olaoluwa Osuntokun
2947076607
peer: store the last ping payload received by a remote peer in an atomic var 2021-08-25 16:47:13 -07:00
Olaoluwa Osuntokun
4287e25494
peer: add message summaries for ping+pong 2021-08-25 16:47:10 -07:00
Olaoluwa Osuntokun
d566e51a52
peer: always send latest block header as part of ping messages
In this commit, we implement a long discussed mechanism to use the
Lightning Network as a redundant block header source. By sending our
latest block header with each ping message, we give peers another source
(outside of the Bitcoin P2P network) they can use to spot check their
chain state. Peers can also use this information to detect if they've
been eclipsed from the traditional Bitcoin P2P network itself.

As is, we only send this data in Ping messages (which are periodically
sent), in the future we could also move to send them as the partial
payload for our pong messages, and also randomize the payload size
requested as well.
2021-08-25 16:47:07 -07:00
eugene
23a4fad4ac
htlcswitch+peer: CreateAndAddLink in switch, add messageSwitch to peer
This commit allows the peer to be tested without relying on a raw
htlcswitch.Switch pointer. This is accomplished by using a messageSwitch
interface and adding the CreateAndAddLink method to the
htlcswitch.Switch.
2021-08-10 17:15:52 -04:00
eugene
e72468646c
htlcswitch+peer: embed ChannelUpdateHandler in ChannelLink
GetLink, GetLinksByInterface now use ChannelUpdateHandler.
2021-08-10 17:15:52 -04:00
eugene
6c6e353597
htlcswitch+peer: pass BestHeight to ChannelLinkConfig
This allows non-test usages of ChannelLinkConfig to omit the raw
htlcswitch.Switch pointer.
2021-08-10 17:15:49 -04:00
Joost Jager
ffd346e2e1
config: add channel commit batch size parameter 2021-04-09 15:10:43 +02:00
Joost Jager
a181d26287
config: add channel commit interval parameter 2021-04-09 15:10:42 +02:00
Wilmer Paulino
f38bf4d7fa
lnwallet: expose required account parameter for WalletController methods 2021-04-05 15:41:05 -07:00
Conner Fromknecht
b4aa661d16
Merge pull request #5064 from ellemouton/set-coop-close-target-confs
multi: allow setting target confs for co-op close
2021-03-16 11:14:15 -07:00
Elle Mouton
3b412ce50f multi: allow setting target confs for co-op close
This commit adds a new config option: "--coop-close-target-confs"
which allows a user to override the default target confirmations of 6
that is used to estimate a fee rate to use during a co-op closure
initiated by a remote peer.
2021-03-04 13:04:41 +02:00
Elliott Jin
5a54d787e1 brontide: log at debug, not error, when ignoring enable request 2021-02-24 07:13:28 -08:00
Elliott Jin
e9baf0e4a2 multi: add bool param to channel enable/disable methods
Add a new boolean parameter without changing any existing
functionality. The parameter will be used to indicate
whether a request to update a channel's status was made
manually by a user (currently always false).
2021-02-24 07:13:28 -08:00
eugene
f8b98a1d3b
lntest/channels: introduce subpackage to deduplicate static structs 2021-01-25 14:04:39 -05:00
Olaoluwa Osuntokun
403d37f426
peer: ensure consistent local+global feature bits when downgrading
In this commit, we fix an issue that would cause peers running lnd 0.12
to not be able to connect to existing peers due to a feature bit
compatibility issue. In a recent PR we started to downgrade our required
feature bit for static key from required to optional, if we had a legacy
(non-tweakless) open with the peer then we would unset the required bit
and set the optional bit to ensure we could still connect to them.

The change implementing this new version of downgrade failed _also_
unset the bit (the required bit) in the "legacy global" feature bit
section. This caused the `RawFeatureVector.Merge` method to fail as we
would have the required bit set in the `GlobalFeatures` section, but the
optional bit set in the `Features` section. The `Merge` method ensures
that a required and optional bit can't be set in two different locations
for the same feature.

This PR fixes this issue by also unsetting the bit in the
`GlobalFeatures` field in the init message.

Fixes #4871
2020-12-17 17:04:15 -08:00
eugene
9c72dd9eba funding+peer: rename Manager interface to Controller 2020-12-17 09:36:34 -05:00
eugene
61e0f67edf funding: rename from fmgr, change references 2020-12-17 09:36:34 -05:00
Johan T. Halseth
0fd76e53b8
multi: cap anchors feerate at configurable maximum
This commit caps the update fee the initiator will send when the anchors
channel type is used. We do not limit anything on the receiver side.

10 sat/vbyte is the current default max fee rate we use. This should be
enough to ensure propagation before anchoring down the commitment
transaction.
2020-12-15 19:54:50 +01:00
Johan T. Halseth
f6f3ab5b0b
Merge pull request #4829 from yyforyongyu/typo-fix
multi: Typo fix
2020-12-10 13:55:35 +01:00
carla
7d1282af70
peer/test: add test for static key downgrade for legacy channels 2020-12-09 16:31:02 +02:00
Johan T. Halseth
0532c21e33
peer: remove static remote required for peers with legacy channels
This commit unsets option static remote key required for peers that
we have existing legacy channels with. This ensures that we can still
connect to peers that do not recognize this feature bit that we have
existing channels with.
2020-12-09 16:18:09 +02:00
yyforyongyu
f46d16ff89
peer: fix typo 2020-12-04 23:07:54 +08:00
Conner Fromknecht
0d0f22aacb
link+peer: thread anchor tower client to link 2020-11-25 15:39:14 -08:00
Federico Bond
10d94f99c0
multi: move several wait group done calls to defer statements 2020-11-23 14:48:44 +01:00
Johan T. Halseth
a97182b1e9
peer: mark channel borked in case of PermanentFailure 2020-11-04 11:16:22 +01:00
eugene
e0859e121f multi: add fmgr.Manager interface, change usage in peer to use Manager
This gets rid of several config functions in the peer and should pave
the way for easier testing of the funding manager and peer.
2020-10-01 10:27:13 -04:00
eugene
fada3dd871 server.go + peer: use MessageConn interface instead of brontide.Conn 2020-09-25 12:05:36 -04:00
Conner Fromknecht
c704c5747a
Merge pull request #4558 from halseth/anchors-spec
[anchor commitment] Make the anchor commitment type spec compliant
2020-09-11 15:43:56 -04:00
Conner Fromknecht
3c606bd9c0
Merge pull request #4542 from Crypt-iQ/mock_signer_cleanup_0817
multi: remove mock.go
2020-09-11 13:16:17 -04:00
Johan T. Halseth
bf18929f0e
peer/brontide: fix pubkey log 2020-09-11 11:10:58 +02:00
eugene
ea467783e9 htlcswitch+peer: remove fwd pkgs once before tick, bump timer to 1hr
This commit changes the logic when garbage collecting forwarding
packages such that they are removed once when the function is called,
and then again upon subsequent ticks. This allows us to bump the
peer timer to 1 hour to limit the number of db transactions happening
in lnd. The forwarding packages need to be removed initially as
otherwise a flappy node will never have them garbage collected.
2020-08-31 20:52:51 -04:00
eugene
c7cbacc35b multi: move mockChainIO, mockNotifier to lntest/mock 2020-08-31 19:41:09 -04:00
eugene
3fa5d042c9 multi: move mockWalletController, mockSecretKeyRing to lntest/mock 2020-08-31 18:36:05 -04:00
eugene
49d8f04197 multi: migrate instances of mockSigner to the mock package
This commit moves all localized instances of mock implementations of
the Signer interface to the lntest/mock package. This allows us to
remove a lot of code and have it housed under a single interface in
many cases.
2020-08-28 15:43:51 -04:00
Olaoluwa Osuntokun
f58b00ef55
multi: split database storage into remote and local instances
In this commit, we split the database storage into two classes: remote
and local data. If etcd isn't active, then everything is actually just
local though we use two pointers everywhere. If etcd is active, then
everything but the graph goes into the remote database.
2020-08-07 18:44:02 -07:00
nsa
cbd54101f8 multi: remove peer.go, change all references to point to peer pkg 2020-07-06 19:16:07 -04:00
nsa
01415f4a5f peer: define Config and LinkUpdater interface
This commit defines a Config for initializing a peer and the
LinkUpdater interface.
2020-07-06 19:16:06 -04:00