Skip to content

Add disable-balances config flag to driver#4271

Closed
felixjff wants to merge 3 commits intocowprotocol:mainfrom
felixjff:feat/driver-disable-balances
Closed

Add disable-balances config flag to driver#4271
felixjff wants to merge 3 commits intocowprotocol:mainfrom
felixjff:feat/driver-disable-balances

Conversation

@felixjff
Copy link
Copy Markdown

@felixjff felixjff commented Mar 18, 2026

Summary

  • Adds a disable-balances TOML config option to the driver (defaults to false)
  • When enabled, skips the background token balance update task (no per-block RPC calls)
  • On-demand balance fetching also returns zero-balance metadata immediately instead of making RPC calls

Motivation

When developing or testing a colocated solver locally, the driver's token balance fetcher continuously queries the RPC node on every new block. This is unnecessary during local development and adds RPC costs. The disable-balances flag lets developers skip all balance-related RPC traffic.

Usage

# driver.config.toml
disable-balances = true

Test plan

  • Verified the driver compiles with cargo build -p driver
  • Existing driver tests pass
  • Manual test: run driver locally with disable-balances = true, confirm no balance RPC calls are made

@felixjff felixjff requested a review from a team as a code owner March 18, 2026 02:16
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@felixjff
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a disable-balances configuration flag to prevent the driver from making RPC calls for token balances, which is useful for local development. The implementation correctly adds the flag and applies it to the tokens::Fetcher to skip background updates and on-demand fetching. However, the account_balances fetcher is not affected by this flag and will continue to make RPC calls. This should be addressed to fully meet the PR's goal of disabling all balance-related RPC traffic.

@felixjff
Copy link
Copy Markdown
Author

recheck

When developing or testing a colocated solver locally, the driver's
token balance fetcher makes continuous RPC calls on every new block.
This adds a `disable-balances` TOML config option (defaults to false)
that skips both the background update task and on-demand balance
fetching, returning zero-balance metadata instead. This avoids
unnecessary RPC costs during local development.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@felixjff felixjff force-pushed the feat/driver-disable-balances branch from d6df27c to 6eb6060 Compare March 18, 2026 02:40
github-actions bot added a commit that referenced this pull request Mar 18, 2026
Instead of scattering `if disable_balances` checks inside the Fetcher,
use an enum with Rpc and Disabled variants so the branch happens once
at construction time.
Clarifies that this flag disables settlement contract token balance
fetching, not user account balance fetching.
@felixjff felixjff requested a review from jmg-duarte March 19, 2026 21:20

/// Provides metadata of tokens.
struct Inner {
pub struct Inner {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pub and Inner should never go in the "same line" as Inner implies internal implementation and should not be exposed.

I like the enum approach as it has some advantages in terms of speed, but it brings more complexities in maintenance; since we're not chasing sub-ms speeds yet, this is unnecessary.

One reason it doesn't scale well in terms of maintenance is the burden of handling different branches, for example, in get we'd need matching on every enum variant we add. Leading to a big match statement that to be eventually be made ergonomic will require more "inner structs" that implement a given trait/interface, which is just a less ergonomic trait implementation.

I think the best way to go about this right now is:

  • Split the enum into two structs — RpcFetcher & DisabledFetcher
  • Extract the get into a trait called SettlementBalanceFetching
  • Implement the trait on the previous structs
  • Update the type of let tokens in the crates/driver/src/infra/api/mod.rs to be Arc<dyn SettlementBalanceFetching>
  • Update where necessary to Arc too (old tokens::Fetcher basically)

/// on-demand). Balances default to 0. Useful for local testing to
/// avoid RPC calls.
#[serde(default)]
disable_settlement_balance_fetcher: bool,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is applied wholesale to the driver, as the driver is intended to handle different solvers this is a setting that should be handled on a per-solver level.

@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed.

@github-actions github-actions bot added the stale label Mar 28, 2026
@github-actions github-actions bot closed this Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants