mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
multi: refactor lnwallet/channel.go to use ChannelParty in select places
We also include changes to contractcourt, htlcswitch and peer to stitch the boundaries together.
This commit is contained in:
parent
33934449ac
commit
0996e4f163
10 changed files with 409 additions and 361 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
|
@ -418,7 +419,7 @@ func (c *chainWatcher) handleUnknownLocalState(
|
|||
// and remote keys for this state. We use our point as only we can
|
||||
// revoke our own commitment.
|
||||
commitKeyRing := lnwallet.DeriveCommitmentKeys(
|
||||
commitPoint, true, c.cfg.chanState.ChanType,
|
||||
commitPoint, lntypes.Local, c.cfg.chanState.ChanType,
|
||||
&c.cfg.chanState.LocalChanCfg, &c.cfg.chanState.RemoteChanCfg,
|
||||
)
|
||||
|
||||
|
@ -891,7 +892,7 @@ func (c *chainWatcher) handlePossibleBreach(commitSpend *chainntnfs.SpendDetail,
|
|||
// Create an AnchorResolution for the breached state.
|
||||
anchorRes, err := lnwallet.NewAnchorResolution(
|
||||
c.cfg.chanState, commitSpend.SpendingTx, retribution.KeyRing,
|
||||
false,
|
||||
lntypes.Remote,
|
||||
)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("unable to create anchor "+
|
||||
|
|
|
@ -2730,7 +2730,12 @@ func (l *channelLink) MayAddOutgoingHtlc(amt lnwire.MilliSatoshi) error {
|
|||
func (l *channelLink) getDustSum(remote bool,
|
||||
dryRunFee fn.Option[chainfee.SatPerKWeight]) lnwire.MilliSatoshi {
|
||||
|
||||
return l.channel.GetDustSum(remote, dryRunFee)
|
||||
party := lntypes.Local
|
||||
if remote {
|
||||
party = lntypes.Remote
|
||||
}
|
||||
|
||||
return l.channel.GetDustSum(party, dryRunFee)
|
||||
}
|
||||
|
||||
// getFeeRate is a wrapper method that retrieves the underlying channel's
|
||||
|
@ -2893,13 +2898,13 @@ func dustHelper(chantype channeldb.ChannelType, localDustLimit,
|
|||
|
||||
if localCommit {
|
||||
return lnwallet.HtlcIsDust(
|
||||
chantype, incoming, true, feerate, amt,
|
||||
chantype, incoming, lntypes.Local, feerate, amt,
|
||||
localDustLimit,
|
||||
)
|
||||
}
|
||||
|
||||
return lnwallet.HtlcIsDust(
|
||||
chantype, incoming, false, feerate, amt,
|
||||
chantype, incoming, lntypes.Remote, feerate, amt,
|
||||
remoteDustLimit,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/labels"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
|
@ -207,8 +208,8 @@ type ChanCloser struct {
|
|||
// settled channel funds to.
|
||||
remoteDeliveryScript []byte
|
||||
|
||||
// locallyInitiated is true if we initiated the channel close.
|
||||
locallyInitiated bool
|
||||
// closer is ChannelParty who initiated the coop close
|
||||
closer lntypes.ChannelParty
|
||||
|
||||
// cachedClosingSigned is a cached copy of a received ClosingSigned that
|
||||
// we use to handle a specific race condition caused by the independent
|
||||
|
@ -267,7 +268,8 @@ func (d *SimpleCoopFeeEstimator) EstimateFee(chanType channeldb.ChannelType,
|
|||
// be populated iff, we're the initiator of this closing request.
|
||||
func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte,
|
||||
idealFeePerKw chainfee.SatPerKWeight, negotiationHeight uint32,
|
||||
closeReq *htlcswitch.ChanClose, locallyInitiated bool) *ChanCloser {
|
||||
closeReq *htlcswitch.ChanClose,
|
||||
closer lntypes.ChannelParty) *ChanCloser {
|
||||
|
||||
chanPoint := cfg.Channel.ChannelPoint()
|
||||
cid := lnwire.NewChanIDFromOutPoint(chanPoint)
|
||||
|
@ -283,7 +285,7 @@ func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte,
|
|||
priorFeeOffers: make(
|
||||
map[btcutil.Amount]*lnwire.ClosingSigned,
|
||||
),
|
||||
locallyInitiated: locallyInitiated,
|
||||
closer: closer,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +368,7 @@ func (c *ChanCloser) initChanShutdown() (*lnwire.Shutdown, error) {
|
|||
// message we are about to send in order to ensure that if a
|
||||
// re-establish occurs then we will re-send the same Shutdown message.
|
||||
shutdownInfo := channeldb.NewShutdownInfo(
|
||||
c.localDeliveryScript, c.locallyInitiated,
|
||||
c.localDeliveryScript, c.closer.IsLocal(),
|
||||
)
|
||||
err := c.cfg.Channel.MarkShutdownSent(shutdownInfo)
|
||||
if err != nil {
|
||||
|
@ -650,7 +652,7 @@ func (c *ChanCloser) BeginNegotiation() (fn.Option[lnwire.ClosingSigned],
|
|||
// externally consistent, and reflect that the channel is being
|
||||
// shutdown by the time the closing request returns.
|
||||
err := c.cfg.Channel.MarkCoopBroadcasted(
|
||||
nil, c.locallyInitiated,
|
||||
nil, c.closer,
|
||||
)
|
||||
if err != nil {
|
||||
return noClosingSigned, err
|
||||
|
@ -861,7 +863,7 @@ func (c *ChanCloser) ReceiveClosingSigned( //nolint:funlen
|
|||
// database, such that it can be republished if something goes
|
||||
// wrong.
|
||||
err = c.cfg.Channel.MarkCoopBroadcasted(
|
||||
closeTx, c.locallyInitiated,
|
||||
closeTx, c.closer,
|
||||
)
|
||||
if err != nil {
|
||||
return noClosing, err
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
|
@ -150,7 +151,9 @@ func (m *mockChannel) ChannelPoint() wire.OutPoint {
|
|||
return m.chanPoint
|
||||
}
|
||||
|
||||
func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx, bool) error {
|
||||
func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx,
|
||||
lntypes.ChannelParty) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -338,7 +341,7 @@ func TestMaxFeeClamp(t *testing.T) {
|
|||
Channel: &channel,
|
||||
MaxFee: test.inputMaxFee,
|
||||
FeeEstimator: &SimpleCoopFeeEstimator{},
|
||||
}, nil, test.idealFee, 0, nil, false,
|
||||
}, nil, test.idealFee, 0, nil, lntypes.Remote,
|
||||
)
|
||||
|
||||
// We'll call initFeeBaseline early here since we need
|
||||
|
@ -379,7 +382,7 @@ func TestMaxFeeBailOut(t *testing.T) {
|
|||
MaxFee: idealFee * 2,
|
||||
}
|
||||
chanCloser := NewChanCloser(
|
||||
closeCfg, nil, idealFee, 0, nil, false,
|
||||
closeCfg, nil, idealFee, 0, nil, lntypes.Remote,
|
||||
)
|
||||
|
||||
// We'll now force the channel state into the
|
||||
|
@ -503,7 +506,7 @@ func TestTaprootFastClose(t *testing.T) {
|
|||
DisableChannel: func(wire.OutPoint) error {
|
||||
return nil
|
||||
},
|
||||
}, nil, idealFee, 0, nil, true,
|
||||
}, nil, idealFee, 0, nil, lntypes.Local,
|
||||
)
|
||||
aliceCloser.initFeeBaseline()
|
||||
|
||||
|
@ -520,7 +523,7 @@ func TestTaprootFastClose(t *testing.T) {
|
|||
DisableChannel: func(wire.OutPoint) error {
|
||||
return nil
|
||||
},
|
||||
}, nil, idealFee, 0, nil, false,
|
||||
}, nil, idealFee, 0, nil, lntypes.Remote,
|
||||
)
|
||||
bobCloser.initFeeBaseline()
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
|
@ -33,7 +34,7 @@ type Channel interface { //nolint:interfacebloat
|
|||
|
||||
// MarkCoopBroadcasted persistently marks that the channel close
|
||||
// transaction has been broadcast.
|
||||
MarkCoopBroadcasted(*wire.MsgTx, bool) error
|
||||
MarkCoopBroadcasted(*wire.MsgTx, lntypes.ChannelParty) error
|
||||
|
||||
// MarkShutdownSent persists the given ShutdownInfo. The existence of
|
||||
// the ShutdownInfo represents the fact that the Shutdown message has
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5196,7 +5196,7 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
|
|||
lc.localUpdateLog.logIndex)
|
||||
|
||||
_, w := lc.availableCommitmentBalance(
|
||||
htlcView, true, FeeBuffer,
|
||||
htlcView, lntypes.Remote, FeeBuffer,
|
||||
)
|
||||
|
||||
return w
|
||||
|
@ -7985,11 +7985,11 @@ func TestChannelFeeRateFloor(t *testing.T) {
|
|||
// TestFetchParent tests lookup of an entry's parent in the appropriate log.
|
||||
func TestFetchParent(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
remoteChain bool
|
||||
remoteLog bool
|
||||
localEntries []*PaymentDescriptor
|
||||
remoteEntries []*PaymentDescriptor
|
||||
name string
|
||||
whoseCommitChain lntypes.ChannelParty
|
||||
whoseUpdateLog lntypes.ChannelParty
|
||||
localEntries []*PaymentDescriptor
|
||||
remoteEntries []*PaymentDescriptor
|
||||
|
||||
// parentIndex is the parent index of the entry that we will
|
||||
// lookup with fetch parent.
|
||||
|
@ -8003,22 +8003,22 @@ func TestFetchParent(t *testing.T) {
|
|||
expectedIndex uint64
|
||||
}{
|
||||
{
|
||||
name: "not found in remote log",
|
||||
localEntries: nil,
|
||||
remoteEntries: nil,
|
||||
remoteChain: true,
|
||||
remoteLog: true,
|
||||
parentIndex: 0,
|
||||
expectErr: true,
|
||||
name: "not found in remote log",
|
||||
localEntries: nil,
|
||||
remoteEntries: nil,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
whoseUpdateLog: lntypes.Remote,
|
||||
parentIndex: 0,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "not found in local log",
|
||||
localEntries: nil,
|
||||
remoteEntries: nil,
|
||||
remoteChain: false,
|
||||
remoteLog: false,
|
||||
parentIndex: 0,
|
||||
expectErr: true,
|
||||
name: "not found in local log",
|
||||
localEntries: nil,
|
||||
remoteEntries: nil,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
whoseUpdateLog: lntypes.Local,
|
||||
parentIndex: 0,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "remote log + chain, remote add height 0",
|
||||
|
@ -8038,10 +8038,10 @@ func TestFetchParent(t *testing.T) {
|
|||
addCommitHeightRemote: 0,
|
||||
},
|
||||
},
|
||||
remoteChain: true,
|
||||
remoteLog: true,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
whoseUpdateLog: lntypes.Remote,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "remote log, local chain, local add height 0",
|
||||
|
@ -8060,11 +8060,11 @@ func TestFetchParent(t *testing.T) {
|
|||
addCommitHeightRemote: 100,
|
||||
},
|
||||
},
|
||||
localEntries: nil,
|
||||
remoteChain: false,
|
||||
remoteLog: true,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
localEntries: nil,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
whoseUpdateLog: lntypes.Remote,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "local log + chain, local add height 0",
|
||||
|
@ -8083,11 +8083,11 @@ func TestFetchParent(t *testing.T) {
|
|||
addCommitHeightRemote: 100,
|
||||
},
|
||||
},
|
||||
remoteEntries: nil,
|
||||
remoteChain: false,
|
||||
remoteLog: false,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
remoteEntries: nil,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
whoseUpdateLog: lntypes.Local,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -8107,11 +8107,11 @@ func TestFetchParent(t *testing.T) {
|
|||
addCommitHeightRemote: 0,
|
||||
},
|
||||
},
|
||||
remoteEntries: nil,
|
||||
remoteChain: true,
|
||||
remoteLog: false,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
remoteEntries: nil,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
whoseUpdateLog: lntypes.Local,
|
||||
parentIndex: 1,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "remote log found",
|
||||
|
@ -8131,11 +8131,11 @@ func TestFetchParent(t *testing.T) {
|
|||
addCommitHeightRemote: 100,
|
||||
},
|
||||
},
|
||||
remoteChain: true,
|
||||
remoteLog: true,
|
||||
parentIndex: 1,
|
||||
expectErr: false,
|
||||
expectedIndex: 2,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
whoseUpdateLog: lntypes.Remote,
|
||||
parentIndex: 1,
|
||||
expectErr: false,
|
||||
expectedIndex: 2,
|
||||
},
|
||||
{
|
||||
name: "local log found",
|
||||
|
@ -8154,12 +8154,12 @@ func TestFetchParent(t *testing.T) {
|
|||
addCommitHeightRemote: 100,
|
||||
},
|
||||
},
|
||||
remoteEntries: nil,
|
||||
remoteChain: false,
|
||||
remoteLog: false,
|
||||
parentIndex: 1,
|
||||
expectErr: false,
|
||||
expectedIndex: 2,
|
||||
remoteEntries: nil,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
whoseUpdateLog: lntypes.Local,
|
||||
parentIndex: 1,
|
||||
expectErr: false,
|
||||
expectedIndex: 2,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -8186,8 +8186,8 @@ func TestFetchParent(t *testing.T) {
|
|||
&PaymentDescriptor{
|
||||
ParentIndex: test.parentIndex,
|
||||
},
|
||||
test.remoteChain,
|
||||
test.remoteLog,
|
||||
test.whoseCommitChain,
|
||||
test.whoseUpdateLog,
|
||||
)
|
||||
gotErr := err != nil
|
||||
if test.expectErr != gotErr {
|
||||
|
@ -8245,11 +8245,11 @@ func TestEvaluateView(t *testing.T) {
|
|||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ourHtlcs []*PaymentDescriptor
|
||||
theirHtlcs []*PaymentDescriptor
|
||||
remoteChain bool
|
||||
mutateState bool
|
||||
name string
|
||||
ourHtlcs []*PaymentDescriptor
|
||||
theirHtlcs []*PaymentDescriptor
|
||||
whoseCommitChain lntypes.ChannelParty
|
||||
mutateState bool
|
||||
|
||||
// ourExpectedHtlcs is the set of our htlcs that we expect in
|
||||
// the htlc view once it has been evaluated. We just store
|
||||
|
@ -8276,9 +8276,9 @@ func TestEvaluateView(t *testing.T) {
|
|||
expectSent lnwire.MilliSatoshi
|
||||
}{
|
||||
{
|
||||
name: "our fee update is applied",
|
||||
remoteChain: false,
|
||||
mutateState: false,
|
||||
name: "our fee update is applied",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
Amount: ourFeeUpdateAmt,
|
||||
|
@ -8293,10 +8293,10 @@ func TestEvaluateView(t *testing.T) {
|
|||
expectSent: 0,
|
||||
},
|
||||
{
|
||||
name: "their fee update is applied",
|
||||
remoteChain: false,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{},
|
||||
name: "their fee update is applied",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
Amount: theirFeeUpdateAmt,
|
||||
|
@ -8311,9 +8311,9 @@ func TestEvaluateView(t *testing.T) {
|
|||
},
|
||||
{
|
||||
// We expect unresolved htlcs to to remain in the view.
|
||||
name: "htlcs adds without settles",
|
||||
remoteChain: false,
|
||||
mutateState: false,
|
||||
name: "htlcs adds without settles",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
|
@ -8345,9 +8345,9 @@ func TestEvaluateView(t *testing.T) {
|
|||
expectSent: 0,
|
||||
},
|
||||
{
|
||||
name: "our htlc settled, state mutated",
|
||||
remoteChain: false,
|
||||
mutateState: true,
|
||||
name: "our htlc settled, state mutated",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: true,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
|
@ -8380,9 +8380,9 @@ func TestEvaluateView(t *testing.T) {
|
|||
expectSent: htlcAddAmount,
|
||||
},
|
||||
{
|
||||
name: "our htlc settled, state not mutated",
|
||||
remoteChain: false,
|
||||
mutateState: false,
|
||||
name: "our htlc settled, state not mutated",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
|
@ -8415,9 +8415,9 @@ func TestEvaluateView(t *testing.T) {
|
|||
expectSent: 0,
|
||||
},
|
||||
{
|
||||
name: "their htlc settled, state mutated",
|
||||
remoteChain: false,
|
||||
mutateState: true,
|
||||
name: "their htlc settled, state mutated",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: true,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
|
@ -8458,9 +8458,10 @@ func TestEvaluateView(t *testing.T) {
|
|||
expectSent: 0,
|
||||
},
|
||||
{
|
||||
name: "their htlc settled, state not mutated",
|
||||
remoteChain: false,
|
||||
mutateState: false,
|
||||
name: "their htlc settled, state not mutated",
|
||||
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
|
@ -8543,7 +8544,7 @@ func TestEvaluateView(t *testing.T) {
|
|||
// Evaluate the htlc view, mutate as test expects.
|
||||
result, err := lc.evaluateHTLCView(
|
||||
view, &ourBalance, &theirBalance, nextHeight,
|
||||
test.remoteChain, test.mutateState,
|
||||
test.whoseCommitChain, test.mutateState,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
@ -8631,12 +8632,12 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
startHeights heights
|
||||
expectedHeights heights
|
||||
remoteChain bool
|
||||
mutate bool
|
||||
expectedFee chainfee.SatPerKWeight
|
||||
name string
|
||||
startHeights heights
|
||||
expectedHeights heights
|
||||
whoseCommitChain lntypes.ChannelParty
|
||||
mutate bool
|
||||
expectedFee chainfee.SatPerKWeight
|
||||
}{
|
||||
{
|
||||
// Looking at local chain, local add is non-zero so
|
||||
|
@ -8654,9 +8655,9 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
remoteAdd: 0,
|
||||
remoteRemove: height,
|
||||
},
|
||||
remoteChain: false,
|
||||
mutate: false,
|
||||
expectedFee: feePerKw,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutate: false,
|
||||
expectedFee: feePerKw,
|
||||
},
|
||||
{
|
||||
// Looking at local chain, local add is zero so the
|
||||
|
@ -8675,9 +8676,9 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
remoteAdd: height,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
mutate: false,
|
||||
expectedFee: ourFeeUpdatePerSat,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutate: false,
|
||||
expectedFee: ourFeeUpdatePerSat,
|
||||
},
|
||||
{
|
||||
// Looking at remote chain, the remote add height is
|
||||
|
@ -8696,9 +8697,9 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
remoteAdd: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
mutate: false,
|
||||
expectedFee: ourFeeUpdatePerSat,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
mutate: false,
|
||||
expectedFee: ourFeeUpdatePerSat,
|
||||
},
|
||||
{
|
||||
// Looking at remote chain, the remote add height is
|
||||
|
@ -8717,9 +8718,9 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
remoteAdd: height,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
mutate: false,
|
||||
expectedFee: feePerKw,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
mutate: false,
|
||||
expectedFee: feePerKw,
|
||||
},
|
||||
{
|
||||
// Local add height is non-zero, so the update has
|
||||
|
@ -8738,9 +8739,9 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
remoteAdd: 0,
|
||||
remoteRemove: height,
|
||||
},
|
||||
remoteChain: false,
|
||||
mutate: true,
|
||||
expectedFee: feePerKw,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutate: true,
|
||||
expectedFee: feePerKw,
|
||||
},
|
||||
{
|
||||
// Local add is zero and we are looking at our local
|
||||
|
@ -8760,9 +8761,9 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
remoteAdd: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
mutate: true,
|
||||
expectedFee: ourFeeUpdatePerSat,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutate: true,
|
||||
expectedFee: ourFeeUpdatePerSat,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -8786,7 +8787,7 @@ func TestProcessFeeUpdate(t *testing.T) {
|
|||
feePerKw: chainfee.SatPerKWeight(feePerKw),
|
||||
}
|
||||
processFeeUpdate(
|
||||
update, nextHeight, test.remoteChain,
|
||||
update, nextHeight, test.whoseCommitChain,
|
||||
test.mutate, view,
|
||||
)
|
||||
|
||||
|
@ -8841,7 +8842,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
startHeights heights
|
||||
remoteChain bool
|
||||
whoseCommitChain lntypes.ChannelParty
|
||||
isIncoming bool
|
||||
mutateState bool
|
||||
ourExpectedBalance lnwire.MilliSatoshi
|
||||
|
@ -8857,7 +8858,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -8878,7 +8879,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -8899,7 +8900,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
isIncoming: true,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -8920,7 +8921,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
isIncoming: true,
|
||||
mutateState: true,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -8942,7 +8943,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance - updateAmount,
|
||||
|
@ -8963,7 +8964,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: false,
|
||||
mutateState: true,
|
||||
ourExpectedBalance: startBalance - updateAmount,
|
||||
|
@ -8984,7 +8985,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: removeHeight,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -9005,7 +9006,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: removeHeight,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -9028,7 +9029,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: true,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance + updateAmount,
|
||||
|
@ -9051,7 +9052,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -9074,7 +9075,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: true,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance,
|
||||
|
@ -9097,7 +9098,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: false,
|
||||
mutateState: false,
|
||||
ourExpectedBalance: startBalance + updateAmount,
|
||||
|
@ -9122,7 +9123,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: false,
|
||||
whoseCommitChain: lntypes.Local,
|
||||
isIncoming: true,
|
||||
mutateState: true,
|
||||
ourExpectedBalance: startBalance + updateAmount,
|
||||
|
@ -9147,7 +9148,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
localRemove: 0,
|
||||
remoteRemove: 0,
|
||||
},
|
||||
remoteChain: true,
|
||||
whoseCommitChain: lntypes.Remote,
|
||||
isIncoming: true,
|
||||
mutateState: true,
|
||||
ourExpectedBalance: startBalance + updateAmount,
|
||||
|
@ -9196,7 +9197,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||
|
||||
process(
|
||||
update, &ourBalance, &theirBalance, nextHeight,
|
||||
test.remoteChain, test.isIncoming,
|
||||
test.whoseCommitChain, test.isIncoming,
|
||||
test.mutateState,
|
||||
)
|
||||
|
||||
|
@ -9752,11 +9753,11 @@ func testGetDustSum(t *testing.T, chantype channeldb.ChannelType) {
|
|||
expRemote lnwire.MilliSatoshi) {
|
||||
|
||||
localDustSum := c.GetDustSum(
|
||||
false, fn.None[chainfee.SatPerKWeight](),
|
||||
lntypes.Local, fn.None[chainfee.SatPerKWeight](),
|
||||
)
|
||||
require.Equal(t, expLocal, localDustSum)
|
||||
remoteDustSum := c.GetDustSum(
|
||||
true, fn.None[chainfee.SatPerKWeight](),
|
||||
lntypes.Remote, fn.None[chainfee.SatPerKWeight](),
|
||||
)
|
||||
require.Equal(t, expRemote, remoteDustSum)
|
||||
}
|
||||
|
@ -9910,8 +9911,9 @@ func deriveDummyRetributionParams(chanState *channeldb.OpenChannel) (uint32,
|
|||
config := chanState.RemoteChanCfg
|
||||
commitHash := chanState.RemoteCommitment.CommitTx.TxHash()
|
||||
keyRing := DeriveCommitmentKeys(
|
||||
config.RevocationBasePoint.PubKey, false, chanState.ChanType,
|
||||
&chanState.LocalChanCfg, &chanState.RemoteChanCfg,
|
||||
config.RevocationBasePoint.PubKey, lntypes.Remote,
|
||||
chanState.ChanType, &chanState.LocalChanCfg,
|
||||
&chanState.RemoteChanCfg,
|
||||
)
|
||||
leaseExpiry := chanState.ThawHeight
|
||||
return leaseExpiry, keyRing, commitHash
|
||||
|
@ -10378,7 +10380,7 @@ func TestExtractPayDescs(t *testing.T) {
|
|||
// NOTE: we use nil commitment key rings to avoid checking the htlc
|
||||
// scripts(`genHtlcScript`) as it should be tested independently.
|
||||
incomingPDs, outgoingPDs, err := lnChan.extractPayDescs(
|
||||
0, 0, htlcs, nil, nil, true,
|
||||
0, 0, htlcs, nil, nil, lntypes.Local,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ type CommitmentKeyRing struct {
|
|||
// of channel, and whether the commitment transaction is ours or the remote
|
||||
// peer's.
|
||||
func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
|
||||
isOurCommit bool, chanType channeldb.ChannelType,
|
||||
whoseCommit lntypes.ChannelParty, chanType channeldb.ChannelType,
|
||||
localChanCfg, remoteChanCfg *channeldb.ChannelConfig) *CommitmentKeyRing {
|
||||
|
||||
tweaklessCommit := chanType.IsTweakless()
|
||||
|
@ -111,7 +111,7 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
|
|||
// Depending on if this is our commit or not, we'll choose the correct
|
||||
// base point.
|
||||
localBasePoint := localChanCfg.PaymentBasePoint
|
||||
if isOurCommit {
|
||||
if whoseCommit.IsLocal() {
|
||||
localBasePoint = localChanCfg.DelayBasePoint
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
|
|||
toRemoteBasePoint *btcec.PublicKey
|
||||
revocationBasePoint *btcec.PublicKey
|
||||
)
|
||||
if isOurCommit {
|
||||
if whoseCommit.IsLocal() {
|
||||
toLocalBasePoint = localChanCfg.DelayBasePoint.PubKey
|
||||
toRemoteBasePoint = remoteChanCfg.PaymentBasePoint.PubKey
|
||||
revocationBasePoint = remoteChanCfg.RevocationBasePoint.PubKey
|
||||
|
@ -169,7 +169,7 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
|
|||
// If this is not our commitment, the above ToRemoteKey will be
|
||||
// ours, and we blank out the local commitment tweak to
|
||||
// indicate that the key should not be tweaked when signing.
|
||||
if !isOurCommit {
|
||||
if whoseCommit.IsRemote() {
|
||||
keyRing.LocalCommitKeyTweak = nil
|
||||
}
|
||||
} else {
|
||||
|
@ -686,20 +686,20 @@ type unsignedCommitmentTx struct {
|
|||
// passed in balances should be balances *before* subtracting any commitment
|
||||
// fees, but after anchor outputs.
|
||||
func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
||||
theirBalance lnwire.MilliSatoshi, isOurs bool,
|
||||
theirBalance lnwire.MilliSatoshi, whoseCommit lntypes.ChannelParty,
|
||||
feePerKw chainfee.SatPerKWeight, height uint64,
|
||||
filteredHTLCView *htlcView,
|
||||
keyRing *CommitmentKeyRing) (*unsignedCommitmentTx, error) {
|
||||
|
||||
dustLimit := cb.chanState.LocalChanCfg.DustLimit
|
||||
if !isOurs {
|
||||
if whoseCommit.IsRemote() {
|
||||
dustLimit = cb.chanState.RemoteChanCfg.DustLimit
|
||||
}
|
||||
|
||||
numHTLCs := int64(0)
|
||||
for _, htlc := range filteredHTLCView.ourUpdates {
|
||||
if HtlcIsDust(
|
||||
cb.chanState.ChanType, false, isOurs, feePerKw,
|
||||
cb.chanState.ChanType, false, whoseCommit, feePerKw,
|
||||
htlc.Amount.ToSatoshis(), dustLimit,
|
||||
) {
|
||||
|
||||
|
@ -710,7 +710,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||
}
|
||||
for _, htlc := range filteredHTLCView.theirUpdates {
|
||||
if HtlcIsDust(
|
||||
cb.chanState.ChanType, true, isOurs, feePerKw,
|
||||
cb.chanState.ChanType, true, whoseCommit, feePerKw,
|
||||
htlc.Amount.ToSatoshis(), dustLimit,
|
||||
) {
|
||||
|
||||
|
@ -763,7 +763,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||
if cb.chanState.ChanType.HasLeaseExpiration() {
|
||||
leaseExpiry = cb.chanState.ThawHeight
|
||||
}
|
||||
if isOurs {
|
||||
if whoseCommit.IsLocal() {
|
||||
commitTx, err = CreateCommitTx(
|
||||
cb.chanState.ChanType, fundingTxIn(cb.chanState), keyRing,
|
||||
&cb.chanState.LocalChanCfg, &cb.chanState.RemoteChanCfg,
|
||||
|
@ -794,7 +794,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||
cltvs := make([]uint32, len(commitTx.TxOut))
|
||||
for _, htlc := range filteredHTLCView.ourUpdates {
|
||||
if HtlcIsDust(
|
||||
cb.chanState.ChanType, false, isOurs, feePerKw,
|
||||
cb.chanState.ChanType, false, whoseCommit, feePerKw,
|
||||
htlc.Amount.ToSatoshis(), dustLimit,
|
||||
) {
|
||||
|
||||
|
@ -802,7 +802,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||
}
|
||||
|
||||
err := addHTLC(
|
||||
commitTx, isOurs, false, htlc, keyRing,
|
||||
commitTx, whoseCommit, false, htlc, keyRing,
|
||||
cb.chanState.ChanType,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -812,7 +812,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||
}
|
||||
for _, htlc := range filteredHTLCView.theirUpdates {
|
||||
if HtlcIsDust(
|
||||
cb.chanState.ChanType, true, isOurs, feePerKw,
|
||||
cb.chanState.ChanType, true, whoseCommit, feePerKw,
|
||||
htlc.Amount.ToSatoshis(), dustLimit,
|
||||
) {
|
||||
|
||||
|
@ -820,7 +820,7 @@ func (cb *CommitmentBuilder) createUnsignedCommitmentTx(ourBalance,
|
|||
}
|
||||
|
||||
err := addHTLC(
|
||||
commitTx, isOurs, true, htlc, keyRing,
|
||||
commitTx, whoseCommit, true, htlc, keyRing,
|
||||
cb.chanState.ChanType,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -1003,8 +1003,9 @@ func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool,
|
|||
// genSegwitV0HtlcScript generates the HTLC scripts for a normal segwit v0
|
||||
// channel.
|
||||
func genSegwitV0HtlcScript(chanType channeldb.ChannelType,
|
||||
isIncoming, ourCommit bool, timeout uint32, rHash [32]byte,
|
||||
keyRing *CommitmentKeyRing) (*WitnessScriptDesc, error) {
|
||||
isIncoming bool, whoseCommit lntypes.ChannelParty, timeout uint32,
|
||||
rHash [32]byte, keyRing *CommitmentKeyRing,
|
||||
) (*WitnessScriptDesc, error) {
|
||||
|
||||
var (
|
||||
witnessScript []byte
|
||||
|
@ -1024,7 +1025,7 @@ func genSegwitV0HtlcScript(chanType channeldb.ChannelType,
|
|||
// The HTLC is paying to us, and being applied to our commitment
|
||||
// transaction. So we need to use the receiver's version of the HTLC
|
||||
// script.
|
||||
case isIncoming && ourCommit:
|
||||
case isIncoming && whoseCommit.IsLocal():
|
||||
witnessScript, err = input.ReceiverHTLCScript(
|
||||
timeout, keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
|
||||
|
@ -1033,7 +1034,7 @@ func genSegwitV0HtlcScript(chanType channeldb.ChannelType,
|
|||
// We're being paid via an HTLC by the remote party, and the HTLC is
|
||||
// being added to their commitment transaction, so we use the sender's
|
||||
// version of the HTLC script.
|
||||
case isIncoming && !ourCommit:
|
||||
case isIncoming && whoseCommit.IsRemote():
|
||||
witnessScript, err = input.SenderHTLCScript(
|
||||
keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
|
||||
|
@ -1042,7 +1043,7 @@ func genSegwitV0HtlcScript(chanType channeldb.ChannelType,
|
|||
// We're sending an HTLC which is being added to our commitment
|
||||
// transaction. Therefore, we need to use the sender's version of the
|
||||
// HTLC script.
|
||||
case !isIncoming && ourCommit:
|
||||
case !isIncoming && whoseCommit.IsLocal():
|
||||
witnessScript, err = input.SenderHTLCScript(
|
||||
keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
|
||||
|
@ -1051,7 +1052,7 @@ func genSegwitV0HtlcScript(chanType channeldb.ChannelType,
|
|||
// Finally, we're paying the remote party via an HTLC, which is being
|
||||
// added to their commitment transaction. Therefore, we use the
|
||||
// receiver's version of the HTLC script.
|
||||
case !isIncoming && !ourCommit:
|
||||
case !isIncoming && whoseCommit.IsRemote():
|
||||
witnessScript, err = input.ReceiverHTLCScript(
|
||||
timeout, keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], confirmedHtlcSpends,
|
||||
|
@ -1076,9 +1077,9 @@ func genSegwitV0HtlcScript(chanType channeldb.ChannelType,
|
|||
|
||||
// genTaprootHtlcScript generates the HTLC scripts for a taproot+musig2
|
||||
// channel.
|
||||
func genTaprootHtlcScript(isIncoming, ourCommit bool, timeout uint32,
|
||||
rHash [32]byte,
|
||||
keyRing *CommitmentKeyRing) (*input.HtlcScriptTree, error) {
|
||||
func genTaprootHtlcScript(isIncoming bool, whoseCommit lntypes.ChannelParty,
|
||||
timeout uint32, rHash [32]byte, keyRing *CommitmentKeyRing,
|
||||
) (*input.HtlcScriptTree, error) {
|
||||
|
||||
var (
|
||||
htlcScriptTree *input.HtlcScriptTree
|
||||
|
@ -1092,37 +1093,37 @@ func genTaprootHtlcScript(isIncoming, ourCommit bool, timeout uint32,
|
|||
// The HTLC is paying to us, and being applied to our commitment
|
||||
// transaction. So we need to use the receiver's version of HTLC the
|
||||
// script.
|
||||
case isIncoming && ourCommit:
|
||||
case isIncoming && whoseCommit.IsLocal():
|
||||
htlcScriptTree, err = input.ReceiverHTLCScriptTaproot(
|
||||
timeout, keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], lntypes.Local,
|
||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||
)
|
||||
|
||||
// We're being paid via an HTLC by the remote party, and the HTLC is
|
||||
// being added to their commitment transaction, so we use the sender's
|
||||
// version of the HTLC script.
|
||||
case isIncoming && !ourCommit:
|
||||
case isIncoming && whoseCommit.IsRemote():
|
||||
htlcScriptTree, err = input.SenderHTLCScriptTaproot(
|
||||
keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], lntypes.Remote,
|
||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||
)
|
||||
|
||||
// We're sending an HTLC which is being added to our commitment
|
||||
// transaction. Therefore, we need to use the sender's version of the
|
||||
// HTLC script.
|
||||
case !isIncoming && ourCommit:
|
||||
case !isIncoming && whoseCommit.IsLocal():
|
||||
htlcScriptTree, err = input.SenderHTLCScriptTaproot(
|
||||
keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], lntypes.Local,
|
||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||
)
|
||||
|
||||
// Finally, we're paying the remote party via an HTLC, which is being
|
||||
// added to their commitment transaction. Therefore, we use the
|
||||
// receiver's version of the HTLC script.
|
||||
case !isIncoming && !ourCommit:
|
||||
case !isIncoming && whoseCommit.IsRemote():
|
||||
htlcScriptTree, err = input.ReceiverHTLCScriptTaproot(
|
||||
timeout, keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], lntypes.Remote,
|
||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1135,19 +1136,20 @@ func genTaprootHtlcScript(isIncoming, ourCommit bool, timeout uint32,
|
|||
// multiplexer for the various spending paths is returned. The script path that
|
||||
// we need to sign for the remote party (2nd level HTLCs) is also returned
|
||||
// along side the multiplexer.
|
||||
func genHtlcScript(chanType channeldb.ChannelType, isIncoming, ourCommit bool,
|
||||
timeout uint32, rHash [32]byte, keyRing *CommitmentKeyRing,
|
||||
func genHtlcScript(chanType channeldb.ChannelType, isIncoming bool,
|
||||
whoseCommit lntypes.ChannelParty, timeout uint32, rHash [32]byte,
|
||||
keyRing *CommitmentKeyRing,
|
||||
) (input.ScriptDescriptor, error) {
|
||||
|
||||
if !chanType.IsTaproot() {
|
||||
return genSegwitV0HtlcScript(
|
||||
chanType, isIncoming, ourCommit, timeout, rHash,
|
||||
chanType, isIncoming, whoseCommit, timeout, rHash,
|
||||
keyRing,
|
||||
)
|
||||
}
|
||||
|
||||
return genTaprootHtlcScript(
|
||||
isIncoming, ourCommit, timeout, rHash, keyRing,
|
||||
isIncoming, whoseCommit, timeout, rHash, keyRing,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1158,7 +1160,7 @@ func genHtlcScript(chanType channeldb.ChannelType, isIncoming, ourCommit bool,
|
|||
// locate the added HTLC on the commitment transaction from the
|
||||
// PaymentDescriptor that generated it, the generated script is stored within
|
||||
// the descriptor itself.
|
||||
func addHTLC(commitTx *wire.MsgTx, ourCommit bool,
|
||||
func addHTLC(commitTx *wire.MsgTx, whoseCommit lntypes.ChannelParty,
|
||||
isIncoming bool, paymentDesc *PaymentDescriptor,
|
||||
keyRing *CommitmentKeyRing, chanType channeldb.ChannelType) error {
|
||||
|
||||
|
@ -1166,7 +1168,7 @@ func addHTLC(commitTx *wire.MsgTx, ourCommit bool,
|
|||
rHash := paymentDesc.RHash
|
||||
|
||||
scriptInfo, err := genHtlcScript(
|
||||
chanType, isIncoming, ourCommit, timeout, rHash, keyRing,
|
||||
chanType, isIncoming, whoseCommit, timeout, rHash, keyRing,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1180,7 +1182,7 @@ func addHTLC(commitTx *wire.MsgTx, ourCommit bool,
|
|||
|
||||
// Store the pkScript of this particular PaymentDescriptor so we can
|
||||
// quickly locate it within the commitment transaction later.
|
||||
if ourCommit {
|
||||
if whoseCommit.IsLocal() {
|
||||
paymentDesc.ourPkScript = pkScript
|
||||
|
||||
paymentDesc.ourWitnessScript = scriptInfo.WitnessScriptToSign()
|
||||
|
@ -1211,7 +1213,7 @@ func findOutputIndexesFromRemote(revocationPreimage *chainhash.Hash,
|
|||
// With the commitment point generated, we can now derive the king ring
|
||||
// which will be used to generate the output scripts.
|
||||
keyRing := DeriveCommitmentKeys(
|
||||
commitmentPoint, false, chanState.ChanType,
|
||||
commitmentPoint, lntypes.Remote, chanState.ChanType,
|
||||
&chanState.LocalChanCfg, &chanState.RemoteChanCfg,
|
||||
)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chanvalidate"
|
||||
|
@ -1475,10 +1476,12 @@ func CreateCommitmentTxns(localBalance, remoteBalance btcutil.Amount,
|
|||
leaseExpiry uint32) (*wire.MsgTx, *wire.MsgTx, error) {
|
||||
|
||||
localCommitmentKeys := DeriveCommitmentKeys(
|
||||
localCommitPoint, true, chanType, ourChanCfg, theirChanCfg,
|
||||
localCommitPoint, lntypes.Local, chanType, ourChanCfg,
|
||||
theirChanCfg,
|
||||
)
|
||||
remoteCommitmentKeys := DeriveCommitmentKeys(
|
||||
remoteCommitPoint, false, chanType, ourChanCfg, theirChanCfg,
|
||||
remoteCommitPoint, lntypes.Remote, chanType, ourChanCfg,
|
||||
theirChanCfg,
|
||||
)
|
||||
|
||||
ourCommitTx, err := CreateCommitTx(
|
||||
|
|
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
|
@ -3017,6 +3018,10 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
|
|||
maxFee = req.MaxFee
|
||||
}
|
||||
|
||||
closer := lntypes.Remote
|
||||
if locallyInitiated {
|
||||
closer = lntypes.Local
|
||||
}
|
||||
chanCloser := chancloser.NewChanCloser(
|
||||
chancloser.ChanCloseCfg{
|
||||
Channel: channel,
|
||||
|
@ -3039,7 +3044,7 @@ func (p *Brontide) createChanCloser(channel *lnwallet.LightningChannel,
|
|||
fee,
|
||||
uint32(startingHeight),
|
||||
req,
|
||||
locallyInitiated,
|
||||
closer,
|
||||
)
|
||||
|
||||
return chanCloser, nil
|
||||
|
|
Loading…
Add table
Reference in a new issue