From daeeca0bc357ae729d4631d2e88fc61fcb39c4ea Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 13 Apr 2018 16:50:31 +0200 Subject: [PATCH] rpcserver: make copy of htlc rhash before returning in listchannels This commit fixes a bug where all the HTLC rhash slices in a ListChannelsResponse would be tied to the loop variable, making them all take the hash of the last HTLC in the list. This commit fixes it by making a copy of the slice. --- rpcserver.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 14cce2d3..601a338e 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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, } }