From 1b7c56b2ed1fea1a136762ee68bc6f4c82657ddc Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 04:42:21 +0800 Subject: [PATCH 01/12] multi: rename `FundingLocked` to `ChannelReady` This commit is created by running, ```shell gofmt -d -w -r 'FundingLocked -> ChannelReady' . gco master channeldb/migration ``` --- funding/manager.go | 4 ++-- funding/manager_test.go | 46 ++++++++++++++++++++-------------------- htlcswitch/link_test.go | 24 ++++++++++----------- htlcswitch/mock.go | 2 +- htlcswitch/test_utils.go | 2 +- lnwire/funding_locked.go | 14 ++++++------ lnwire/lnwire_test.go | 2 +- lnwire/message.go | 2 +- lnwire/message_test.go | 2 +- peer/brontide.go | 4 ++-- 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index 2d702ba48..113a30343 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -889,7 +889,7 @@ 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) @@ -3394,7 +3394,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, - msg *lnwire.FundingLocked) { + msg *lnwire.ChannelReady) { defer f.wg.Done() log.Debugf("Received FundingLocked for ChannelID(%v) from "+ diff --git a/funding/manager_test.go b/funding/manager_test.go index f386e3de5..0d33e60bb 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -901,7 +901,7 @@ func assertFundingMsgSent(t *testing.T, msgChan chan lnwire.Message, case "FundingSigned": sentMsg, ok = msg.(*lnwire.FundingSigned) case "FundingLocked": - sentMsg, ok = msg.(*lnwire.FundingLocked) + sentMsg, ok = msg.(*lnwire.ChannelReady) case "Error": sentMsg, ok = msg.(*lnwire.Error) default: @@ -1408,12 +1408,12 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly assertFundingLockedSent(t, alice, bob, fundingOutPoint) @@ -1679,7 +1679,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { // Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) @@ -1708,7 +1708,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // The state should now be fundingLockedSent assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) @@ -1836,7 +1836,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { // Bob will send funding locked to Alice fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) @@ -1884,7 +1884,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { // This should make Alice send the fundingLocked. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // The state should now be fundingLockedSent assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) @@ -2313,12 +2313,12 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly assertFundingLockedSent(t, alice, bob, fundingOutPoint) @@ -2424,12 +2424,12 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly assertFundingLockedSent(t, alice, bob, fundingOutPoint) @@ -2521,12 +2521,12 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly assertFundingLockedSent(t, alice, bob, fundingOutPoint) @@ -2614,12 +2614,12 @@ func TestFundingManagerPrivateChannel(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly assertFundingLockedSent(t, alice, bob, fundingOutPoint) @@ -2737,12 +2737,12 @@ func TestFundingManagerPrivateRestart(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly assertFundingLockedSent(t, alice, bob, fundingOutPoint) @@ -3172,12 +3172,12 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { // fundingLocked to Bob. fundingLockedAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. fundingLockedBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) // Exchange the fundingLocked messages. alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) @@ -3489,11 +3489,11 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) { // Expect both to be sending FundingLocked. _ = assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) _ = assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) } @@ -4205,14 +4205,14 @@ func TestFundingManagerZeroConf(t *testing.T) { // Assert that Bob's funding_locked message has an AliasScid. bobFundingLocked := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) require.NotNil(t, bobFundingLocked.AliasScid) require.Equal(t, *bobFundingLocked.AliasScid, alias) // Do the same for Alice as well. aliceFundingLocked := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", - ).(*lnwire.FundingLocked) + ).(*lnwire.ChannelReady) require.NotNil(t, aliceFundingLocked.AliasScid) require.Equal(t, *aliceFundingLocked.AliasScid, alias) 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/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/lnwire/funding_locked.go b/lnwire/funding_locked.go index fb47356ba..ab741433d 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/funding_locked.go @@ -13,7 +13,7 @@ import ( // blockchain. FundingLocked 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 @@ -35,8 +35,8 @@ type FundingLocked struct { // NewFundingLocked creates a new FundingLocked message, populating it with the // necessary IDs and revocation secret. -func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *FundingLocked { - return &FundingLocked{ +func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady { + return &ChannelReady{ ChanID: cid, NextPerCommitmentPoint: npcp, ExtraData: make([]byte, 0), @@ -45,14 +45,14 @@ func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *FundingLocked { // A compile time check to ensure FundingLocked 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 // 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, @@ -85,7 +85,7 @@ func (c *FundingLocked) Decode(r io.Reader, pver uint32) error { // 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 } @@ -110,6 +110,6 @@ func (c *FundingLocked) Encode(w *bytes.Buffer, pver uint32) error { // FundingLocked message on the wire. // // This is part of the lnwire.Message interface. -func (c *FundingLocked) MsgType() MessageType { +func (c *ChannelReady) MsgType() MessageType { return MsgFundingLocked } diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index 96d0c8ae5..d4b4e7dab 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -1014,7 +1014,7 @@ func TestLightningWireProtocol(t *testing.T) { }, { msgType: MsgFundingLocked, - scenario: func(m FundingLocked) bool { + scenario: func(m ChannelReady) bool { return mainScenario(&m) }, }, diff --git a/lnwire/message.go b/lnwire/message.go index 2e71173e5..7ededf595 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -191,7 +191,7 @@ func makeEmptyMessage(msgType MessageType) (Message, error) { case MsgFundingSigned: msg = &FundingSigned{} case MsgFundingLocked: - msg = &FundingLocked{} + msg = &ChannelReady{} case MsgShutdown: msg = &Shutdown{} case MsgClosingSigned: diff --git a/lnwire/message_test.go b/lnwire/message_test.go index 090978a74..b016fc35c 100644 --- a/lnwire/message_test.go +++ b/lnwire/message_test.go @@ -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 newMsgFundingLocked(t testing.TB, r io.Reader) *lnwire.ChannelReady { t.Helper() var c [32]byte diff --git a/peer/brontide.go b/peer/brontide.go index 9ea85edd1..fda3f01e1 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -1545,7 +1545,7 @@ out: *lnwire.AcceptChannel, *lnwire.FundingCreated, *lnwire.FundingSigned, - *lnwire.FundingLocked: + *lnwire.ChannelReady: p.cfg.FundingManager.ProcessFundingMsg(msg, p) @@ -1794,7 +1794,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()) From c8e835891811eb219a1fa5b071f886f551a1b79d Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 04:44:15 +0800 Subject: [PATCH 02/12] channeldb+lnwire: rename `MsgFundingLocked` to `MsgChannelReady` This commit is created by running, ```shell gofmt -d -w -r 'MsgFundingLocked -> MsgChannelReady' . gco master channeldb/migration ``` --- lnwire/funding_locked.go | 2 +- lnwire/fuzz_test.go | 2 +- lnwire/lnwire_test.go | 4 ++-- lnwire/message.go | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lnwire/funding_locked.go b/lnwire/funding_locked.go index ab741433d..e2625f48b 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/funding_locked.go @@ -111,5 +111,5 @@ func (c *ChannelReady) Encode(w *bytes.Buffer, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *ChannelReady) MsgType() MessageType { - return MsgFundingLocked + return MsgChannelReady } diff --git a/lnwire/fuzz_test.go b/lnwire/fuzz_test.go index 34d144c84..bd1995eab 100644 --- a/lnwire/fuzz_test.go +++ b/lnwire/fuzz_test.go @@ -289,7 +289,7 @@ func FuzzFundingCreated(f *testing.F) { func FuzzFundingLocked(f *testing.F) { f.Fuzz(func(t *testing.T, data []byte) { // Prefix with MsgFundingLocked. - data = prefixWithMsgType(data, MsgFundingLocked) + 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 d4b4e7dab..d55b4efda 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -566,7 +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 { @@ -1013,7 +1013,7 @@ func TestLightningWireProtocol(t *testing.T) { }, }, { - msgType: MsgFundingLocked, + msgType: MsgChannelReady, scenario: func(m ChannelReady) bool { return mainScenario(&m) }, diff --git a/lnwire/message.go b/lnwire/message.go index 7ededf595..ad065bb46 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,7 +88,7 @@ func (t MessageType) String() string { return "MsgFundingCreated" case MsgFundingSigned: return "MsgFundingSigned" - case MsgFundingLocked: + case MsgChannelReady: return "FundingLocked" case MsgShutdown: return "Shutdown" @@ -190,7 +190,7 @@ func makeEmptyMessage(msgType MessageType) (Message, error) { msg = &FundingCreated{} case MsgFundingSigned: msg = &FundingSigned{} - case MsgFundingLocked: + case MsgChannelReady: msg = &ChannelReady{} case MsgShutdown: msg = &Shutdown{} From 2dc08a2a7629cd301da387771b3ec101b06f339c Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 04:46:30 +0800 Subject: [PATCH 03/12] multi: rename `NewFundingLocked` to `NewChannelReady` This commit is created by the following command, ```shell gofmt -d -w -r 'NewFundingLocked -> NewChannelReady' . ``` --- funding/manager.go | 4 ++-- htlcswitch/link.go | 2 +- lnwire/funding_locked.go | 2 +- lnwire/lnwire_test.go | 2 +- lnwire/message_test.go | 2 +- peer/brontide.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index 113a30343..edd56b712 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -2909,7 +2909,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) + fundingLockedMsg := 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 @@ -3517,7 +3517,7 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer, return } - fundingLockedMsg := lnwire.NewFundingLocked( + fundingLockedMsg := lnwire.NewChannelReady( chanID, secondPoint, ) fundingLockedMsg.AliasScid = &alias diff --git a/htlcswitch/link.go b/htlcswitch/link.go index b1836c7c7..2ef8d1f93 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -734,7 +734,7 @@ func (l *channelLink) syncChanStates() error { "revocation: %v", err) } - fundingLockedMsg := lnwire.NewFundingLocked( + fundingLockedMsg := lnwire.NewChannelReady( l.ChanID(), nextRevocation, ) diff --git a/lnwire/funding_locked.go b/lnwire/funding_locked.go index e2625f48b..0995f91d3 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/funding_locked.go @@ -35,7 +35,7 @@ type ChannelReady struct { // NewFundingLocked creates a new FundingLocked message, populating it with the // necessary IDs and revocation secret. -func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady { +func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady { return &ChannelReady{ ChanID: cid, NextPerCommitmentPoint: npcp, diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index d55b4efda..baefa4a6a 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -580,7 +580,7 @@ func TestLightningWireProtocol(t *testing.T) { return } - req := NewFundingLocked(ChannelID(c), pubKey) + req := NewChannelReady(ChannelID(c), pubKey) v[0] = reflect.ValueOf(*req) }, diff --git a/lnwire/message_test.go b/lnwire/message_test.go index b016fc35c..1d540455f 100644 --- a/lnwire/message_test.go +++ b/lnwire/message_test.go @@ -452,7 +452,7 @@ func newMsgFundingLocked(t testing.TB, r io.Reader) *lnwire.ChannelReady { 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/peer/brontide.go b/peer/brontide.go index fda3f01e1..7064805f7 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -746,7 +746,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) ( return nil, err } - fundingLockedMsg := lnwire.NewFundingLocked( + fundingLockedMsg := lnwire.NewChannelReady( chanID, second, ) fundingLockedMsg.AliasScid = &aliasScid From 112dc1faca3a7e4a517684712524177e0d6eab6d Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 04:58:04 +0800 Subject: [PATCH 04/12] 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' . ``` --- funding/config_integration.go | 2 +- funding/manager.go | 64 +++++++++++++++++------------------ funding/manager_test.go | 12 +++---- 3 files changed, 39 insertions(+), 39 deletions(-) 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/manager.go b/funding/manager.go index edd56b712..ba43c3ad0 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -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" @@ -617,16 +617,16 @@ 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 } @@ -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() diff --git a/funding/manager_test.go b/funding/manager_test.go index 0d33e60bb..b7a17171b 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -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) From 539cae19999f8ea639c6ecee0175d340f88e5024 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 05:00:17 +0800 Subject: [PATCH 05/12] multi: rename `fundingLockedMsg` to `channelReadyMsg` This commit is created by running, ```shell gofmt -d -w -r 'fundingLockedMsg -> channelReadyMsg' . ``` --- funding/manager.go | 18 +++++++++--------- htlcswitch/link.go | 6 +++--- peer/brontide.go | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index ba43c3ad0..9190a2778 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -2909,7 +2909,7 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, if err != nil { return fmt.Errorf("unable to create next revocation: %v", err) } - fundingLockedMsg := lnwire.NewChannelReady(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,7 +2926,7 @@ func (f *Manager) sendChannelReady(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 @@ -2956,7 +2956,7 @@ func (f *Manager) sendChannelReady(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 @@ -2983,16 +2983,16 @@ func (f *Manager) sendChannelReady(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 "+ "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 @@ -3517,12 +3517,12 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, return } - fundingLockedMsg := lnwire.NewChannelReady( + 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) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 2ef8d1f93..1151286ee 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -734,7 +734,7 @@ func (l *channelLink) syncChanStates() error { "revocation: %v", err) } - fundingLockedMsg := lnwire.NewChannelReady( + channelReadyMsg := lnwire.NewChannelReady( l.ChanID(), nextRevocation, ) @@ -756,10 +756,10 @@ 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) diff --git a/peer/brontide.go b/peer/brontide.go index 7064805f7..7e838a62c 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -746,12 +746,12 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) ( return nil, err } - fundingLockedMsg := lnwire.NewChannelReady( + 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 From 015446559bf7fbdc9db5c0feb1294049467f1c90 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 05:04:26 +0800 Subject: [PATCH 06/12] funding+lnwire: rename `FundingLocked` related tests This commit is created by running the following commands, ```shell gofmt -d -w -r 'fundingLockedAlice -> channelReadyAlice' . gofmt -d -w -r 'fundingLockedBob -> channelReadyBob' . gofmt -d -w -r 'assertHandleFundingLocked -> assertHandleChannelReady' . gofmt -d -w -r 'assertFundingLockedSent -> assertChannelReadySent' . gofmt -d -w -r 'aliceFundingLocked -> aliceChannelReady' . gofmt -d -w -r 'bobFundingLocked -> bobChannelReady' . gofmt -d -w -r 'FuzzFundingLocked -> FuzzChannelReady' . gofmt -d -w -r 'newMsgFundingLocked -> newMsgChannelReady' . gofmt -d -w -r 'TestFundingManagerReceiveFundingLockedTwice -> TestFundingManagerReceiveChannelReadyTwice' . gofmt -d -w -r 'TestFundingManagerRestartAfterReceivingFundingLocked -> TestFundingManagerRestartAfterReceivingChannelReady' . ``` --- funding/manager_test.go | 132 ++++++++++++++++++++-------------------- lnwire/fuzz_test.go | 2 +- lnwire/message_test.go | 4 +- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/funding/manager_test.go b/funding/manager_test.go index b7a17171b..967669a22 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -1050,7 +1050,7 @@ 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() @@ -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. @@ -1406,25 +1406,25 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // 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) + 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. @@ -1677,7 +1677,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { } // Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) @@ -1706,7 +1706,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { return errChan } - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) @@ -1723,12 +1723,12 @@ func TestFundingManagerRestartBehavior(t *testing.T) { } // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + 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. @@ -1834,7 +1834,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { } // Bob will send funding locked to Alice - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) @@ -1882,7 +1882,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { con <- bob // This should make Alice send the fundingLocked. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) @@ -1890,12 +1890,12 @@ func TestFundingManagerOfflinePeer(t *testing.T) { assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + 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. @@ -2275,7 +2275,7 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) { // TestFundingManagerReceiveFundingLockedTwice checks that the fundingManager // continues to operate as expected in case we receive a duplicate fundingLocked // message. -func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { +func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { t.Parallel() alice, bob := setupFundingManagers(t) @@ -2311,26 +2311,26 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // 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) + 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. @@ -2343,7 +2343,7 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { // Another fundingLocked 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") @@ -2422,25 +2422,25 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // 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) + 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. @@ -2483,7 +2483,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // TestFundingManagerRestartAfterReceivingFundingLocked checks that the // fundingManager continues to operate as expected after it has received // fundingLocked and then gets restarted. -func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) { +func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { t.Parallel() alice, bob := setupFundingManagers(t) @@ -2519,27 +2519,27 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // 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) + alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) // Also let Bob get the fundingLocked message. - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + 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) @@ -2612,25 +2612,25 @@ func TestFundingManagerPrivateChannel(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // 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) + 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. @@ -2735,25 +2735,25 @@ func TestFundingManagerPrivateRestart(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // 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) + 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. @@ -3170,22 +3170,22 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. - fundingLockedAlice := assertFundingMsgSent( + channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. - fundingLockedBob := assertFundingMsgSent( + channelReadyBob := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) // Exchange the fundingLocked messages. - alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) - bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) + 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. @@ -4203,25 +4203,25 @@ func TestFundingManagerZeroConf(t *testing.T) { } // Assert that Bob's funding_locked message has an AliasScid. - bobFundingLocked := assertFundingMsgSent( + bobChannelReady := assertFundingMsgSent( t, bob.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) - require.NotNil(t, bobFundingLocked.AliasScid) - require.Equal(t, *bobFundingLocked.AliasScid, alias) + require.NotNil(t, bobChannelReady.AliasScid) + require.Equal(t, *bobChannelReady.AliasScid, alias) // Do the same for Alice as well. - aliceFundingLocked := assertFundingMsgSent( + aliceChannelReady := assertFundingMsgSent( t, alice.msgChan, "FundingLocked", ).(*lnwire.ChannelReady) - require.NotNil(t, aliceFundingLocked.AliasScid) - require.Equal(t, *aliceFundingLocked.AliasScid, alias) + 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) + 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/lnwire/fuzz_test.go b/lnwire/fuzz_test.go index bd1995eab..7e3823773 100644 --- a/lnwire/fuzz_test.go +++ b/lnwire/fuzz_test.go @@ -286,7 +286,7 @@ 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, MsgChannelReady) diff --git a/lnwire/message_test.go b/lnwire/message_test.go index 1d540455f..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.ChannelReady { +func newMsgChannelReady(t testing.TB, r io.Reader) *lnwire.ChannelReady { t.Helper() var c [32]byte From f8a8326141cf234b02e345185b1f266f25094a48 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 05:36:58 +0800 Subject: [PATCH 07/12] multi: replace `FundingLocked` and `funding_locked` strings This commit is created by running the following commands, ```shell find . -name "*.go" -exec sed -i '' 's/\"FundingLocked/\"ChannelReady/g' {} \; find . -name "*.go" -exec sed -i '' 's/FundingLocked\"/ChannelReady\"/g' {} \; find . -name "*.go" -exec sed -i '' 's/\ funding_locked/\ channel_ready/g' {} \; ``` --- aliasmgr/aliasmgr.go | 6 ++--- channeldb/channel.go | 2 +- funding/interfaces.go | 6 ++--- funding/manager.go | 18 +++++++-------- funding/manager_test.go | 50 ++++++++++++++++++++--------------------- htlcswitch/link.go | 6 ++--- lnwire/features.go | 4 ++-- lnwire/message.go | 2 +- peer/brontide.go | 8 +++---- 9 files changed, 51 insertions(+), 51 deletions(-) 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..ed09605ef 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() 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 9190a2778..7faeb098c 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -1022,7 +1022,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, } log.Debugf("Channel(%v) with ShortChanID %v: successfully "+ - "sent FundingLocked", chanID, shortChanID) + "sent ChannelReady", chanID, shortChanID) return nil @@ -1054,7 +1054,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. @@ -2963,7 +2963,7 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, // alias feature was negotiated, check if we already // have an alias stored in case handleFundingLocked 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, @@ -2989,7 +2989,7 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, } } - 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, channelReadyMsg); err == nil { @@ -3028,7 +3028,7 @@ func (f *Manager) receivedChannelReady(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 } @@ -3397,7 +3397,7 @@ 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()) @@ -3487,14 +3487,14 @@ func (f *Manager) handleChannelReady(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 + // channel_ready message here in case the link is created // before sendFundingLocked 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) @@ -3535,7 +3535,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, // already processed fundingLocked 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 diff --git a/funding/manager_test.go b/funding/manager_test.go index 967669a22..fe358e673 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -900,7 +900,7 @@ func assertFundingMsgSent(t *testing.T, msgChan chan lnwire.Message, sentMsg, ok = msg.(*lnwire.FundingCreated) case "FundingSigned": sentMsg, ok = msg.(*lnwire.FundingSigned) - case "FundingLocked": + case "ChannelReady": sentMsg, ok = msg.(*lnwire.ChannelReady) case "Error": sentMsg, ok = msg.(*lnwire.Error) @@ -1407,12 +1407,12 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly @@ -1678,7 +1678,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { // Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Alice should still be markedOpen @@ -1707,7 +1707,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { } channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // The state should now be fundingLockedSent @@ -1835,7 +1835,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { // Bob will send funding locked to Alice channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Alice should still be markedOpen @@ -1883,7 +1883,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { // This should make Alice send the fundingLocked. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // The state should now be fundingLockedSent @@ -2312,12 +2312,12 @@ func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly @@ -2423,12 +2423,12 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly @@ -2520,12 +2520,12 @@ func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly @@ -2613,12 +2613,12 @@ func TestFundingManagerPrivateChannel(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly @@ -2736,12 +2736,12 @@ func TestFundingManagerPrivateRestart(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Check that the state machine is updated accordingly @@ -3171,12 +3171,12 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { // After the funding transaction is mined, Alice will send // fundingLocked to Bob. channelReadyAlice := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // And similarly Bob will send funding locked to Alice. channelReadyBob := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) // Exchange the fundingLocked messages. @@ -3488,11 +3488,11 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) { // Expect both to be sending FundingLocked. _ = assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) _ = assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) } @@ -4202,21 +4202,21 @@ func TestFundingManagerZeroConf(t *testing.T) { Index: 0, } - // Assert that Bob's funding_locked message has an AliasScid. + // Assert that Bob's channel_ready message has an AliasScid. bobChannelReady := assertFundingMsgSent( - t, bob.msgChan, "FundingLocked", + t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) require.NotNil(t, bobChannelReady.AliasScid) require.Equal(t, *bobChannelReady.AliasScid, alias) // Do the same for Alice as well. aliceChannelReady := assertFundingMsgSent( - t, alice.msgChan, "FundingLocked", + t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) require.NotNil(t, aliceChannelReady.AliasScid) require.Equal(t, *aliceChannelReady.AliasScid, alias) - // Exchange the funding_locked messages. + // Exchange the channel_ready messages. alice.fundingMgr.ProcessFundingMsg(bobChannelReady, bob) bob.fundingMgr.ProcessFundingMsg(aliceChannelReady, alice) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 1151286ee..20aa90bb7 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -726,7 +726,7 @@ func (l *channelLink) syncChanStates() error { 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 { @@ -740,7 +740,7 @@ func (l *channelLink) syncChanStates() error { // 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. @@ -762,7 +762,7 @@ func (l *channelLink) syncChanStates() error { 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/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/message.go b/lnwire/message.go index ad065bb46..02447b806 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -89,7 +89,7 @@ func (t MessageType) String() string { case MsgFundingSigned: return "MsgFundingSigned" case MsgChannelReady: - return "FundingLocked" + return "ChannelReady" case MsgShutdown: return "Shutdown" case MsgClosingSigned: diff --git a/peer/brontide.go b/peer/brontide.go index 7e838a62c..063e82c56 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,7 +740,7 @@ 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 @@ -2372,7 +2372,7 @@ out: } p.log.Infof("Processing retransmitted "+ - "FundingLocked for ChannelPoint(%v)", + "ChannelReady for ChannelPoint(%v)", chanPoint) nextRevoke := newChan.RemoteNextRevocation From 6b9217acfcb4aa69c4492c81a14ae4162b9ef5ef Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 05:45:14 +0800 Subject: [PATCH 08/12] multi: replace `FundingLocked` related docs This commit replaces `FundingLocked` found in docs using the following command, ```shell find . -name "*.go" -exec sed -i '' 's/FundingLocked/ChannelReady/g' {} \; find . -name "*.go" -exec sed -i '' 's/FundingLock/ChannelReady/g' {} \; ``` --- channeldb/channel.go | 2 +- funding/manager.go | 22 +++++++++++----------- funding/manager_test.go | 12 ++++++------ htlcswitch/link.go | 2 +- htlcswitch/switch_test.go | 2 +- lntest/README.md | 4 ++-- lnwallet/channel.go | 4 ++-- lnwire/funding_locked.go | 16 ++++++++-------- lnwire/fuzz_test.go | 2 +- netann/chan_status_manager.go | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index ed09605ef..b731028ee 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -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/funding/manager.go b/funding/manager.go index 7faeb098c..c43b99830 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -40,8 +40,8 @@ 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. @@ -1040,9 +1040,9 @@ 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(checkPeerChannelReadyInterval): case <-f.quit: @@ -1213,7 +1213,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,7 +2890,7 @@ func (f *Manager) handleFundingConfirmation( return nil } -// sendFundingLocked creates and sends the fundingLocked message. +// sendChannelReady 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) sendChannelReady(completeChan *channeldb.OpenChannel, @@ -2961,7 +2961,7 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, // 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 // channel_ready. Otherwise, request and store an // alias and use that. @@ -3005,7 +3005,7 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, 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) receivedChannelReady(node *btcec.PublicKey, chanID lnwire.ChannelID) (bool, error) { @@ -3391,7 +3391,7 @@ 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) handleChannelReady(peer lnpeer.Peer, msg *lnwire.ChannelReady) { @@ -3464,7 +3464,7 @@ func (f *Manager) handleChannelReady(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 @@ -3488,7 +3488,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, // 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 // channel_ready message here in case the link is created - // before sendFundingLocked is called. + // before sendChannelReady is called. aliases := f.cfg.AliasManager.GetAliases( channel.ShortChannelID, ) diff --git a/funding/manager_test.go b/funding/manager_test.go index fe358e673..8779dd7b4 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -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: @@ -1868,7 +1868,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) { @@ -2272,7 +2272,7 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) { assertNumPendingChannelsBecomes(t, bob, 0) } -// TestFundingManagerReceiveFundingLockedTwice checks that the fundingManager +// TestFundingManagerReceiveChannelReadyTwice checks that the fundingManager // continues to operate as expected in case we receive a duplicate fundingLocked // message. func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { @@ -2480,7 +2480,7 @@ 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 TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { @@ -3486,7 +3486,7 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) { Tx: txs[i], } - // Expect both to be sending FundingLocked. + // Expect both to be sending ChannelReady. _ = assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 20aa90bb7..2b158d7dc 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -721,7 +721,7 @@ 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() { 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/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/funding_locked.go index 0995f91d3..9027997de 100644 --- a/lnwire/funding_locked.go +++ b/lnwire/funding_locked.go @@ -8,9 +8,9 @@ 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 ChannelReady struct { @@ -33,7 +33,7 @@ type ChannelReady 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 NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady { return &ChannelReady{ @@ -43,12 +43,12 @@ func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady { } } -// 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 = (*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. @@ -80,7 +80,7 @@ func (c *ChannelReady) 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. // @@ -107,7 +107,7 @@ func (c *ChannelReady) 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 *ChannelReady) MsgType() MessageType { diff --git a/lnwire/fuzz_test.go b/lnwire/fuzz_test.go index 7e3823773..f578663a3 100644 --- a/lnwire/fuzz_test.go +++ b/lnwire/fuzz_test.go @@ -288,7 +288,7 @@ func FuzzFundingCreated(f *testing.F) { func FuzzChannelReady(f *testing.F) { f.Fuzz(func(t *testing.T, data []byte) { - // Prefix with MsgFundingLocked. + // Prefix with MsgChannelReady. data = prefixWithMsgType(data, MsgChannelReady) // Pass the message into our general fuzz harness for wire 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 From 465285efb81a5788818df71ceaec717a5aeca77a Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 05:52:35 +0800 Subject: [PATCH 09/12] funding: replace `fundingLocked` with `channelReady` --- funding/manager.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index c43b99830..fa6833e4f 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -605,7 +605,7 @@ func (c channelOpeningState) String() string { case markedOpen: return "markedOpen" case channelReadySent: - return "fundingLocked" + return "channelReady" case addedToRouterGraph: return "addedToRouterGraph" default: @@ -1004,7 +1004,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, case markedOpen: err := f.sendChannelReady(channel, lnChannel) if err != nil { - return fmt.Errorf("failed sending fundingLocked: %v", + return fmt.Errorf("failed sending channelReady: %v", err) } @@ -1018,7 +1018,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, ) 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 "+ @@ -2998,7 +2998,7 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, 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) } @@ -3406,7 +3406,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, 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.handleChannelReadyMtx.Unlock() return @@ -3541,7 +3541,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, // 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 } From d4ad5f362f4b8e811856aeffe5981b3c43fbac75 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 05:55:02 +0800 Subject: [PATCH 10/12] funding: replace `fundingLocked` found in docs This commit is created by running, ```shell find . -name "*.go" -exec sed -i '' 's/fundingLocked/channelReady/g' {} \; ``` --- funding/manager.go | 34 ++++++++++----------- funding/manager_test.go | 68 ++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/funding/manager.go b/funding/manager.go index fa6833e4f..05b3e2bcb 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -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. @@ -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. 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 ) @@ -1000,7 +1000,7 @@ 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.sendChannelReady(channel, lnChannel) if err != nil { @@ -1008,7 +1008,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, 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. @@ -1026,7 +1026,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel, 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 channelReadySent: // We must wait until we've received the peer's funding locked @@ -2890,7 +2890,7 @@ func (f *Manager) handleFundingConfirmation( return nil } -// sendChannelReady 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) sendChannelReady(completeChan *channeldb.OpenChannel, @@ -2930,15 +2930,15 @@ func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel, } // 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) @@ -3140,7 +3140,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 @@ -3412,7 +3412,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, 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.handleChannelReadyBarriers[msg.ChanID] = struct{}{} f.handleChannelReadyMtx.Unlock() @@ -3532,7 +3532,7 @@ func (f *Manager) handleChannelReady(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 // channel_ready messages use the same per commitment point (the diff --git a/funding/manager_test.go b/funding/manager_test.go index 8779dd7b4..15ff462ac 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -1405,7 +1405,7 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -1418,7 +1418,7 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) @@ -1635,7 +1635,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 +1666,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 { @@ -1684,11 +1684,11 @@ func TestFundingManagerRestartBehavior(t *testing.T) { // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) - // While Bob successfully sent fundingLocked. + // 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 { @@ -1710,7 +1710,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) - // The state should now be fundingLockedSent + // The state should now be channelReadySent assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) // Check that the channel announcements were never sent @@ -1722,7 +1722,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) { // Expected } - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) @@ -1771,7 +1771,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 +1791,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 +1823,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 { @@ -1841,7 +1841,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) { // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) - // While Bob successfully sent fundingLocked. + // While Bob successfully sent channelReady. assertDatabaseState(t, bob, fundingOutPoint, channelReadySent) // Alice should be waiting for the server to notify when Bob comes back @@ -1881,15 +1881,15 @@ func TestFundingManagerOfflinePeer(t *testing.T) { bob.sendMessage = workingSendMessage con <- bob - // This should make Alice send the fundingLocked. + // This should make Alice send the channelReady. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) - // The state should now be fundingLockedSent + // The state should now be channelReadySent assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) @@ -2273,7 +2273,7 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) { } // TestFundingManagerReceiveChannelReadyTwice checks that the fundingManager -// continues to operate as expected in case we receive a duplicate fundingLocked +// continues to operate as expected in case we receive a duplicate channelReady // message. func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { t.Parallel() @@ -2310,7 +2310,7 @@ func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -2323,7 +2323,7 @@ func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Send the fundingLocked message twice to Alice, and once to Bob. + // 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) @@ -2341,7 +2341,7 @@ func TestFundingManagerReceiveChannelReadyTwice(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(channelReadyBob, bob) select { @@ -2384,7 +2384,7 @@ func TestFundingManagerReceiveChannelReadyTwice(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,7 +2421,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -2434,7 +2434,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) @@ -2454,7 +2454,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) @@ -2482,7 +2482,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // TestFundingManagerRestartAfterReceivingChannelReady checks that the // fundingManager continues to operate as expected after it has received -// fundingLocked and then gets restarted. +// channelReady and then gets restarted. func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { t.Parallel() @@ -2518,7 +2518,7 @@ func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -2531,10 +2531,10 @@ func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Let Alice immediately get the fundingLocked message. + // Let Alice immediately get the channelReady message. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) - // Also let Bob get the fundingLocked message. + // Also let Bob get the channelReady message. bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) // Check that they notify the breach arbiter and peer about the new @@ -2611,7 +2611,7 @@ func TestFundingManagerPrivateChannel(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -2624,7 +2624,7 @@ func TestFundingManagerPrivateChannel(t *testing.T) { // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) @@ -2734,7 +2734,7 @@ func TestFundingManagerPrivateRestart(t *testing.T) { assertMarkedOpen(t, alice, bob, fundingOutPoint) // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -2747,7 +2747,7 @@ func TestFundingManagerPrivateRestart(t *testing.T) { // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) @@ -3169,7 +3169,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { } // After the funding transaction is mined, Alice will send - // fundingLocked to Bob. + // channelReady to Bob. channelReadyAlice := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) @@ -3179,7 +3179,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) - // Exchange the fundingLocked messages. + // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice) From dc3f83c670ca1db90fabfb3270f41d378473de00 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 06:04:27 +0800 Subject: [PATCH 11/12] funding+lnwire: rename and fix make lint Fix linter and rename `funding_locked.go` to `channel_ready.go` --- funding/manager.go | 34 +++++++---- funding/manager_test.go | 60 ++++++++++++------- .../{funding_locked.go => channel_ready.go} | 0 lnwire/lnwire_test.go | 1 - 4 files changed, 64 insertions(+), 31 deletions(-) rename lnwire/{funding_locked.go => channel_ready.go} (100%) diff --git a/funding/manager.go b/funding/manager.go index 05b3e2bcb..83c9a1d21 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -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{}), - handleChannelReadyBarriers: 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 } diff --git a/funding/manager_test.go b/funding/manager_test.go index 15ff462ac..dc40c4d8f 100644 --- a/funding/manager_test.go +++ b/funding/manager_test.go @@ -1406,14 +1406,16 @@ func TestFundingManagerNormalWorkflow(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) @@ -1677,9 +1679,10 @@ func TestFundingManagerRestartBehavior(t *testing.T) { } // Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) @@ -1706,9 +1709,10 @@ func TestFundingManagerRestartBehavior(t *testing.T) { return errChan } - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // The state should now be channelReadySent assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) @@ -1834,9 +1838,10 @@ func TestFundingManagerOfflinePeer(t *testing.T) { } // Bob will send funding locked to Alice - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Alice should still be markedOpen assertDatabaseState(t, alice, fundingOutPoint, markedOpen) @@ -1882,9 +1887,10 @@ func TestFundingManagerOfflinePeer(t *testing.T) { con <- bob // This should make Alice send the channelReady. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // The state should now be channelReadySent assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) @@ -2311,14 +2317,16 @@ func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) @@ -2422,14 +2430,16 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) @@ -2519,14 +2529,16 @@ func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) @@ -2612,14 +2624,16 @@ func TestFundingManagerPrivateChannel(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) @@ -2735,14 +2749,16 @@ func TestFundingManagerPrivateRestart(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Check that the state machine is updated accordingly assertChannelReadySent(t, alice, bob, fundingOutPoint) @@ -3170,14 +3186,16 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) { // After the funding transaction is mined, Alice will send // channelReady to Bob. - channelReadyAlice := assertFundingMsgSent( + channelReadyAlice, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // And similarly Bob will send funding locked to Alice. - channelReadyBob := assertFundingMsgSent( + channelReadyBob, ok := assertFundingMsgSent( t, bob.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) // Exchange the channelReady messages. alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) @@ -4203,16 +4221,18 @@ func TestFundingManagerZeroConf(t *testing.T) { } // Assert that Bob's channel_ready message has an AliasScid. - bobChannelReady := assertFundingMsgSent( + 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. - aliceChannelReady := assertFundingMsgSent( + aliceChannelReady, ok := assertFundingMsgSent( t, alice.msgChan, "ChannelReady", ).(*lnwire.ChannelReady) + require.True(t, ok) require.NotNil(t, aliceChannelReady.AliasScid) require.Equal(t, *aliceChannelReady.AliasScid, alias) diff --git a/lnwire/funding_locked.go b/lnwire/channel_ready.go similarity index 100% rename from lnwire/funding_locked.go rename to lnwire/channel_ready.go diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index baefa4a6a..1ad93c96b 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -567,7 +567,6 @@ func TestLightningWireProtocol(t *testing.T) { v[0] = reflect.ValueOf(req) }, 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) From c4aea6e7899352d9c5d3a09c7cb90f4b452778e1 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 16 Mar 2023 21:56:51 +0800 Subject: [PATCH 12/12] docs: update release note for `channel_ready` --- docs/release-notes/release-notes-0.16.1.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/release-notes/release-notes-0.16.1.md b/docs/release-notes/release-notes-0.16.1.md index 983f4f358..84485cc94 100644 --- a/docs/release-notes/release-notes-0.16.1.md +++ b/docs/release-notes/release-notes-0.16.1.md @@ -26,6 +26,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) * Elle Mouton