From 5dd7b157a0328e5212d66707741d3cac1132b956 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 19 Jun 2017 17:43:45 +0200 Subject: [PATCH] lnwallet: fix race condition when forwarding by creating new pubkey This commit fixes a race condition that would at times occur in the htlcswitch.TestChannelLinkBidirectionalOneHopPayments test case. A race condition would occur in the goroutine running ReceiveNewCommitment compared with the grouting that would obtain the snapshot in order to make a forwarding decision. We fix this by creating a new public key for each new commitment transaction such that we complete avoid the read/write race condition. --- lnwallet/channel.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index b4d0f9ac..38a51272 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1838,11 +1838,15 @@ func (lc *LightningChannel) ReceiveNewCommitment(rawSig []byte) error { // Ensure that the newly constructed commitment state has a valid // signature. - theirMultiSigKey.Curve = btcec.S256() + verifyKey := btcec.PublicKey{ + X: theirMultiSigKey.X, + Y: theirMultiSigKey.Y, + Curve: btcec.S256(), + } sig, err := btcec.ParseSignature(rawSig, btcec.S256()) if err != nil { return err - } else if !sig.Verify(sigHash, theirMultiSigKey) { + } else if !sig.Verify(sigHash, &verifyKey) { return fmt.Errorf("invalid commitment signature") }