Skip to content

Commit

Permalink
fix(Dataworker): Send msgValue to pay for Linea leaf executions IFF a…
Browse files Browse the repository at this point in the history
…mountToReturn > 0 (#1347)

Currently we are sending the fee for every single Linea leaf execution. This ultimately means we are donating the fee to the LP pool because the LineaSpokePool will deposit any ETH in its balance into WETH rather than keep an ETH balance to use for these leaf executions. (In other words, the Linea SpokePool is dumb and doesn't segregate leaf execution fees from LP funds, therefore it is the responsibility of the leaf executor to only send an appropriate amount to pay for fees exactly when those fees are meant to be used).

The damage right now is minimal, totalling ~0.01 ETH for 10 leaf executions.
  • Loading branch information
nicholaspai authored Mar 22, 2024
1 parent 4e268da commit d4cbd89
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/dataworker/Dataworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2082,9 +2082,16 @@ export class Dataworker {
// If the chain is Linea, then we need to allocate ETH in the call to executeRelayerRefundLeaf. This is currently
// unique to the L2 -> L1 relay direction for Linea. We will make this variable generic defaulting to undefined
// for other chains.
const valueToPassViaPayable = sdkUtils.chainIsLinea(chainId)
const LINEA_FEE_TO_SEND_MSG_TO_L1 = sdkUtils.chainIsLinea(chainId)
? await this._getRequiredEthForLineaRelayLeafExecution(client)
: undefined;
const getMsgValue = (leaf: RelayerRefundLeaf): BigNumber | undefined => {
// Only need to include a msg.value if amountToReturn > 0 and we need to send tokens back to HubPool.
if (LINEA_FEE_TO_SEND_MSG_TO_L1 && leaf.amountToReturn.gt(0)) {
return LINEA_FEE_TO_SEND_MSG_TO_L1;
}
return undefined;
};

// Filter for leaves where the contract has the funding to send the required tokens.
const fundedLeaves = (
Expand All @@ -2104,6 +2111,8 @@ export class Dataworker {
amount: totalSent,
},
];

const valueToPassViaPayable = getMsgValue(leaf);
// If we have to pass ETH via the payable function, then we need to add a balance request for the signer
// to ensure that it has enough ETH to send.
// NOTE: this is ETH required separately from the amount required to send the tokens
Expand Down Expand Up @@ -2154,6 +2163,7 @@ export class Dataworker {
leaf.leafId
}\nchainId: ${chainId}\ntoken: ${l1TokenInfo?.symbol}\namount: ${leaf.amountToReturn.toString()}`;
if (submitExecution) {
const valueToPassViaPayable = getMsgValue(leaf);
this.clients.multiCallerClient.enqueueTransaction({
value: valueToPassViaPayable,
contract: client.spokePool,
Expand Down

0 comments on commit d4cbd89

Please sign in to comment.