From d6de4a2f4ecbbf0bc42369d638dc235b925b0759 Mon Sep 17 00:00:00 2001 From: Lijun Wang <83639177+lijunwangs@users.noreply.github.com> Date: Wed, 22 Dec 2021 00:58:51 -0800 Subject: [PATCH] Fix transaction pk violation (#22057) * Handle PK violation issue for transaction notification. The transaction might be replayed due to validator restart. --- .../src/postgres_client/postgres_client_transaction.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/accountsdb-plugin-postgres/src/postgres_client/postgres_client_transaction.rs b/accountsdb-plugin-postgres/src/postgres_client/postgres_client_transaction.rs index f48b2456cf..b2019f70f5 100644 --- a/accountsdb-plugin-postgres/src/postgres_client/postgres_client_transaction.rs +++ b/accountsdb-plugin-postgres/src/postgres_client/postgres_client_transaction.rs @@ -492,7 +492,15 @@ impl SimplePostgresClient { ) -> Result { let stmt = "INSERT INTO transaction AS txn (signature, is_vote, slot, message_type, legacy_message, \ v0_loaded_message, signatures, message_hash, meta, updated_on) \ - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)"; + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) \ + ON CONFLICT (slot, signature) DO UPDATE SET is_vote=excluded.is_vote, \ + message_type=excluded.message_type, \ + legacy_message=excluded.legacy_message, \ + v0_loaded_message=excluded.v0_loaded_message, \ + signatures=excluded.signatures, \ + message_hash=excluded.message_hash, \ + meta=excluded.meta, \ + updated_on=excluded.updated_on"; let stmt = client.prepare(stmt);