Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(dataworker): Remove transferThreshold #937

Merged
merged 17 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@across-protocol/contracts-v2": "2.4.3",
"@across-protocol/sdk-v2": "0.15.24",
"@across-protocol/sdk-v2": "0.16.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we get this far behind...? Can you just double check the changes that get pulled in here (considering the number of bumps)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 0.15.24 was the last release before 0.16 and that's because https://github.com/across-protocol/sdk-v2/releases/tag/v0.16.0 introduced the removal of the transferThreshold variable!

This PR has been sitting for a while haha

"@arbitrum/sdk": "^3.1.3",
"@defi-wonderland/smock": "^2.3.5",
"@eth-optimism/sdk": "^3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/clients/TokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export class TokenClient {
// requirement to send all seen relays and the total remaining balance of the relayer.
getTokenShortfall(): {
[chainId: number]: {
[token: string]: { balance: BigNumber; needed: BigNumber; shortfall: BigNumber; deposits: BigNumber };
[token: string]: { balance: BigNumber; needed: BigNumber; shortfall: BigNumber; deposits: number[] };
};
} {
const tokenShortfall: {
[chainId: number]: {
[token: string]: { balance: BigNumber; needed: BigNumber; shortfall: BigNumber; deposits: BigNumber };
[token: string]: { balance: BigNumber; needed: BigNumber; shortfall: BigNumber; deposits: number[] };
};
} = {};
Object.entries(this.tokenShortfall).forEach(([_chainId, tokenMap]) => {
Expand Down
27 changes: 16 additions & 11 deletions src/dataworker/Dataworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
RunningBalances,
PoolRebalanceLeaf,
RelayerRefundLeaf,
BigNumberForToken,
} from "../interfaces";
import { DataworkerClients } from "./DataworkerClientHelper";
import { SpokePoolClient, UBAClient, BalanceAllocator } from "../clients";
Expand Down Expand Up @@ -92,7 +91,6 @@ export class Dataworker {
readonly chainIdListForBundleEvaluationBlockNumbers: number[],
readonly maxRefundCountOverride: number | undefined,
readonly maxL1TokenCountOverride: number | undefined,
readonly tokenTransferThreshold: BigNumberForToken = {},
readonly blockRangeEndBlockBuffer: { [chainId: number]: number } = {},
readonly spokeRootsLookbackCount = 0,
readonly bufferToPropose = 0,
Expand All @@ -102,7 +100,6 @@ export class Dataworker {
if (
maxRefundCountOverride !== undefined ||
maxL1TokenCountOverride !== undefined ||
Object.keys(tokenTransferThreshold).length > 0 ||
Object.keys(blockRangeEndBlockBuffer).length > 0
) {
this.logger.debug({
Expand All @@ -111,7 +108,6 @@ export class Dataworker {
chainIdListForBundleEvaluationBlockNumbers,
maxRefundCountOverride: this.maxRefundCountOverride,
maxL1TokenCountOverride: this.maxL1TokenCountOverride,
tokenTransferThreshold: this.tokenTransferThreshold,
blockRangeEndBlockBuffer: this.blockRangeEndBlockBuffer,
});
}
Expand Down Expand Up @@ -157,8 +153,7 @@ export class Dataworker {
poolRebalanceLeaves,
runningBalances,
this.clients,
maxRefundCount,
this.tokenTransferThreshold
maxRefundCount
);
}

Expand Down Expand Up @@ -531,8 +526,7 @@ export class Dataworker {
this.clients,
this.maxRefundCountOverride
? this.maxRefundCountOverride
: this.clients.configStoreClient.getMaxRefundCountForRelayerRefundLeafForBlock(mainnetBundleEndBlock),
this.tokenTransferThreshold
: this.clients.configStoreClient.getMaxRefundCountForRelayerRefundLeafForBlock(mainnetBundleEndBlock)
);
const slowRelayRoot = _buildSlowRelayRoot(unfilledDeposits);

Expand Down Expand Up @@ -729,7 +723,6 @@ export class Dataworker {
poolRebalanceLeafData.bundleLpFees,
this.clients.configStoreClient,
this.maxL1TokenCountOverride,
this.tokenTransferThreshold,
poolRebalanceLeafData.incentivePoolBalances,
poolRebalanceLeafData.netSendAmounts,
true
Expand Down Expand Up @@ -804,7 +797,6 @@ export class Dataworker {
this.maxRefundCountOverride
? this.maxRefundCountOverride
: this.clients.configStoreClient.getMaxRefundCountForRelayerRefundLeafForBlock(mainnetBundleEndBlock),
this.tokenTransferThreshold,
true // Instruct function to always set amountToReturn = -netSendAmount iff netSendAmount < 0
);
return relayerRefundRoot;
Expand Down Expand Up @@ -1138,12 +1130,26 @@ export class Dataworker {
reason: "out-of-date-config-store-version",
};
}

let rootBundleData: ProposeRootBundleReturnType;
const mainnetBundleStartBlock = getBlockRangeForChain(
blockRangesImpliedByBundleEndBlocks,
hubPoolChainId,
this.chainIdListForBundleEvaluationBlockNumbers
)[0];

// Check if we have the right code to validate a bundle for the given block ranges.
const versionAtProposalBlock =
this.clients.configStoreClient.getConfigStoreVersionForBlock(mainnetBundleStartBlock);

// Bundles that need to be validated with older code should emit helpful error logs about which code to run.
// @dev only throw this error if the hub chain ID is 1, suggesting we're running on production.
if (hubPoolChainId === 1 && versionAtProposalBlock <= sdk.constants.TRANSFER_THRESHOLD_MAX_CONFIG_STORE_VERSION) {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(
"Must use relayer-v2 code at commit 412ddc30af72c2ac78f9e4c8dccfccfd0eb478ab to validate a bundle with transferThreshold set"
);
}

let isUBA = false;
if (
sdk.clients.isUBAActivatedAtBlock(
Expand Down Expand Up @@ -2248,7 +2254,6 @@ export class Dataworker {
spokePoolClients,
this.chainIdListForBundleEvaluationBlockNumbers,
this.maxL1TokenCountOverride,
this.tokenTransferThreshold,
logSlowFillExcessData ? this.logger : undefined
);
}
Expand Down
5 changes: 0 additions & 5 deletions src/dataworker/DataworkerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BigNumber, assert, toBNWei } from "../utils";
export class DataworkerConfig extends CommonConfig {
readonly maxPoolRebalanceLeafSizeOverride: number;
readonly maxRelayerRepaymentLeafSizeOverride: number;
readonly tokenTransferThresholdOverride: { [l1TokenAddress: string]: BigNumber };
readonly rootBundleExecutionThreshold: BigNumber;
readonly spokeRootsLookbackCount: number; // Consider making this configurable per chain ID.

Expand Down Expand Up @@ -42,7 +41,6 @@ export class DataworkerConfig extends CommonConfig {
constructor(env: ProcessEnv) {
const {
ROOT_BUNDLE_EXECUTION_THRESHOLD,
TOKEN_TRANSFER_THRESHOLD_OVERRIDE,
MAX_POOL_REBALANCE_LEAF_SIZE_OVERRIDE,
MAX_RELAYER_REPAYMENT_LEAF_SIZE_OVERRIDE,
DISPUTER_ENABLED,
Expand Down Expand Up @@ -76,9 +74,6 @@ export class DataworkerConfig extends CommonConfig {
if (this.maxRelayerRepaymentLeafSizeOverride !== undefined) {
assert(this.maxRelayerRepaymentLeafSizeOverride > 0, "Max leaf count set to 0");
}
this.tokenTransferThresholdOverride = TOKEN_TRANSFER_THRESHOLD_OVERRIDE
? JSON.parse(TOKEN_TRANSFER_THRESHOLD_OVERRIDE)
: {};
this.rootBundleExecutionThreshold = ROOT_BUNDLE_EXECUTION_THRESHOLD
? toBNWei(ROOT_BUNDLE_EXECUTION_THRESHOLD)
: toBNWei("500000");
Expand Down
16 changes: 2 additions & 14 deletions src/dataworker/DataworkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SpokePoolClient } from "../clients";
import { spokesThatHoldEthAndWeth } from "../common/Constants";
import { CONTRACT_ADDRESSES } from "../common/ContractAddresses";
import {
BigNumberForToken,
DepositWithBlock,
FillsToRefund,
FillWithBlock,
Expand Down Expand Up @@ -192,7 +191,6 @@ export function _buildRelayerRefundRoot(
runningBalances: RunningBalances,
clients: DataworkerClients,
maxRefundCount: number,
tokenTransferThresholdOverrides: BigNumberForToken,
isUBA = false
): {
leaves: RelayerRefundLeaf[];
Expand Down Expand Up @@ -226,9 +224,6 @@ export function _buildRelayerRefundRoot(
l2TokenAddress,
endBlockForMainnet
);
const transferThreshold =
tokenTransferThresholdOverrides[l1TokenCounterpart] ||
clients.configStoreClient.getTokenTransferThresholdForBlock(l1TokenCounterpart, endBlockForMainnet);

const spokePoolTargetBalance = clients.configStoreClient.getSpokeTargetBalancesForBlock(
l1TokenCounterpart,
Expand All @@ -238,7 +233,6 @@ export function _buildRelayerRefundRoot(

// The `amountToReturn` for a { repaymentChainId, L2TokenAddress} should be set to max(-netSendAmount, 0).
amountToReturn = getAmountToReturnForRelayerRefundLeaf(
transferThreshold,
spokePoolTargetBalance,
runningBalances[repaymentChainId][l1TokenCounterpart]
);
Expand Down Expand Up @@ -285,18 +279,13 @@ export function _buildRelayerRefundRoot(
// If UBA model we don't need to do the following to figure out the amount to return:
let amountToReturn = netSendAmount.mul(-1);
if (!isUBA) {
const transferThreshold =
tokenTransferThresholdOverrides[leaf.l1Tokens[index]] ||
clients.configStoreClient.getTokenTransferThresholdForBlock(leaf.l1Tokens[index], endBlockForMainnet);

const spokePoolTargetBalance = clients.configStoreClient.getSpokeTargetBalancesForBlock(
leaf.l1Tokens[index],
leaf.chainId,
endBlockForMainnet
);

amountToReturn = getAmountToReturnForRelayerRefundLeaf(
transferThreshold,
spokePoolTargetBalance,
runningBalances[leaf.chainId][leaf.l1Tokens[index]]
);
Expand Down Expand Up @@ -334,7 +323,6 @@ export async function _buildPoolRebalanceRoot(
spokePoolClients: SpokePoolClientsByChain,
chainIdListForBundleEvaluationBlockNumbers: number[],
maxL1TokenCountOverride: number | undefined,
tokenTransferThreshold: BigNumberForToken,
logger?: winston.Logger
): Promise<PoolRebalanceRoot> {
// Running balances are the amount of tokens that we need to send to each SpokePool to pay for all instant and
Expand Down Expand Up @@ -369,6 +357,7 @@ export async function _buildPoolRebalanceRoot(
allValidFills,
allValidFillsInRange
);

if (logger && Object.keys(fillsTriggeringExcesses).length > 0) {
logger.debug({
at: "Dataworker#DataworkerUtils",
Expand Down Expand Up @@ -407,8 +396,7 @@ export async function _buildPoolRebalanceRoot(
runningBalances,
realizedLpFees,
clients.configStoreClient,
maxL1TokenCountOverride,
tokenTransferThreshold
maxL1TokenCountOverride
);

return {
Expand Down
27 changes: 4 additions & 23 deletions src/dataworker/PoolRebalanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ConfigStoreClient, HubPoolClient, SpokePoolClient } from "../clients";
import { Clients } from "../common";
import * as interfaces from "../interfaces";
import {
BigNumberForToken,
PendingRootBundle,
PoolRebalanceLeaf,
RelayerRefundLeaf,
Expand Down Expand Up @@ -300,7 +299,6 @@ export function constructPoolRebalanceLeaves(
realizedLpFees: interfaces.RunningBalances,
configStoreClient: ConfigStoreClient,
maxL1TokenCount?: number,
tokenTransferThreshold?: BigNumberForToken,
incentivePoolBalances?: interfaces.RunningBalances,
netSendAmounts?: interfaces.RunningBalances,
ubaMode = false
Expand All @@ -326,12 +324,6 @@ export function constructPoolRebalanceLeaves(
for (let i = 0; i < sortedL1Tokens.length; i += maxL1TokensPerLeaf) {
const l1TokensToIncludeInThisLeaf = sortedL1Tokens.slice(i, i + maxL1TokensPerLeaf);

const transferThresholds = l1TokensToIncludeInThisLeaf.map(
(l1Token) =>
tokenTransferThreshold[l1Token] ||
configStoreClient.getTokenTransferThresholdForBlock(l1Token, latestMainnetBlock)
);

const spokeTargetBalances = l1TokensToIncludeInThisLeaf.map((l1Token) =>
configStoreClient.getSpokeTargetBalancesForBlock(l1Token, Number(chainId), latestMainnetBlock)
);
Expand All @@ -349,11 +341,7 @@ export function constructPoolRebalanceLeaves(
if (ubaMode && netSendAmounts?.[chainId] && netSendAmounts[chainId][l1Token]) {
return netSendAmounts[chainId][l1Token];
} else if (runningBalances[chainId] && runningBalances[chainId][l1Token]) {
return getNetSendAmountForL1Token(
transferThresholds[index],
spokeTargetBalances[index],
runningBalances[chainId][l1Token]
);
return getNetSendAmountForL1Token(spokeTargetBalances[index], runningBalances[chainId][l1Token]);
} else {
return toBN(0);
}
Expand All @@ -366,11 +354,7 @@ export function constructPoolRebalanceLeaves(
if (ubaMode) {
return runningBalances[chainId][l1Token];
} else {
return getRunningBalanceForL1Token(
transferThresholds[index],
spokeTargetBalances[index],
runningBalances[chainId][l1Token]
);
return getRunningBalanceForL1Token(spokeTargetBalances[index], runningBalances[chainId][l1Token]);
}
} else {
return toBN(0);
Expand Down Expand Up @@ -438,21 +422,18 @@ export function computeDesiredTransferAmountToSpoke(
// 0, indicating that we do not want the data worker to trigger a token transfer between hub pool and spoke
// pool when executing this leaf.
export function getNetSendAmountForL1Token(
transferThreshold: BigNumber,
spokePoolTargetBalance: SpokePoolTargetBalance,
runningBalance: BigNumber
): BigNumber {
const desiredTransferAmount = computeDesiredTransferAmountToSpoke(runningBalance, spokePoolTargetBalance);
return desiredTransferAmount.abs().gte(transferThreshold) ? desiredTransferAmount : toBN(0);
return computeDesiredTransferAmountToSpoke(runningBalance, spokePoolTargetBalance);
}

export function getRunningBalanceForL1Token(
transferThreshold: BigNumber,
spokePoolTargetBalance: SpokePoolTargetBalance,
runningBalance: BigNumber
): BigNumber {
const desiredTransferAmount = computeDesiredTransferAmountToSpoke(runningBalance, spokePoolTargetBalance);
return desiredTransferAmount.abs().lt(transferThreshold) ? runningBalance : runningBalance.sub(desiredTransferAmount);
return runningBalance.sub(desiredTransferAmount);
}

// This returns a possible next block range that could be submitted as a new root bundle, or used as a reference
Expand Down
7 changes: 1 addition & 6 deletions src/dataworker/RelayerRefundUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ import { BigNumber, compareAddresses, toBN } from "../utils";
import { getNetSendAmountForL1Token } from "./PoolRebalanceUtils";

export function getAmountToReturnForRelayerRefundLeaf(
transferThreshold: BigNumber,
spokePoolTargetBalance: SpokePoolTargetBalance,
runningBalanceForLeaf: BigNumber
): BigNumber {
const netSendAmountForLeaf = getNetSendAmountForL1Token(
transferThreshold,
spokePoolTargetBalance,
runningBalanceForLeaf
);
const netSendAmountForLeaf = getNetSendAmountForL1Token(spokePoolTargetBalance, runningBalanceForLeaf);
return netSendAmountForLeaf.mul(toBN(-1)).gt(toBN(0)) ? netSendAmountForLeaf.mul(toBN(-1)) : toBN(0);
}

Expand Down
1 change: 0 additions & 1 deletion src/dataworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function createDataworker(
clients.configStoreClient.getChainIdIndicesForBlock(),
config.maxRelayerRepaymentLeafSizeOverride,
config.maxPoolRebalanceLeafSizeOverride,
config.tokenTransferThresholdOverride,
config.blockRangeEndBlockBuffer,
config.spokeRootsLookbackCount,
config.bufferToPropose,
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type BigNumberForToken = interfaces.BigNumberForToken;

// ConfigStore interfaces
export type ParsedTokenConfig = interfaces.ParsedTokenConfig;
export type L1TokenTransferThreshold = interfaces.L1TokenTransferThreshold;
export type SpokePoolTargetBalance = interfaces.SpokePoolTargetBalance;
export type SpokeTargetBalanceUpdate = interfaces.SpokeTargetBalanceUpdate;
export type RouteRateModelUpdate = interfaces.RouteRateModelUpdate;
Expand Down
Loading