Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fe06ac0
lnwallet: populate resolution blob for htlc retribution
GeorgeTsagk Apr 14, 2026
82966fc
sweep+contractcourt: notify aux sweeper only on confirmed sweeps
GeorgeTsagk Apr 14, 2026
e846294
lnwallet: pass breach height to HTLC resolution requests
GeorgeTsagk Apr 14, 2026
e0eed79
contractcourt: add tests for notifyConfirmedJusticeTx
GeorgeTsagk Apr 14, 2026
684d28d
lnwallet: extend FetchLeavesFromRevocation with channel state params
GeorgeTsagk Apr 14, 2026
70ba956
lnwallet: preserve resolution request for HTLC resolutions
GeorgeTsagk Apr 14, 2026
9ab4f2f
contractcourt: enhance breach arbiter for second-level HTLC revocation
GeorgeTsagk Apr 14, 2026
089ded9
lnwallet+contractcourt: gate HTLC sighash on negotiated feature bit
GeorgeTsagk Apr 14, 2026
f9c7158
lnwallet: bake fees into second-level HTLCs under SigHashDefault
GeorgeTsagk Apr 14, 2026
d04c9b9
contractcourt: publish pre-signed second-level HTLCs under SigHashDef…
GeorgeTsagk Apr 14, 2026
36960b2
contractcourt: track historic justice tx variants across rebuild cycles
GeorgeTsagk Apr 14, 2026
e998372
input: remove ErrTweakOverdose check from SignDescriptor.Decode
GeorgeTsagk Apr 14, 2026
3771d02
sweep+contractcourt: replace skipBroadcast bool with AuxNotifyOpts
GeorgeTsagk Apr 14, 2026
15e0501
lnwallet: populate AuxSigDesc for breach HTLC retribution
GeorgeTsagk Apr 14, 2026
d6d8d43
contractcourt: use dust limit for justice tx sweep output check
GeorgeTsagk Apr 14, 2026
7952e88
multi: add revocation AuxSig signing and verification
GeorgeTsagk Apr 14, 2026
275ea44
squash-fixup: gate aux revocation paths on custom-channel type
GeorgeTsagk Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
554 changes: 514 additions & 40 deletions contractcourt/breach_arbitrator.go

Large diffs are not rendered by default.

