Skip to content

Commit 30a0296

Browse files
authored
Merge pull request #1067 from oasisprotocol/ptrus/fix/roflmarket-mark-deleted
roflmarket: Properly mark removed instances/offers
2 parents c31b965 + 5ee2719 commit 30a0296

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

.changelog/1067.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
roflmarket: Properly mark removed instances/offers

analyzer/queries/queries.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,32 +1494,32 @@ var (
14941494
id
14951495
FROM chain.roflmarket_offers
14961496
WHERE
1497-
runtime = $1 AND
1498-
provider = $2`
1497+
runtime = $1::runtime AND
1498+
provider = $2::oasis_addr`
14991499

15001500
RuntimeRoflMarketProviderInstanceIds = `
15011501
SELECT
15021502
id
15031503
FROM chain.roflmarket_instances
15041504
WHERE
1505-
runtime = $1 AND
1506-
provider = $2`
1505+
runtime = $1::runtime AND
1506+
provider = $2::oasis_addr`
15071507

15081508
RuntimeRoflmarketOfferRemoved = `
15091509
UPDATE chain.roflmarket_offers
15101510
SET
15111511
removed = TRUE
15121512
WHERE
1513-
runtime = $1 AND
1514-
provider = $2 AND
1515-
id = $3`
1513+
runtime = $1::runtime AND
1514+
provider = $2::oasis_addr AND
1515+
id = $3::bytea`
15161516

15171517
RuntimeRoflmarketInstanceRemoved = `
15181518
UPDATE chain.roflmarket_instances
15191519
SET
15201520
removed = TRUE
15211521
WHERE
1522-
runtime = $1 AND
1523-
provider = $2 AND
1524-
id = $3`
1522+
runtime = $1::runtime AND
1523+
provider = $2::oasis_addr AND
1524+
id = $3::bytea`
15251525
)

analyzer/roflmarket/roflmarket.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package roflmarket
44

55
import (
6+
"bytes"
67
"context"
7-
"encoding/hex"
88
"fmt"
99
"slices"
1010
"time"
@@ -168,13 +168,13 @@ func (p *processor) queueRoflmarketOffersRefresh(ctx context.Context, batch *sto
168168
return fmt.Errorf("querying rofl market provider offers: %w", err)
169169
}
170170
defer rows.Close()
171-
var existingOffers []string
171+
var existingOffers [][]byte
172172
for rows.Next() {
173173
var offerID []byte
174174
if err := rows.Scan(&offerID); err != nil {
175175
return fmt.Errorf("scanning rofl market provider offer: %w", err)
176176
}
177-
existingOffers = append(existingOffers, hex.EncodeToString(offerID))
177+
existingOffers = append(existingOffers, offerID)
178178
}
179179

180180
// Fetch offers from the node.
@@ -185,8 +185,8 @@ func (p *processor) queueRoflmarketOffersRefresh(ctx context.Context, batch *sto
185185

186186
// Update offers.
187187
for _, offer := range offers {
188-
existingOffers = slices.DeleteFunc(existingOffers, func(id string) bool {
189-
return id == offer.ID.String()
188+
existingOffers = slices.DeleteFunc(existingOffers, func(id []byte) bool {
189+
return bytes.Equal(id, offer.ID[:])
190190
})
191191

192192
batch.Queue(
@@ -221,13 +221,13 @@ func (p *processor) queueRoflmarketInstancesRefresh(ctx context.Context, batch *
221221
return fmt.Errorf("querying rofl market provider instances: %w", err)
222222
}
223223
defer rows.Close()
224-
var existingInstances []string
224+
var existingInstances [][]byte
225225
for rows.Next() {
226226
var instanceID []byte
227227
if err := rows.Scan(&instanceID); err != nil {
228228
return fmt.Errorf("scanning rofl market provider instance: %w", err)
229229
}
230-
existingInstances = append(existingInstances, hex.EncodeToString(instanceID))
230+
existingInstances = append(existingInstances, instanceID)
231231
}
232232

233233
// Fetch instances from the node.
@@ -238,8 +238,8 @@ func (p *processor) queueRoflmarketInstancesRefresh(ctx context.Context, batch *
238238

239239
// Update instances.
240240
for _, instance := range instances {
241-
existingInstances = slices.DeleteFunc(existingInstances, func(id string) bool {
242-
return id == instance.ID.String()
241+
existingInstances = slices.DeleteFunc(existingInstances, func(id []byte) bool {
242+
return bytes.Equal(id, instance.ID[:])
243243
})
244244

245245
// Query instance commands.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BEGIN;
2+
3+
-- Ensure refresh of providers with the fixed code.
4+
UPDATE chain.roflmarket_providers
5+
SET last_processed_round = NULL;
6+
7+
COMMIT;

0 commit comments

Comments
 (0)