Skip to content

Commit

Permalink
fix(ARCO-293): Fix conflict on mined transaction insert (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
shotasilagadzetaal authored Nov 26, 2024
1 parent 01b46e2 commit 04cabdc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/blocktx/store/postgresql/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ func TestPostgresStore_UpsertBlockTransactions(t *testing.T) {

expectedErr error
expectedUpdatedResLen int
upsertRepeat bool
}{
{
name: "upsert all registered transactions (updates only)",
Expand Down Expand Up @@ -542,6 +543,17 @@ func TestPostgresStore_UpsertBlockTransactions(t *testing.T) {
},
expectedUpdatedResLen: 6,
},
{
name: "upsert all registered transactions cause conflict with txid and blockid",
txsWithMerklePaths: []store.TxWithMerklePath{
{
Hash: testutils.RevChainhash(t, "8b7d038db4518ac4c665abfc5aeaacbd2124ad8ca70daa8465ed2c4427c41b9b")[:],
MerklePath: "test7",
},
},
upsertRepeat: true,
expectedUpdatedResLen: 1,
},
}

// common setup for test cases
Expand All @@ -558,6 +570,10 @@ func TestPostgresStore_UpsertBlockTransactions(t *testing.T) {

// when
res, err := sut.UpsertBlockTransactions(ctx, testBlockID, tc.txsWithMerklePaths)
if tc.upsertRepeat {
res, err = sut.UpsertBlockTransactions(ctx, testBlockID, tc.txsWithMerklePaths)
require.NoError(t, err)
}

// then
if tc.expectedErr != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (p *PostgreSQL) UpsertBlockTransactions(ctx context.Context, blockID uint64
it.id,
t.merkle_path
FROM inserted_transactions it
JOIN LATERAL UNNEST($2::BYTEA[], $3::TEXT[]) AS t(hash, merkle_path) ON it.hash = t.hash;
JOIN LATERAL UNNEST($2::BYTEA[], $3::TEXT[]) AS t(hash, merkle_path) ON it.hash = t.hash
ON CONFLICT(blockid, txid) DO NOTHING;
`

qRegisteredTransactions := `
Expand Down

0 comments on commit 04cabdc

Please sign in to comment.