From 9399e150ead745fe308632f3dd7fb17101dc050a Mon Sep 17 00:00:00 2001 From: Elias Van Ootegem Date: Fri, 13 Sep 2024 11:19:09 +0100 Subject: [PATCH 1/2] fix: handle PK conflicts for funding payments Signed-off-by: Elias Van Ootegem --- CHANGELOG.md | 1 + datanode/sqlstore/funding_payments.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e2dd2afb9..de60d4a97b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### 🐛 Fixes - [11672](https://github.com/vegaprotocol/vega/issues/11672) - Add missing fees in GraphQL bindings. +- [11681](https://github.com/vegaprotocol/vega/issues/11681) - Account for conflicts inserting funding payment records. ## 0.78.2 diff --git a/datanode/sqlstore/funding_payments.go b/datanode/sqlstore/funding_payments.go index 270f8df75b..456f46a92b 100644 --- a/datanode/sqlstore/funding_payments.go +++ b/datanode/sqlstore/funding_payments.go @@ -52,7 +52,12 @@ func (fp *FundingPayments) Add( for _, v := range fundingPayments { _, err := fp.Exec(ctx, `insert into funding_payment(market_id, party_id, funding_period_seq, amount, vega_time, tx_hash, loss_socialisation_amount) -values ($1, $2, $3, $4, $5, $6, $7)`, +values ($1, $2, $3, $4, $5, $6, $7) + ON CONFLICT (party_id, market_id, vega_time) DO UPDATE SET + funding_period_seq=EXCLUDED.funding_period_seq, + amount=EXCLUDED.amount + tx_hash=EXCLUDED.tx_hash + loss_socialisation_amount=EXCLUDED.loss_socialisation_amount`, v.MarketID, v.PartyID, v.FundingPeriodSeq, v.Amount, v.VegaTime, v.TxHash, v.LossSocialisationAmount) if err != nil { return err From 2a9ed7752e90b6b93250a762a17f74c015afb99e Mon Sep 17 00:00:00 2001 From: Elias Van Ootegem Date: Fri, 13 Sep 2024 11:39:27 +0100 Subject: [PATCH 2/2] fix: typo in query Signed-off-by: Elias Van Ootegem --- datanode/sqlstore/funding_payments.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datanode/sqlstore/funding_payments.go b/datanode/sqlstore/funding_payments.go index 456f46a92b..85dfc78f15 100644 --- a/datanode/sqlstore/funding_payments.go +++ b/datanode/sqlstore/funding_payments.go @@ -55,8 +55,8 @@ func (fp *FundingPayments) Add( values ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (party_id, market_id, vega_time) DO UPDATE SET funding_period_seq=EXCLUDED.funding_period_seq, - amount=EXCLUDED.amount - tx_hash=EXCLUDED.tx_hash + amount=EXCLUDED.amount, + tx_hash=EXCLUDED.tx_hash, loss_socialisation_amount=EXCLUDED.loss_socialisation_amount`, v.MarketID, v.PartyID, v.FundingPeriodSeq, v.Amount, v.VegaTime, v.TxHash, v.LossSocialisationAmount) if err != nil {