Skip to content

rpcserver: Support named and null parameters, Review optionals on rpc internal methods, Stronger Response and Error codes#831

Open
jaoleal wants to merge 4 commits intogetfloresta:masterfrom
jaoleal:some_fixes_rpcserver
Open

rpcserver: Support named and null parameters, Review optionals on rpc internal methods, Stronger Response and Error codes#831
jaoleal wants to merge 4 commits intogetfloresta:masterfrom
jaoleal:some_fixes_rpcserver

Conversation

@jaoleal
Copy link
Copy Markdown
Collaborator

@jaoleal jaoleal commented Feb 6, 2026

Description and Notes

Some time ago i was messing with the server trying to fix some pains that i had developing methods on it and i encountered some points to upgrade.

4839dc6 - fixes #827 by matching errors and returning constant values, i also mapped some custom error codes to internal errors as I understood that were allowed by the spec.

29220da- Adds named and null parameters support, I also reviewed some Options in internal rpc methods that actually had internal defaults, created a getter for that case.

fix #827
fix #704

How to verify the changes you have done?

Pushed some extensive tests regarding request and result parsing and behavior, checking that calls are accepted when expected and when refused we assert the error response.

Contributor Checklist

  • I've followed the contribution guidelines
  • I've verified one of the following:
    • Ran just pcc (recommended but slower)
    • Ran just lint-features '-- -D warnings' && cargo test --release
    • Confirmed CI passed on my fork
  • I've linked any related issue(s) in the sections above

