mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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:
parent
dbac12ed78
commit
e710ea5e8f
2 changed files with 40 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue