Skip to content

Commit

Permalink
feat(monitor/xfeemngr): slow sync on ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhalliday committed Oct 31, 2024
1 parent ac1f411 commit d547bef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
12 changes: 10 additions & 2 deletions monitor/xfeemngr/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type feeOracle struct {
chain evmchain.Metadata // source chain
tick ticker.Ticker // ticker to sync fee oracle
toSync []evmchain.Metadata // chains to sync on fee oracle
gprice *gasprice.Buffer // gas price buffer
tprice *tokenprice.Buffer // token price buffer
Expand All @@ -34,6 +35,12 @@ func makeOracle(chain netconf.Chain, toSync []evmchain.Metadata, ethCl ethclient
return feeOracle{}, errors.New("chain metadata not found", "chain", chain.ID)
}

syncInterval := feeOracleSyncInterval
override, ok := chainSyncOverrides[chain.ID]
if ok {
syncInterval = override
}

getContract := func() func(context.Context) (contract.FeeOracleV1, error) {
var c *contract.BoundFeeOracleV1

Expand All @@ -55,6 +62,7 @@ func makeOracle(chain netconf.Chain, toSync []evmchain.Metadata, ethCl ethclient

return feeOracle{
chain: chainmeta,
tick: ticker.New(ticker.WithInterval(syncInterval)),
toSync: toSync,
gprice: gprice,
tprice: tprice,
Expand All @@ -63,10 +71,10 @@ func makeOracle(chain netconf.Chain, toSync []evmchain.Metadata, ethCl ethclient
}

// syncForever syncs the on-chain gas price and token conversion rates with their respective buffers, forever.
func (o feeOracle) syncForever(ctx context.Context, tick ticker.Ticker) {
func (o feeOracle) syncForever(ctx context.Context) {
ctx = log.WithCtx(ctx, "component", "feeOracle", "chain", o.chain.Name)
log.Info(ctx, "Starting fee oracle sync")
tick.Go(ctx, o.syncOnce)
o.tick.Go(ctx, o.syncOnce)
}

// syncOnce syncs the on-chain gas price and token conversion rates with their respective buffers, once.
Expand Down
14 changes: 10 additions & 4 deletions monitor/xfeemngr/xfeemngr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/omni-network/omni/lib/tokens/coingecko"
"github.com/omni-network/omni/lib/xchain"
"github.com/omni-network/omni/monitor/xfeemngr/gasprice"
"github.com/omni-network/omni/monitor/xfeemngr/ticker"
"github.com/omni-network/omni/monitor/xfeemngr/tokenprice"

"github.com/ethereum/go-ethereum"
Expand All @@ -25,7 +24,6 @@ type Manager struct {
gprice *gasprice.Buffer
tprice *tokenprice.Buffer
oracles map[uint64]feeOracle
ticker ticker.Ticker
}

type Config struct {
Expand Down Expand Up @@ -57,6 +55,14 @@ const (
maxSaneEthPerOmni = float64(1)
)

var chainSyncOverrides = map[uint64]time.Duration{
// override for ethereum mainnet, to reduce spend
evmchain.IDEthereum: 90 * time.Minute,

// overide on holesky too, to test overide on omega
evmchain.IDHolesky: 90 * time.Minute,
}

func Start(ctx context.Context, network netconf.Network, cfg Config, privKeyPath string) error {
log.Info(ctx, "Starting fee manager", "endpoint", cfg.RPCEndpoints)

Expand Down Expand Up @@ -89,7 +95,7 @@ func Start(ctx context.Context, network netconf.Network, cfg Config, privKeyPath
gprice: gprice,
tprice: tprice,
oracles: oracles,
ticker: ticker.New(ticker.WithInterval(feeOracleSyncInterval)),
// ticker: ticker.New(ticker.WithInterval(feeOracleSyncInterval)),
}

startMonitoring(ctx, network, ethClients)
Expand All @@ -108,7 +114,7 @@ func (m *Manager) start(ctx context.Context) {

// start oracle sync
for _, oracle := range m.oracles {
oracle.syncForever(ctx, m.ticker)
oracle.syncForever(ctx)
}
}

Expand Down
6 changes: 3 additions & 3 deletions monitor/xfeemngr/xfeemngr_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestStart(t *testing.T) {
tpriceBuf := tokenprice.NewBuffer(tokenPricer, tokens.OMNI, tokens.ETH, tokenprice.WithThresholdPct(tpriceThreshold), tokenprice.WithTicker(tick))

chains := makeChains(chainIDs)
oracles := makeMockOracles(chains, gpriceBuf, tpriceBuf)
oracles := makeMockOracles(chains, tick, gpriceBuf, tpriceBuf)

// make sure all postsTo are zero, at start
// this way when we check them later, we know they have been updated
Expand All @@ -90,7 +90,6 @@ func TestStart(t *testing.T) {
mngr := Manager{
gprice: gpriceBuf,
tprice: tpriceBuf,
ticker: tick,
oracles: oracles,
}

Expand Down Expand Up @@ -216,7 +215,7 @@ func TestStart(t *testing.T) {
expectInitials()
}

func makeMockOracles(chains []evmchain.Metadata, gprice *gasprice.Buffer, tprice *tokenprice.Buffer) map[uint64]feeOracle {
func makeMockOracles(chains []evmchain.Metadata, tick ticker.Ticker, gprice *gasprice.Buffer, tprice *tokenprice.Buffer) map[uint64]feeOracle {
oracles := make(map[uint64]feeOracle)

for _, chain := range chains {
Expand All @@ -225,6 +224,7 @@ func makeMockOracles(chains []evmchain.Metadata, gprice *gasprice.Buffer, tprice

oracles[chain.ChainID] = feeOracle{
chain: chain,
tick: tick,
toSync: chains,
gprice: gprice,
tprice: tprice,
Expand Down

0 comments on commit d547bef

Please sign in to comment.