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