Merge pull request #1093 from halseth/copy-htlc-rhash
[bugfix] Copy htlc rhash when returing ListChannelsResponse
This commit is contained in:
commit
f23848cac0
83
lnd_test.go
83
lnd_test.go
@ -3063,21 +3063,36 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
return len(chanGraph.Edges)
|
||||
}
|
||||
|
||||
aliceChans := numChannels(net.Alice)
|
||||
if aliceChans != 4 {
|
||||
t.Fatalf("expected Alice to know 4 edges, had %v", aliceChans)
|
||||
}
|
||||
bobChans := numChannels(net.Bob)
|
||||
if bobChans != 3 {
|
||||
t.Fatalf("expected Bob to know 3 edges, had %v", bobChans)
|
||||
}
|
||||
carolChans := numChannels(carol)
|
||||
if carolChans != 4 {
|
||||
t.Fatalf("expected Carol to know 4 edges, had %v", carolChans)
|
||||
}
|
||||
daveChans := numChannels(dave)
|
||||
if daveChans != 3 {
|
||||
t.Fatalf("expected Dave to know 3 edges, had %v", daveChans)
|
||||
var predErr error
|
||||
err = lntest.WaitPredicate(func() bool {
|
||||
aliceChans := numChannels(net.Alice)
|
||||
if aliceChans != 4 {
|
||||
predErr = fmt.Errorf("expected Alice to know 4 edges, "+
|
||||
"had %v", aliceChans)
|
||||
return false
|
||||
}
|
||||
bobChans := numChannels(net.Bob)
|
||||
if bobChans != 3 {
|
||||
predErr = fmt.Errorf("expected Bob to know 3 edges, "+
|
||||
"had %v", bobChans)
|
||||
return false
|
||||
}
|
||||
carolChans := numChannels(carol)
|
||||
if carolChans != 4 {
|
||||
predErr = fmt.Errorf("expected Carol to know 4 edges, "+
|
||||
"had %v", carolChans)
|
||||
return false
|
||||
}
|
||||
daveChans := numChannels(dave)
|
||||
if daveChans != 3 {
|
||||
predErr = fmt.Errorf("expected Dave to know 3 edges, "+
|
||||
"had %v", daveChans)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}, time.Second*15)
|
||||
if err != nil {
|
||||
t.Fatalf("%v", predErr)
|
||||
}
|
||||
|
||||
// Close all channels.
|
||||
@ -5341,6 +5356,8 @@ func testBidirectionalAsyncPayments(net *lntest.NetworkHarness, t *harnessTest)
|
||||
closeChannelAndAssert(ctxt, t, net, net.Alice, chanPoint, false)
|
||||
}
|
||||
|
||||
// assertActiveHtlcs makes sure all the passed nodes have the _exact_ HTLCs
|
||||
// matching payHashes on _all_ their channels.
|
||||
func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error {
|
||||
req := &lnrpc.ListChannelsRequest{}
|
||||
ctxb := context.Background()
|
||||
@ -5351,27 +5368,31 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error {
|
||||
}
|
||||
|
||||
for _, channel := range nodeChans.Channels {
|
||||
if len(channel.PendingHtlcs) == 0 {
|
||||
return fmt.Errorf("node %x has no htlcs: %v",
|
||||
node.PubKey[:], spew.Sdump(channel))
|
||||
// Record all payment hashes active for this channel.
|
||||
htlcHashes := make(map[string]struct{})
|
||||
for _, htlc := range channel.PendingHtlcs {
|
||||
_, ok := htlcHashes[string(htlc.HashLock)]
|
||||
if ok {
|
||||
return fmt.Errorf("duplicate HashLock")
|
||||
}
|
||||
htlcHashes[string(htlc.HashLock)] = struct{}{}
|
||||
}
|
||||
|
||||
for _, htlc := range channel.PendingHtlcs {
|
||||
// Channel should have exactly the payHashes active.
|
||||
if len(payHashes) != len(htlcHashes) {
|
||||
return fmt.Errorf("node %x had %v htlcs active, "+
|
||||
"expected %v", node.PubKey[:],
|
||||
len(htlcHashes), len(payHashes))
|
||||
}
|
||||
|
||||
var htlcIsMatch bool
|
||||
for _, payHash := range payHashes {
|
||||
if bytes.Equal(htlc.HashLock, payHash) {
|
||||
htlcIsMatch = true
|
||||
}
|
||||
}
|
||||
|
||||
if htlcIsMatch {
|
||||
// Make sure all the payHashes are active.
|
||||
for _, payHash := range payHashes {
|
||||
if _, ok := htlcHashes[string(payHash)]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("node %x doesn't have expected "+
|
||||
"payment hashes: %v", node.PubKey[:],
|
||||
spew.Sdump(channel.PendingHtlcs))
|
||||
return fmt.Errorf("node %x didn't have the "+
|
||||
"payHash %v active", node.PubKey[:],
|
||||
payHash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1636,10 +1636,12 @@ func (r *rpcServer) ListChannels(ctx context.Context,
|
||||
}
|
||||
|
||||
for i, htlc := range localCommit.Htlcs {
|
||||
var rHash [32]byte
|
||||
copy(rHash[:], htlc.RHash[:])
|
||||
channel.PendingHtlcs[i] = &lnrpc.HTLC{
|
||||
Incoming: htlc.Incoming,
|
||||
Amount: int64(htlc.Amt.ToSatoshis()),
|
||||
HashLock: htlc.RHash[:],
|
||||
HashLock: rHash[:],
|
||||
ExpirationHeight: htlc.RefundTimeout,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user