Skip to content

Commit

Permalink
lnwallet: fix bug in verifyFundingInputs skip dual funder tests for n…
Browse files Browse the repository at this point in the history
…eutrino

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.
  • Loading branch information
Roasbeef committed Dec 2, 2019
1 parent 6b729ec commit b1940d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions lnwallet/interface_test.go
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions lnwallet/wallet.go
Expand Up @@ -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 "+
Expand Down

0 comments on commit b1940d6

Please sign in to comment.