From a4e394596ba53872fa476fa29e3d1d396e5451db Mon Sep 17 00:00:00 2001 From: corver <29249923+corverroos@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:11:54 +0200 Subject: [PATCH] chore(monitor/routerecon): support mainnet (#2648) Enable routerecon for mainnet. issue: https://github.com/omni-network/ops/issues/654 --- monitor/routerecon/recon.go | 9 ++------- monitor/routerecon/recon_internal_test.go | 6 ++++-- monitor/routerecon/routescan.go | 20 ++++++++++++++----- monitor/routerecon/routescan_internal_test.go | 7 ++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/monitor/routerecon/recon.go b/monitor/routerecon/recon.go index 5f7a85438..e750a74ea 100644 --- a/monitor/routerecon/recon.go +++ b/monitor/routerecon/recon.go @@ -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" @@ -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 } @@ -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() @@ -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") } diff --git a/monitor/routerecon/recon_internal_test.go b/monitor/routerecon/recon_internal_test.go index 17b0d87c0..637f63f3a 100644 --- a/monitor/routerecon/recon_internal_test.go +++ b/monitor/routerecon/recon_internal_test.go @@ -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) @@ -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() { diff --git a/monitor/routerecon/routescan.go b/monitor/routerecon/routescan.go index 0c3b3260a..9a585a066 100644 --- a/monitor/routerecon/routescan.go +++ b/monitor/routerecon/routescan.go @@ -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 != "" { @@ -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) diff --git a/monitor/routerecon/routescan_internal_test.go b/monitor/routerecon/routescan_internal_test.go index 1b084b66a..be5620e10 100644 --- a/monitor/routerecon/routescan_internal_test.go +++ b/monitor/routerecon/routescan_internal_test.go @@ -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() { @@ -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) @@ -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)