mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-28 10:41:57 +01:00
contractcourt: update the anchor resolver for taproot chans
This commit is contained in:
parent
47d4eb341d
commit
2010239b63
@ -33,6 +33,9 @@ type anchorResolver struct {
|
|||||||
// chanPoint is the channel point of the original contract.
|
// chanPoint is the channel point of the original contract.
|
||||||
chanPoint wire.OutPoint
|
chanPoint wire.OutPoint
|
||||||
|
|
||||||
|
// chanType denotes the type of channel the contract belongs to.
|
||||||
|
chanType channeldb.ChannelType
|
||||||
|
|
||||||
// currentReport stores the current state of the resolver for reporting
|
// currentReport stores the current state of the resolver for reporting
|
||||||
// over the rpc interface.
|
// over the rpc interface.
|
||||||
currentReport ContractReport
|
currentReport ContractReport
|
||||||
@ -97,12 +100,16 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) {
|
|||||||
// to the sweeper.
|
// to the sweeper.
|
||||||
relayFeeRate := c.Sweeper.RelayFeePerKW()
|
relayFeeRate := c.Sweeper.RelayFeePerKW()
|
||||||
|
|
||||||
|
witnessType := input.CommitmentAnchor
|
||||||
|
|
||||||
|
// For taproot channels, we need to use the proper witness type.
|
||||||
|
if c.chanType.IsTaproot() {
|
||||||
|
witnessType = input.TaprootAnchorSweepSpend
|
||||||
|
}
|
||||||
|
|
||||||
anchorInput := input.MakeBaseInput(
|
anchorInput := input.MakeBaseInput(
|
||||||
&c.anchor,
|
&c.anchor, witnessType, &c.anchorSignDescriptor,
|
||||||
input.CommitmentAnchor,
|
c.broadcastHeight, nil,
|
||||||
&c.anchorSignDescriptor,
|
|
||||||
c.broadcastHeight,
|
|
||||||
nil,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
resultChan, err := c.Sweeper.SweepInput(
|
resultChan, err := c.Sweeper.SweepInput(
|
||||||
@ -195,7 +202,8 @@ func (c *anchorResolver) IsResolved() bool {
|
|||||||
// state required for the proper resolution of a contract.
|
// state required for the proper resolution of a contract.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the ContractResolver interface.
|
// NOTE: Part of the ContractResolver interface.
|
||||||
func (c *anchorResolver) SupplementState(_ *channeldb.OpenChannel) {
|
func (c *anchorResolver) SupplementState(state *channeldb.OpenChannel) {
|
||||||
|
c.chanType = state.ChanType
|
||||||
}
|
}
|
||||||
|
|
||||||
// report returns a report on the resolution state of the contract.
|
// report returns a report on the resolution state of the contract.
|
||||||
|
@ -885,7 +885,8 @@ func (c *chainWatcher) handlePossibleBreach(commitSpend *chainntnfs.SpendDetail,
|
|||||||
// TODO(roasbeef): make keyring for taproot chans to pass in instead of
|
// TODO(roasbeef): make keyring for taproot chans to pass in instead of
|
||||||
// nil
|
// nil
|
||||||
anchorRes, err := lnwallet.NewAnchorResolution(
|
anchorRes, err := lnwallet.NewAnchorResolution(
|
||||||
c.cfg.chanState, commitSpend.SpendingTx, nil, false,
|
c.cfg.chanState, commitSpend.SpendingTx, retribution.KeyRing,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("unable to create anchor "+
|
return false, fmt.Errorf("unable to create anchor "+
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@ -728,7 +729,7 @@ func (c *ChannelArbitrator) relaunchResolvers(commitSet *CommitSet,
|
|||||||
for i := range unresolvedContracts {
|
for i := range unresolvedContracts {
|
||||||
resolver := unresolvedContracts[i]
|
resolver := unresolvedContracts[i]
|
||||||
|
|
||||||
if chanState != nil {
|
if chanState != nil {
|
||||||
resolver.SupplementState(chanState)
|
resolver.SupplementState(chanState)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -766,7 +767,12 @@ func (c *ChannelArbitrator) relaunchResolvers(commitSet *CommitSet,
|
|||||||
ChannelArbitratorConfig: c.cfg,
|
ChannelArbitratorConfig: c.cfg,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
anchorResolver.SupplementState(chanState)
|
||||||
|
|
||||||
unresolvedContracts = append(unresolvedContracts, anchorResolver)
|
unresolvedContracts = append(unresolvedContracts, anchorResolver)
|
||||||
|
|
||||||
|
// TODO(roasbeef): this isn't re-launched?
|
||||||
}
|
}
|
||||||
|
|
||||||
c.launchResolvers(unresolvedContracts)
|
c.launchResolvers(unresolvedContracts)
|
||||||
@ -1292,10 +1298,21 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
|
|||||||
"anchor of %s commit tx %v", c.cfg.ChanPoint,
|
"anchor of %s commit tx %v", c.cfg.ChanPoint,
|
||||||
anchorPath, anchor.CommitAnchor)
|
anchorPath, anchor.CommitAnchor)
|
||||||
|
|
||||||
|
witnessType := input.CommitmentAnchor
|
||||||
|
|
||||||
|
// For taproot channels, we need to use the proper witness
|
||||||
|
// type.
|
||||||
|
if txscript.IsPayToTaproot(
|
||||||
|
anchor.AnchorSignDescriptor.Output.PkScript,
|
||||||
|
) {
|
||||||
|
|
||||||
|
witnessType = input.TaprootAnchorSweepSpend
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare anchor output for sweeping.
|
// Prepare anchor output for sweeping.
|
||||||
anchorInput := input.MakeBaseInput(
|
anchorInput := input.MakeBaseInput(
|
||||||
&anchor.CommitAnchor,
|
&anchor.CommitAnchor,
|
||||||
input.CommitmentAnchor,
|
witnessType,
|
||||||
&anchor.AnchorSignDescriptor,
|
&anchor.AnchorSignDescriptor,
|
||||||
heightHint,
|
heightHint,
|
||||||
&input.TxInfo{
|
&input.TxInfo{
|
||||||
@ -2181,6 +2198,8 @@ func (c *ChannelArbitrator) prepContractResolutions(
|
|||||||
contractResolutions.AnchorResolution.CommitAnchor,
|
contractResolutions.AnchorResolution.CommitAnchor,
|
||||||
height, c.cfg.ChanPoint, resolverCfg,
|
height, c.cfg.ChanPoint, resolverCfg,
|
||||||
)
|
)
|
||||||
|
anchorResolver.SupplementState(chanState)
|
||||||
|
|
||||||
htlcResolvers = append(htlcResolvers, anchorResolver)
|
htlcResolvers = append(htlcResolvers, anchorResolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user