Skip to content

fix: validate force_small_change_as_fee in the API server - #686

Open
eval-exec wants to merge 1 commit into
nervosnetwork:developfrom
eval-exec:fix/api-server-transfer-args
Open

eval-exec wants to merge 1 commit into
nervosnetwork:developfrom
eval-exec:fix/api-server-transfer-args

Conversation

@eval-exec

@eval-exec eval-exec commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

The API server's transfer method accepted force_small_change_as_fee as a free-form string and passed it straight through to WalletSubCommand::transfer, while the equivalent --max-tx-fee CLI flag is validated by clap.

Changes

  • ApiRpc::transfer validates force_small_change_as_fee before any wallet lock is taken, so a value that cannot be parsed as a capacity is reported as -32602.
  • WalletSubCommand::transfer propagates the parse error rather than assuming success.
  • Saturates the capacity arithmetic used to build the --max-tx-fee suggestion.
  • Documents the field in docs/API-Server.md.

Compatibility

No wire-format change: force_small_change_as_fee stays an optional capacity string in CKB, the same unit as the --max-tx-fee CLI flag. Existing clients are unaffected.

Tests

Three unit tests cover the validation and the field's wire format:

cargo test --bin ckb-cli api_server::tests

Copilot AI lite review requested due to automatic review settings September 22, 2026 07:34
@eval-exec
eval-exec force-pushed the fix/api-server-transfer-args branch from 1a9aafc to bfdb2b7 Compare September 22, 2026 07:36

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

The changelog entry should explicitly flag the wire-format breaking change for force_small_change_as_fee, and a small naming clarity fix is needed in the new conversion code.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR tightens validation and error handling for the API server transfer flow by changing force_small_change_as_fee from a free-form string into a typed u64 (shannons), aligning the API behavior with CLI validation and preventing panics in downstream parsing.

Changes:

  • Change force_small_change_as_fee in the API server transfer args to Option<u64> and convert it back via HumanCapacity for internal CLI-compatible handling.
  • Propagate parse failures in WalletSubCommand::transfer instead of unwrap()-ing and potentially panicking.
  • Prevent overflow in the --max-tx-fee suggestion calculation by using saturating arithmetic, and document the field in the API docs.
File Description
src/​subcommands/​wallet.rs Avoids panic by propagating parse errors; prevents overflow in fee suggestion capacity math.
src/​subcommands/​api_server.rs Makes force_small_change_as_fee typed (u64) at the JSON-RPC boundary and adds unit tests for deserialization/conversion.
docs/​API-Server.md Documents force_small_change_as_fee and clarifies its unit (Shannon).
CHANGELOG.md Notes the fixes in Unreleased (should also call out the breaking wire-format change).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread CHANGELOG.md

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

The new API documentation for force_small_change_as_fee should explicitly show it is a JSON string (quoted) to prevent client-side type mistakes, and there is also a small typo in the transfer log message.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Low severity

Open (2)
Resolved since last review (1)

Comment thread docs/API-Server.md
Comment thread src/subcommands/api_server.rs
The API server's `transfer` method took `force_small_change_as_fee` as a
free-form string and passed it straight through to
`WalletSubCommand::transfer`, while the equivalent `--max-tx-fee` CLI flag
is validated by clap.

Validate it in the RPC method before any wallet lock is taken, so a value
that cannot be parsed as a capacity is reported as invalid params, and
propagate the parse error in `WalletSubCommand::transfer` rather than
assuming success. The field keeps its wire format: an optional capacity
string in CKB, for example "0.001".

Also saturates the capacity arithmetic behind the `--max-tx-fee`
suggestion, and documents the field in docs/API-Server.md.
@eval-exec
eval-exec force-pushed the fix/api-server-transfer-args branch from bfdb2b7 to 8e05718 Compare September 22, 2026 07:46

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

The change is small, self-contained, consistent with existing parsing/error-handling conventions, and covered by new tests with docs and changelog updated.

Review effort: Balanced
Findings: None

Resolved since last review (2)

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.

2 participants