Finally, you are encouraged to sign all your commits (it proves authorship and guards against tampering—see How (and why) to sign Git commits and GitHub's guide to signing commits).

@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 6, 2026

cc @csgui

Why i cant alter the name of the PR 😭

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch from 766648c to 5cd9007 Compare February 6, 2026 23:25
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 6, 2026

Can someone with permission to alter the pr title fix it for me ?

rpcserver: Support named and null parameters, Review optionals on rpc internal methods, Stronger Response and Error codes.

@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 6, 2026

5cd9007 Unrelated test fail

@Davidson-Souza Davidson-Souza added RPC Changes something with our JSON-RPC interface code quality Generally improves code readability and maintainability labels Feb 7, 2026
@Davidson-Souza Davidson-Souza changed the title rpcserver: Support named and null parameters, Review optionals on rpc internal methods, rpcserver: Support named and null parameters, Review optionals on rpc internal methods, Stronger Response and Error codes Feb 7, 2026
@csgui
Copy link
Copy Markdown
Collaborator

csgui commented Feb 8, 2026

@jaoleal double check if you can use <T: DeserializeOwned> or <'de, T: Deserialize<'de>>. Not both, choose one.

That would makes more sense and allows the remove of clone in the code. When parsing RPC parameters clone can cause performance issues and increased memory pressure under heavy load. We do not have control on what Floresta user is passing to a RPC call.

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch 2 times, most recently from c13b68a to 0e160f5 Compare February 9, 2026 09:22
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 9, 2026

top commit: 0e160f5

  • Removed a clone from get_at, lifetime matching solved that.
  • Included back MempoolAccept, sorry conflict problems.
  • Fixed a bug matching against params in get_arr_at where it would result unwrapping in a malformed input.
  • Added extensive tests, they were written by claudiao but i reviewed it and found a bug.
  • Fixed a bug when an optional parameter is omitted when params are omitted as a whole.

Thanks for the suggestions @csgui

@moisesPompilio
Copy link
Copy Markdown
Collaborator

I think the commit descriptions are missing because they only have titles.

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch from 0e160f5 to 781ea91 Compare February 9, 2026 19:07
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 9, 2026

[781ea91 Rebased and extended commit message with descriptions.

@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 9, 2026

Added formal fix statement for the issues that this pr fixes.

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch from 781ea91 to 994e4b7 Compare February 10, 2026 01:44
@jaoleal

This comment was marked as outdated.

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch 4 times, most recently from 2d230a8 to bd4d7a1 Compare February 10, 2026 15:45
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 10, 2026

gaddamit these conflicts

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch from bd4d7a1 to d18e6dd Compare February 10, 2026 20:32
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Feb 10, 2026

unrelated fail on functional tests d18e6dd

@jaoleal jaoleal requested a review from csgui February 11, 2026 18:07
@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch 5 times, most recently from a5653bc to f8aa0e3 Compare March 9, 2026 17:58
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Mar 9, 2026

Okay, applied requested changes: f8aa0e3.

cc @Davidson-Souza @moisesPompilio

@Davidson-Souza Davidson-Souza removed this from the v0.9.0 milestone Mar 10, 2026
@csgui csgui added reliability Related to runtime reliability, stability and production readiness and removed code quality Generally improves code readability and maintainability RPC Changes something with our JSON-RPC interface labels Mar 11, 2026
@csgui csgui added this to the Q2/2026 milestone Mar 11, 2026
@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch from f8aa0e3 to 0f62bfa Compare March 12, 2026 17:06
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Mar 12, 2026

@moisesPompilio done in 0f62bfa

@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch 2 times, most recently from edad67c to d4afa59 Compare March 16, 2026 17:37
@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Mar 16, 2026

rebased

//! [`RpcError`]: jsonrpc_interface::RpcError
//! [`JsonRpcError`]: jsonrpc_interface::JsonRpcError

use std::fmt::Debug;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e8938d4

use core instead std

Comment on lines +30 to +31
use std::fmt::Display;
use std::fmt::Formatter;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e8938d4

use core instead std

@moisesPompilio
Copy link
Copy Markdown
Collaborator

need rebase

jaoleal added 4 commits March 18, 2026 03:10
- Add named constants for floresta-specific rpc server error codes
  (TX_NOT_FOUND, BLOCK_NOT_FOUND, PEER_NOT_FOUND, etc.)
- Add SERIALIZATION_EXPECT and HTTP_RESPONSE_EXPECT constants for
  expect() messages
- Add From<BlockchainError> for JsonRpcError conversion.
- Change ScriptPubKeyJson.address to Option<String> for nonstandard
  scripts (matching Bitcoin Core behavior)
- Rewrite arg_parser with organic get_at(), get_with_default(),
  get_arr_at(), and optional().
- Change RpcRequest.params to support named (object) parameters alongside
positional (array) parameters.
- Split method dispatch into no-param methods (early return) and
  param methods (with params.unwrap_or_default()).
- Replace .unwrap() calls with .expect() using descriptive constants.
- Build explicit HTTP responses for parse errors with proper status codes.
…d clippy lint

- Replace all .unwrap() calls in blockchain.rs with proper error
  propagation via map_err and the ? operator
- Apply #[deny(clippy::unwrap_used)] lint to the json_rpc module
- Add comprehensive tests covering positional and named parameters,
  null/omitted params, optional defaults, error codes, and response
  structure validation
@jaoleal jaoleal force-pushed the some_fixes_rpcserver branch from d4afa59 to 8ecf173 Compare March 18, 2026 06:15
@csgui
Copy link
Copy Markdown
Collaborator

csgui commented Mar 20, 2026

@jaoleal

Double-checking this PR, and it seems there are still some things to improve.

1 - Run the command below and check the response:

command: curl -i --data-binary '{"jsonrpc":"1.0","id":"xyz","method":"getblock","params":42}' -H 'content-type: application/json;' http://127.0.0.1:8332

response: {"result":null,"error":{"code":-32602,"message":"Missing parameter","data":"block_hash"},"id":"xyz"}

The correct response would be something like InvalidParameterType. params is a number. The server accepted the malformed param and is blaming a missing field instead of identifying the actual problem.

2 - Run the command below and check the response:

command: curl -i --data-binary '{"jsonrpc":"1.0","id":"xyz","method":"getblock","params":null}' -H 'content-type: application/json;' http://127.0.0.1:8332

response: {"result":null,"error":{"code":-32602,"message":"Missing parameter","data":"block_hash"},"id":"xyz"}

It is the same MissingParameter instead of the server recognizing that getblock requires params and rejects the request.

Also, corner cases like those, should be covered by some kind of test.

@jaoleal
Copy link
Copy Markdown
Collaborator Author

jaoleal commented Mar 20, 2026

Thanks for finding these bugs @csgui, ill investigate them and address a fix.

By intuition a fix would be a general check done on each request, as it is now problems are found by the command execution pipeline.

Also, corner cases like those, should be covered by some kind of test.

Ill be more aggressive on these

@jaoleal jaoleal added RPC Changes something with our JSON-RPC interface architecture labels Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

architecture reliability Related to runtime reliability, stability and production readiness RPC Changes something with our JSON-RPC interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace JSON-RPC error code literals with named constants [Bug] json-rpc server doesn't support named parameter

5 participants