Skip to content

Add optional mode argument to blockchain.estimatefee#1293

Open
PeterXMR wants to merge 1 commit into
romanz:masterfrom
PeterXMR:estimatefee-mode-1241
Open

Add optional mode argument to blockchain.estimatefee#1293
PeterXMR wants to merge 1 commit into
romanz:masterfrom
PeterXMR:estimatefee-mode-1241

Conversation

@PeterXMR
Copy link
Copy Markdown

Refs #1241 — checks off the blockchain.estimatefee mode item on the v1.6 protocol checklist.

Summary

Electrum protocol v1.6 adds an optional second mode argument to blockchain.estimatefee that is forwarded to bitcoind's estimatesmartfee as estimate_mode.

  • Accepted values (case-insensitive): UNSET, ECONOMICAL, CONSERVATIVE
  • Backwards-compatible: existing 1-arg calls [nblocks] keep working — handled via an #[serde(untagged)] enum that accepts either form (same pattern as BroadcastArgs).
  • Invalid mode strings produce a JSON-RPC error rather than being silently forwarded to bitcoind.

The string→enum parsing (parse_estimate_mode) is a free function so it can be unit-tested without an RPC client.

Test plan

  • 5 new unit tests in electrum::tests: known values, case-insensitivity, invalid value rejection, 1-arg deserialization, 2-arg deserialization
  • cargo test --lib — 26/26 pass
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo fmt --check — clean
  • Live tested against Bitcoin Core v31.0.0 on regtest covering all paths:
$ printf '{"id":0,"method":"server.version","params":["test","1.4"]}
{"id":1,"method":"blockchain.estimatefee","params":[6]}
{"id":2,"method":"blockchain.estimatefee","params":[6,"ECONOMICAL"]}
{"id":3,"method":"blockchain.estimatefee","params":[6,"conservative"]}
{"id":4,"method":"blockchain.estimatefee","params":[6,"turbo"]}
' | nc -w 3 127.0.0.1 60401

{"id":0,"jsonrpc":"2.0","result":["electrs/0.11.1","1.4"]}
{"id":1,"jsonrpc":"2.0","result":-1}
{"id":2,"jsonrpc":"2.0","result":-1}
{"id":3,"jsonrpc":"2.0","result":-1}
{"error":{"code":1,"message":"invalid estimatefee mode \"turbo\"; expected ECONOMICAL, CONSERVATIVE, or UNSET"},"id":4,"jsonrpc":"2.0"}

The -1 return values are the expected UNKNOWN_FEE because regtest has no fee history — the point of the demo is showing that all four dispatch paths (1-arg, 2-arg with each mode, invalid mode) behave correctly.

Electrum protocol v1.6 adds an optional second `mode` argument to
`blockchain.estimatefee` that is forwarded to bitcoind's
`estimatesmartfee` as `estimate_mode`. Accepted values
(case-insensitive): `UNSET`, `ECONOMICAL`, `CONSERVATIVE`.

Parsing uses an `#[serde(untagged)]` enum that accepts both the
legacy 1-argument form `[nblocks]` and the v1.6 2-argument form
`[nblocks, mode]`, so existing clients keep working.

Invalid mode strings produce a JSON-RPC error rather than being
silently forwarded to bitcoind.

Spec: https://electrum-protocol.readthedocs.io/en/latest/protocol-methods.html#blockchain-estimatefee

Refs romanz#1241
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