Skip to content

Commit

Permalink
improve: Update to sdk 18.0 (#1124)
Browse files Browse the repository at this point in the history
* feat: Update to [email protected] and replace latestBlockNumber property in clients with latestBlockSearched

* Update Dataworker.ts

* add 18.0

* Update src/clients/BundleDataClient.ts

Co-authored-by: Paul <[email protected]>

* Update src/dataworker/DataworkerUtils.ts

Co-authored-by: Paul <[email protected]>

* Update src/monitor/Monitor.ts

Co-authored-by: Paul <[email protected]>

* Update src/monitor/Monitor.ts

Co-authored-by: Paul <[email protected]>

* Update src/monitor/Monitor.ts

Co-authored-by: Paul <[email protected]>

* Update Dataworker.blockRangeUtils.ts

* lint

Signed-off-by: nicholaspai <[email protected]>

---------

Signed-off-by: nicholaspai <[email protected]>
Co-authored-by: Paul <[email protected]>
  • Loading branch information
nicholaspai and pxrl authored Dec 20, 2023
1 parent a43d645 commit fc41922
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 74 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.7",
"@across-protocol/contracts-v2": "2.4.7",
"@across-protocol/sdk-v2": "0.17.17",
"@across-protocol/sdk-v2": "0.18.0",
"@arbitrum/sdk": "^3.1.3",
"@defi-wonderland/smock": "^2.3.5",
"@eth-optimism/sdk": "^3.1.0",
Expand Down
8 changes: 4 additions & 4 deletions src/clients/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export class BundleDataClient {

async getPendingRefundsFromValidBundles(bundleLookback: number): Promise<FillsToRefund[]> {
const refunds = [];
if (!this.clients.hubPoolClient.isUpdated || this.clients.hubPoolClient.latestBlockNumber === undefined) {
if (!this.clients.hubPoolClient.isUpdated) {
throw new Error("BundleDataClient::getPendingRefundsFromValidBundles HubPoolClient not updated.");
}

let latestBlock = this.clients.hubPoolClient.latestBlockNumber;
let latestBlock = this.clients.hubPoolClient.latestBlockSearched;
for (let i = 0; i < bundleLookback; i++) {
const bundle = this.clients.hubPoolClient.getLatestFullyExecutedRootBundle(latestBlock);
if (bundle !== undefined) {
Expand Down Expand Up @@ -114,8 +114,8 @@ export class BundleDataClient {
this.spokePoolClients,
getEndBlockBuffers(this.chainIdListForBundleEvaluationBlockNumbers, this.blockRangeEndBlockBuffer),
this.clients,
this.clients.hubPoolClient.latestBlockNumber,
this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockNumber)
this.clients.hubPoolClient.latestBlockSearched,
this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestBlockSearched)
);
// Refunds that will be processed in the next bundle that will be proposed after the current pending bundle
// (if any) has been fully executed.
Expand Down
4 changes: 2 additions & 2 deletions src/clients/ConfigStoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export class ConfigStoreClient extends clients.AcrossConfigStoreClient {
if (isDefined(this.injectedChain)) {
const { chainId: injectedChainId, blockNumber: injectedBlockNumber } = this.injectedChain;
// Sanity check to ensure that this event doesn't happen in the future
if (injectedBlockNumber > this.latestBlockNumber) {
if (injectedBlockNumber > this.latestBlockSearched) {
this.logger.debug({
at: "ConfigStore[Relayer]#update",
message: `Injected block number ${injectedBlockNumber} is greater than the latest block number ${this.latestBlockNumber}`,
message: `Injected block number ${injectedBlockNumber} is greater than the latest block number ${this.latestBlockSearched}`,
});
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/clients/bridges/BaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export abstract class BaseAdapter {

// Note: this must be called after the SpokePoolClients are updated.
getUpdatedSearchConfigs(): { l1SearchConfig: EventSearchConfig; l2SearchConfig: EventSearchConfig } {
const l1LatestBlock = this.spokePoolClients[this.hubChainId].latestBlockNumber;
const l2LatestBlock = this.spokePoolClients[this.chainId].latestBlockNumber;
const l1LatestBlock = this.spokePoolClients[this.hubChainId].latestBlockSearched;
const l2LatestBlock = this.spokePoolClients[this.chainId].latestBlockSearched;
if (l1LatestBlock === 0 || l2LatestBlock === 0) {
throw new Error("One or more SpokePoolClients have not been updated");
}
Expand Down
34 changes: 13 additions & 21 deletions src/dataworker/Dataworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class Dataworker {
// are executed so we want to make sure that these are all older than the mainnet bundle end block which is
// sometimes treated as the "latest" mainnet block.
const mostRecentProposedRootBundle = this.clients.hubPoolClient.getLatestFullyExecutedRootBundle(
this.clients.hubPoolClient.latestBlockNumber
this.clients.hubPoolClient.latestBlockSearched
);

// If there has never been a validated root bundle, then we can always propose a new one:
Expand Down Expand Up @@ -270,7 +270,7 @@ export class Dataworker {
const { configStoreClient, hubPoolClient } = this.clients;

// Check if a bundle is pending.
if (!hubPoolClient.isUpdated || !hubPoolClient.latestBlockNumber) {
if (!hubPoolClient.isUpdated) {
throw new Error("HubPoolClient not updated");
}
if (!this.forceProposal && hubPoolClient.hasPendingProposal()) {
Expand All @@ -295,7 +295,7 @@ export class Dataworker {
// list, and the order of chain ID's is hardcoded in the ConfigStore client.
const nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(
this.chainIdListForBundleEvaluationBlockNumbers,
hubPoolClient.latestBlockNumber,
hubPoolClient.latestBlockSearched,
hubPoolClient.chainId
);
const blockRangesForProposal = this._getWidestPossibleBlockRangeForNextBundle(
Expand Down Expand Up @@ -350,7 +350,7 @@ export class Dataworker {
return;
}

const { chainId: hubPoolChainId, latestBlockNumber } = this.clients.hubPoolClient;
const { chainId: hubPoolChainId, latestBlockSearched } = this.clients.hubPoolClient;
const [mainnetBundleStartBlock, mainnetBundleEndBlock] = getBlockRangeForChain(
blockRangesForProposal,
hubPoolChainId,
Expand All @@ -365,7 +365,7 @@ export class Dataworker {

const rootBundleDataProducer = isUBA
? this.UBA_proposeRootBundle(blockRangesForProposal, ubaClient, spokePoolClients, true)
: this.Legacy_proposeRootBundle(blockRangesForProposal, spokePoolClients, latestBlockNumber, true);
: this.Legacy_proposeRootBundle(blockRangesForProposal, spokePoolClients, latestBlockSearched, true);

this.logger.debug({
at: "Dataworker#propose",
Expand Down Expand Up @@ -810,11 +810,7 @@ export class Dataworker {
earliestBlocksInSpokePoolClients: { [chainId: number]: number } = {},
ubaClient?: UBAClient
): Promise<void> {
if (
!this.clients.hubPoolClient.isUpdated ||
this.clients.hubPoolClient.currentTime === undefined ||
this.clients.hubPoolClient.latestBlockNumber === undefined
) {
if (!this.clients.hubPoolClient.isUpdated || this.clients.hubPoolClient.currentTime === undefined) {
throw new Error("HubPoolClient not updated");
}
const hubPoolChainId = this.clients.hubPoolClient.chainId;
Expand Down Expand Up @@ -847,7 +843,7 @@ export class Dataworker {

const nextBundleMainnetStartBlock = this.clients.hubPoolClient.getNextBundleStartBlockNumber(
this.chainIdListForBundleEvaluationBlockNumbers,
this.clients.hubPoolClient.latestBlockNumber,
this.clients.hubPoolClient.latestBlockSearched,
this.clients.hubPoolClient.chainId
);
const widestPossibleExpectedBlockRange = this._getWidestPossibleBlockRangeForNextBundle(
Expand Down Expand Up @@ -1281,7 +1277,7 @@ export class Dataworker {

const followingBlockNumber =
this.clients.hubPoolClient.getFollowingRootBundle(bundle)?.blockNumber ||
this.clients.hubPoolClient.latestBlockNumber;
this.clients.hubPoolClient.latestBlockSearched;

if (!followingBlockNumber) {
return false;
Expand Down Expand Up @@ -1587,11 +1583,7 @@ export class Dataworker {
message: "Executing pool rebalance leaves",
});

if (
!this.clients.hubPoolClient.isUpdated ||
this.clients.hubPoolClient.currentTime === undefined ||
this.clients.hubPoolClient.latestBlockNumber === undefined
) {
if (!this.clients.hubPoolClient.isUpdated || this.clients.hubPoolClient.currentTime === undefined) {
throw new Error("HubPoolClient not updated");
}
const hubPoolChainId = this.clients.hubPoolClient.chainId;
Expand All @@ -1614,7 +1606,7 @@ export class Dataworker {

const nextBundleMainnetStartBlock = this.clients.hubPoolClient.getNextBundleStartBlockNumber(
this.chainIdListForBundleEvaluationBlockNumbers,
this.clients.hubPoolClient.latestBlockNumber,
this.clients.hubPoolClient.latestBlockSearched,
this.clients.hubPoolClient.chainId
);
const widestPossibleExpectedBlockRange = this._getWidestPossibleBlockRangeForNextBundle(
Expand Down Expand Up @@ -1681,7 +1673,7 @@ export class Dataworker {

const executedLeaves = this.clients.hubPoolClient.getExecutedLeavesForRootBundle(
this.clients.hubPoolClient.getLatestProposedRootBundle(),
this.clients.hubPoolClient.latestBlockNumber
this.clients.hubPoolClient.latestBlockSearched
);

// Filter out previously executed leaves.
Expand Down Expand Up @@ -1940,7 +1932,7 @@ export class Dataworker {
return false;
}
const followingBlockNumber =
hubPoolClient.getFollowingRootBundle(bundle)?.blockNumber || hubPoolClient.latestBlockNumber;
hubPoolClient.getFollowingRootBundle(bundle)?.blockNumber || hubPoolClient.latestBlockSearched;

if (followingBlockNumber === undefined) {
return false;
Expand Down Expand Up @@ -2297,7 +2289,7 @@ export class Dataworker {
spokePoolClients,
getEndBlockBuffers(this.chainIdListForBundleEvaluationBlockNumbers, this.blockRangeEndBlockBuffer),
this.clients,
this.clients.hubPoolClient.latestBlockNumber,
this.clients.hubPoolClient.latestBlockSearched,
// We only want to count enabled chains at the same time that we are loading chain ID indices.
this.clients.configStoreClient.getEnabledChains(mainnetBundleStartBlock)
);
Expand Down
3 changes: 1 addition & 2 deletions src/dataworker/DataworkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export function blockRangesAreInvalidForSpokeClients(
return true;
}

const clientLastBlockQueried =
spokePoolClients[chainId].eventSearchConfig.toBlock ?? spokePoolClients[chainId].latestBlockNumber;
const clientLastBlockQueried = spokePoolClients[chainId].latestBlockSearched;

// Note: Math.max the from block with the deployment block of the spoke pool to handle the edge case for the first
// bundle that set its start blocks equal 0.
Expand Down
6 changes: 3 additions & 3 deletions src/dataworker/PoolRebalanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function updateRunningBalanceForEarlyDeposit(
// TODO: this must be handled s.t. it doesn't depend on when this is run.
// For now, tokens do not change their mappings often, so this will work, but
// to keep the system resilient, this must be updated.
hubPoolClient.latestBlockNumber
hubPoolClient.latestBlockSearched
);

updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart, updateAmount);
Expand Down Expand Up @@ -234,7 +234,7 @@ export async function subtractExcessFromPreviousSlowFillsFromRunningBalances(
.map(async (fill: interfaces.FillWithBlock) => {
const { lastMatchingFillInSameBundle, rootBundleEndBlockContainingFirstFill } =
await getFillDataForSlowFillFromPreviousRootBundle(
hubPoolClient.latestBlockNumber,
hubPoolClient.latestBlockSearched,
fill,
allValidFills,
hubPoolClient,
Expand All @@ -257,7 +257,7 @@ export async function subtractExcessFromPreviousSlowFillsFromRunningBalances(
// first fill for this deposit. If it is the same as the ProposeRootBundle event containing the
// current fill, then the first fill is in the current bundle and we can exit early.
const rootBundleEndBlockContainingFullFill = hubPoolClient.getRootBundleEvalBlockNumberContainingBlock(
hubPoolClient.latestBlockNumber,
hubPoolClient.latestBlockSearched,
fill.blockNumber,
fill.destinationChainId
);
Expand Down
2 changes: 1 addition & 1 deletion src/finalizer/utils/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function multicallArbitrumFinalizations(
const l1TokenCounterpart = hubPoolClient.getL1TokenCounterpartAtBlock(
CHAIN_ID,
message.info.l2TokenAddress,
hubPoolClient.latestBlockNumber
hubPoolClient.latestBlockSearched
);
const l1TokenInfo = hubPoolClient.getTokenInfo(1, l1TokenCounterpart);
const amountFromWei = convertFromWei(message.info.amountToReturn.toString(), l1TokenInfo.decimals);
Expand Down
4 changes: 2 additions & 2 deletions src/finalizer/utils/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async function multicallPolygonFinalizations(
const l1TokenCounterpart = hubPoolClient.getL1TokenCounterpartAtBlock(
CHAIN_ID,
message.l2TokenAddress,
hubPoolClient.latestBlockNumber
hubPoolClient.latestBlockSearched
);
const l1TokenInfo = hubPoolClient.getTokenInfo(1, l1TokenCounterpart);
const amountFromWei = convertFromWei(message.amountToReturn.toString(), l1TokenInfo.decimals);
Expand All @@ -208,7 +208,7 @@ async function retrieveTokenFromMainnetTokenBridger(
mainnetSigner: Signer,
hubPoolClient: HubPoolClient
): Promise<Multicall2Call> {
const l1Token = hubPoolClient.getL1TokenCounterpartAtBlock(CHAIN_ID, l2Token, hubPoolClient.latestBlockNumber);
const l1Token = hubPoolClient.getL1TokenCounterpartAtBlock(CHAIN_ID, l2Token, hubPoolClient.latestBlockSearched);
const mainnetTokenBridger = getMainnetTokenBridger(mainnetSigner);
const callData = await mainnetTokenBridger.populateTransaction.retrieve(l1Token);
return {
Expand Down
2 changes: 1 addition & 1 deletion src/finalizer/utils/zkSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function zkSyncFinalizer(
const l1TokenCounterpart = hubPoolClient.getL1TokenCounterpartAtBlock(
l2ChainId,
l2TokenAddress,
hubPoolClient.latestBlockNumber
hubPoolClient.latestBlockSearched
);
const { decimals, symbol: l1TokenSymbol } = hubPoolClient.getTokenInfo(l1ChainId, l1TokenCounterpart);
const amountFromWei = convertFromWei(amountToReturn.toString(), decimals);
Expand Down
4 changes: 2 additions & 2 deletions src/monitor/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export class Monitor {
// should stay unstuck for longer than one bundle.
async checkStuckRebalances(): Promise<void> {
const hubPoolClient = this.clients.hubPoolClient;
const lastFullyExecutedBundle = hubPoolClient.getLatestFullyExecutedRootBundle(hubPoolClient.latestBlockNumber);
const lastFullyExecutedBundle = hubPoolClient.getLatestFullyExecutedRootBundle(hubPoolClient.latestBlockSearched);
// This case shouldn't happen outside of tests as Across V2 has already launched.
if (lastFullyExecutedBundle === undefined) {
return;
Expand Down Expand Up @@ -940,7 +940,7 @@ export class Monitor {
// is now aware of those executions.
await new Contract(token, ERC20.abi, this.clients.spokePoolClients[chainId].spokePool.provider).balanceOf(
account,
{ blockTag: this.clients.spokePoolClients[chainId].latestBlockNumber }
{ blockTag: this.clients.spokePoolClients[chainId].latestBlockSearched }
);
if (!this.balanceCache[chainId]) {
this.balanceCache[chainId] = {};
Expand Down
6 changes: 3 additions & 3 deletions src/relayer/Relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class Relayer {
.filter((x) => {
return (
x.deposit.blockNumber <=
spokePoolClients[x.deposit.originChainId].latestBlockNumber - mdcPerChain[x.deposit.originChainId]
spokePoolClients[x.deposit.originChainId].latestBlockSearched - mdcPerChain[x.deposit.originChainId]
);
})
.sort((a, b) =>
Expand Down Expand Up @@ -522,8 +522,8 @@ export class Relayer {

const message = `${nRefunds === 0 ? "No" : nRefunds} outstanding fills with eligible cross-chain refunds found.`;
const blockRanges = Object.fromEntries(
spokePoolClients.map(({ chainId, deploymentBlock, latestBlockNumber }) => {
return [chainId, [fromBlocks[chainId] ?? deploymentBlock, latestBlockNumber]];
spokePoolClients.map(({ chainId, deploymentBlock, latestBlockSearched }) => {
return [chainId, [fromBlocks[chainId] ?? deploymentBlock, latestBlockSearched]];
})
);
this.logger.info({ at: "Relayer::requestRefunds", message, blockRanges });
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/validateRunningBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function runScript(_logger: winston.Logger, baseSigner: Signer): Pr
mrkdwn += `Bundle proposed at ${mostRecentValidatedBundle.transactionHash}`;
const followingBlockNumber =
clients.hubPoolClient.getFollowingRootBundle(mostRecentValidatedBundle)?.blockNumber ||
clients.hubPoolClient.latestBlockNumber;
clients.hubPoolClient.latestBlockSearched;
const poolRebalanceLeaves = clients.hubPoolClient.getExecutedLeavesForRootBundle(
mostRecentValidatedBundle,
followingBlockNumber
Expand Down Expand Up @@ -167,7 +167,7 @@ export async function runScript(_logger: winston.Logger, baseSigner: Signer): Pr
if (leaf.chainId !== clients.hubPoolClient.chainId) {
const _followingBlockNumber =
clients.hubPoolClient.getFollowingRootBundle(previousValidatedBundle)?.blockNumber ||
clients.hubPoolClient.latestBlockNumber;
clients.hubPoolClient.latestBlockSearched;
const previousBundlePoolRebalanceLeaves = clients.hubPoolClient.getExecutedLeavesForRootBundle(
previousValidatedBundle,
_followingBlockNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TestAdapter extends BaseAdapter {
constructor() {
super(
{
1: { latestBlockNumber: 123 } as unknown as SpokePoolClient,
1: { latestBlockSearched: 123 } as unknown as SpokePoolClient,
},
1,
["0xmonitored"],
Expand Down
Loading

0 comments on commit fc41922

Please sign in to comment.