Skip to content

Commit

Permalink
improve(relayer): Limit HubPoolClient lookback (#1275)
Browse files Browse the repository at this point in the history
The HubPoolClient now has logic to override the requested lookback for
specific events if it has not previously been updated. This is the same
logic that is implemented for the SpokePoolClients. As a result, it's
now possible to be much more restrictive on the lookback for the
HubPoolClient. The relayer can benefit from this be only querying
RootBundle events for the past ~12 hours, which should be sufficient for
the InventoryManager to determine repayment chains.
  • Loading branch information
pxrl authored Mar 9, 2024
1 parent b163618 commit cd91c00
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@across-protocol/constants-v2": "1.0.11",
"@across-protocol/contracts-v2": "2.5.0-beta.7",
"@across-protocol/sdk-v2": "0.22.10",
"@across-protocol/sdk-v2": "0.22.11",
"@arbitrum/sdk": "^3.1.3",
"@defi-wonderland/smock": "^2.3.5",
"@eth-optimism/sdk": "^3.2.1",
Expand Down
17 changes: 10 additions & 7 deletions src/common/ClientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { HubPoolClient, MultiCallerClient, ConfigStoreClient, SpokePoolClient } from "../clients";
import { CommonConfig } from "./Config";
import { SpokePoolClientsByChain } from "../interfaces";
import { clients } from "@across-protocol/sdk-v2";
import { clients, utils as sdkUtils } from "@across-protocol/sdk-v2";

export interface Clients {
hubPoolClient: HubPoolClient;
Expand Down Expand Up @@ -263,7 +263,8 @@ export async function updateSpokePoolClients(
export async function constructClients(
logger: winston.Logger,
config: CommonConfig,
baseSigner: Signer
baseSigner: Signer,
hubPoolLookback?: number
): Promise<Clients> {
const hubPoolProvider = await getProvider(config.hubPoolChainId, logger);
const hubSigner = baseSigner.connect(hubPoolProvider);
Expand All @@ -283,18 +284,20 @@ export async function constructClients(
config.maxConfigVersion
);

const hubPoolClientSearchSettings = {
...rateModelClientSearchSettings,
fromBlock: Number(getDeploymentBlockNumber("HubPool", config.hubPoolChainId)),
};
const hubPoolDeploymentBlock = Number(getDeploymentBlockNumber("HubPool", config.hubPoolChainId));
const { average: avgMainnetBlockTime } = await sdkUtils.averageBlockTime(hubPoolProvider);
const fromBlock = isDefined(hubPoolLookback)
? Math.max(latestMainnetBlock - hubPoolLookback / avgMainnetBlockTime, hubPoolDeploymentBlock)
: hubPoolDeploymentBlock;
const hubPoolClientSearchSettings = { ...rateModelClientSearchSettings, fromBlock };

// Create contract instances for each chain for each required contract.
const hubPool = getDeployedContract("HubPool", config.hubPoolChainId, hubSigner);
const hubPoolClient = new HubPoolClient(
logger,
hubPool,
configStoreClient,
Number(getDeploymentBlockNumber("HubPool", config.hubPoolChainId)),
hubPoolDeploymentBlock,
config.hubPoolChainId,
hubPoolClientSearchSettings,
await getRedisCache(logger),
Expand Down
5 changes: 4 additions & 1 deletion src/relayer/RelayerClientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export async function constructRelayerClients(
baseSigner: Signer
): Promise<RelayerClients> {
const signerAddr = await baseSigner.getAddress();
const commonClients = await constructClients(logger, config, baseSigner);
// The relayer only uses the HubPoolClient to query repayments refunds for the latest validated
// bundle and the pending bundle. 12 hours should cover these bundles in almost all cases.
const hubPoolLookBack = 3600 * 12;
const commonClients = await constructClients(logger, config, baseSigner, hubPoolLookBack);
const { configStoreClient, hubPoolClient } = commonClients;
await updateClients(commonClients, config);
await hubPoolClient.update();
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
"@openzeppelin/contracts" "4.1.0"
"@uma/core" "^2.18.0"

"@across-protocol/[email protected].10":
version "0.22.10"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk-v2/-/sdk-v2-0.22.10.tgz#3cba4df6b0c29faf50b68b683f60ce9ed0f3ce92"
integrity sha512-UlGEQrIGXUe0qRz3Cdtl+d2eyMu7sKlTrYUTRME+Ctv6ASo7P277oUPs9QQzpPaUViIWeO4Qh/dJi1wC+y06Rw==
"@across-protocol/[email protected].11":
version "0.22.11"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk-v2/-/sdk-v2-0.22.11.tgz#a6a83e6e0f232d22e37acfaa7a7d59a2c6639b2f"
integrity sha512-e+L52wL81PYnjsK5UvAPzi8SSuI1BJpNL3rYSQ7TWgbr3ds0Iqefy8A6q+ZkjqeqEd6VFdmPU0IUdGtkycUz7A==
dependencies:
"@across-protocol/across-token" "^1.0.0"
"@across-protocol/constants-v2" "^1.0.12"
Expand Down

0 comments on commit cd91c00

Please sign in to comment.