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() {
// For itest, we will use a much shorter checking interval here as
// 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.
//
// 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
@ -570,8 +570,8 @@ type Manager struct {
localDiscoveryMtx sync.Mutex
localDiscoverySignals map[lnwire.ChannelID]chan struct{}
handleFundingLockedMtx sync.RWMutex
handleFundingLockedBarriers map[lnwire.ChannelID]struct{}
handleChannelReadyMtx sync.RWMutex
handleChannelReadyBarriers map[lnwire.ChannelID]struct{}
quit chan struct{}
wg sync.WaitGroup
@ -591,7 +591,7 @@ const (
// fundingLockedSent is the opening state of a channel if the
// fundingLocked message has successfully been sent to the other peer,
// but we still haven't announced the channel to the network.
fundingLockedSent
channelReadySent
// addedToRouterGraph is the opening state of a channel if the
// channel has been successfully added to the router graph
@ -604,7 +604,7 @@ func (c channelOpeningState) String() string {
switch c {
case markedOpen:
return "markedOpen"
case fundingLockedSent:
case channelReadySent:
return "fundingLocked"
case addedToRouterGraph:
return "addedToRouterGraph"
@ -625,7 +625,7 @@ func NewFundingManager(cfg Config) (*Manager, error) {
fundingMsgs: make(chan *fundingMsg, msgBufferSize),
fundingRequests: make(chan *InitFundingMsg, msgBufferSize),
localDiscoverySignals: make(map[lnwire.ChannelID]chan struct{}),
handleFundingLockedBarriers: make(map[lnwire.ChannelID]struct{}),
handleChannelReadyBarriers: make(map[lnwire.ChannelID]struct{}),
quit: make(chan struct{}),
}, nil
}
@ -891,7 +891,7 @@ func (f *Manager) reservationCoordinator() {
case *lnwire.ChannelReady:
f.wg.Add(1)
go f.handleFundingLocked(fmsg.peer, msg)
go f.handleChannelReady(fmsg.peer, msg)
case *lnwire.Warning:
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
// send the fundingLocked message to the peer, so let's do that now.
case markedOpen:
err := f.sendFundingLocked(channel, lnChannel)
err := f.sendChannelReady(channel, lnChannel)
if err != nil {
return fmt.Errorf("failed sending fundingLocked: %v",
err)
@ -1013,7 +1013,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// will be moved to the last state (actually deleted from the
// database) after the channel is finally announced.
err = f.saveChannelOpeningState(
&channel.FundingOutpoint, fundingLockedSent,
&channel.FundingOutpoint, channelReadySent,
shortChanID,
)
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
// 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
// before sending a channel_update according to BOLT#07.
received, err := f.receivedFundingLocked(
received, err := f.receivedChannelReady(
channel.IdentityPub, chanID,
)
if err != nil {
@ -1044,7 +1044,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// to the next iteration of the loop after sleeping for
// checkPeerFundingLockInterval.
select {
case <-time.After(checkPeerFundingLockInterval):
case <-time.After(checkPeerChannelReadyInterval):
case <-f.quit:
return ErrFundingManagerShuttingDown
}
@ -2893,7 +2893,7 @@ func (f *Manager) handleFundingConfirmation(
// sendFundingLocked creates and sends the fundingLocked message.
// This should be called after the funding transaction has been confirmed,
// and the channelState is 'markedOpen'.
func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel,
func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel,
channel *lnwallet.LightningChannel) error {
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
// 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) {
// 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
// channel to enter normal operating mode.
func (f *Manager) handleFundingLocked(peer lnpeer.Peer,
func (f *Manager) handleChannelReady(peer lnpeer.Peer,
msg *lnwire.ChannelReady) {
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
// message for this channel, ignore.
f.handleFundingLockedMtx.Lock()
_, ok := f.handleFundingLockedBarriers[msg.ChanID]
f.handleChannelReadyMtx.Lock()
_, ok := f.handleChannelReadyBarriers[msg.ChanID]
if ok {
log.Infof("Already handling fundingLocked for "+
"ChannelID(%v), ignoring.", msg.ChanID)
f.handleFundingLockedMtx.Unlock()
f.handleChannelReadyMtx.Unlock()
return
}
// If not already handling fundingLocked for this channel, set up
// barrier, and move on.
f.handleFundingLockedBarriers[msg.ChanID] = struct{}{}
f.handleFundingLockedMtx.Unlock()
f.handleChannelReadyBarriers[msg.ChanID] = struct{}{}
f.handleChannelReadyMtx.Unlock()
defer func() {
f.handleFundingLockedMtx.Lock()
delete(f.handleFundingLockedBarriers, msg.ChanID)
f.handleFundingLockedMtx.Unlock()
f.handleChannelReadyMtx.Lock()
delete(f.handleChannelReadyBarriers, msg.ChanID)
f.handleChannelReadyMtx.Unlock()
}()
f.localDiscoveryMtx.Lock()

View File

@ -1055,8 +1055,8 @@ func assertFundingLockedSent(t *testing.T, alice, bob *testNode,
t.Helper()
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent)
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent)
assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
}
func assertAddedToRouterGraph(t *testing.T, alice, bob *testNode,
@ -1685,7 +1685,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
// 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
// implementation, and expect it to retry sending the fundingLocked
@ -1711,7 +1711,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
).(*lnwire.ChannelReady)
// The state should now be fundingLockedSent
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent)
assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
// Check that the channel announcements were never sent
select {
@ -1842,7 +1842,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
// 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
// online.
@ -1887,7 +1887,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
).(*lnwire.ChannelReady)
// The state should now be fundingLockedSent
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent)
assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
// Exchange the fundingLocked messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob)