Skip to content

Commit 28cb488

Browse files
Roasbeefguggero
authored andcommitted
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 a841a9b commit 28cb488

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-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: 14 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,18 @@ 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, we also need to communicate the internal
217+
// key to the caller. Otherwise, they cannot verify the construction of
218+
// the P2TR output script.
219+
pOut.TaprootInternalKey = fn.MapOptionZ(
220+
i.TaprootInternalKey(), schnorr.SerializePubKey,
221+
)
222+
223+
packet.Outputs = append(packet.Outputs, pOut)
224+
212225
return addr, out.Value, packet, nil
213226
}
214227

0 commit comments

Comments
 (0)