Skip to content

Commit 6e20769

Browse files
committed
lnwallet: for PsbtIntent return the internal key in the POutput
We also add a new assertion to the itests to ensure the field is being properly set.
1 parent 8a69b67 commit 6e20769

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

itest/lnd_psbt_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ func runPsbtChanFunding(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
177177
},
178178
)
179179

180+
// If this is a taproot channel, then we'll decode the PSBT to assert
181+
// that an internal key is included.
182+
if commitType == lnrpc.CommitmentType_SIMPLE_TAPROOT {
183+
decodedPSBT, err := psbt.NewFromRawBytes(
184+
bytes.NewReader(tempPsbt), false,
185+
)
186+
require.NoError(ht, err)
187+
188+
require.Len(ht, decodedPSBT.Outputs[0].TaprootInternalKey, 32)
189+
}
190+
180191
// Let's add a second channel to the batch. This time between Carol and
181192
// Alice. We will publish the batch TX once this channel funding is
182193
// complete.

lnwallet/chanfunding/psbt_assembler.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"sync"
77

88
"github.com/btcsuite/btcd/btcec/v2"
9+
"github.com/btcsuite/btcd/btcec/v2/schnorr"
910
"github.com/btcsuite/btcd/btcutil"
1011
"github.com/btcsuite/btcd/btcutil/psbt"
1112
"github.com/btcsuite/btcd/chaincfg"
1213
"github.com/btcsuite/btcd/txscript"
1314
"github.com/btcsuite/btcd/wire"
15+
"github.com/lightningnetwork/lnd/fn"
1416
"github.com/lightningnetwork/lnd/input"
1517
"github.com/lightningnetwork/lnd/keychain"
1618
)
@@ -208,7 +210,17 @@ func (i *PsbtIntent) FundingParams() (btcutil.Address, int64, *psbt.Packet,
208210
}
209211
}
210212
packet.UnsignedTx.TxOut = append(packet.UnsignedTx.TxOut, out)
211-
packet.Outputs = append(packet.Outputs, psbt.POutput{})
213+
214+
var pOut psbt.POutput
215+
216+
// If this is a musig2 channel, then we'll also return the internal key
217+
// information as well along side the output.
218+
pOut.TaprootInternalKey = fn.MapOptionZ(
219+
i.TaprootInternalKey(), schnorr.SerializePubKey,
220+
)
221+
222+
packet.Outputs = append(packet.Outputs, pOut)
223+
212224
return addr, out.Value, packet, nil
213225
}
214226

0 commit comments

Comments
 (0)