diff --git a/aliasmgr/aliasmgr.go b/aliasmgr/aliasmgr.go index 381476a73..f33eb391e 100644 --- a/aliasmgr/aliasmgr.go +++ b/aliasmgr/aliasmgr.go @@ -38,7 +38,7 @@ var ( lastAliasKey = []byte("last-alias-key") // invoiceAliasBucket is a root-level bucket that stores the alias - // SCIDs that our peers send us in the funding_locked TLV. The keys are + // SCIDs that our peers send us in the channel_ready TLV. The keys are // the ChannelID generated from the FundingOutpoint and the values are // the remote peer's alias SCID. invoiceAliasBucket = []byte("invoice-alias-bucket") @@ -88,7 +88,7 @@ type Manager struct { aliasToBase map[lnwire.ShortChannelID]lnwire.ShortChannelID // peerAlias is a cache for the alias SCIDs that our peers send us in - // the funding_locked TLV. The keys are the ChannelID generated from + // the channel_ready TLV. The keys are the ChannelID generated from // the FundingOutpoint and the values are the remote peer's alias SCID. // The values should match the ones stored in the "invoice-alias-bucket" // bucket. @@ -341,7 +341,7 @@ func (m *Manager) DeleteSixConfs(baseScid lnwire.ShortChannelID) error { } // PutPeerAlias stores the peer's alias SCID once we learn of it in the -// funding_locked message. +// channel_ready message. func (m *Manager) PutPeerAlias(chanID lnwire.ChannelID, alias lnwire.ShortChannelID) error { diff --git a/channeldb/channel.go b/channeldb/channel.go index d71f17047..b731028ee 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -1345,7 +1345,7 @@ func (c *OpenChannel) MarkBorked() error { } // SecondCommitmentPoint returns the second per-commitment-point for use in the -// funding_locked message. +// channel_ready message. func (c *OpenChannel) SecondCommitmentPoint() (*btcec.PublicKey, error) { c.RLock() defer c.RUnlock() @@ -3770,7 +3770,7 @@ func putChanRevocationState(chanBucket kvdb.RwBucket, channel *OpenChannel) erro // TODO(roasbeef): don't keep producer on disk // If the next revocation is present, which is only the case after the - // FundingLocked message has been sent, then we'll write it to disk. + // ChannelReady message has been sent, then we'll write it to disk. if channel.RemoteNextRevocation != nil { err = WriteElements(&b, channel.RemoteNextRevocation) if err != nil { diff --git a/docs/release-notes/release-notes-0.16.1.md b/docs/release-notes/release-notes-0.16.1.md index 790388eed..0265abc4c 100644 --- a/docs/release-notes/release-notes-0.16.1.md +++ b/docs/release-notes/release-notes-0.16.1.md @@ -42,6 +42,13 @@ added to `lnrpc` so the node operator can know whether a certain request has happened or not. +* Message `funding_locked` [has been + renamed](https://github.com/lightningnetwork/lnd/pull/7517) to + `channel_ready` internally to match the specs update. This should not change + anything for the users since the message type(36) stays unchanged, except in + the logging all the appearance of `funding_locked` replated experssion is + replaced with `channel_ready`. + # Contributors (Alphabetical Order) * ardevd diff --git a/funding/config_integration.go b/funding/config_integration.go index 06bb6e173..f032a3338 100644 --- a/funding/config_integration.go +++ b/funding/config_integration.go @@ -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 } diff --git a/funding/interfaces.go b/funding/interfaces.go index 09270d149..b87705424 100644 --- a/funding/interfaces.go +++ b/funding/interfaces.go @@ -23,15 +23,15 @@ type Controller interface { // aliasHandler is an interface that abstracts the managing of aliases. type aliasHandler interface { // RequestAlias lets the funding manager request a unique SCID alias to - // use in the funding_locked message. + // use in the channel_ready message. RequestAlias() (lnwire.ShortChannelID, error) // PutPeerAlias lets the funding manager store the received alias SCID - // in the funding_locked message. + // in the channel_ready message. PutPeerAlias(lnwire.ChannelID, lnwire.ShortChannelID) error // GetPeerAlias lets the funding manager lookup the received alias SCID - // from the funding_locked message. This is not the same as GetAliases + // from the channel_ready message. This is not the same as GetAliases // which retrieves OUR aliases for a given channel. GetPeerAlias(lnwire.ChannelID) (lnwire.ShortChannelID, error) diff --git a/funding/manager.go b/funding/manager.go index 2d702ba48..83c9a1d21 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -40,12 +40,12 @@ var ( // buffers. byteOrder = binary.BigEndian - // checkPeerFundingLockInterval is used when we are waiting for the - // peer to send us FundingLocked. We will check every 1 second to see + // checkPeerChannelReadyInterval is used when we are waiting for the + // peer to send us ChannelReady. We will check every 1 second to see // 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 @@ -377,7 +377,7 @@ type Config struct { // NotifyWhenOnline allows the FundingManager to register with a // subsystem that will notify it when the peer comes online. This is - // used when sending the fundingLocked message, since it MUST be + // used when sending the channelReady message, since it MUST be // delivered after the funding transaction is confirmed. // // NOTE: The peerChan channel must be buffered. @@ -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 @@ -584,18 +584,18 @@ type channelOpeningState uint8 const ( // markedOpen is the opening state of a channel if the funding - // transaction is confirmed on-chain, but fundingLocked is not yet + // transaction is confirmed on-chain, but channelReady is not yet // successfully sent to the other peer. markedOpen channelOpeningState = iota - // fundingLockedSent is the opening state of a channel if the - // fundingLocked message has successfully been sent to the other peer, + // channelReadySent is the opening state of a channel if the + // channelReady 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 - // immediately after the fundingLocked message has been sent, but + // immediately after the channelReady message has been sent, but // we still haven't announced the channel to the network. addedToRouterGraph ) @@ -604,8 +604,8 @@ func (c channelOpeningState) String() string { switch c { case markedOpen: return "markedOpen" - case fundingLockedSent: - return "fundingLocked" + case channelReadySent: + return "channelReady" case addedToRouterGraph: return "addedToRouterGraph" default: @@ -617,16 +617,30 @@ func (c channelOpeningState) String() string { // fundingManager. func NewFundingManager(cfg Config) (*Manager, error) { return &Manager{ - cfg: &cfg, - chanIDKey: cfg.TempChanIDSeed, - activeReservations: make(map[serializedPubKey]pendingChannels), - signedReservations: make(map[lnwire.ChannelID][32]byte), - newChanBarriers: make(map[lnwire.ChannelID]chan struct{}), - fundingMsgs: make(chan *fundingMsg, msgBufferSize), - fundingRequests: make(chan *InitFundingMsg, msgBufferSize), - localDiscoverySignals: make(map[lnwire.ChannelID]chan struct{}), - handleFundingLockedBarriers: make(map[lnwire.ChannelID]struct{}), - quit: make(chan struct{}), + cfg: &cfg, + chanIDKey: cfg.TempChanIDSeed, + activeReservations: make( + map[serializedPubKey]pendingChannels, + ), + signedReservations: make( + map[lnwire.ChannelID][32]byte, + ), + newChanBarriers: make( + map[lnwire.ChannelID]chan struct{}, + ), + fundingMsgs: make( + chan *fundingMsg, msgBufferSize, + ), + fundingRequests: make( + chan *InitFundingMsg, msgBufferSize, + ), + localDiscoverySignals: make( + map[lnwire.ChannelID]chan struct{}, + ), + handleChannelReadyBarriers: make( + map[lnwire.ChannelID]struct{}, + ), + quit: make(chan struct{}), }, nil } @@ -889,9 +903,9 @@ func (f *Manager) reservationCoordinator() { case *lnwire.FundingSigned: f.handleFundingSigned(fmsg.peer, msg) - case *lnwire.FundingLocked: + 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) @@ -1000,38 +1014,38 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, switch channelState { // 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 channelReady 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", + return fmt.Errorf("failed sending channelReady: %v", err) } - // As the fundingLocked message is now sent to the peer, the + // As the channelReady message is now sent to the peer, the // channel is moved to the next state of the state machine. It // 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 { return fmt.Errorf("error setting channel state to"+ - " fundingLockedSent: %v", err) + " channelReadySent: %v", err) } log.Debugf("Channel(%v) with ShortChanID %v: successfully "+ - "sent FundingLocked", chanID, shortChanID) + "sent ChannelReady", chanID, shortChanID) return nil - // fundingLocked was sent to peer, but the channel was not added to the + // channelReady 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 { @@ -1040,11 +1054,11 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, } if !received { - // We haven't received FundingLocked, so we'll continue + // We haven't received ChannelReady, so we'll continue // to the next iteration of the loop after sleeping for - // checkPeerFundingLockInterval. + // checkPeerChannelReadyInterval. select { - case <-time.After(checkPeerFundingLockInterval): + case <-time.After(checkPeerChannelReadyInterval): case <-f.quit: return ErrFundingManagerShuttingDown } @@ -1054,7 +1068,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, var peerAlias *lnwire.ShortChannelID if channel.IsZeroConf() { - // We'll need to wait until funding_locked has been + // We'll need to wait until channel_ready has been // received and the peer lets us know the alias they // want to use for the channel. With this information, // we can then construct a ChannelUpdate for them. @@ -1213,7 +1227,7 @@ func (f *Manager) advancePendingChannelState( f.cfg.NotifyOpenChannelEvent(channel.FundingOutpoint) // Find and close the discoverySignal for this channel such - // that FundingLocked messages will be processed. + // that ChannelReady messages will be processed. chanID := lnwire.NewChanIDFromOutPoint( &channel.FundingOutpoint, ) @@ -2890,10 +2904,10 @@ func (f *Manager) handleFundingConfirmation( return nil } -// sendFundingLocked creates and sends the fundingLocked message. +// sendChannelReady creates and sends the channelReady 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) @@ -2909,7 +2923,7 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel, if err != nil { return fmt.Errorf("unable to create next revocation: %v", err) } - fundingLockedMsg := lnwire.NewFundingLocked(chanID, nextRevocation) + channelReadyMsg := lnwire.NewChannelReady(chanID, nextRevocation) // If the channel negotiated the option-scid-alias feature bit, we'll // send a TLV segment that includes an alias the peer can use in their @@ -2926,19 +2940,19 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel, // We can use a pointer to aliases since GetAliases returns a // copy of the alias slice. - fundingLockedMsg.AliasScid = &aliases[0] + channelReadyMsg.AliasScid = &aliases[0] } // If the peer has disconnected before we reach this point, we will need - // to wait for him to come back online before sending the fundingLocked - // message. This is special for fundingLocked, since failing to send any + // to wait for him to come back online before sending the channelReady + // message. This is special for channelReady, since failing to send any // of the previous messages in the funding flow just cancels the flow. // But now the funding transaction is confirmed, the channel is open - // and we have to make sure the peer gets the fundingLocked message when + // and we have to make sure the peer gets the channelReady message when // it comes back online. This is also crucial during restart of lnd, - // where we might try to resend the fundingLocked message before the + // where we might try to resend the channelReady message before the // server has had the time to connect to the peer. We keep trying to - // send fundingLocked until we succeed, or the fundingManager is shut + // send channelReady until we succeed, or the fundingManager is shut // down. for { peer, err := f.waitForPeerOnline(completeChan.IdentityPub) @@ -2956,14 +2970,14 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel, // We could also refresh the channel state instead of checking // whether the feature was negotiated, but this saves us a // database read. - if fundingLockedMsg.AliasScid == nil && localAlias && + if channelReadyMsg.AliasScid == nil && localAlias && remoteAlias { // If an alias was not assigned above and the scid // alias feature was negotiated, check if we already - // have an alias stored in case handleFundingLocked was + // have an alias stored in case handleChannelReady was // called before this. If an alias exists, use that in - // funding_locked. Otherwise, request and store an + // channel_ready. Otherwise, request and store an // alias and use that. aliases := f.cfg.AliasManager.GetAliases( completeChan.ShortChannelID, @@ -2983,31 +2997,31 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel, return err } - fundingLockedMsg.AliasScid = &alias + channelReadyMsg.AliasScid = &alias } else { - fundingLockedMsg.AliasScid = &aliases[0] + channelReadyMsg.AliasScid = &aliases[0] } } - log.Infof("Peer(%x) is online, sending FundingLocked "+ + log.Infof("Peer(%x) is online, sending ChannelReady "+ "for ChannelID(%v)", peerKey, chanID) - if err := peer.SendMessage(true, fundingLockedMsg); err == nil { + if err := peer.SendMessage(true, channelReadyMsg); err == nil { // Sending succeeded, we can break out and continue the // funding flow. break } - log.Warnf("Unable to send fundingLocked to peer %x: %v. "+ + log.Warnf("Unable to send channelReady to peer %x: %v. "+ "Will retry when online", peerKey, err) } return nil } -// receivedFundingLocked checks whether or not we've received a FundingLocked +// receivedChannelReady checks whether or not we've received a ChannelReady // 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. @@ -3028,7 +3042,7 @@ func (f *Manager) receivedFundingLocked(node *btcec.PublicKey, channel, err := f.cfg.FindChannel(node, chanID) if err != nil { log.Errorf("Unable to locate ChannelID(%v) to determine if "+ - "FundingLocked was received", chanID) + "ChannelReady was received", chanID) return false, err } @@ -3140,7 +3154,7 @@ func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel, } // annAfterSixConfs broadcasts the necessary channel announcement messages to -// the network after 6 confs. Should be called after the fundingLocked message +// the network after 6 confs. Should be called after the channelReady message // is sent and the channel is added to the router graph (channelState is // 'addedToRouterGraph') and the channel is ready to be used. This is the last // step in the channel opening process, and the opening state will be deleted @@ -3391,36 +3405,36 @@ func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel, return nil } -// handleFundingLocked finalizes the channel funding process and enables the +// handleChannelReady finalizes the channel funding process and enables the // channel to enter normal operating mode. -func (f *Manager) handleFundingLocked(peer lnpeer.Peer, - msg *lnwire.FundingLocked) { +func (f *Manager) handleChannelReady(peer lnpeer.Peer, + msg *lnwire.ChannelReady) { defer f.wg.Done() - log.Debugf("Received FundingLocked for ChannelID(%v) from "+ + log.Debugf("Received ChannelReady for ChannelID(%v) from "+ "peer %x", msg.ChanID, peer.IdentityKey().SerializeCompressed()) // 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 "+ + log.Infof("Already handling channelReady for "+ "ChannelID(%v), ignoring.", msg.ChanID) - f.handleFundingLockedMtx.Unlock() + f.handleChannelReadyMtx.Unlock() return } - // If not already handling fundingLocked for this channel, set up + // If not already handling channelReady 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() @@ -3464,7 +3478,7 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer, // during invoice creation. In the zero-conf case, it is also used to // provide a ChannelUpdate to the remote peer. This is done before the // call to InsertNextRevocation in case the call to PutPeerAlias fails. - // If it were to fail on the first call to handleFundingLocked, we + // If it were to fail on the first call to handleChannelReady, we // wouldn't want the channel to be usable yet. if channel.NegotiatedAliasFeature() { // If the AliasScid field is nil, we must fail out. We will @@ -3487,14 +3501,14 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer, // If we do not have an alias stored, we'll create one now. // This is only used in the upgrade case where a user toggles // the option-scid-alias feature-bit to on. We'll also send the - // funding_locked message here in case the link is created - // before sendFundingLocked is called. + // channel_ready message here in case the link is created + // before sendChannelReady is called. aliases := f.cfg.AliasManager.GetAliases( channel.ShortChannelID, ) if len(aliases) == 0 { // No aliases were found so we'll request and store an - // alias and use it in the funding_locked message. + // alias and use it in the channel_ready message. alias, err := f.cfg.AliasManager.RequestAlias() if err != nil { log.Errorf("unable to request alias: %v", err) @@ -3517,12 +3531,12 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer, return } - fundingLockedMsg := lnwire.NewFundingLocked( + channelReadyMsg := lnwire.NewChannelReady( chanID, secondPoint, ) - fundingLockedMsg.AliasScid = &alias + channelReadyMsg.AliasScid = &alias - err = peer.SendMessage(true, fundingLockedMsg) + err = peer.SendMessage(true, channelReadyMsg) if err != nil { log.Errorf("unable to send funding locked: %v", err) @@ -3532,16 +3546,16 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer, } // If the RemoteNextRevocation is non-nil, it means that we have - // already processed fundingLocked for this channel, so ignore. This + // already processed channelReady for this channel, so ignore. This // check is after the alias logic so we store the peer's most recent // alias. The spec requires us to validate that subsequent - // funding_locked messages use the same per commitment point (the + // channel_ready messages use the same per commitment point (the // second), but it is not actually necessary since we'll just end up // ignoring it. We are, however, required to *send* the same per // commitment point, since another pedantic implementation might // verify it. if channel.RemoteNextRevocation != nil { - log.Infof("Received duplicate fundingLocked for "+ + log.Infof("Received duplicate channelReady for "+ "ChannelID(%v), ignoring.", chanID) return } diff --git a/funding/manager_test.go b/funding/manager_test.go index f386e3de5..dc40c4d8f 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -900,8 +900,8 @@ func assertFundingMsgSent(t *testing.T, msgChan chan lnwire.Message, sentMsg, ok = msg.(*lnwire.FundingCreated) case "FundingSigned": sentMsg, ok = msg.(*lnwire.FundingSigned) - case "FundingLocked": - sentMsg, ok = msg.(*lnwire.FundingLocked) + case "ChannelReady": + sentMsg, ok = msg.(*lnwire.ChannelReady) case "Error": sentMsg, ok = msg.(*lnwire.Error) default: @@ -1050,13 +1050,13 @@ func assertMarkedOpen(t *testing.T, alice, bob *testNode, assertDatabaseState(t, bob, fundingOutPoint, markedOpen) } -func assertFundingLockedSent(t *testing.T, alice, bob *testNode, +func assertChannelReadySent(t *testing.T, alice, bob *testNode, fundingOutPoint *wire.OutPoint) { 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, @@ -1082,7 +1082,7 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode, t.Helper() - // After the FundingLocked message is sent, Alice and Bob will each send + // After the ChannelReady message is sent, Alice and Bob will each send // the following messages to their gossiper: // 1) ChannelAnnouncement // 2) ChannelUpdate @@ -1222,7 +1222,7 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode, func assertAnnouncementSignatures(t *testing.T, alice, bob *testNode) { t.Helper() - // After the FundingLocked message is sent and six confirmations have + // After the ChannelReady message is sent and six confirmations have // been reached, the channel will be announced to the greater network // by having the nodes exchange announcement signatures. // Two distinct messages will be sent: @@ -1347,7 +1347,7 @@ func assertInitialFwdingPolicyNotFound(t *testing.T, node *testNode, fwdingPolicy) } -func assertHandleFundingLocked(t *testing.T, alice, bob *testNode) { +func assertHandleChannelReady(t *testing.T, alice, bob *testNode) { t.Helper() // They should both send the new channel state to their peer. @@ -1405,26 +1405,28 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly - assertFundingLockedSent(t, alice, bob, fundingOutPoint) + assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Make sure both fundingManagers send the expected channel // announcements. @@ -1635,7 +1637,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { ) // After the funding transaction gets mined, both nodes will send the - // fundingLocked message to the other peer. If the funding node fails + // channelReady message to the other peer. If the funding node fails // before this message has been successfully sent, it should retry // sending it on restart. We mimic this behavior by letting the // SendToPeer method return an error, as if the message was not @@ -1666,7 +1668,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction was mined, Bob should have successfully - // sent the fundingLocked message, while Alice failed sending it. In + // sent the channelReady message, while Alice failed sending it. In // Alice's case this means that there should be no messages for Bob, and // the channel should still be in state 'markedOpen' select { @@ -1677,18 +1679,19 @@ func TestFundingManagerRestartBehavior(t *testing.T) { } // Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) - // While Bob successfully sent fundingLocked. - assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) + // While Bob successfully sent channelReady. + assertDatabaseState(t, bob, fundingOutPoint, channelReadySent) // 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 channelReady // message. We'll explicitly shut down Alice's funding manager to // prevent a race when overriding the sendMessage implementation. if err := alice.fundingMgr.Stop(); err != nil { @@ -1706,12 +1709,13 @@ func TestFundingManagerRestartBehavior(t *testing.T) { return errChan } - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) - // The state should now be fundingLockedSent - assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) + // The state should now be channelReadySent + assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) // Check that the channel announcements were never sent select { @@ -1722,13 +1726,13 @@ func TestFundingManagerRestartBehavior(t *testing.T) { // Expected } - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Next up, we check that Alice rebroadcasts the announcement // messages on restart. Bob should as expected send announcements. @@ -1771,7 +1775,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { // TestFundingManagerOfflinePeer checks that the fundingManager waits for the // server to notify when the peer comes online, in case sending the -// fundingLocked message fails the first time. +// channelReady message fails the first time. func TestFundingManagerOfflinePeer(t *testing.T) { t.Parallel() @@ -1791,8 +1795,8 @@ func TestFundingManagerOfflinePeer(t *testing.T) { ) // After the funding transaction gets mined, both nodes will send the - // fundingLocked message to the other peer. If the funding node fails - // to send the fundingLocked message to the peer, it should wait for + // channelReady message to the other peer. If the funding node fails + // to send the channelReady message to the peer, it should wait for // the server to notify it that the peer is back online, and try again. // We'll save the current implementation of sendMessage to restore the // original behavior later on. @@ -1823,7 +1827,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction was mined, Bob should have successfully - // sent the fundingLocked message, while Alice failed sending it. In + // sent the channelReady message, while Alice failed sending it. In // Alice's case this means that there should be no messages for Bob, and // the channel should still be in state 'markedOpen' select { @@ -1834,15 +1838,16 @@ func TestFundingManagerOfflinePeer(t *testing.T) { } // Bob will send funding locked to Alice - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) - // While Bob successfully sent fundingLocked. - assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) + // While Bob successfully sent channelReady. + assertDatabaseState(t, bob, fundingOutPoint, channelReadySent) // Alice should be waiting for the server to notify when Bob comes back // online. @@ -1868,7 +1873,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { } // Before sending on the con chan, update Alice's NotifyWhenOnline - // function so that the next invocation in receivedFundingLocked will + // function so that the next invocation in receivedChannelReady will // use this new function. alice.fundingMgr.cfg.NotifyWhenOnline = func(peer [33]byte, connected chan<- lnpeer.Peer) { @@ -1881,21 +1886,22 @@ func TestFundingManagerOfflinePeer(t *testing.T) { bob.sendMessage = workingSendMessage con <- bob - // This should make Alice send the fundingLocked. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // This should make Alice send the channelReady. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) - // The state should now be fundingLockedSent - assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) + // The state should now be channelReadySent + assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Make sure both fundingManagers send the expected channel // announcements. @@ -2272,10 +2278,10 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) { assertNumPendingChannelsBecomes(t, bob, 0) } -// TestFundingManagerReceiveFundingLockedTwice checks that the fundingManager -// continues to operate as expected in case we receive a duplicate fundingLocked +// TestFundingManagerReceiveChannelReadyTwice checks that the fundingManager +// continues to operate as expected in case we receive a duplicate channelReady // message. -func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { +func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { t.Parallel() alice, bob := setupFundingManagers(t) @@ -2310,27 +2316,29 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly - assertFundingLockedSent(t, alice, bob, fundingOutPoint) + assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Send the fundingLocked message twice to Alice, and once to Bob. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Send the channelReady message twice to Alice, and once to Bob. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Alice should not send the channel state the second time, as the // second funding locked should just be ignored. @@ -2341,9 +2349,9 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { // Expected } - // Another fundingLocked should also be ignored, since Alice should + // Another channelReady should also be ignored, since Alice should // have updated her database at this point. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) select { case <-alice.newChannels: t.Fatalf("alice sent new channel to peer a second time") @@ -2384,7 +2392,7 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { } // TestFundingManagerRestartAfterChanAnn checks that the fundingManager properly -// handles receiving a fundingLocked after the its own fundingLocked and channel +// handles receiving a channelReady after the its own channelReady and channel // announcement is sent and gets restarted. func TestFundingManagerRestartAfterChanAnn(t *testing.T) { t.Parallel() @@ -2421,26 +2429,28 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly - assertFundingLockedSent(t, alice, bob, fundingOutPoint) + assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Make sure both fundingManagers send the expected channel // announcements. @@ -2454,7 +2464,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { waitForOpenUpdate(t, updateChan) // At this point we restart Alice's fundingManager, before she receives - // the fundingLocked message. After restart, she will receive it, and + // the channelReady message. After restart, she will receive it, and // we expect her to be able to handle it correctly. recreateAliceFundingManager(t, alice) @@ -2480,10 +2490,10 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { assertNoFwdingPolicy(t, alice, bob, fundingOutPoint) } -// TestFundingManagerRestartAfterReceivingFundingLocked checks that the +// TestFundingManagerRestartAfterReceivingChannelReady checks that the // fundingManager continues to operate as expected after it has received -// fundingLocked and then gets restarted. -func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) { +// channelReady and then gets restarted. +func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { t.Parallel() alice, bob := setupFundingManagers(t) @@ -2518,28 +2528,30 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly - assertFundingLockedSent(t, alice, bob, fundingOutPoint) + assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Let Alice immediately get the fundingLocked message. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) + // Let Alice immediately get the channelReady message. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) - // Also let Bob get the fundingLocked message. - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Also let Bob get the channelReady message. + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // At this point we restart Alice's fundingManager. recreateAliceFundingManager(t, alice) @@ -2611,26 +2623,28 @@ func TestFundingManagerPrivateChannel(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly - assertFundingLockedSent(t, alice, bob, fundingOutPoint) + assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Make sure both fundingManagers send the expected channel // announcements. @@ -2734,26 +2748,28 @@ func TestFundingManagerPrivateRestart(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly - assertFundingLockedSent(t, alice, bob, fundingOutPoint) + assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Make sure both fundingManagers send the expected channel // announcements. @@ -3169,23 +3185,25 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { } // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + // channelReady to Bob. + channelReadyAlice, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + channelReadyBob, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) - // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + // Exchange the channelReady messages. + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) + bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new // channel. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // Make sure both fundingManagers send the expected channel // announcements. @@ -3486,14 +3504,14 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) { Tx: txs[i], } - // Expect both to be sending FundingLocked. + // Expect both to be sending ChannelReady. _ = assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) _ = assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) } @@ -4202,26 +4220,28 @@ func TestFundingManagerZeroConf(t *testing.T) { Index: 0, } - // Assert that Bob's funding_locked message has an AliasScid. - bobFundingLocked := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) - require.NotNil(t, bobFundingLocked.AliasScid) - require.Equal(t, *bobFundingLocked.AliasScid, alias) + // Assert that Bob's channel_ready message has an AliasScid. + bobChannelReady, ok := assertFundingMsgSent( + t, bob.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) + require.NotNil(t, bobChannelReady.AliasScid) + require.Equal(t, *bobChannelReady.AliasScid, alias) // Do the same for Alice as well. - aliceFundingLocked := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) - require.NotNil(t, aliceFundingLocked.AliasScid) - require.Equal(t, *aliceFundingLocked.AliasScid, alias) + aliceChannelReady, ok := assertFundingMsgSent( + t, alice.msgChan, "ChannelReady", + ).(*lnwire.ChannelReady) + require.True(t, ok) + require.NotNil(t, aliceChannelReady.AliasScid) + require.Equal(t, *aliceChannelReady.AliasScid, alias) - // Exchange the funding_locked messages. - alice.fundingMgr.ProcessFundingMsg(bobFundingLocked, bob) - bob.fundingMgr.ProcessFundingMsg(aliceFundingLocked, alice) + // Exchange the channel_ready messages. + alice.fundingMgr.ProcessFundingMsg(bobChannelReady, bob) + bob.fundingMgr.ProcessFundingMsg(aliceChannelReady, alice) // We'll assert that they both create new links. - assertHandleFundingLocked(t, alice, bob) + assertHandleChannelReady(t, alice, bob) // We'll now assert that both sides send ChannelAnnouncement and // ChannelUpdate messages. diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 335ec351f..d2dfc20ab 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -724,12 +724,12 @@ func (l *channelLink) syncChanStates() error { // done any state updates yet, then we'll retransmit the // funding locked message first. We do this, as at this point // we can't be sure if they've really received the - // FundingLocked message. + // ChannelReady message. if remoteChanSyncMsg.NextLocalCommitHeight == 1 && localChanSyncMsg.NextLocalCommitHeight == 1 && !l.channel.IsPending() { - l.log.Infof("resending FundingLocked message to peer") + l.log.Infof("resending ChannelReady message to peer") nextRevocation, err := l.channel.NextRevocationKey() if err != nil { @@ -737,13 +737,13 @@ func (l *channelLink) syncChanStates() error { "revocation: %v", err) } - fundingLockedMsg := lnwire.NewFundingLocked( + channelReadyMsg := lnwire.NewChannelReady( l.ChanID(), nextRevocation, ) // For channels that negotiated the option-scid-alias // feature bit, ensure that we send over the alias in - // the funding_locked message. We'll send the first + // the channel_ready message. We'll send the first // alias we find for the channel since it does not // matter which alias we send. We'll error out if no // aliases are found. @@ -759,13 +759,13 @@ func (l *channelLink) syncChanStates() error { // getAliases returns a copy of the alias slice // so it is ok to use a pointer to the first // entry. - fundingLockedMsg.AliasScid = &aliases[0] + channelReadyMsg.AliasScid = &aliases[0] } - err = l.cfg.Peer.SendMessage(false, fundingLockedMsg) + err = l.cfg.Peer.SendMessage(false, channelReadyMsg) if err != nil { return fmt.Errorf("unable to re-send "+ - "FundingLocked: %v", err) + "ChannelReady: %v", err) } } diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index b58c8a63b..72afa2ebb 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1684,8 +1684,8 @@ func TestChannelLinkSingleHopMessageOrdering(t *testing.T) { {"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false}, - {"alice", "bob", &lnwire.FundingLocked{}, false}, - {"bob", "alice", &lnwire.FundingLocked{}, false}, + {"alice", "bob", &lnwire.ChannelReady{}, false}, + {"bob", "alice", &lnwire.ChannelReady{}, false}, {"alice", "bob", &lnwire.UpdateAddHTLC{}, false}, {"alice", "bob", &lnwire.CommitSig{}, false}, @@ -3303,8 +3303,8 @@ func TestChannelRetransmission(t *testing.T) { {"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false}, - {"alice", "bob", &lnwire.FundingLocked{}, false}, - {"bob", "alice", &lnwire.FundingLocked{}, false}, + {"alice", "bob", &lnwire.ChannelReady{}, false}, + {"bob", "alice", &lnwire.ChannelReady{}, false}, // Send payment from Alice to Bob and intercept // the last revocation message, in this case @@ -3343,8 +3343,8 @@ func TestChannelRetransmission(t *testing.T) { {"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false}, - {"alice", "bob", &lnwire.FundingLocked{}, false}, - {"bob", "alice", &lnwire.FundingLocked{}, false}, + {"alice", "bob", &lnwire.ChannelReady{}, false}, + {"bob", "alice", &lnwire.ChannelReady{}, false}, // Send payment from Alice to Bob and intercept // the last revocation message, in this case @@ -3385,8 +3385,8 @@ func TestChannelRetransmission(t *testing.T) { {"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false}, - {"alice", "bob", &lnwire.FundingLocked{}, false}, - {"bob", "alice", &lnwire.FundingLocked{}, false}, + {"alice", "bob", &lnwire.ChannelReady{}, false}, + {"bob", "alice", &lnwire.ChannelReady{}, false}, // Attempt make a payment from Alice to Bob, // which is intercepted, emulating the Bob @@ -3399,8 +3399,8 @@ func TestChannelRetransmission(t *testing.T) { {"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false}, - {"alice", "bob", &lnwire.FundingLocked{}, false}, - {"bob", "alice", &lnwire.FundingLocked{}, false}, + {"alice", "bob", &lnwire.ChannelReady{}, false}, + {"bob", "alice", &lnwire.ChannelReady{}, false}, // After Bob has notified Alice that he didn't // receive updates Alice should re-send them. @@ -3816,8 +3816,8 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) { {"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false}, - {"alice", "bob", &lnwire.FundingLocked{}, false}, - {"bob", "alice", &lnwire.FundingLocked{}, false}, + {"alice", "bob", &lnwire.ChannelReady{}, false}, + {"bob", "alice", &lnwire.ChannelReady{}, false}, // First fee update. {"alice", "bob", &lnwire.UpdateFee{}, false}, diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 866e7d36f..cec170a35 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -627,7 +627,7 @@ func (s *mockServer) readHandler(message lnwire.Message) error { targetChan = msg.ChanID case *lnwire.CommitSig: targetChan = msg.ChanID - case *lnwire.FundingLocked: + case *lnwire.ChannelReady: // Ignore return nil case *lnwire.ChannelReestablish: diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index b1e134954..099fdb8f6 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -82,7 +82,7 @@ func TestSwitchAddDuplicateLink(t *testing.T) { // TestSwitchHasActiveLink tests the behavior of HasActiveLink, and asserts that // it only returns true if a link's short channel id has confirmed (meaning the // channel is no longer pending) and it's EligibleToForward method returns true, -// i.e. it has received FundingLocked from the remote peer. +// i.e. it has received ChannelReady from the remote peer. func TestSwitchHasActiveLink(t *testing.T) { t.Parallel() diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index e1bd6783a..c1bfb1f55 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -495,7 +495,7 @@ func getChanID(msg lnwire.Message) (lnwire.ChannelID, error) { chanID = msg.ChanID case *lnwire.ChannelReestablish: chanID = msg.ChanID - case *lnwire.FundingLocked: + case *lnwire.ChannelReady: chanID = msg.ChanID case *lnwire.UpdateFee: chanID = msg.ChanID diff --git a/lntest/README.md b/lntest/README.md index be28b218f..5752031ec 100644 --- a/lntest/README.md +++ b/lntest/README.md @@ -101,8 +101,8 @@ the real-world has. Aside from that, `lnd` has several places that use different code, which is triggered by the build flag `integration`, to speed up the tests. They are summarized as followings, -1. `funding.checkPeerFundingLockInterval`, which is used when we wait for the - peer to send us `FundingLocked`. This value is 1 second in `lnd`, and 10 +1. `funding.checkPeerChannelReadyInterval`, which is used when we wait for the + peer to send us `ChannelReady`. This value is 1 second in `lnd`, and 10 milliseconds in `lntest`. 2. `lncfg.ProtocolOptions`, which is used to specify protocol flags. In `lnd`, anchor and script enforced lease are enabled by default, while in `lntest`, diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 97b7ac44d..d715d5ed6 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -4063,7 +4063,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg( // If we get a failure due to not knowing their next // point, then this is fine as they'll either send - // FundingLocked, or revoke their next state to allow + // ChannelReady, or revoke their next state to allow // us to continue forwards. case err == ErrNoWindow: @@ -7220,7 +7220,7 @@ func (lc *LightningChannel) generateRevocation(height uint64) (*lnwire.RevokeAnd // Along with this revocation, we'll also send the _next_ commitment // point that the remote party should use to create our next commitment // transaction. We use a +2 here as we already gave them a look ahead - // of size one after the FundingLocked message was sent: + // of size one after the ChannelReady message was sent: // // 0: current revocation, 1: their "next" revocation, 2: this revocation // diff --git a/lnwire/funding_locked.go b/lnwire/channel_ready.go similarity index 73% rename from lnwire/funding_locked.go rename to lnwire/channel_ready.go index fb47356ba..9027997de 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/channel_ready.go @@ -8,12 +8,12 @@ import ( "github.com/lightningnetwork/lnd/tlv" ) -// FundingLocked is the message that both parties to a new channel creation +// ChannelReady is the message that both parties to a new channel creation // send once they have observed the funding transaction being confirmed on the -// blockchain. FundingLocked contains the signatures necessary for the channel +// blockchain. ChannelReady contains the signatures necessary for the channel // participants to advertise the existence of the channel to the rest of the // network. -type FundingLocked struct { +type ChannelReady struct { // ChanID is the outpoint of the channel's funding transaction. This // can be used to query for the channel in the database. ChanID ChannelID @@ -33,26 +33,26 @@ type FundingLocked struct { ExtraData ExtraOpaqueData } -// NewFundingLocked creates a new FundingLocked message, populating it with the +// NewChannelReady creates a new ChannelReady message, populating it with the // necessary IDs and revocation secret. -func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *FundingLocked { - return &FundingLocked{ +func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady { + return &ChannelReady{ ChanID: cid, NextPerCommitmentPoint: npcp, ExtraData: make([]byte, 0), } } -// A compile time check to ensure FundingLocked implements the lnwire.Message +// A compile time check to ensure ChannelReady implements the lnwire.Message // interface. -var _ Message = (*FundingLocked)(nil) +var _ Message = (*ChannelReady)(nil) -// Decode deserializes the serialized FundingLocked message stored in the -// passed io.Reader into the target FundingLocked using the deserialization +// Decode deserializes the serialized ChannelReady message stored in the +// passed io.Reader into the target ChannelReady using the deserialization // rules defined by the passed protocol version. // // This is part of the lnwire.Message interface. -func (c *FundingLocked) Decode(r io.Reader, pver uint32) error { +func (c *ChannelReady) Decode(r io.Reader, pver uint32) error { // Read all the mandatory fields in the message. err := ReadElements(r, &c.ChanID, @@ -80,12 +80,12 @@ func (c *FundingLocked) Decode(r io.Reader, pver uint32) error { return nil } -// Encode serializes the target FundingLocked message into the passed io.Writer +// Encode serializes the target ChannelReady message into the passed io.Writer // implementation. Serialization will observe the rules defined by the passed // protocol version. // // This is part of the lnwire.Message interface. -func (c *FundingLocked) Encode(w *bytes.Buffer, pver uint32) error { +func (c *ChannelReady) Encode(w *bytes.Buffer, pver uint32) error { if err := WriteChannelID(w, c.ChanID); err != nil { return err } @@ -107,9 +107,9 @@ func (c *FundingLocked) Encode(w *bytes.Buffer, pver uint32) error { } // MsgType returns the uint32 code which uniquely identifies this message as a -// FundingLocked message on the wire. +// ChannelReady message on the wire. // // This is part of the lnwire.Message interface. -func (c *FundingLocked) MsgType() MessageType { - return MsgFundingLocked +func (c *ChannelReady) MsgType() MessageType { + return MsgChannelReady } diff --git a/lnwire/features.go b/lnwire/features.go index c386fd37b..76dab3b05 100644 --- a/lnwire/features.go +++ b/lnwire/features.go @@ -169,12 +169,12 @@ const ( // ScidAliasRequired is a required feature bit that signals that the // node requires understanding of ShortChannelID aliases in the TLV - // segment of the funding_locked message. + // segment of the channel_ready message. ScidAliasRequired FeatureBit = 46 // ScidAliasOptional is an optional feature bit that signals that the // node understands ShortChannelID aliases in the TLV segment of the - // funding_locked message. + // channel_ready message. ScidAliasOptional FeatureBit = 47 // PaymentMetadataRequired is a required bit that denotes that if an diff --git a/lnwire/fuzz_test.go b/lnwire/fuzz_test.go index 34d144c84..f578663a3 100644 --- a/lnwire/fuzz_test.go +++ b/lnwire/fuzz_test.go @@ -286,10 +286,10 @@ func FuzzFundingCreated(f *testing.F) { }) } -func FuzzFundingLocked(f *testing.F) { +func FuzzChannelReady(f *testing.F) { f.Fuzz(func(t *testing.T, data []byte) { - // Prefix with MsgFundingLocked. - data = prefixWithMsgType(data, MsgFundingLocked) + // Prefix with MsgChannelReady. + data = prefixWithMsgType(data, MsgChannelReady) // Pass the message into our general fuzz harness for wire // messages! diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index 96d0c8ae5..1ad93c96b 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -566,8 +566,7 @@ func TestLightningWireProtocol(t *testing.T) { v[0] = reflect.ValueOf(req) }, - MsgFundingLocked: func(v []reflect.Value, r *rand.Rand) { - + MsgChannelReady: func(v []reflect.Value, r *rand.Rand) { var c [32]byte if _, err := r.Read(c[:]); err != nil { t.Fatalf("unable to generate chan id: %v", err) @@ -580,7 +579,7 @@ func TestLightningWireProtocol(t *testing.T) { return } - req := NewFundingLocked(ChannelID(c), pubKey) + req := NewChannelReady(ChannelID(c), pubKey) v[0] = reflect.ValueOf(*req) }, @@ -1013,8 +1012,8 @@ func TestLightningWireProtocol(t *testing.T) { }, }, { - msgType: MsgFundingLocked, - scenario: func(m FundingLocked) bool { + msgType: MsgChannelReady, + scenario: func(m ChannelReady) bool { return mainScenario(&m) }, }, diff --git a/lnwire/message.go b/lnwire/message.go index 2e71173e5..02447b806 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -31,7 +31,7 @@ const ( MsgAcceptChannel = 33 MsgFundingCreated = 34 MsgFundingSigned = 35 - MsgFundingLocked = 36 + MsgChannelReady = 36 MsgShutdown = 38 MsgClosingSigned = 39 MsgUpdateAddHTLC = 128 @@ -88,8 +88,8 @@ func (t MessageType) String() string { return "MsgFundingCreated" case MsgFundingSigned: return "MsgFundingSigned" - case MsgFundingLocked: - return "FundingLocked" + case MsgChannelReady: + return "ChannelReady" case MsgShutdown: return "Shutdown" case MsgClosingSigned: @@ -190,8 +190,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) { msg = &FundingCreated{} case MsgFundingSigned: msg = &FundingSigned{} - case MsgFundingLocked: - msg = &FundingLocked{} + case MsgChannelReady: + msg = &ChannelReady{} case MsgShutdown: msg = &Shutdown{} case MsgClosingSigned: diff --git a/lnwire/message_test.go b/lnwire/message_test.go index 090978a74..f39a88995 100644 --- a/lnwire/message_test.go +++ b/lnwire/message_test.go @@ -268,7 +268,7 @@ func makeAllMessages(t testing.TB, r *rand.Rand) []lnwire.Message { msgAll = append(msgAll, newMsgAcceptChannel(t, r)) msgAll = append(msgAll, newMsgFundingCreated(t, r)) msgAll = append(msgAll, newMsgFundingSigned(t, r)) - msgAll = append(msgAll, newMsgFundingLocked(t, r)) + msgAll = append(msgAll, newMsgChannelReady(t, r)) msgAll = append(msgAll, newMsgShutdown(t, r)) msgAll = append(msgAll, newMsgClosingSigned(t, r)) msgAll = append(msgAll, newMsgUpdateAddHTLC(t, r)) @@ -442,7 +442,7 @@ func newMsgFundingSigned(t testing.TB, r io.Reader) *lnwire.FundingSigned { return msg } -func newMsgFundingLocked(t testing.TB, r io.Reader) *lnwire.FundingLocked { +func newMsgChannelReady(t testing.TB, r io.Reader) *lnwire.ChannelReady { t.Helper() var c [32]byte @@ -452,7 +452,7 @@ func newMsgFundingLocked(t testing.TB, r io.Reader) *lnwire.FundingLocked { pubKey := randPubKey(t) - msg := lnwire.NewFundingLocked(lnwire.ChannelID(c), pubKey) + msg := lnwire.NewChannelReady(lnwire.ChannelID(c), pubKey) msg.ExtraData = createExtraData(t, r) return msg diff --git a/netann/chan_status_manager.go b/netann/chan_status_manager.go index 8f29888e5..8340c202c 100644 --- a/netann/chan_status_manager.go +++ b/netann/chan_status_manager.go @@ -54,7 +54,7 @@ type ChanStatusConfig struct { // IsChannelActive checks whether the channel identified by the provided // ChannelID is considered active. This should only return true if the // channel has been sufficiently confirmed, the channel has received - // FundingLocked, and the remote peer is online. + // ChannelReady, and the remote peer is online. IsChannelActive func(lnwire.ChannelID) bool // ApplyChannelUpdate processes new ChannelUpdates signed by our node by diff --git a/peer/brontide.go b/peer/brontide.go index 09f016851..edc6c6b51 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -717,11 +717,11 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) ( // manager are not aware of each other's states and if // we did not do this, we would accept alias channel // updates after 6 confirmations, which would be buggy. - // We'll queue a funding_locked message with the new + // We'll queue a channel_ready message with the new // alias. This should technically be done *after* the // reestablish, but this behavior is pre-existing since // the funding manager may already queue a - // funding_locked before the channel_reestablish. + // channel_ready before the channel_reestablish. if !dbChan.IsPending { aliasScid, err := p.cfg.RequestAlias() if err != nil { @@ -740,18 +740,18 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) ( ) // Fetch the second commitment point to send in - // the funding_locked message. + // the channel_ready message. second, err := dbChan.SecondCommitmentPoint() if err != nil { return nil, err } - fundingLockedMsg := lnwire.NewFundingLocked( + channelReadyMsg := lnwire.NewChannelReady( chanID, second, ) - fundingLockedMsg.AliasScid = &aliasScid + channelReadyMsg.AliasScid = &aliasScid - msgs = append(msgs, fundingLockedMsg) + msgs = append(msgs, channelReadyMsg) } // If we've negotiated the option-scid-alias feature @@ -1549,7 +1549,7 @@ out: *lnwire.AcceptChannel, *lnwire.FundingCreated, *lnwire.FundingSigned, - *lnwire.FundingLocked: + *lnwire.ChannelReady: p.cfg.FundingManager.ProcessFundingMsg(msg, p) @@ -1798,7 +1798,7 @@ func messageSummary(msg lnwire.Message) string { case *lnwire.FundingSigned: return fmt.Sprintf("chan_id=%v", msg.ChanID) - case *lnwire.FundingLocked: + case *lnwire.ChannelReady: return fmt.Sprintf("chan_id=%v, next_point=%x", msg.ChanID, msg.NextPerCommitmentPoint.SerializeCompressed()) @@ -2376,7 +2376,7 @@ out: } p.log.Infof("Processing retransmitted "+ - "FundingLocked for ChannelPoint(%v)", + "ChannelReady for ChannelPoint(%v)", chanPoint) nextRevoke := newChan.RemoteNextRevocation