funding: rename FundingLocked related functions and variables

This commit is created by running the following commands,
```shell
gofmt -d -w -r 'sendFundingLocked -> sendChannelReady' .

gofmt -d -w -r 'handleFundingLockedMtx -> handleChannelReadyMtx' .

gofmt -d -w -r 'handleFundingLockedBarriers -> handleChannelReadyBarriers' .

gofmt -d -w -r 'receivedFundingLocked -> receivedChannelReady' .

gofmt -d -w -r 'handleFundingLocked -> handleChannelReady' .

gofmt -d -w -r 'fundingLockedSent -> channelReadySent' .

gofmt -d -w -r 'checkPeerFundingLockInterval -> checkPeerChannelReadyInterval' .
```
This commit is contained in:
yyforyongyu 2023-03-16 04:58:04 +08:00
parent 2dc08a2a76
commit 112dc1faca
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
3 changed files with 39 additions and 39 deletions

View File

@ -7,5 +7,5 @@ import "time"
func init() { func init() {
// For itest, we will use a much shorter checking interval here as // For itest, we will use a much shorter checking interval here as
// local communications are very fast. // local communications are very fast.
checkPeerFundingLockInterval = 10 * time.Millisecond checkPeerChannelReadyInterval = 10 * time.Millisecond
} }

View File

