Skip to content

Commit

Permalink
lnwallet: for PsbtIntent return the internal key in the POutput
Browse files Browse the repository at this point in the history
We also add a new assertion to the itests to ensure the field is being properly set.
  • Loading branch information
Roasbeef authored and guggero committed Apr 24, 2024
1 parent 50f0e1d commit 036a5a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions itest/lnd_psbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ func runPsbtChanFunding(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
},
)

// If this is a taproot channel, then we'll decode the PSBT to assert
// that an internal key is included.
if commitType == lnrpc.CommitmentType_SIMPLE_TAPROOT {
decodedPSBT, err := psbt.NewFromRawBytes(
bytes.NewReader(tempPsbt), false,
)
require.NoError(ht, err)

require.Len(ht, decodedPSBT.Outputs[0].TaprootInternalKey, 32)
}

// Let's add a second channel to the batch. This time between Carol and
// Alice. We will publish the batch TX once this channel funding is
// complete.
Expand Down
14 changes: 13 additions & 1 deletion lnwallet/chanfunding/psbt_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"sync"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
)
Expand Down Expand Up @@ -208,7 +210,17 @@ func (i *PsbtIntent) FundingParams() (btcutil.Address, int64, *psbt.Packet,
}
}
packet.UnsignedTx.TxOut = append(packet.UnsignedTx.TxOut, out)
packet.Outputs = append(packet.Outputs, psbt.POutput{})

var pOut psbt.POutput

// If this is a musig2 channel, then we'll also return the internal key
// information as well along side the output.
pOut.TaprootInternalKey = fn.MapOptionZ(
i.TaprootInternalKey(), schnorr.SerializePubKey,
)

packet.Outputs = append(packet.Outputs, pOut)

return addr, out.Value, packet, nil
}

Expand Down

0 comments on commit 036a5a9

Please sign in to comment.