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:
Keagan McClelland committed 2024-07-31 14:50:26 -07:00
1 parent 33934449ac
commit 0996e4f163
10 files changed
+409 -361

No files matched your search

+9 -7
View File
@@ -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
+8 -5
View File
@@ -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()
+2 -1
View File
@@ -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