Skip to content

fix(staking): network-aware, fail-open resource-code validation#943

Open
gummy789j wants to merge 2 commits into
release_v4.9.7from
fix/network-aware-resource-code
Open

fix(staking): network-aware, fail-open resource-code validation#943
gummy789j wants to merge 2 commits into
release_v4.9.7from
fix/network-aware-resource-code

Conversation

@gummy789j

@gummy789j gummy789j commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Align resource-code handling across REPL and standard CLI with the node's actuator behavior, per the discussion in #939:

  • freeze/unfreeze accept 2 (TRON_POWER) only when the chain parameter getAllowNewResourceModel is enabled; delegate/undelegate reject 2 unconditionally (BANDWIDTH/ENERGY only).
  • Fail-open: when chain params can't be fetched (offline/timeout), skip the client-side pre-check and defer to the node's validate() at broadcast; text mode warns on stderr, JSON/quiet stays silent.
  • Only query chain params when resource == 2 (0/1 short-circuit, no RPC).

REPL previously did no validation at all; standard CLI hardcoded 0/1. Reuses the existing getChainParameters() plumbing. Docs updated for consistency.

@gummy789j gummy789j changed the title fix(staking): network-aware, fail-open resource-code validation (#939) fix(staking): network-aware, fail-open resource-code validation Jul 2, 2026
Align resource-code handling across REPL and standard CLI with the node's
actuator behavior, per the discussion in
#939:

- freeze/unfreeze accept 2 (TRON_POWER) only when the chain parameter
  getAllowNewResourceModel is enabled; delegate/undelegate reject 2
  unconditionally (BANDWIDTH/ENERGY only).
- Fail-open: when chain params can't be fetched (offline/timeout), skip the
  client-side pre-check and defer to the node's validate() at broadcast; text
  mode warns on stderr, JSON/quiet stays silent.
- Only query chain params when resource == 2 (0/1 short-circuit, no RPC).

REPL previously had no resource-code range check (permissive pass-through);
standard CLI hardcoded 0/1. Reuses the existing getChainParameters() plumbing.
Docs updated for consistency.

Refs: #939
@gummy789j gummy789j force-pushed the fix/network-aware-resource-code branch from c0e1966 to 1d3ff25 Compare July 2, 2026 06:53
v1 freezeBalance/unfreezeBalance with a receiver is a delegated freeze,
where TRON_POWER is not delegatable. Both the standard CLI and the REPL
previously passed freezeContext=true unconditionally, so resource=2 could
be let through to the node when getAllowNewResourceModel was on. Derive the
context from the receiver instead (freezeContext = receiver == null); v2
self-stake and delegate/undelegate paths are unchanged.

Add StakingResourceGuardTest covering the tri-state getAllowNewResourceModel
behavior (enabled / disabled / unknown fail-open), unconditional TRON_POWER
rejection for delegation, and the receiver-aware v1 semantics.

Docs: fix stale "1 CPU" to "1 ENERGY" and drop TRON_POWER from the
delegate-resource section (not delegatable).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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