From 8dcf274a2d78a2735a52caffe490100426e299f9 Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Sun, 30 Oct 2016 17:54:59 +0300 Subject: [PATCH 1/2] fix typos --- lnwire/commit_signature.go | 8 ++++---- peer.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lnwire/commit_signature.go b/lnwire/commit_signature.go index 5747b363..42902de2 100644 --- a/lnwire/commit_signature.go +++ b/lnwire/commit_signature.go @@ -10,8 +10,8 @@ import ( ) // CommitSignature is sent by either side to stage any pending HTLC's in the -// reciever's pending set which has not explcitly been rejected via an -// HTLCAddReject message. Implictly, the new commitment transaction constructed +// receiver's pending set which has not explicitly been rejected via an +// HTLCAddReject message. Implicitly, the new commitment transaction constructed // which has been signed by CommitSig includes all HTLC's in the remote node's // pending set. A CommitSignature message may be sent after a series of HTLCAdd // messages in order to batch add several HTLC's with a single signature @@ -21,7 +21,7 @@ type CommitSignature struct { // CommitSignature applies to. ChannelPoint *wire.OutPoint - // LogIndex is the index into the reciever's HTLC log to which this + // LogIndex is the index into the receiver's HTLC log to which this // commitment signature covers. In order to properly verify this // signature, the receiver should include all the HTLC's within their // log with an index less-than-or-equal to the listed log-index. @@ -35,7 +35,7 @@ type CommitSignature struct { // CommitSig is Alice's signature for Bob's new commitment transaction. // Alice is able to send this signature without requesting any additional // data due to the piggybacking of Bob's next revocation hash in his - // prior CommitRevocation message, as well as the cannonical ordering + // prior CommitRevocation message, as well as the canonical ordering // used for all inputs/outputs within commitment transactions. CommitSig *btcec.Signature } diff --git a/peer.go b/peer.go index 2c6a0d05..28a01589 100644 --- a/peer.go +++ b/peer.go @@ -980,7 +980,7 @@ out: // update in some time, check to see if we have any // pending updates we need to commit. If so, then send // an update incrementing the unacked counter is - // succesful. + // successfully. if !state.channel.PendingUpdates() && len(state.htlcsToSettle) == 0 { continue @@ -1221,7 +1221,7 @@ func (p *peer) handleUpstreamMsg(state *commitmentState, msg lnwire.Message) { // If any of the htlc's eligible for forwarding are pending // settling or timeing out previous outgoing payments, then we - // can them from the pending set, and signal the requster (if + // can them from the pending set, and signal the requester (if // existing) that the payment has been fully fulfilled. var bandwidthUpdate btcutil.Amount settledPayments := make(map[lnwallet.PaymentHash]struct{}) From 6d57fb08b3147ff8c24ba65af265096013630460 Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Sun, 30 Oct 2016 17:55:25 +0300 Subject: [PATCH 2/2] tests: temporary fix multi hop test --- lnd_test.go | 87 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 23 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index da1ba917..30b5b357 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -16,6 +16,7 @@ import ( "github.com/roasbeef/btcutil" "golang.org/x/net/context" "google.golang.org/grpc" + "sync/atomic" ) // harnessTest wraps a regular testing.T providing enchanced error detection @@ -616,41 +617,81 @@ func testMultiHopPayments(net *networkHarness, t *harnessTest) { } assertAsymmetricBalance := func(node *lightningNode, - chanPoint *wire.OutPoint, localBalance, + chanPoint wire.OutPoint, localBalance, remoteBalance int64) { - listReq := &lnrpc.ListChannelsRequest{} - resp, err := node.ListChannels(ctxb, listReq) - if err != nil { - t.Fatalf("unable to for node's channels: %v", err) + channelName := "" + switch chanPoint { + case carolFundPoint: + channelName = "Carol(local) => Alice(remote)" + case aliceFundPoint: + channelName = "Alice(local) => Bob(remote)" } - for _, channel := range resp.Channels { - if channel.ChannelPoint != chanPoint.String() { - continue - } - if channel.LocalBalance != localBalance || - channel.RemoteBalance != remoteBalance { - t.Fatalf("incorrect balances: %v", - spew.Sdump(channel)) + checkBalance := func() error { + listReq := &lnrpc.ListChannelsRequest{} + resp, err := node.ListChannels(ctxb, listReq) + if err != nil { + return fmt.Errorf("unable to for node's "+ + "channels: %v", err) + } + for _, channel := range resp.Channels { + if channel.ChannelPoint != chanPoint.String() { + continue + } + + if channel.LocalBalance != localBalance { + return fmt.Errorf("%v: incorrect local "+ + "balances: %v != %v", channelName, + channel.LocalBalance, localBalance) + } + + if channel.RemoteBalance != remoteBalance { + return fmt.Errorf("%v: incorrect remote "+ + "balances: %v != %v", channelName, + channel.RemoteBalance, remoteBalance) + } + + return nil + } + return fmt.Errorf("channel not found") + } + + // As far as HTLC inclusion in commitment transaction might be + // postponed we will try to check the balance couple of + // times, and then if after some period of time we receive wrong + // balance return the error. + // TODO(roasbeef): remove sleep after invoice notification hooks + // are in place + var timeover uint32 + go func() { + <-time.After(time.Second * 20) + atomic.StoreUint32(&timeover, 1) + }() + + for { + isTimeover := atomic.LoadUint32(&timeover) == 1 + if err := checkBalance(); err != nil { + if isTimeover { + t.Fatalf("Check balance failed: %v", err) + } + } else { + break } - return } - t.Fatalf("channel not found") } // At this point all the channels within our proto network should be // shifted by 5k satoshis in the direction of Bob, the sink within the - // payment flow generated above. - // TODO(roasbeef): remove sleep after invoice notification hooks are in - // place - time.Sleep(time.Second * 3) + // payment flow generated above. The order of asserts corresponds to + // increasing of time is needed to embed the HTLC in commitment + // transaction, in channel Carol->Alice->Bob, order is Bob,Alice,Carol. const sourceBal = int64(95000) const sinkBal = int64(5000) - assertAsymmetricBalance(carol, &carolFundPoint, sourceBal, sinkBal) - assertAsymmetricBalance(net.Alice, &carolFundPoint, sinkBal, sourceBal) - assertAsymmetricBalance(net.Alice, &aliceFundPoint, sourceBal, sinkBal) - assertAsymmetricBalance(net.Bob, &aliceFundPoint, sinkBal, sourceBal) + assertAsymmetricBalance(net.Bob, aliceFundPoint, sinkBal, sourceBal) + assertAsymmetricBalance(net.Alice, aliceFundPoint, sourceBal, sinkBal) + assertAsymmetricBalance(net.Alice, carolFundPoint, sinkBal, sourceBal) + assertAsymmetricBalance(carol, carolFundPoint, sourceBal, sinkBal) ctxt, _ = context.WithTimeout(ctxb, timeout) closeChannelAndAssert(t, net, ctxt, net.Alice, chanPointAlice)