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)