From 0570e80fd26d90dca51d0daaf7684bf3e38dc487 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 21 May 2018 16:47:01 -0700 Subject: [PATCH] lnwallet: check commitment sanity within createCommitmentTx In this commit, we move the check to CheckTransactionSanity into createCommitmentTx. We do this as within wallet.go (during the funding process) we actually end up calling this helper function twice, and also moving it up until right when we create the fully commitment transaction ensures we making our assertion against the final version. --- lnwallet/channel.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index c98a5356..9e17a597 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2338,6 +2338,12 @@ func (lc *LightningChannel) createCommitmentTx(c *commitment, // instead we'll just send signatures. txsort.InPlaceSort(commitTx) + // Next, we'll ensure that we don't accidentally create a commitment + // transaction which would be invalid by consensus. + uTx := btcutil.NewTx(commitTx) + if err := blockchain.CheckTransactionSanity(uTx); err != nil { + return err + } c.txn = commitTx c.fee = commitFee c.ourBalance = ourBalance @@ -5795,13 +5801,6 @@ func CreateCommitTx(fundingOutput wire.TxIn, }) } - // Finally, we'll ensure that we don't accidentally create a commitment - // transaction which would be invalid by consensus. - uTx := btcutil.NewTx(commitTx) - if err := blockchain.CheckTransactionSanity(uTx); err != nil { - return nil, err - } - return commitTx, nil }