Commit Graph

460 Commits

Author SHA1 Message Date
yyforyongyu
3857b9e9a6
contractcourt: improve logging for failing dangling htlcs 2023-06-07 17:34:06 +08:00
Matt Morehouse
da10cb95b5
contractcourt: fully use chanPoint variable
When we create a temporary chanPoint variable to shorten up the code, we
should use it everywhere for consistency and clarity.
2023-05-31 10:56:08 -05:00
Olaoluwa Osuntokun
7686d10075 contractcourt: force the sweeper to always resolve outgoing HTLCs
In this commit, we attempt to fix an issue that may lead to force closes due
to small value HTLCs. The sweeper has built in a "negative yield" heuristic
where it won't sweep something that'll result in paying more fees than the
HTLC amount. However for HTLCs, we want to always sweep them, as we don't
cancel back the HTLCs before the outgoing contract is fully resolved.

In the future, we'll start to make more uneconomical decisions about if we
should go to chain at all for small value HTLCs, and also do things like
cancel back early if the HTLC is small and we think we might be contested by
chain fees.
2023-05-26 15:15:36 -07:00
yyforyongyu
186569c610
contractcourt: skip checkpoint timeout resolver upon mempool spend
Previously when a block spend is found for the outpoint, our htlc
timeout resolver will do a checkpoint, which implicitly creates a db
record if there isn't one. Now, if the spend is found in mempool,
the resolver will be deleted once the contract is resolved. Later on
when the spend is found in the block again, the resolver will be created
again, but never gets resolved this time.
2023-04-28 20:38:01 +08:00
yyforyongyu
56dcda0f7c
contractcourt: add debug logs for unresolved contracts 2023-04-28 20:38:00 +08:00
yyforyongyu
dccf9c77ca
lnd+contractcourt: add more debug logs
This commit adds more debug logs for witness beacon and channel
arbitrator.
2023-04-19 01:18:19 +08:00
yyforyongyu
556c38fefd
contractcourt+lnd: watch for preimage reveal in mempool
This commit extends the current htlc timeout resolver to also watch for
preimage spend in mempool for a full node backend.

If mempool enabled, the resolver will watch the spend of the htlc output
in mempool and blocks **concurrently**, as if they are independent.

Ideally, a transaction will first appear in mempool then in a block.
However, there's no guarantee it will appear in **our** mempool since
there's no global mempool, thus we need to watch the spend in two places
in case it doesn't go through our mempool.

The current design favors the spend event found in blocks, that is, when
the tx is confirmed, we'd abort the monitoring and conitnue since the
outpoint cannot be double spent and re-appear in mempool again. This is
not true in the rare case of reorg, and we will handle reorg seperately.
2023-04-19 01:18:19 +08:00
yyforyongyu
7ef8072724
contractcourt: refactor spendHtlcOutput for clarity
Also fixes the docs and rename `isSuccessSpend` to `isPreimageSpend`.
2023-04-19 01:18:19 +08:00
yyforyongyu
edba938996
multi: add new build tag integration
This commit adds a new build tag `integration` and removes the old tag
`rpctest` for clarity. Multiple unnecessary usages of `build !rpctest`
is also removed.
2023-02-23 21:56:09 +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
positiveblue
5ff5225245
multi: break invoice depenency on channeldb
Now that we have the new package `lnd/channeldb/models` we can invert the
depenency between `channeldb` and `invoices`.

- Move all the invoice related types and errors to the
`invoices` package.

- Ensure that all the packages dealing with invoices use the types and
  interfaces defined in the `invoices` package.

- Implement the InvoiceDB interface (defined in `lnd/invoices`) in
  channeldb.

- Add new mock for InterfaceDB.

- `InvoiceRegistery` tests are now in its own subpacakge (they need to
  import both invoices & channeldb). This is temporary until we can
  decouple them.
