Skip to content

fix(balances): degrade gracefully when staking is unavailable#389

Merged
MuncleUscles merged 1 commit into
v0.40-devfrom
fix/balances-studio-graceful
Jul 10, 2026
Merged

fix(balances): degrade gracefully when staking is unavailable#389
MuncleUscles merged 1 commit into
v0.40-devfrom
fix/balances-studio-graceful

Conversation

@MuncleUscles

Copy link
Copy Markdown
Member

What

genlayer balances scans the global validator set (active + quarantined + banned) to compute each vesting's delegated committed principal. Those SDK reads throw on networks with no staking contract (Staking is not supported on studio-based networks), so the whole command failed on studio — even though wallet balance and vesting totals need no staking data at all.

This gates the scan on staking availability, mirroring the SDK's own guard (missing or zero staking address ⇒ unsupported). When staking is unavailable the validator set is empty, so delegated principal is 0 (correct — there is no delegation without staking) and the command still renders wallet + vesting holdings. Self-stake, vested/withdrawable and available-to-stake all come from vesting/wallet reads and are unaffected.

Why

Surfaced by genlayer-cli (studio) e2e: 090_cli_network_and_balances scenario 2 ("Read the signer wallet balance through the balances command") failed on studio because balances hit the staking read and exited 1. dev-env (staking present) was unaffected.

Test

  • Existing scan-path tests pinned to testnet-bradbury (which has a staking contract) so they still exercise the union/de-dup scan.
  • New test (a'): on studionet (no staking contract) the scan is skipped, no staking read is called, no failure, and wallet + vesting + self-stake are still reported with delegated principal 0.

Validated end-to-end via genlayer-e2e #653 (Depends-On).

The balances command scans the global validator set (active + quarantined +
banned) to compute delegated committed principal per vesting. Those SDK reads
throw on networks with no staking contract ("Staking is not supported on
studio-based networks"), so `genlayer balances` failed outright on studio —
even though wallet balance and vesting totals need no staking data.

Gate the scan on staking availability, mirroring the SDK's own guard (missing
or zero staking address ⇒ unsupported): when absent, use an empty validator set
so delegated principal is 0 (correct — there is no delegation without staking)
and still render wallet + vesting holdings. Self-stake, vested/withdrawable and
available-to-stake all come from vesting/wallet reads and are unaffected.

Fixes genlayer-cli (studio) e2e 090_cli_network_and_balances #2.
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7115d6e-fd17-494a-8fc7-04cf25e0287a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/balances-studio-graceful

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MuncleUscles MuncleUscles merged commit 8cdcb8a into v0.40-dev Jul 10, 2026
9 of 10 checks passed
MuncleUscles added a commit that referenced this pull request Jul 10, 2026
…391)

After #389 stopped the staking scan from crashing balances on studio, the
next consensus-dependent read surfaced: the vesting-factory lookup resolves
through ConsensusMain → AddressManager, and on a network without that
infrastructure deployed (studio, or a custom profile on a bare RPC) it decodes
garbage — `genlayer balances` died with 'Position 32 is out of bounds ...
name()' (e2e 090 scenario 2 on the studio stack).

Custom networks inherit the base chain's ConsensusMain address even without a
--consensus-main override, so a studio profile carries a non-null (localnet)
address that simply isn't deployed on the studio RPC — a static check can't
tell them apart. Probe eth_getCode(consensusMain) once up front: if empty, the
consensus infra isn't deployed, so skip the whole consensus-dependent section
(vesting + staking) and render the wallet balance only, with a clear note.
Handles the entire missing-infra class in one capability check rather than one
revert at a time. dev-env (real deployed address) is unaffected.

Verified against a live studio stack: e2e 090 (both scenarios) green.
772/772 unit tests pass.
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