Skip to content

Commit

Permalink
feat(monitor/xfeemngr): always refresh full price buffer (#2752)
Browse files Browse the repository at this point in the history
When a single live token price falls outside threshold, update all
buffered prices.

This should keep buffered token <> token conversion rates more in sync
with live conversion rates.

issue: none
  • Loading branch information
kevinhalliday authored Jan 7, 2025
1 parent a244190 commit ead6061
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 10 additions & 3 deletions monitor/xfeemngr/tokenprice/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,23 @@ func (b *buffer) stream(ctx context.Context) {

guageLive(prices)

// update buffered prices, if necessary
// check if any prices have changed by more than the threshold
refresh := false
for token, price := range prices {
buffed, ok := b.price(token)

// if price is buffered, and is within threshold, skip
if ok && inThreshold(price, buffed, b.threshold) {
continue
}

b.setPrice(token, price)
refresh = true
}

// if any outside threshold, update all
if refresh {
for token, price := range prices {
b.setPrice(token, price)
}
}

b.gaugeBuffered()
Expand Down
15 changes: 13 additions & 2 deletions monitor/xfeemngr/tokenprice/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,22 @@ func TestBufferStream(t *testing.T) {
live, err := pricer.Price(ctx, tokens.OMNI, tokens.ETH)
require.NoError(t, err)

// check if any live price is outside threshold
shouldRefresh := false
for token, price := range live {
if inThreshold(price, buffed[token], thresh) {
require.InEpsilon(t, buffed[token], b.Price(token), 0.001, "should not update")
} else {
continue
}

shouldRefresh = true
}

// if any price is outside threshold, all prices should be updated
for token, price := range live {
if shouldRefresh {
require.InEpsilon(t, price, b.Price(token), 0.001, "should update")
} else {
require.InEpsilon(t, buffed[token], b.Price(token), 0.001, "should not update")
}
}
}
Expand Down

0 comments on commit ead6061

Please sign in to comment.