2023-01-16 07:31:09 -08:00
positiveblue
383cb40f8d
multi: create channeldb/models package
Add a new subpackage to `lnd/channeldb` to hold some of the types that
are used in the package itself and in other packages that should not
depend on `channeldb`.
2023-01-16 07:14:55 -08:00
yyforyongyu
84fd911b47
multi: fix make lint
Fixes new lint errors caught by the latest version.
2022-11-18 20:48:23 +08:00
Joost Jager
511fb00777
htlcswitch: add final htlc event to notifier 2022-10-27 16:42:36 +02:00
Joost Jager
28256b7ea8
htlcswitch: keep final htlc outcome 2022-10-27 16:42:36 +02:00
yyforyongyu
5ed37166ef
contractcourt: return htlcResolution when currentHeight has reached expiry
Only create the sweep tx when the height has reached, otherwise we will
get a broadcast error. Previously it wasn't caught by itest due to the
blocks were mined very fast, so the lock time was always reached.
2022-10-27 01:11:35 +08:00
yyforyongyu
2285bfdf9f
contractcourt+brontide: fix typo and inaccurate logging 2022-10-27 01:11:35 +08: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
Eng Zer Jun
d1541d6628
contractcourt: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 08:58:16 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
Olaoluwa Osuntokun
cd313eba24
contractcourt: the breach arb now uses P2TR outputs for sweep addrs 2022-08-11 17:26:10 -07: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
eugene
3fc53c673b
contractcourt: set proper height hint for zero-conf channels
The contractcourt's chain watcher is now zero-conf aware and will use
an appropriate heightHint when scanning the chain.
2022-07-07 17:10:29 -04:00
eugene
c9f5912601
channeldb: BigSize migration, store zero-conf, scid-alias bits
This introduces a BigSize migration that is used to expand the width
of the ChannelStatus and ChannelType fields. Three channel "types"
are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit.
ScidAliasChanBit denotes that the scid-alias channel type was
negotiated for the channel. ScidAliasFeatureBit denotes that the
scid-alias feature bit was negotiated during the *lifetime* of the
channel. Several helper functions on the OpenChannel struct are
exposed to aid callers from different packages.

The RefreshShortChanID has been renamed to Refresh.

A new function BroadcastHeight is used to guard access to the
mutable FundingBroadcastHeight member. This prevents data races.
2022-07-07 17:10:27 -04:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Olaoluwa Osuntokun
9b0718ae35
contractcourt: unify the lease specific HTLC sweeping logic
In this commit, we consolidate the _lease specific_ logic for the
success and timeout HTLC resolvers. We do this with the addition of a
new struct which is then composed via struct embedding with the two
existing structs. This fixes a flake in the integration tests by
ensuring the height is set up front, rather than eventually once the
height matches the lock time.
2022-06-01 16:42:33 -07:00
eugene
160d63b88e
contractcourt: make empty htlcSets for closed channels
This prevents a panic where an insert is attempted on a nil map via
updateActiveHTLCs. This panic would occur if the channel arbitrator
was in a buggy state, possibly introduced by power loss or via
SIGKILL.
2022-05-27 16:18:02 -04: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
Olaoluwa Osuntokun
54adc6996b
Merge pull request #6322 from Crypt-iQ/handoff_deadlock_fix
contractcourt: deadlock fix via temporary unmerged map
2022-05-03 15:12:20 -07:00
eugene
f7b3da4bb2
htlcswitch+lntest: modify Switch to persist resolution messages
Include unit tests for the Switch, and integration tests that
exercise the persistence logic.
2022-04-29 16:40:19 -04:00
eugene
ef83370dcf
contractcourt: deadlock fix via temporary unmerged map
The main idea is that NotifyContractUpdate adds the ContractUpdate to
a map called unmerged. It is populated in Start by shallow-copying the
activeHTLCs map values (htlcSet). The htlcSets underlying maps are not
copied, and so unmerged will just contain pointers to them. This should
be fine since unmerged will not modify them. At the call-sites of
activeHTLCs, it is updated to include the unmerged sets. This happens
with a mutex and should not cause any data race, even though it is
copying the underlying map pointers. No persistence should be
necessary since on restart, activeHTLCs and unmerged will just be
populated again.
2022-04-19 17:24:21 -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
291a8e4eff
contractcourt: move breach handling into its own function
This commit refactors the breach handling logic into its own function
so that the related code can be unit tested.
2022-04-20 01:18:12 +08:00
yyforyongyu
fea97699ec
contractcourt: remove unused bucket justice-txn
We never writes data to this bucket so it's removed.
2022-04-20 01:18:11 +08:00
Joost Jager
721fb4ee88
contractcourt: add onchain interception 2022-04-13 11:31:33 +02:00
Oliver Gugger
6e2214fd0f
Merge pull request #6365 from antonilol/some_typos
fix some typos
2022-03-28 09:23:43 +02:00
Antoni Spaanderman
1516310257
channelarbitrator: fix typo in comment [skip ci] 2022-03-27 15:54:56 +02: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
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
Olaoluwa Osuntokun
4d9a05c2f4
Merge pull request #6221 from Crypt-iQ/link_handoff
multi: reliable hand-off from htlcswitch to contractcourt
2022-02-24 17:01:36 -08:00
Olaoluwa Osuntokun
10fba3d859
Merge pull request #6214 from yyforyongyu/server-start-order
server: start htlcswitch early in the pipeline
2022-02-24 15:32:46 -08: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
13f187046b
multi: fix issues reported by whitespace linter 2022-02-15 16:26:08 +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
eugene
ebaffb953a server+contractcourt: hand-off BreachCloseInfo to channel arbitrator
This also changes the chain_watcher and breacharbiter handoff. The
new logic ensures that the channel is only marked as pending closed
when the channel arbitrator has persisted the resolutions and commit
set.
2022-01-25 15:42:20 -05:00