channeldb+lntest: code style fixes

This commit is contained in:
Olaoluwa Osuntokun 2019-11-27 15:20:06 -06:00
parent 8b3dd9415e
commit 5bdb0d3d66
No known key found for this signature in database
GPG Key ID: BC13F65E2DC84465
2 changed files with 39 additions and 24 deletions

@ -596,6 +596,7 @@ func (c *OpenChannel) hasChanStatus(status ChannelStatus) bool {
// RefreshShortChanID updates the in-memory channel state using the latest // RefreshShortChanID updates the in-memory channel state using the latest
// value observed on disk. // value observed on disk.
//
// TODO: the name of this function should be changed to reflect the fact that // TODO: the name of this function should be changed to reflect the fact that
// it is not only refreshing the short channel id but all the channel state. // it is not only refreshing the short channel id but all the channel state.
// maybe Refresh/Reload? // maybe Refresh/Reload?
@ -611,7 +612,8 @@ func (c *OpenChannel) RefreshShortChanID() error {
return err return err
} }
// populating the in-memory channel with the info fetched from disk. // We'll re-populating the in-memory channel with the info
// fetched from disk.
if err := fetchChanInfo(chanBucket, c); err != nil { if err := fetchChanInfo(chanBucket, c); err != nil {
return fmt.Errorf("unable to fetch chan info: %v", err) return fmt.Errorf("unable to fetch chan info: %v", err)
} }

@ -1221,30 +1221,34 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) {
// testPaymentFollowingChannelOpen tests that the channel transition from // testPaymentFollowingChannelOpen tests that the channel transition from
// 'pending' to 'open' state does not cause any inconsistencies within other // 'pending' to 'open' state does not cause any inconsistencies within other
// subsystems trying to udpate the channel state in the db. We follow // subsystems trying to udpate the channel state in the db. We follow this
// this transition with a payment that updates the commitment state and // transition with a payment that updates the commitment state and verify that
// verify that the pending state is up to date. // the pending state is up to date.
func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest) { func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
ctxb := context.Background() ctxb := context.Background()
// We first establish a channel between Alice and Bob.
const paymentAmt = btcutil.Amount(100) const paymentAmt = btcutil.Amount(100)
ctxt, _ := context.WithTimeout(ctxb, channelOpenTimeout)
channelCapacity := btcutil.Amount(paymentAmt * 1000) channelCapacity := btcutil.Amount(paymentAmt * 1000)
pendingUpdate, err := net.OpenPendingChannel(ctxt, net.Alice, net.Bob,
channelCapacity, 0) // We first establish a channel between Alice and Bob.
ctxt, cancel := context.WithTimeout(ctxb, channelOpenTimeout)
defer cancel()
pendingUpdate, err := net.OpenPendingChannel(
ctxt, net.Alice, net.Bob, channelCapacity, 0,
)
if err != nil { if err != nil {
t.Fatalf("unable to open channel: %v", err) t.Fatalf("unable to open channel: %v", err)
} }
// At this point, the channel's funding transaction will have // At this point, the channel's funding transaction will have been
// been broadcast, but not confirmed. Alice and Bob's nodes // broadcast, but not confirmed. Alice and Bob's nodes
// should reflect this when queried via RPC. // should reflect this when queried via RPC.
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 1) assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 1)
// We are restarting Bob's node to let the link be created for the pending // We are restarting Bob's node to let the link be created for the
// channel. // pending channel.
if err := net.RestartNode(net.Bob, nil); err != nil { if err := net.RestartNode(net.Bob, nil); err != nil {
t.Fatalf("Bob restart failed: %v", err) t.Fatalf("Bob restart failed: %v", err)
} }
@ -1259,12 +1263,12 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
_ = mineBlocks(t, net, 6, 1)[0] _ = mineBlocks(t, net, 6, 1)[0]
// We verify that the chanel is open from both nodes point of view. // We verify that the chanel is open from both nodes point of view.
time.Sleep(time.Millisecond * 300) ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) defer cancel()
assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 0) assertNumOpenChannelsPending(ctxt, t, net.Alice, net.Bob, 0)
// With the channel open, we'll create invoices for Bob that Alice // With the channel open, we'll create invoices for Bob that Alice will
// will pay to in order to advance the state of the channel. // pay to in order to advance the state of the channel.
bobPayReqs, _, _, err := createPayReqs( bobPayReqs, _, _, err := createPayReqs(
net.Bob, paymentAmt, 1, net.Bob, paymentAmt, 1,
) )
@ -1272,16 +1276,24 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
t.Fatalf("unable to create pay reqs: %v", err) t.Fatalf("unable to create pay reqs: %v", err)
} }
// Send payment to Bob so there a chanel update to disk will be executed. // Send payment to Bob so there a chanel update to disk will be
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) // executed.
_, err = net.Alice.SendPaymentSync(ctxt, ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
&lnrpc.SendRequest{PaymentRequest: bobPayReqs[0]}) defer cancel()
_, err = net.Alice.SendPaymentSync(
ctxt,
&lnrpc.SendRequest{
PaymentRequest: bobPayReqs[0],
},
)
if err != nil { if err != nil {
t.Fatalf("unable to create payment stream for alice: %v", err) t.Fatalf("unable to create payment stream for alice: %v", err)
} }
// At this point we want to make sure the channel is opened and not pending. // At this point we want to make sure the channel is opened and not
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) // pending.
ctxt, cancel = context.WithTimeout(ctxb, defaultTimeout)
defer cancel()
res, err := net.Bob.ListChannels(ctxt, &lnrpc.ListChannelsRequest{}) res, err := net.Bob.ListChannels(ctxt, &lnrpc.ListChannelsRequest{})
if err != nil { if err != nil {
t.Fatalf("unable to list bob channels: %v", err) t.Fatalf("unable to list bob channels: %v", err)
@ -1299,7 +1311,8 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
}, },
OutputIndex: pendingUpdate.OutputIndex, OutputIndex: pendingUpdate.OutputIndex,
} }
ctxt, _ = context.WithTimeout(ctxb, channelCloseTimeout) ctxt, cancel = context.WithTimeout(ctxb, channelCloseTimeout)
defer cancel()
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false) closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
} }