Skip to content

feat(profitability): allow per-chain RELAYER_GAS_PADDING overrides#3489

Open
droplet-rl wants to merge 2 commits into
masterfrom
droplet/per-chain-gas-padding
Open

feat(profitability): allow per-chain RELAYER_GAS_PADDING overrides#3489
droplet-rl wants to merge 2 commits into
masterfrom
droplet/per-chain-gas-padding

Conversation

@droplet-rl

Copy link
Copy Markdown
Contributor

Summary

Adds a `RELAYER_GAS_PADDING_` env override pattern so we can scale the relayer's gas-cost padding per destination chain, rather than carrying the same blanket cushion (currently 2.5%) for every route.

The global default exists to absorb estimation noise on EVM destinations where the actual fill can consume more gas than the simulator predicts. On Tron the simulator is essentially exact (energy is governance-fixed and bandwidth scales with serialized bytes, which we already model in sdk#1459) — the 2.5% cushion just adds margin the relayer never spends. That cushion is also the line item flipping borderline Mainnet → Tron multicall fills to "unprofitable" in the primary bot's check, even after the bandwidth fix landed (cross-ref: deposit `3986569` analysis in #devops).

Approach

Mirror the existing per-chain env conventions (`RELAYER_MIN_FILL_TIME_`, `SEND_MESSAGE_RELAYS_`):

  • `RelayerConfig.relayerGasPaddingOverrides`: parsed inside the existing `chainIds.forEach` block from `RELAYER_GAS_PADDING_` env vars. Stored as raw padding fractions.
  • `ProfitClient.chainGasPadding`: holds the already-folded `1 + padding` form, validated 0%–200% per entry.
  • `ProfitClient.resolveGasPadding(chainId)` returns the per-chain multiplier if configured, otherwise the global `gasPadding`. All four padding application sites (`estimateFillCost` per-fill, `update` gas-cost cache, the two log emissions) route through it.

No behavior change for chains without an override — every existing call resolves through `resolveGasPadding` to the same `this.gasPadding` value as before.

Followups (not in this PR)

  • Configurama: add `RELAYER_GAS_PADDING_728126428: "0.015"` to the prod inputs for `zion-across-relayer-primary`, `-secondary`, `-sweeper` once this lands.
  • Companion change in across-protocol/quote-api so the quote-api budgets a slightly higher gas cushion than the relayer evaluates, ensuring the quote stays comfortably above breakeven.

Test plan

  • `yarn typecheck` clean
  • `yarn lint` clean
  • Smoke-check in zion shadow / sandbox before promoting to prod

🤖 Generated with Claude Code

The relayer pads every estimated gas cost by `RELAYER_GAS_PADDING` (2.5%
in prod) before checking profitability. The padding is appropriate for
EVM destinations where simulator output can diverge from actual fill,
but it's overkill for chains where the gas-side input is governance-
fixed (Tron energy price), and that extra cushion is exactly what's been
flipping borderline Mainnet → Tron multicall fills to "unprofitable"
even after the bandwidth accounting from across-protocol/sdk#1459 landed.

Add a `RELAYER_GAS_PADDING_<chainId>` env override pattern, mirroring
the existing `RELAYER_MIN_FILL_TIME_<chainId>` / `SEND_MESSAGE_RELAYS_
<chainId>` conventions:

- `RelayerConfig.relayerGasPaddingOverrides`: parsed from
  `RELAYER_GAS_PADDING_<chainId>` env vars for every chain the relayer
  cares about. Stored as raw padding fractions (e.g. `0.015` for 1.5%).
- `ProfitClient.chainGasPadding`: holds the already-folded `1 + pad`
  form, validated 0%–200% per entry.
- `ProfitClient.resolveGasPadding(chainId)` returns the per-chain
  multiplier if configured, otherwise the global `gasPadding`. All
  three padding application sites (`estimateFillCost` per-fill,
  `update` gas-cost cache, the two log emissions) route through it.

No behavior change for chains without an override.

`yarn typecheck` + `yarn lint` clean.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98c805fe8d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

: process.env["SEND_MESSAGE_RELAYS"] === "true";
this.sendingMessageRelaysEnabled[chainId] = sendMessageRelays;

const gasPaddingOverride = process.env[`RELAYER_GAS_PADDING_${chainId}`];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Document RELAYER_GAS_PADDING chain overrides

Adding RELAYER_GAS_PADDING_<chainId> here changes relayer configuration, but the commit does not update any README/AGENTS docs. /workspace/relayer/AGENTS.md explicitly says to keep relevant AGENTS.md and README.md files updated whenever configuration changes; without a src/relayer/README.md or src/clients/README.md entry, operators can only discover this chain-specific profitability knob by reading code, which makes production tuning easy to miss or misconfigure.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — added a 'Per-destination-chain gas padding' subsection to src/clients/README.md (commit 48919c8) covering the global default, the RELAYER_GAS_PADDING_<chainId> override, the 0%–200% validation, the Tron motivation, and a worked example, mirroring the existing RELAYER_GAS_MULTIPLIER policy docs in the same file. No src/relayer/README.md change — the knob lives entirely in the Profit Client, and src/relayer/README.md already routes profitability questions there via its quick index.

Add a "Per-destination-chain gas padding" section to src/clients/README.md
covering the global RELAYER_GAS_PADDING default and the new
RELAYER_GAS_PADDING_<chainId> override, including the 0%-200% validation,
the Tron motivation, and a worked example. Addresses codex P2 review note
on PR #3489 — AGENTS.md requires keeping module READMEs in sync with
configuration changes.
@droplet-rl

Copy link
Copy Markdown
Contributor Author

@codex addressed your P2 review note on documenting the new RELAYER_GAS_PADDING_<chainId> override.

  • Added a "Per-destination-chain gas padding" subsection to src/clients/README.md (commit 48919c8) covering the global RELAYER_GAS_PADDING default (0.15 = 15% from src/common/Constants.ts), the per-chain override, the 0%–200% validation range, the Tron motivation, and a worked example — mirroring the structure of the existing RELAYER_GAS_MULTIPLIER policy section above it.
  • Left src/relayer/README.md alone: the knob lives entirely in the Profit Client, and that README already points profitability questions there via its quick index.

Inline reply posted on the original discussion. Please take another pass.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@droplet-rl

Copy link
Copy Markdown
Contributor Author

Thanks — re-review confirms the docs commit (48919c8) closes the P2 note. No further changes on my end; this PR is ready for human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant