openchannel: reject duplicate outpoints in open channel request

Duplicate outpoints in the request lead to fee miscalculation and an
invalid PSBT with the same input listed twice. Validate early and return
a clear error message.
This commit is contained in:
Slyghtning 2026-02-19 09:54:58 +01:00
parent dbac12ed78
commit e710ea5e8f
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
2 changed files with 40 additions and 0 deletions

View file

@ -299,6 +299,18 @@ func (m *Manager) OpenChannel(ctx context.Context,
err)
}
// Check for duplicate outpoints which would lead to fee
// miscalculation and an invalid PSBT with the same input
// listed twice.
seen := make(map[wire.OutPoint]struct{}, len(outpoints))
for _, op := range outpoints {
if _, ok := seen[op]; ok {
return nil, fmt.Errorf("duplicate outpoint "+
"%v in request", op)
}
seen[op] = struct{}{}
}
deposits, allActive =
m.cfg.DepositManager.AllOutpointsActiveDeposits(
outpoints, deposit.Deposited,

View file

@ -210,6 +210,34 @@ func testOutPoint(b byte) wire.OutPoint {
}
}
func TestOpenChannelDuplicateOutpoints(t *testing.T) {
t.Parallel()
op := testOutPoint(1)
manager := &Manager{
cfg: &Config{},
}
req := &lnrpc.OpenChannelRequest{
NodePubkey: make([]byte, 33),
LocalFundingAmount: 100000,
SatPerVbyte: 10,
Outpoints: []*lnrpc.OutPoint{
{
TxidStr: op.Hash.String(),
OutputIndex: op.Index,
},
{
TxidStr: op.Hash.String(),
OutputIndex: op.Index,
},
},
}
_, err := manager.OpenChannel(context.Background(), req)
require.ErrorContains(t, err, "duplicate outpoint")
}
func TestValidateInitialPsbtFlags(t *testing.T) {
t.Parallel()