Commit Graph
100 Commits
Author SHA1 Message Date
yyforyongyu 6eb9bb1ed6 multi: add new method ChainArbitrator.RedispatchBlockbeat
This commit adds a new method to enable us resending the blockbeat in
`ChainArbitrator`, which is needed for the channel restore as the chain
watcher and channel arbitrator are added after the start of the chain
arbitrator.
2024-12-20 17:54:07 +08:00
yyforyongyu 4d765668cc contractcourt: use close height instead of best height
This commit adds the closing height to the logging and fixes a wrong
height used in handling the breach event.
2024-12-20 17:54:07 +08:00
yyforyongyu 3822c23833 contractcourt: notify blockbeat for chainWatcher
We now start notifying the blockbeat from the ChainArbitrator to the
chainWatcher.
2024-12-20 17:54:07 +08:00
yyforyongyu 8237598ed1 contractcourt: handle blockbeat in chainWatcher 2024-12-20 17:54:07 +08:00
yyforyongyu 4e30598263 contractcourt: add method handleCommitSpend
To prepare for the blockbeat handler.
2024-12-20 17:54:07 +08:00
yyforyongyu c1a9390c36 contractcourt: register spend notification during init
This commit moves the creation of the spending notification from `Start`
to `newChainWatcher` so we subscribe the spending event before handling
the block, which is needed to properly handle the blockbeat.
2024-12-20 17:54:06 +08:00
yyforyongyu 07cb3aef00 contractcourt: implement Consumer on chainWatcher 2024-12-20 17:54:06 +08:00
yyforyongyu 63aa5aa6e9 contractcourt: offer outgoing htlc one block earlier before its expiry
We need to offer the outgoing htlc one block earlier to make sure when
the expiry height hits, the sweeper will not miss sweeping it in the
same block. This also means the outgoing contest resolver now only does
one thing - watch for preimage spend till height expiry-1, which can
easily be moved into the timeout resolver instead in the future.
2024-12-20 17:54:06 +08:00
yyforyongyu 819c15fa0b contractcourt: break launchResolvers into two steps
In this commit, we break the old `launchResolvers` into two steps - step
one is to launch the resolvers synchronously, and step two is to
actually waiting for the resolvers to be resolved. This is critical as
in the following commit we will require the resolvers to be launched at
the same blockbeat when a force close event is sent by the chain watcher.
2024-12-20 17:54:06 +08:00
yyforyongyu d2e81a19fd contractcourt: fix concurrent access to launched 2024-12-20 17:54:06 +08:00
yyforyongyu 4f5ccb8650 contractcourt: fix concurrent access to resolved
This commit makes `resolved` an atomic bool to avoid data race. This
field is now defined in `contractResolverKit` to avoid code duplication.
2024-12-20 17:54:06 +08:00
yyforyongyu 47722292c5 contractcourt: add Launch method to outgoing contest resolver 2024-12-20 17:54:05 +08:00
yyforyongyu ef98c52d10 contractcourt: add Launch method to incoming contest resolver
A minor refactor is done to support implementing `Launch`.
2024-12-20 17:54:05 +08:00
yyforyongyu 025d787fd2 invoices: exit early when the subscriber chan is nil
When calling `NotifyExitHopHtlc` it is allowed to pass a chan to
subscribe to the HTLC's resolution when it's settled. However, this
method will also return immediately if there's already a resolution,
which means it behaves like a notifier and a getter. If the caller
decides to only use the getter to do a non-blocking lookup, it can pass
a nil subscriber chan to bypass the notification.
2024-12-20 17:54:05 +08:00
yyforyongyu 71aec7bd94 contractcourt: add Launch method to htlc timeout resolver
This commit breaks the `Resolve` into two parts - the first part is
moved into a `Launch` method that handles sending sweep requests, and
the second part remains in `Resolve` which handles waiting for the
spend. Since we are using both utxo nursery and sweeper at the same
time, to make sure this change doesn't break the existing behavior, we
implement the `Launch` as following,
- zero-fee htlc - handled by the sweeper
- direct output from the remote commit - handled by the sweeper
- legacy htlc - handled by the utxo nursery
2024-12-20 17:54:05 +08:00
yyforyongyu cf105e67f4 contractcourt: add Launch method to htlc success resolver
This commit breaks the `Resolve` into two parts - the first part is
moved into a `Launch` method that handles sending sweep requests, and
the second part remains in `Resolve` which handles waiting for the
spend. Since we are using both utxo nursery and sweeper at the same
time, to make sure this change doesn't break the existing behavior, we
implement the `Launch` as following,
- zero-fee htlc - handled by the sweeper
- direct output from the remote commit - handled by the sweeper
- legacy htlc - handled by the utxo nursery
2024-12-20 17:54:05 +08:00
yyforyongyu 913f5d4657 contractcourt: add Launch method to commit resolver 2024-12-20 17:54:05 +08:00
yyforyongyu a98763494f contractcourt: add Launch method to anchor/breach resolver
We will use this and its following commits to break the original
`Resolve` methods into two parts - the first part is moved to a new
method `Launch`, which handles sending a sweep request to the sweeper.
The second part remains in `Resolve`, which is mainly waiting for a
spending tx.

