Skip to content

fix(wallet): return an error instead of panicking on invalid force_small_change_as_fee - #691

Merged
chenyukang merged 1 commit into
nervosnetwork:developfrom
Officeyutong:fix/api-transfer-max-tx-fee-panic
Nov 16, 2026
Merged

chenyukang merged 1 commit into
nervosnetwork:developfrom
Officeyutong:fix/api-transfer-max-tx-fee-panic

Conversation

@Officeyutong

Copy link
Copy Markdown
Contributor

Summary

WalletSubCommand::transfer called unwrap() when parsing force_small_change_as_fee. On the CLI path this is harmless, because clap validates --max-tx-fee first. The API server's transfer method, however, passes force_small_change_as_fee straight from the request JSON as an unchecked String. A value that is not a valid capacity (e.g. "NOT_A_CAPACITY") therefore panics the HTTP worker instead of returning a JSON-RPC error.

The panic happens inside ApiRpcImpl::with_wallet while the rpc_client and plugin_mgr mutexes are held, so both get poisoned. After that, every transfer and get_capacity_by_address call panics too, and the API server stays unusable until it is restarted.

Change

Parse force_small_change_as_fee with .transpose()?, the same way the neighbouring arguments in transfer are parsed. Invalid input now comes back to API clients as an invalid_params error, and the server keeps working.

Testing

  • cargo check, cargo fmt --check and cargo clippy --all-targets all pass.
  • Not tested end-to-end against a running node.

@sunchengzhu

Copy link
Copy Markdown

Reproduced the original issue on the base version and verified the fix in this PR. Invalid force_small_change_as_fee input now returns a parameter error, and subsequent balance queries and valid transfers work without restarting the API server. Also verified a CLI transfer with --max-tx-fee 0.001 (valid fee parameter coverage).

@chenyukang
chenyukang merged commit 1ba2665 into nervosnetwork:develop Nov 16, 2026
9 of 11 checks passed
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.

3 participants