672 changes: 669 additions & 3 deletions contractcourt/breach_arbitrator_test.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions contractcourt/chain_arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ func (c *ChainArbitrator) WatchNewChannel(
extractStateNumHint: lnwallet.GetStateNumHint,
auxLeafStore: c.cfg.AuxLeafStore,
auxResolver: c.cfg.AuxResolver,
auxSigner: c.cfg.AuxSigner,
auxCloser: c.cfg.AuxCloser,
chanCloseConfs: c.cfg.ChannelCloseConfs,
notifyEarlyCoopClose: c.cfg.NotifyEarlyClosedChannel,
Expand Down Expand Up @@ -1385,6 +1386,7 @@ func (c *ChainArbitrator) loadOpenChannels() error {
extractStateNumHint: lnwallet.GetStateNumHint,
auxLeafStore: c.cfg.AuxLeafStore,
auxResolver: c.cfg.AuxResolver,
auxSigner: c.cfg.AuxSigner,
auxCloser: c.cfg.AuxCloser,
chanCloseConfs: c.cfg.ChannelCloseConfs,
notifyEarlyCoopClose: notifyEarlyClose,
Expand Down
8 changes: 7 additions & 1 deletion contractcourt/chain_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ type chainWatcherConfig struct {
// auxResolver is used to supplement contract resolution.
auxResolver fn.Option[lnwallet.AuxContractResolver]

// auxSigner is an optional signer that can be used to determine
// channel-specific HTLC sighash types based on negotiated features.
auxSigner fn.Option[lnwallet.AuxSigner]

// auxCloser is used to finalize cooperative closes.
auxCloser fn.Option[AuxChanCloser]

Expand Down Expand Up @@ -1160,6 +1164,7 @@ func (c *chainWatcher) handlePossibleBreach(commitSpend *chainntnfs.SpendDetail,
retribution, err := lnwallet.NewBreachRetribution(
c.cfg.chanState, broadcastStateNum, spendHeight,
commitSpend.SpendingTx, c.cfg.auxLeafStore, c.cfg.auxResolver,
c.cfg.auxSigner,
)

switch {
Expand Down Expand Up @@ -1574,7 +1579,7 @@ func (c *chainWatcher) dispatchLocalForceClose(
forceClose, err := lnwallet.NewLocalForceCloseSummary(
c.cfg.chanState, c.cfg.signer, commitSpend.SpendingTx,
uint32(commitSpend.SpendingHeight), stateNum,
c.cfg.auxLeafStore, c.cfg.auxResolver,
c.cfg.auxLeafStore, c.cfg.auxResolver, c.cfg.auxSigner,
)
if err != nil {
return err
Expand Down Expand Up @@ -1681,6 +1686,7 @@ func (c *chainWatcher) dispatchRemoteForceClose(
uniClose, err := lnwallet.NewUnilateralCloseSummary(
c.cfg.chanState, c.cfg.signer, commitSpend, remoteCommit,
commitPoint, c.cfg.auxLeafStore, c.cfg.auxResolver,
c.cfg.auxSigner,
)
if err != nil {
return err
Expand Down
21 changes: 21 additions & 0 deletions contractcourt/contract_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"io"
"sync/atomic"

"github.com/btcsuite/btcd/txscript/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/sweep"
)

Expand Down Expand Up @@ -184,3 +186,22 @@ var (
// progressing because it received the quit signal.
errResolverShuttingDown = errors.New("resolver shutting down")
)

// isSecondLevelSigHashDefault returns true when a pre-signed second-level
// HTLC transaction was signed with SigHashDefault. In this case the tx
// has baked-in fees and must be broadcast as-is — the sweeper cannot add
// wallet inputs or change outputs without invalidating the peer's
// signature.
//
// The channel type is the authoritative gate: only aux (taproot-assets)
// channels — identified by TapscriptRootBit — use SigHashDefault for
// second-level HTLCs. Without this gate, the zero-value SigHashType
// (0x00 == SigHashDefault) would accidentally match on regular lnd
// channels that never explicitly populate SignDetails.SigHashType.
func isSecondLevelSigHashDefault(signDetails *input.SignDetails,
chanType channeldb.ChannelType) bool {

return signDetails != nil &&
signDetails.SigHashType == txscript.SigHashDefault &&
chanType.HasTapscriptRoot()
}
134 changes: 133 additions & 1 deletion contractcourt/htlc_success_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,73 @@ func (h *htlcSuccessResolver) isZeroFeeOutput() bool {
h.htlcResolution.SignDetails != nil
}

// isSigHashDefault returns true when the second-level HTLC transaction
// was signed with SigHashDefault. See isSecondLevelSigHashDefault.
func (h *htlcSuccessResolver) isSigHashDefault() bool {
return isSecondLevelSigHashDefault(
h.htlcResolution.SignDetails, h.chanType,
)
}

// isAuxChannel reports whether this resolver is running for an aux/custom
// (taproot asset) channel. Only such channels carry a tapscript root, so
// this is the authoritative, self-contained predicate used to keep every
// aux-specific code path in this resolver from running on non-custom
// channels.
func (h *htlcSuccessResolver) isAuxChannel() bool {
return h.chanType.HasTapscriptRoot()
}

// buildSecondLevelResolveReq returns a ResolutionReq targeting the
// just-confirmed second-level HTLC tx. The fast path clones the
// ResolveReq preserved on htlcResolution at force-close time and updates
// only the fields that differ for a second-level sweep. The slow path
// (used when the resolver was recovered from the briefcase and the
// in-memory ResolveReq is gone) reconstructs the request from historical
// channel state.
func (h *htlcSuccessResolver) buildSecondLevelResolveReq(
witType input.WitnessType, secondLevelTx *wire.MsgTx,
spendingHeight uint32) (*lnwallet.ResolutionReq, error) {

if h.htlcResolution.ResolveReq != nil {
req := *h.htlcResolution.ResolveReq
req.Type = witType
req.SecondLevel = fn.Some(lnwallet.SecondLevelInfo{
Tx: secondLevelTx,
BlockHeight: spendingHeight,
})

return &req, nil
}

chanState, err := h.FetchHistoricalChannel()
if err != nil {
return nil, fmt.Errorf("fetch historical channel: %w", err)
}

return lnwallet.NewSecondLevelResolveReq(
chanState, &h.htlc, h.htlcResolution.SignDetails,
h.htlcResolution.SweepSignDesc, h.htlcResolution.CsvDelay,
h.broadcastHeight, secondLevelTx, spendingHeight, witType,
)
}

// publishSuccessTx directly broadcasts the pre-signed second-level HTLC
// success transaction. This is used when the transaction was signed with
// SigHashDefault (baked-in fees), where the sweeper's normal tx-rebuilding
// flow would invalidate the peer's signature.
func (h *htlcSuccessResolver) publishSuccessTx() error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolvers shouldn't publish themselves, that's an old relic. The sweeper should continue to handle this. It should already be able to broadcast a pre-signed transaction (legacy channels pre anchor).

h.log.Infof("publishing pre-signed 2nd-level HTLC success tx=%v "+
"(SigHashDefault, baked-in fees)",
h.htlcResolution.SignedSuccessTx.TxHash())

label := labels.MakeLabel(
labels.LabelTypeChannelClose, &h.ShortChanID,
)

return h.PublishTx(h.htlcResolution.SignedSuccessTx, label)
}

// isTaproot returns true if the resolver is for a taproot output.
func (h *htlcSuccessResolver) isTaproot() bool {
return txscript.IsPayToTaproot(
Expand Down Expand Up @@ -605,12 +672,69 @@ func (h *htlcSuccessResolver) sweepSuccessTxOutput() error {
default:
witType = input.HtlcAcceptedSuccessSecondLevel
}

// Under DeterministicHTLCs the pre-signed second-level HTLC tx was
// published directly via PublishTx, bypassing the sweeper's
// NotifyBroadcast hook. As a result the aux sweeper never imported
// the second-level proof transition into its archive, and the
// upcoming output sweep would fail to fetch its input proof. Give
// the aux resolver a chance to import the second-level tx into its
// proof archive before we offer the output sweep to the sweeper.
//
// We prefer the ResolveReq preserved on htlcResolution at force-close
// time and only fall back to reconstructing it from historical
// channel state when that field is unavailable — the briefcase
// encoder doesn't currently round-trip ResolveReq, so resolvers
// recovered from a checkpoint have it nil.
resolutionBlob := h.htlcResolution.ResolutionBlob

// The aux blob re-resolution below is an aux/custom (taproot asset)
// channel concern only. The AuxResolver is a daemon-global option
// (present on every resolver whenever tapd is attached, regardless of
// channel type), so we additionally gate on the channel type here to
// guarantee this path never executes for a non-custom channel.
auxResolver := fn.None[lnwallet.AuxContractResolver]()
if h.isAuxChannel() {
auxResolver = h.AuxResolver
}
auxResolver.WhenSome(func(a lnwallet.AuxContractResolver) {
secondLevelReq, err := h.buildSecondLevelResolveReq(
witType, h.htlcResolution.SignedSuccessTx,
uint32(commitSpend.SpendingHeight),
)
if err != nil {
h.log.Errorf("Unable to build second-level success "+
"ResolveReq (htlcID=%v): %v — falling back "+
"to original blob", h.htlc.HtlcIndex, err)

return
}

resolveBlob := a.ResolveContract(*secondLevelReq)
if err := resolveBlob.Err(); err != nil {
h.log.Errorf("Unable to re-resolve aux blob for "+
"second-level success output sweep "+
"(htlcID=%v): %v — falling back to original "+
"blob; output sweep may fail aux proof "+
"verification",
h.htlc.HtlcIndex, err)

return
}
h.log.Infof("sweepSuccessTxOutput: re-resolved aux blob "+
"for second-level success output sweep "+
"(htlcID=%v, secondLevelTxid=%v)",
h.htlc.HtlcIndex,
h.htlcResolution.SignedSuccessTx.TxHash())
resolutionBlob = resolveBlob.OkToSome()
})

inp := h.makeSweepInput(
op, witType,
input.LeaseHtlcAcceptedSuccessSecondLevel,
&h.htlcResolution.SweepSignDesc,
h.htlcResolution.CsvDelay, uint32(commitSpend.SpendingHeight),
h.htlc.RHash, h.htlcResolution.ResolutionBlob,
h.htlc.RHash, resolutionBlob,
)

// Calculate the budget for this sweep.
Expand Down Expand Up @@ -798,6 +922,14 @@ func (h *htlcSuccessResolver) Launch() error {
return h.sweepSuccessTxOutput()
}

// When the peer signed with SigHashDefault the pre-signed
// second-level tx has baked-in fees and cannot be modified
// (adding wallet inputs would invalidate the signature).
// Publish it directly instead of going through the sweeper.
if h.isSigHashDefault() {
return h.publishSuccessTx()
}

// Otherwise, sweep the second level tx.
return h.sweepSuccessTx()

Expand Down
Loading
Loading