Breach resolver currently doesn't do anything in its `Launch` since the
sweeping of justice outputs are not handled by the sweeper yet.
2024-12-20 17:54:04 +08:00
yyforyongyu 730b605ed4 contractcourt: add resolve handlers in htlcTimeoutResolver
This commit adds more methods to handle resolving the spending of the
output based on different spending paths.
2024-12-20 17:54:04 +08:00
yyforyongyu 7083302fa0 contractcourt: add methods to checkpoint states
This commit adds checkpoint methods in `htlcTimeoutResolver`, which are
similar to those used in `htlcSuccessResolver`.
2024-12-20 17:54:04 +08:00
yyforyongyu bfc95b8b2c contractcourt: add sweep senders in htlcTimeoutResolver
This commit adds new methods to handle making sweep requests based on
the spending path used by the outgoing htlc output.
2024-12-20 17:54:04 +08:00
yyforyongyu cb18940e75 contractcourt: remove redundant return value in claimCleanUp 2024-12-20 17:54:04 +08:00
yyforyongyu c92d7f0fd0 contractcourt: add resolver handlers in htlcSuccessResolver
This commit refactors the `Resolve` method by adding two resolver
handlers to handle waiting for spending confirmations.
2024-12-20 17:54:04 +08:00
yyforyongyu fb499bc4cc contractcourt: add sweep senders in htlcSuccessResolver
This commit is a pure refactor in which moves the sweep handling logic
into the new methods.
2024-12-20 17:54:04 +08:00
yyforyongyu 10e5a43e46 contractcourt: add spend path helpers in timeout/success resolver
This commit adds a few helper methods to decide how the htlc output
should be spent.
2024-12-20 17:54:03 +08:00
yyforyongyu 1f2cfc6a60 contractcourt: add verbose logging in resolvers
We now put the outpoint in the resolvers's logging so it's easier to
debug.
2024-12-20 17:54:03 +08:00
yyforyongyu 0bab6b3419 chainio: use errgroup to limit num of goroutines 2024-12-20 17:54:03 +08:00
yyforyongyu 45b243c91c contractcourt: fix linter funlen
Refactor the `Start` method to fix the linter error:
```
contractcourt/chain_arbitrator.go:568: Function 'Start' is too long (242 > 200) (funlen)
```
2024-12-20 17:54:03 +08:00
yyforyongyu 8fc9154506 lnd: start blockbeatDispatcher and register consumers 2024-12-20 17:54:03 +08:00
yyforyongyu 16a8b623b3 lnd: add new method startLowLevelServices
In this commit we start to break up the starting process into smaller
pieces, which is needed in the following commit to initialize blockbeat
consumers.
2024-12-20 17:54:02 +08:00
yyforyongyu 545cea0546 multi: start consumers with a starting blockbeat
This is needed so the consumers have an initial state about the current
block.
2024-12-20 17:54:02 +08:00
yyforyongyu 802353036e contractcourt: start channel arbitrator with blockbeat
To avoid calling GetBestBlock again.
2024-12-20 17:54:02 +08:00
yyforyongyu e2e59bd90c contractcourt: remove the immediate param used in Resolve
This `immediate` flag was added as a hack so during a restart, the
pending resolvers would offer the inputs to the sweeper and ask it to
sweep them immediately. This is no longer need due to `blockbeat`, as
now during restart, a block is always sent to all subsystems via the
flow `ChainArb` -> `ChannelArb` -> resolvers -> sweeper. Thus, when
there are pending inputs offered, they will be processed by the sweeper
immediately.
2024-12-20 17:54:02 +08:00
yyforyongyu 71295534bb contractcourt: remove block subscription in channel arbitrator
This commit removes the block subscriptions used in `ChannelArbitrator`,
replaced them with the blockbeat managed by `BlockbeatDispatcher`.
2024-12-20 17:54:02 +08:00
yyforyongyu 045f8432b7 contractcourt: remove block subscription in chain arbitrator
This commit removes the block subscriptions used in `ChainArbitrator`
and replaced them with the blockbeat managed by `BlockbeatDispatcher`.
2024-12-20 17:54:02 +08:00
yyforyongyu 5f9d473702 contractcourt: remove waitForHeight in resolvers
The sweeper can handle the waiting so there's no need to wait for blocks
inside the resolvers. By offering the inputs prior to their mature
heights also guarantees the inputs with the same deadline are
aggregated.
2024-12-20 17:54:02 +08:00
yyforyongyu 3ac6752a77 sweep: remove redundant notifications during shutdown
This commit removes the hack introduced in #4851. Previously we had this
issue because the chain notifier was stopped before the sweeper, which
was changed a while back and we now always stop the chain notifier last.
In addition, since we no longer subscribe to the block epoch chan
directly, this issue can no longer happen.
2024-12-20 17:54:01 +08:00
yyforyongyu e113f39d26 sweep: remove block subscription in UtxoSweeper and TxPublisher
This commit removes the independent block subscriptions in `UtxoSweeper`
and `TxPublisher`. These subsystems now listen to the `BlockbeatChan`
for new blocks.
2024-12-20 17:54:01 +08:00
yyforyongyu 801fd6b85b multi: implement Consumer on subsystems
This commit implements `Consumer` on `TxPublisher`, `UtxoSweeper`,
`ChainArbitrator` and `ChannelArbitrator`.
2024-12-20 17:54:01 +08:00
yyforyongyu b5a3a27c77 chainio: add partial implementation of Consumer interface 2024-12-20 17:54:01 +08:00
yyforyongyu 4b83d87baa chainio: add BlockbeatDispatcher to dispatch blockbeats
This commit adds a blockbeat dispatcher which handles sending new blocks
to all subscribed consumers.
2024-12-20 17:54:01 +08:00
yyforyongyu a1eb87e280 chainio: add helper methods to dispatch beats
This commit adds two methods to handle dispatching beats. These are
exported methods so other systems can send beats to their managed
subinstances.
2024-12-20 17:54:01 +08:00
yyforyongyu 01ac713aec chainio: implement Blockbeat
In this commit, a minimal implementation of `Blockbeat` is added to
synchronize block heights, which will be used in `ChainArb`, `Sweeper`,
and `TxPublisher` so blocks are processed sequentially among them.
2024-12-20 17:54:00 +08:00
yyforyongyu 060ff013c1 chainio: introduce chainio to handle block synchronization
This commit inits the package `chainio` and defines the interface
`Blockbeat` and `Consumer`. The `Consumer` must be implemented by other
subsystems if it requires block epoch subscription.
2024-12-20 17:54:00 +08:00
yyforyongyu 30ee450091 sweep: make sure nil tx is handled
After previous commit, it should be clear that the tx may be failed to
created in a `TxFailed` event. We now make sure to catch it to avoid
panic.
2024-12-20 17:54:00 +08:00
yyforyongyu 78ce757e7b sweep: break initialBroadcast into two steps
With the combination of the following commit we can have a more granular
control over the bump result when handling it in the sweeper.
2024-12-20 17:54:00 +08:00
yyforyongyu f0c4e6dba1 sweep: remove redundant loopvar assign 2024-12-20 17:54:00 +08:00
yyforyongyu 77ff2c0585 sweep: add handleInitialBroadcast to handle initial broadcast
This commit adds a new method `handleInitialBroadcast` to handle the
initial broadcast. Previously we'd broadcast immediately inside
`Broadcast`, which soon will not work after the `blockbeat` is
implemented as the action to publish is now always triggered by a new
block. Meanwhile, we still keep the option to bypass the block trigger
so users can broadcast immediately by setting `Immediate` to true.
2024-12-20 17:53:59 +08:00
yyforyongyu 2479dc7f2e sweep: handle inputs locally instead of relying on the tx
This commit changes how inputs are handled upon receiving a bump result.
Previously the inputs are taken from the `BumpResult.Tx`, which is now
instead being handled locally as we will remember the input set when
sending the bump request, and handle this input set when a result is
received.
2024-12-20 17:53:59 +08:00
yyforyongyu d0c7fd8aac sweep: add new interface method Immediate
This prepares the following commit where we now let the fee bumpr
decides whether to broadcast immediately or not.
2024-12-20 17:53:59 +08:00
yyforyongyu 5f64280df4 sweep: add new error ErrZeroFeeRateDelta 2024-12-20 17:53:59 +08:00
yyforyongyu 785cef2a96 gomod: remove replace of sqldb and kvdb 2024-12-19 19:02:46 +08:00
yyforyongyu 7882e1ccff lnwallet: add debug logs 2024-12-16 16:07:22 +08:00
yyforyongyu 39584be7e1 routing: fix nil pointer dereference in exitWithErr
In a rare case when the critical log is triggered when using postgres as
db backend, the `payment` could be nil cause the server is shutting
down, causing the payment fetching to return an error. We now cache its
state before fetching it from the db.
2024-12-16 16:07:22 +08:00
yyforyongyu 944f16255a htlcswitch: handle nil circuit properly when settling
We have two sources which can call `handlePacketSettle`, either through
the link's `<-s.htlcPlex`, or the `<-s.resolutionMsgs`, which means the
`closeCircuit` could be call twice. Previously we already caught this
case inside `closeCircuit`, in that we would return a nil circuit upon
seeing `ErrUnknownCircuit`, indicating the circuit was removed. However,
we still need to account the case when the circuit is the process of
being closed, which is now fixed as we will ignore when seeing
`ErrCircuitClosing`.
2024-12-16 15:58:23 +08:00
yyforyongyu 5867f0040f gomod: update btcd for shutdown fix 2024-12-10 19:56:03 +08:00
yyforyongyu f03e242515 chainntnfs: ensure previous test succeeded before running 2024-12-10 19:56:01 +08:00
yyforyongyu 7374392abe lnrpc: sort Invoice.HTLCs based on HtlcIndex
So the returned HTLCs are ordered.
2024-12-07 09:54:46 +08:00
yyforyongyu d108e14c5d multi: rename lll to ll and remove unused nolint 2024-12-04 07:20:59 +08:00
yyforyongyu b243394049 lnwallet: log the amounts in the same unit 2024-11-21 20:42:47 +08:00
yyforyongyu 57084804d4 lnd: stop graphBuilder during shutdown 2024-11-21 15:37:49 +08:00
yyforyongyu db6901c9f3 chainntnfs: skip duplicate numConfsLeft notifications
This commit adds a new state to the `ConfNtfn` struct to start tracking
the number of confs left to be notified to avoid sending duplicate
notifications.
2024-11-19 16:27:26 +08:00
yyforyongyu 7695880c13 chainntnfs: add new method notifyNumConfsLeft
So it's easier to handle the following commit where we start skipping
duplicate notifications.
2024-11-19 16:02:19 +08:00
yyforyongyu 0c3b2b5e06 docs: update release notes 2024-11-19 15:56:27 +08:00
yyforyongyu 4ff1f19fbf chainntnfs: make sure notification is sent to the whole set
This commit fixes a bug where the confirmation details may be missed.
When the same tx is subscribed via `RegisterConfirmationsNtfn`, we will
put them into the same set and notify the whole set. However, this logic
is missing when performing the rescan - once the confirmation detail is
found, we only notify the current subscriber. Later we will skip
notifying other subscribers in `UpdateConfDetails` due to the
`confSet.details != nil` check. We now fix it by immediately notify all
the subscribers when the confirmation detail is found during the rescan.
2024-11-19 15:56:08 +08:00
yyforyongyu 1200b75546 chainntnfs: always notify txns before block
This commit changes the order of notifications when a relevant tx is
found in a block and now we will always notify the tx subscribers before
notifying the block, which has implications in the upcoming blockbeat.