@ -45,7 +45,7 @@ var (
// if the message is received. // if the message is received.
// //
// NOTE: for itest, this value is changed to 10ms. // NOTE: for itest, this value is changed to 10ms.
checkPeerFundingLockInterval = 1 * time.Second checkPeerChannelReadyInterval = 1 * time.Second
) )
// WriteOutpoint writes an outpoint to an io.Writer. This is not the same as // WriteOutpoint writes an outpoint to an io.Writer. This is not the same as
@ -570,8 +570,8 @@ type Manager struct {
localDiscoveryMtx sync.Mutex localDiscoveryMtx sync.Mutex
localDiscoverySignals map[lnwire.ChannelID]chan struct{} localDiscoverySignals map[lnwire.ChannelID]chan struct{}
handleFundingLockedMtx sync.RWMutex handleChannelReadyMtx sync.RWMutex
handleFundingLockedBarriers map[lnwire.ChannelID]struct{} handleChannelReadyBarriers map[lnwire.ChannelID]struct{}
quit chan struct{} quit chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
@ -591,7 +591,7 @@ const (
// fundingLockedSent is the opening state of a channel if the // fundingLockedSent is the opening state of a channel if the
// fundingLocked message has successfully been sent to the other peer, // fundingLocked message has successfully been sent to the other peer,
// but we still haven't announced the channel to the network. // but we still haven't announced the channel to the network.
fundingLockedSent channelReadySent
// addedToRouterGraph is the opening state of a channel if the // addedToRouterGraph is the opening state of a channel if the
// channel has been successfully added to the router graph // channel has been successfully added to the router graph
@ -604,7 +604,7 @@ func (c channelOpeningState) String() string {
switch c { switch c {
case markedOpen: case markedOpen:
return "markedOpen" return "markedOpen"
case fundingLockedSent: case channelReadySent:
return "fundingLocked" return "fundingLocked"
case addedToRouterGraph: case addedToRouterGraph:
return "addedToRouterGraph" return "addedToRouterGraph"
@ -617,16 +617,16 @@ func (c channelOpeningState) String() string {
// fundingManager. // fundingManager.
func NewFundingManager(cfg Config) (*Manager, error) { func NewFundingManager(cfg Config) (*Manager, error) {
return &Manager{ return &Manager{
cfg: &cfg, cfg: &cfg,
chanIDKey: cfg.TempChanIDSeed, chanIDKey: cfg.TempChanIDSeed,
activeReservations: make(map[serializedPubKey]pendingChannels), activeReservations: make(map[serializedPubKey]pendingChannels),
signedReservations: make(map[lnwire.ChannelID][32]byte), signedReservations: make(map[lnwire.ChannelID][32]byte),
newChanBarriers: make(map[lnwire.ChannelID]chan struct{}), newChanBarriers: make(map[lnwire.ChannelID]chan struct{}),
fundingMsgs: make(chan *fundingMsg, msgBufferSize), fundingMsgs: make(chan *fundingMsg, msgBufferSize),
fundingRequests: make(chan *InitFundingMsg, msgBufferSize), fundingRequests: make(chan *InitFundingMsg, msgBufferSize),
localDiscoverySignals: make(map[lnwire.ChannelID]chan struct{}), localDiscoverySignals: make(map[lnwire.ChannelID]chan struct{}),
handleFundingLockedBarriers: make(map[lnwire.ChannelID]struct{}), handleChannelReadyBarriers: make(map[lnwire.ChannelID]struct{}),
quit: make(chan struct{}), quit: make(chan struct{}),
}, nil }, nil
} }
@ -891,7 +891,7 @@ func (f *Manager) reservationCoordinator() {
case *lnwire.ChannelReady: case *lnwire.ChannelReady:
f.wg.Add(1) f.wg.Add(1)
go f.handleFundingLocked(fmsg.peer, msg) go f.handleChannelReady(fmsg.peer, msg)
case *lnwire.Warning: case *lnwire.Warning:
f.handleWarningMsg(fmsg.peer, msg) f.handleWarningMsg(fmsg.peer, msg)
@ -1002,7 +1002,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// The funding transaction was confirmed, but we did not successfully // The funding transaction was confirmed, but we did not successfully
// send the fundingLocked message to the peer, so let's do that now. // send the fundingLocked message to the peer, so let's do that now.
case markedOpen: case markedOpen:
err := f.sendFundingLocked(channel, lnChannel) err := f.sendChannelReady(channel, lnChannel)
if err != nil { if err != nil {
return fmt.Errorf("failed sending fundingLocked: %v", return fmt.Errorf("failed sending fundingLocked: %v",
err) err)
@ -1013,7 +1013,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// will be moved to the last state (actually deleted from the // will be moved to the last state (actually deleted from the
// database) after the channel is finally announced. // database) after the channel is finally announced.
err = f.saveChannelOpeningState( err = f.saveChannelOpeningState(
&channel.FundingOutpoint, fundingLockedSent, &channel.FundingOutpoint, channelReadySent,
shortChanID, shortChanID,
) )
if err != nil { if err != nil {
@ -1028,10 +1028,10 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// fundingLocked was sent to peer, but the channel was not added to the // fundingLocked was sent to peer, but the channel was not added to the
// router graph and the channel announcement was not sent. // router graph and the channel announcement was not sent.
case fundingLockedSent: case channelReadySent:
// We must wait until we've received the peer's funding locked // We must wait until we've received the peer's funding locked
// before sending a channel_update according to BOLT#07. // before sending a channel_update according to BOLT#07.
received, err := f.receivedFundingLocked( received, err := f.receivedChannelReady(
channel.IdentityPub, chanID, channel.IdentityPub, chanID,
) )
if err != nil { if err != nil {
@ -1044,7 +1044,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// to the next iteration of the loop after sleeping for // to the next iteration of the loop after sleeping for
// checkPeerFundingLockInterval. // checkPeerFundingLockInterval.
select { select {
case <-time.After(checkPeerFundingLockInterval): case <-time.After(checkPeerChannelReadyInterval):
case <-f.quit: case <-f.quit:
return ErrFundingManagerShuttingDown return ErrFundingManagerShuttingDown
} }
@ -2893,7 +2893,7 @@ func (f *Manager) handleFundingConfirmation(
// sendFundingLocked creates and sends the fundingLocked message. // sendFundingLocked creates and sends the fundingLocked message.
// This should be called after the funding transaction has been confirmed, // This should be called after the funding transaction has been confirmed,
// and the channelState is 'markedOpen'. // and the channelState is 'markedOpen'.
func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel, func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel,
channel *lnwallet.LightningChannel) error { channel *lnwallet.LightningChannel) error {
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint) chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
@ -3007,7 +3007,7 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel,
// receivedFundingLocked checks whether or not we've received a FundingLocked // receivedFundingLocked checks whether or not we've received a FundingLocked
// from the remote peer. If we have, RemoteNextRevocation will be set. // from the remote peer. If we have, RemoteNextRevocation will be set.
func (f *Manager) receivedFundingLocked(node *btcec.PublicKey, func (f *Manager) receivedChannelReady(node *btcec.PublicKey,
chanID lnwire.ChannelID) (bool, error) { chanID lnwire.ChannelID) (bool, error) {
// If the funding manager has exited, return an error to stop looping. // If the funding manager has exited, return an error to stop looping.
@ -3393,7 +3393,7 @@ func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel,
// handleFundingLocked finalizes the channel funding process and enables the // handleFundingLocked finalizes the channel funding process and enables the
// channel to enter normal operating mode. // channel to enter normal operating mode.
func (f *Manager) handleFundingLocked(peer lnpeer.Peer, func (f *Manager) handleChannelReady(peer lnpeer.Peer,
msg *lnwire.ChannelReady) { msg *lnwire.ChannelReady) {
defer f.wg.Done() defer f.wg.Done()
@ -3403,24 +3403,24 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer,
// If we are currently in the process of handling a funding locked // If we are currently in the process of handling a funding locked
// message for this channel, ignore. // message for this channel, ignore.
f.handleFundingLockedMtx.Lock() f.handleChannelReadyMtx.Lock()
_, ok := f.handleFundingLockedBarriers[msg.ChanID] _, ok := f.handleChannelReadyBarriers[msg.ChanID]
if ok { if ok {
log.Infof("Already handling fundingLocked for "+ log.Infof("Already handling fundingLocked for "+
"ChannelID(%v), ignoring.", msg.ChanID) "ChannelID(%v), ignoring.", msg.ChanID)
f.handleFundingLockedMtx.Unlock() f.handleChannelReadyMtx.Unlock()
return return
} }
// If not already handling fundingLocked for this channel, set up // If not already handling fundingLocked for this channel, set up
// barrier, and move on. // barrier, and move on.
f.handleFundingLockedBarriers[msg.ChanID] = struct{}{} f.handleChannelReadyBarriers[msg.ChanID] = struct{}{}
f.handleFundingLockedMtx.Unlock() f.handleChannelReadyMtx.Unlock()
defer func() { defer func() {
f.handleFundingLockedMtx.Lock() f.handleChannelReadyMtx.Lock()
delete(f.handleFundingLockedBarriers, msg.ChanID) delete(f.handleChannelReadyBarriers, msg.ChanID)
f.handleFundingLockedMtx.Unlock() f.handleChannelReadyMtx.Unlock()
}() }()
f.localDiscoveryMtx.Lock() f.localDiscoveryMtx.Lock()

View File

@ -1055,8 +1055,8 @@ func assertFundingLockedSent(t *testing.T, alice, bob *testNode,
t.Helper() t.Helper()
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
} }
func assertAddedToRouterGraph(t *testing.T, alice, bob *testNode, func assertAddedToRouterGraph(t *testing.T, alice, bob *testNode,
@ -1685,7 +1685,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
assertDatabaseState(t, alice, fundingOutPoint, markedOpen) assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
// While Bob successfully sent fundingLocked. // While Bob successfully sent fundingLocked.
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
// We now recreate Alice's fundingManager with the correct sendMessage // We now recreate Alice's fundingManager with the correct sendMessage
// implementation, and expect it to retry sending the fundingLocked // implementation, and expect it to retry sending the fundingLocked
@ -1711,7 +1711,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
// The state should now be fundingLockedSent // The state should now be fundingLockedSent
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
// Check that the channel announcements were never sent // Check that the channel announcements were never sent
select { select {
@ -1842,7 +1842,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
assertDatabaseState(t, alice, fundingOutPoint, markedOpen) assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
// While Bob successfully sent fundingLocked. // While Bob successfully sent fundingLocked.
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
// Alice should be waiting for the server to notify when Bob comes back // Alice should be waiting for the server to notify when Bob comes back
// online. // online.
@ -1887,7 +1887,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
// The state should now be fundingLockedSent // The state should now be fundingLockedSent
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
// Exchange the fundingLocked messages. // Exchange the fundingLocked messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob)