Skip to content

Commit

Permalink
fix order polling pagination restart
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 committed Dec 18, 2024
1 parent c26a714 commit 0057175
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions eibc/order_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func NewOrderClient(cfg config.Config, logger *zap.Logger) (*orderClient, error)
return nil, fmt.Errorf("failed to parse min operator fee share: %w", err)
}

var poller orderPoller

oc := &orderClient{
config: cfg,
fulfillers: make(map[string]*orderFulfiller),
Expand All @@ -62,7 +60,7 @@ func NewOrderClient(cfg config.Config, logger *zap.Logger) (*orderClient, error)
orderCh,
cfg.OrderPolling.Interval, // we can use the same interval for order polling and LP balance checking
cfg.Validation.Interval,
poller.resetOrderPolling,
nil, // set below
logger,
),
logger: logger,
Expand All @@ -75,6 +73,7 @@ func NewOrderClient(cfg config.Config, logger *zap.Logger) (*orderClient, error)
cfg.OrderPolling,
logger,
)
oc.orderTracker.resetPoller = oc.orderPoller.resetOrderPolling
}

oc.orderEventer = newOrderEventer(
Expand Down
11 changes: 6 additions & 5 deletions eibc/order_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"strconv"
"strings"
"sync/atomic"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -25,7 +26,7 @@ type orderPoller struct {

getOrders func() ([]Order, error)
orderTracker *orderTracker
lastBlockHeight uint64
lastBlockHeight atomic.Uint64
}

func newOrderPoller(
Expand Down Expand Up @@ -101,8 +102,8 @@ func (p *orderPoller) pollPendingDemandOrders() error {
p.logger.Error("failed to parse block height", zap.Error(err))
continue
}
if blockHeight > p.lastBlockHeight {
p.lastBlockHeight = blockHeight
if blockHeight > p.lastBlockHeight.Load() {
p.lastBlockHeight.Store(blockHeight)
}
demandOrders = append(demandOrders, order)
}
Expand Down Expand Up @@ -209,7 +210,7 @@ func (p *orderPoller) convertOrders(demandOrders []Order) (orders []*demandOrder
}

func (p *orderPoller) getDemandOrdersFromIndexer() ([]Order, error) {
queryStr := fmt.Sprintf(ordersQuery, p.chainID, fmt.Sprint(p.lastBlockHeight))
queryStr := fmt.Sprintf(ordersQuery, p.chainID, fmt.Sprint(p.lastBlockHeight.Load()))
body := strings.NewReader(queryStr)

resp, err := p.indexerClient.Post(p.indexerURL, "application/json", body)
Expand All @@ -230,5 +231,5 @@ func (p *orderPoller) getDemandOrdersFromIndexer() ([]Order, error) {
}

func (p *orderPoller) resetOrderPolling() {
p.lastBlockHeight = 0
p.lastBlockHeight.Store(0)
}

0 comments on commit 0057175

Please sign in to comment.