Skip to content

Commit

Permalink
chore(monitor/routerecon): support mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
corverroos committed Dec 6, 2024
1 parent 045e569 commit dad843b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
9 changes: 2 additions & 7 deletions monitor/routerecon/recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/omni-network/omni/e2e/app/eoa"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/ethclient"
"github.com/omni-network/omni/lib/evmchain"
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/xchain"
Expand All @@ -19,7 +18,7 @@ import (
)

func ReconForever(ctx context.Context, network netconf.Network, xprov xchain.Provider, ethCls map[uint64]ethclient.Client) {
if network.ID != netconf.Omega {
if network.ID.IsEphemeral() {
return
}

Expand All @@ -32,10 +31,6 @@ func ReconForever(ctx context.Context, network netconf.Network, xprov xchain.Pro
return
case <-ticker.C:
for _, stream := range network.EVMStreams() {
if stream.DestChainID == evmchain.IDArbSepolia || stream.SourceChainID == evmchain.IDArbSepolia {
continue // TODO(corver): Remove when routescan adds support for arb_sepolia.
}

err := reconStreamOnce(ctx, network, xprov, ethCls, stream)
if err != nil {
reconFailure.Inc()
Expand Down Expand Up @@ -71,7 +66,7 @@ func reconStreamOnce(
return nil // Skip recon for empty streams
}

crossTx, err := paginateLatestCrossTx(ctx, queryFilter{Stream: stream})
crossTx, err := paginateLatestCrossTx(ctx, network.ID, queryFilter{Stream: stream})
if err != nil {
return errors.Wrap(err, "fetch latest cross tx")
}
Expand Down
6 changes: 4 additions & 2 deletions monitor/routerecon/recon_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ func TestBasicHistorical(t *testing.T) {
t.Skip("skipping integration test")
}

network := netconf.Omega

ctx := context.Background()
conn, err := xconnect.New(ctx, netconf.Omega)
conn, err := xconnect.New(ctx, network)
require.NoError(t, err)

offsetsByStream := make(map[xchain.StreamID]map[uint64]crossTxJSON)
Expand All @@ -75,7 +77,7 @@ func TestBasicHistorical(t *testing.T) {
return nil
}

_, err = paginateLatestCrossTx(ctx, allCallback(callback))
_, err = paginateLatestCrossTx(ctx, network, allCallback(callback))
require.ErrorContains(t, err, "empty response") // Final pagination fails

for _, streamID := range conn.Network.EVMStreams() {
Expand Down
20 changes: 15 additions & 5 deletions monitor/routerecon/routescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@ import (

"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/evmchain"
"github.com/omni-network/omni/lib/netconf"
)

const (
baseURL = "https://api.routescan.io"
crossTxURL = "/v2/network/testnet/evm/cross-transactions"
crossTxURL = "/v2/network/%s/evm/cross-transactions"
)

func paginateLatestCrossTx(ctx context.Context, filter filter) (crossTxJSON, error) {
func getCrossTxURL(network netconf.ID) string {
net := "mainnet"
if network == netconf.Omega {
net = "testnet"
}

return fmt.Sprintf(crossTxURL, net)
}

func paginateLatestCrossTx(ctx context.Context, network netconf.ID, filter filter) (crossTxJSON, error) {
var (
resp crossTxJSON
next string
err error
)
for {
resp, next, err = queryLatestCrossTx(ctx, filter, next)
resp, next, err = queryLatestCrossTx(ctx, network, filter, next)
if err != nil {
return crossTxJSON{}, errors.Wrap(err, "query latest cross tx")
} else if next != "" {
Expand All @@ -44,11 +54,11 @@ type filter interface {
Match(tx crossTxJSON) (bool, error)
}

func queryLatestCrossTx(ctx context.Context, filter filter, next string) (crossTxJSON, string, error) {
func queryLatestCrossTx(ctx context.Context, network netconf.ID, filter filter, next string) (crossTxJSON, string, error) {
url := baseURL + next
if next == "" {
// Build initial path
url += crossTxURL
url += getCrossTxURL(network)
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
Expand Down
7 changes: 4 additions & 3 deletions monitor/routerecon/routescan_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ func TestReconLag(t *testing.T) {
t.Skip("skipping integration test")
}

network := netconf.Omega
ctx := context.Background()
conn, err := connect.New(ctx, netconf.Omega)
conn, err := connect.New(ctx, network)
require.NoError(t, err)

for _, stream := range conn.Network.EVMStreams() {
Expand All @@ -44,7 +45,7 @@ func TestReconLag(t *testing.T) {
continue
}

crossTx, err := paginateLatestCrossTx(ctx, queryFilter{Stream: stream})
crossTx, err := paginateLatestCrossTx(ctx, network, queryFilter{Stream: stream})
require.NoError(t, err, streamName)

lag := float64(cursor.MsgOffset) - float64(crossTx.Data.Offset)
Expand All @@ -59,7 +60,7 @@ func TestQueryLatestXChain(t *testing.T) {
}

ctx := context.Background()
resp, err := paginateLatestCrossTx(ctx, queryFilter{})
resp, err := paginateLatestCrossTx(ctx, netconf.Mainnet, queryFilter{})
require.NoError(t, err)
require.NotEmpty(t, resp.ID)

Expand Down

0 comments on commit dad843b

Please sign in to comment.