When a block notification is subscribed via `RegisterBlockEpochNtfn` and
a confirm or spend is subscribed via `RegisterConfirmationsNtfn` or
`RegisterSpendNtfn`, we would always notify the block first before the
tx, causing the subsystem to think there's no relevant txns found in
this block, while the notifications are sent later. We now fix it by
always sending the txns notifications first, so the subsystem can
receive the txns, process them, then attempt to advance its state based
on the block received.
2024-11-19 15:55:22 +08:00
yyforyongyu 3ab5669ff2 docs: update release notes 2024-11-18 18:49:34 +08:00
yyforyongyu fe03aa0201 peer+lnd: fix peer blocking on node shutdown
This commit fixes a case where the peer blocks the shutdown process.
During the shutdown, the server will call `s.DisconnectPeer`, which
calls `peer.Disconnect`. Because the peer never enters `peer.Start` via
`s.peerInitializer`, the `startReady` chan will not be closed, causing
`peer.Disconnect` to hang forever. We now fix it by only block on
`startReady` when the peer is started.
2024-11-18 18:49:34 +08:00
Yong 0876173c45 Merge pull request #9261 from yyforyongyu/fix-rpcclient-shutdown
multi: fix rpcclient shutdown
2024-11-14 03:18:07 +08:00
yyforyongyu 1c6d89446d docs: update release notes 2024-11-14 01:22:32 +08:00
yyforyongyu fc5f8e32f5 chanfitness: exit early when there are no updates 2024-11-14 01:22:32 +08:00
yyforyongyu 523ecc0653 multi: wait for rpcclients shutdown to complete
We need to call `WaitForShutdown` after stopping the rpc clients of the
chain backends.
2024-11-14 01:22:31 +08:00
yyforyongyu 653a8ac55e lntest+itest: add new method AssertChannelInGraph
This commit replaces `AssertTopologyChannelOpen` with
`AssertChannelInGraph`, which asserts a given channel edge is found.
`AssertTopologyChannelOpen` only asserts a given edge has been received
via the topology subscription, while we need to make sure the channel is
in the graph before continuing our tests.
2024-11-12 23:55:40 +08:00
yyforyongyu 7dda2960a5 lntest: update the block height of HarnessTest during start 2024-11-12 23:55:40 +08:00
yyforyongyu 2905e7b3df lntest+itest: kill node and wait its process
Fix a flake found in `testRPCMiddlewareInterceptor` when running in
macOS.
2024-11-12 23:55:40 +08:00
yyforyongyu 90bca1022b lntest: retry finding the payment from ListPayments 2024-11-12 23:55:40 +08:00
yyforyongyu 4506fd30cb lntest: change the nodeCounter to be atomic 2024-11-12 23:55:13 +08:00
yyforyongyu cc6ff150b9 lntest: remove deprecated config --profile 2024-11-12 14:46:31 +08:00
yyforyongyu 6ac588e655 lntest: remove an invalid check
`openChannelsForNodes` is called inside `openZeroConfChannelsForNodes`
so this value can be true.
2024-11-12 14:46:30 +08:00
Yong 4f6b510869 Merge pull request #9248 from yyforyongyu/fix-itest
lntest: fix edge assertion and reset min relay fee
2024-11-11 22:16:03 +08:00
yyforyongyu 7dd9a17625 lntest+itest: fix testUpdateChanStatus 2024-11-11 20:57:50 +08:00
yyforyongyu d27ff34b04 lntest+itest: rename AssertNumEdges to AssertNumActiveEdges
To properly reflect what the assertion is.
2024-11-11 20:57:49 +08:00
yyforyongyu 35992e1503 lntest+itest: expore method createSimpleNetwork
So it can be used via `ht.CreateSimpleNetwork`.
2024-11-11 20:57:49 +08:00
yyforyongyu 9682aa7a78 itest: fix testZeroConfChannelOpen and testOptionScidAlias
Use a new node instead of standby node to avoid closing the channels in
the end.
2024-11-11 20:54:10 +08:00
yyforyongyu a745d74e7c lntest: make sure standby nodes' edges are cleaned 2024-11-11 20:54:10 +08:00
yyforyongyu e7d0754615 lntest: make sure minRelayFeerate is reset
So every test starts with the default minRelayFeerate.
2024-11-11 20:54:10 +08:00
yyforyongyu 4fe36f1887 docs: add release notes 2024-11-08 01:53:07 +08:00
yyforyongyu 227cc3a45c routing: fix missionControlStore blocks on shutting down 2024-11-08 01:23:33 +08:00
yyforyongyu 8311bc56e5 htlcswitch: fix flake in TestChannelLinkCancelFullCommitment
We bring down the max number of inflight HTLCs in the link's unit tests
to speed up the tests.
2024-10-31 20:23:31 +08:00
yyforyongyu 611405f59c chainntnfs/btcdnotify: remove redundant config params re-assignment 2024-10-30 02:01:14 +08:00
yyforyongyu 785e058b77 itest: fix flake in testPaymentFailureReasonCanceled
Fix the case,
```
--- FAIL: TestLightningNetworkDaemon/tranche01/46-of-191/bitcoind/payment_failure_reason_canceled (20.86s)
        harness.go:2113:
            	Error Trace:	/home/runner/work/lnd/lnd/lntest/harness.go:2113
            	            				/home/runner/work/lnd/lnd/itest/lnd_payment_test.go:1183
            	            				/home/runner/work/lnd/lnd/itest/lnd_payment_test.go:1138
            	            				/home/runner/work/lnd/lnd/lntest/harness.go:396
            	            				/home/runner/work/lnd/lnd/itest/lnd_test.go:139
            	Error:      	err from HTLC interceptor stream
            	Test:       	TestLightningNetworkDaemon/tranche01/46-of-191/bitcoind/payment_failure_reason_canceled
            	Messages:   	received err from HTLC interceptor stream: rpc error: code = Unknown desc = interceptor already exists
```
2024-10-29 15:32:17 +08:00
yyforyongyu 21535826ba lntest: remove redundant MineBlocks 2024-10-29 15:31:21 +08:00
Yong 6a5a79fb88 Merge pull request #9209 from guggero/lntest-shutdown
lntest: shutdown all nodes at end of test
2024-10-23 02:00:39 +08:00
Yong caff5a00d1 Merge pull request #9138 from ziggie1984/detail_debug_process
Detail LND's debug procedures.
2024-10-22 20:26:11 +08:00
yyforyongyu 7849e63e0f docs: update release doc 2024-10-17 07:45:06 +08:00
yyforyongyu bf8ae68eea lntest: add method AssertTxnsNotInMempool
So we only need to do one `GetRawMempool` lookup when checking the
exclusion of multiple txns.
2024-10-17 07:34:40 +08:00
yyforyongyu e560e00aeb lntest: remove unused return value 2024-10-17 07:34:25 +08:00
yyforyongyu ed3cb26188 itest+lntest: stop using pointer to chainhash.Hash
This commit fixes the methods used in `lntest` so they stop using
pointers to chainhash.
2024-10-17 07:14:51 +08:00
Yong da7f8aeb61 Merge pull request #9099 from lightningnetwork/kvdb-wallet-db
kvdb: update to latest walletdb version
2024-09-15 15:22:15 +08:00
yyforyongyu db332db025 Makefile: add -test.v for make itest 2024-09-10 17:21:03 +08:00