From b1940d677907d954ee95e5482b71c33e755cfeb6 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 20 Nov 2019 19:54:47 -0800 Subject: [PATCH] lnwallet: fix bug in verifyFundingInputs skip dual funder tests for neutrino In this commit, we fix a long standing bug within the newly created `verifyFundingInputs` method. Before this commit, the method would attempt to derive the pkScript by looking at the last items on the witness stack, and making a p2wsh output script from that. This is incorrect as typically non of these scripts will actually be p2wsh, and instead will be p2wkh. We fix this by using the newly available `txscript.ComputePkScript` method to derive the proper pkScript. This resolves an issue w.r.t passing incorrect arguments for all backends, but an issue still stands for the neutrino backend. As is, we pass a height hint of zero into the `GetUtxo` method call. With the way the current utxo scanner is set up for neutrino, this'll cause it to never find the UTXO, as it takes the height hint as a UTXO birth height, rather than a lower bound of the birth of the UTXO. --- lnwallet/interface_test.go | 9 +++++++++ lnwallet/wallet.go | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index 53b77800..989e7017 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -3130,9 +3130,18 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver, // Execute every test, clearing possibly mutated // wallet state after each step. for _, walletTest := range walletTests { + + walletTest := walletTest + testName := fmt.Sprintf("%v/%v:%v", walletType, backEnd, walletTest.name) success := t.Run(testName, func(t *testing.T) { + if backEnd == "neutrino" && + strings.Contains(walletTest.name, "dual funder") { + t.Skip("skipping dual funder tests for neutrino") + } + return + walletTest.test(miningNode, alice, bob, t) }) if !success { diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 55ef7123..16dc50f9 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -1057,16 +1057,19 @@ func (l *LightningWallet) verifyFundingInputs(fundingTx *wire.MsgTx, // // TODO(roasbeef): when dual funder pass actual // height-hint - pkScript, err := input.WitnessScriptHash( - txin.Witness[len(txin.Witness)-1], + // + // TODO(roasbeef): this fails for neutrino always as it + // treats the height hint as an exact birthday of the + // utxo rather than a lower bound + pkScript, err := txscript.ComputePkScript( + txin.SignatureScript, txin.Witness, ) if err != nil { return fmt.Errorf("cannot create script: %v", err) } - output, err := l.Cfg.ChainIO.GetUtxo( &txin.PreviousOutPoint, - pkScript, 0, l.quit, + pkScript.Script(), 0, l.quit, ) if output == nil { return fmt.Errorf("input to funding tx does "+