diff --git a/internal/metamorph/store/postgresql/fixtures/metamorph.transactions.yaml b/internal/metamorph/store/postgresql/fixtures/metamorph.transactions.yaml index aa05c2e96..b660ee404 100644 --- a/internal/metamorph/store/postgresql/fixtures/metamorph.transactions.yaml +++ b/internal/metamorph/store/postgresql/fixtures/metamorph.transactions.yaml @@ -33,6 +33,13 @@ announced_at: 2023-10-01 14:05:00 mined_at: 2023-10-01 14:10:00 inserted_at_num: 2023100114 +- hash: 0xa24845611f9518f0c1a5978b77a18317b6878086ce5d81f65c3d778db33a7b1d + locked_by: metamorph-1 + status: 9 + stored_at: 2023-10-01 14:00:00 + announced_at: 2023-10-01 14:05:00 + mined_at: 2023-10-01 14:10:00 + inserted_at_num: 2023100114 - hash: 0x12c04cfc5643f1cd25639ad42d6f8f0489557699d92071d7e0a5b940438c4357 locked_by: NONE status: 4 diff --git a/internal/metamorph/store/postgresql/postgres.go b/internal/metamorph/store/postgresql/postgres.go index 251d8be4c..d4124a46a 100644 --- a/internal/metamorph/store/postgresql/postgres.go +++ b/internal/metamorph/store/postgresql/postgres.go @@ -445,7 +445,7 @@ func (p *PostgreSQL) UpdateStatusBulk(ctx context.Context, updates []store.Updat AS t(hash, status, reject_reason) ) AS bulk_query WHERE - metamorph.transactions.hash=bulk_query.hash AND metamorph.transactions.locked_by = $4 + metamorph.transactions.hash=bulk_query.hash AND metamorph.transactions.locked_by = $4 AND metamorph.transactions.status != $5 AND metamorph.transactions.status != $6 RETURNING metamorph.transactions.stored_at ,metamorph.transactions.announced_at ,metamorph.transactions.mined_at @@ -464,7 +464,7 @@ func (p *PostgreSQL) UpdateStatusBulk(ctx context.Context, updates []store.Updat ; ` - rows, err := p.db.QueryContext(ctx, qBulk, pq.Array(txHashes), pq.Array(statuses), pq.Array(rejectReasons), p.hostname) + rows, err := p.db.QueryContext(ctx, qBulk, pq.Array(txHashes), pq.Array(statuses), pq.Array(rejectReasons), p.hostname, metamorph_api.Status_SEEN_ON_NETWORK, metamorph_api.Status_MINED) if err != nil { return nil, err } diff --git a/internal/metamorph/store/postgresql/postgres_test.go b/internal/metamorph/store/postgresql/postgres_test.go index 0a3df7a41..3b9309fa5 100644 --- a/internal/metamorph/store/postgresql/postgres_test.go +++ b/internal/metamorph/store/postgresql/postgres_test.go @@ -366,6 +366,14 @@ func TestPostgresDB(t *testing.T) { metamorph3Hash, err := chainhash.NewHashFromStr("538808e847d0add40ed9622fff53954c79e1f52db7c47ea0b6cdc0df972f3dcd") require.NoError(t, err) + // will not be updated because has already status seen on network + seenOnNetworkHash, err := chainhash.NewHashFromStr("aaf6dcac409778330982371560bd4e4f7064e4154aa1e66a3e3d8946b7f576ee") + require.NoError(t, err) + + // will not be updated because has already status mined + minedHash, err := chainhash.NewHashFromStr("1d7b3ab38d773d5cf6815dce868087b61783a1778b97a5c1f018951f614548a2") + require.NoError(t, err) + updates := []store.UpdateStatus{ { Hash: *testdata.TX1Hash, @@ -389,6 +397,14 @@ func TestPostgresDB(t *testing.T) { Hash: *metamorph3Hash, Status: metamorph_api.Status_MINED, }, + { + Hash: *seenOnNetworkHash, + Status: metamorph_api.Status_REQUESTED_BY_NETWORK, + }, + { + Hash: *minedHash, + Status: metamorph_api.Status_SENT_TO_NETWORK, + }, } statusUpdates, err := postgresDB.UpdateStatusBulk(ctx, updates) @@ -413,6 +429,14 @@ func TestPostgresDB(t *testing.T) { assert.Equal(t, metamorph_api.Status_REJECTED, returnedDataRequested.Status) assert.Equal(t, "missing inputs", returnedDataRequested.RejectReason) assert.Equal(t, testdata.TX6RawBytes, returnedDataRequested.RawTx) + + returnedDataSeen, err := postgresDB.Get(ctx, seenOnNetworkHash[:]) + require.NoError(t, err) + assert.Equal(t, metamorph_api.Status_SEEN_ON_NETWORK, returnedDataSeen.Status) + + returnedDataMined, err := postgresDB.Get(ctx, minedHash[:]) + require.NoError(t, err) + assert.Equal(t, metamorph_api.Status_MINED, returnedDataMined.Status) }) t.Run("update mined", func(t *testing.T) { @@ -505,6 +529,6 @@ func TestPostgresDB(t *testing.T) { var numberOfRemainingTxs int err = postgresDB.db.QueryRowContext(ctx, "SELECT count(*) FROM metamorph.transactions;").Scan(&numberOfRemainingTxs) require.NoError(t, err) - require.Equal(t, 9, numberOfRemainingTxs) + require.Equal(t, 10, numberOfRemainingTxs) }) }