funding+lnwire: rename and fix make lint

Fix linter and rename `funding_locked.go` to `channel_ready.go`
This commit is contained in:
yyforyongyu committed 2023-03-17 18:21:59 +08:00
1 parent d4ad5f362f
commit dc3f83c670
4 files changed
+64 -31

No files matched your search

+24 -10
View File
@@ -617,16 +617,30 @@ func (c channelOpeningState) String() string {
// fundingManager. // fundingManager.
func NewFundingManager(cfg Config) (*Manager, error) { func NewFundingManager(cfg Config) (*Manager, error) {
return &Manager{ return &Manager{
cfg: &cfg, cfg: &cfg,
chanIDKey: cfg.TempChanIDSeed, chanIDKey: cfg.TempChanIDSeed,
activeReservations: make(map[serializedPubKey]pendingChannels), activeReservations: make(
signedReservations: make(map[lnwire.ChannelID][32]byte), map[serializedPubKey]pendingChannels,
newChanBarriers: make(map[lnwire.ChannelID]chan struct{}), ),
fundingMsgs: make(chan *fundingMsg, msgBufferSize), signedReservations: make(
fundingRequests: make(chan *InitFundingMsg, msgBufferSize), map[lnwire.ChannelID][32]byte,
localDiscoverySignals: make(map[lnwire.ChannelID]chan struct{}), ),
handleChannelReadyBarriers: make(map[lnwire.ChannelID]struct{}), newChanBarriers: make(
quit: make(chan struct{}), 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 }, nil
} }
+40 -20
View File
@@ -1406,14 +1406,16 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertChannelReadySent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
@@ -1677,9 +1679,10 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
} }
// Bob will send funding locked to Alice. // Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Alice should still be markedOpen // Alice should still be markedOpen
assertDatabaseState(t, alice, fundingOutPoint, markedOpen) assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
@@ -1706,9 +1709,10 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
return errChan return errChan
} }
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// The state should now be channelReadySent // The state should now be channelReadySent
assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
@@ -1834,9 +1838,10 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
} }
// Bob will send funding locked to Alice // Bob will send funding locked to Alice
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Alice should still be markedOpen // Alice should still be markedOpen
assertDatabaseState(t, alice, fundingOutPoint, markedOpen) assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
@@ -1882,9 +1887,10 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
con <- bob con <- bob
// This should make Alice send the channelReady. // This should make Alice send the channelReady.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// The state should now be channelReadySent // The state should now be channelReadySent
assertDatabaseState(t, alice, fundingOutPoint, channelReadySent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
@@ -2311,14 +2317,16 @@ func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertChannelReadySent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
@@ -2422,14 +2430,16 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertChannelReadySent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
@@ -2519,14 +2529,16 @@ func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertChannelReadySent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
@@ -2612,14 +2624,16 @@ func TestFundingManagerPrivateChannel(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertChannelReadySent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
@@ -2735,14 +2749,16 @@ func TestFundingManagerPrivateRestart(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertChannelReadySent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
@@ -3170,14 +3186,16 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// channelReady to Bob. // channelReady to Bob.
channelReadyAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
channelReadyBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Exchange the channelReady messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
@@ -4203,16 +4221,18 @@ func TestFundingManagerZeroConf(t *testing.T) {
} }
// Assert that Bob's channel_ready message has an AliasScid. // Assert that Bob's channel_ready message has an AliasScid.
bobChannelReady := assertFundingMsgSent( bobChannelReady, ok := assertFundingMsgSent(
t, bob.msgChan, "ChannelReady", t, bob.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
require.NotNil(t, bobChannelReady.AliasScid) require.NotNil(t, bobChannelReady.AliasScid)
require.Equal(t, *bobChannelReady.AliasScid, alias) require.Equal(t, *bobChannelReady.AliasScid, alias)
// Do the same for Alice as well. // Do the same for Alice as well.
aliceChannelReady := assertFundingMsgSent( aliceChannelReady, ok := assertFundingMsgSent(
t, alice.msgChan, "ChannelReady", t, alice.msgChan, "ChannelReady",
).(*lnwire.ChannelReady) ).(*lnwire.ChannelReady)
require.True(t, ok)
require.NotNil(t, aliceChannelReady.AliasScid) require.NotNil(t, aliceChannelReady.AliasScid)
require.Equal(t, *aliceChannelReady.AliasScid, alias) require.Equal(t, *aliceChannelReady.AliasScid, alias)
File renamed without changes.
-1
View File
@@ -567,7 +567,6 @@ func TestLightningWireProtocol(t *testing.T) {
v[0] = reflect.ValueOf(req) v[0] = reflect.ValueOf(req)
}, },
MsgChannelReady: func(v []reflect.Value, r *rand.Rand) { MsgChannelReady: func(v []reflect.Value, r *rand.Rand) {
var c [32]byte var c [32]byte
if _, err := r.Read(c[:]); err != nil { if _, err := r.Read(c[:]); err != nil {
t.Fatalf("unable to generate chan id: %v", err) t.Fatalf("unable to generate chan id: %v", err)