Centralize server-side defaults and align addnode behavior with Bitcoin Core#986
Centralize server-side defaults and align addnode behavior with Bitcoin Core#986moisesPompilio wants to merge 3 commits into
addnode behavior with Bitcoin Core#986Conversation
| command: AddNodeCommand, | ||
| v2transport: Option<bool>, | ||
| ) -> Result<Value> { | ||
| let mut params = vec![Value::String(node), Value::String(command.to_string())]; |
There was a problem hiding this comment.
I think that we could work out some helpers for this, an example is the arg helpers on jsonrpc
There was a problem hiding this comment.
I introduced RpcArg and rpc_params(), which already handle these parameter treatments automatically, so when it’s an option that should not be displayed, it automatically hides that option.
|
cACK @moisesPompilio ... i think a small test for the new behaviour is worth introducing...at minimum |
| node_address: String, | ||
| command: String, | ||
| v2transport: bool, | ||
| v2transport: Option<bool>, |
There was a problem hiding this comment.
is this change worth documenting as a minor bump for downstream users of this RPC? or maybe that doesnt matter much right now since the commmunity building on floresta is not large yet?
more of a check question for myself too since i have recently worked on an RPC that modified fieldnames
There was a problem hiding this comment.
This is already documented in the RPC docs; this field is optional, so nothing changes for the user.
There was a problem hiding this comment.
I think its a fair point, i think its fine to break things now because we didnt made the 1.0 release yet. The user count is not something we can be much sure of, AFAIK...
|
Also @moisesPompilio, do a check if the defaults changes arent being solved on #831 I changed a lot about how we do defaults there |
… defaults The v2transport parameter in addnode is now optional. When omitted, the server applies its configured default value: - true (unless --allow-v1-fallback is set) - false (if --allow-v1-fallback is configured) This removes the requirement for explicit specification in the CLI while allowing the server's configuration to determine the connection behavior.
Remove unwrap_or() calls that force default values on the client side. Optional parameters are now omitted when None, letting the server determine appropriate defaults instead of the CLI forcing them. Introduce RpcArg enum and rpc_params() helper function to enable this: - RpcArg::Value wraps required parameters - RpcArg::Optional wraps optional parameters and filters None values - rpc_params() automatically collects parameters and handles filtering Implement From trait conversions for String, bool, u32, Txid, BlockHash, Vec<T>, and Option<T> types to provide seamless parameter construction across the RPC layer without manual error handling. Add comprehensive unit tests validating RpcArg conversions, parameter filtering behavior.
Add unit tests validating the behavior and correctness of all FlorestaRPC trait methods. Tests verify that method calls are properly forwarded to the JSON-RPC client, parameters are correctly serialized and passed, and returned values match expected results. Includes tests for all RPC methods including parameter handling, optional arguments filtering, and deserialization of responses.
8c62280 to
e077196
Compare
|
e077196 I introduced the |
This PR is specifically to remove the default handling from |
| } | ||
| } | ||
|
|
||
| enum RpcArg { |
There was a problem hiding this comment.
Perhaps this can be an extension just like done in HeaderExtension ?
There was a problem hiding this comment.
The Value type itself have enough capacity to handle this without the RpcArg enum or any middle structure.
There was a problem hiding this comment.
Perhaps this can be an extension just like done in HeaderExtension ?
In this case, it can’t be an extension because it needs to be a separate enum. It checks, when it is an Option, whether the element should be added to the Vec stack. So I can’t really make it an extension the Value, for example. Also, I don’t think any other part of the code will need this, because it is directly tied only to when we make a request to the server, since it exists solely to hide information when it is null.
The Value type itself have enough capacity to handle this without the RpcArg enum or any middle structure.
Value doesn’t handle that case, because if a null value is pushed onto the stack, it preserves the null entry. If it removed it, the Vec would lose consistency with the items that were inserted
| let params = rpc_params([tx.into()]); | ||
| self.call("sendrawtransaction", ¶ms) |
There was a problem hiding this comment.
Really liked how we consume this.
| vec![txids] | ||
| } | ||
| }; | ||
| let params = rpc_params([txids.into(), blockhash.into()]); |
There was a problem hiding this comment.
I think you can get rid of those into somehow
There was a problem hiding this comment.
It could be hidden using a macro, but I don’t think removing it is possible because it’s being converted into another object. However, I’m not sure whether using a macro here would be a good idea
| impl MockRpcClient { | ||
| fn set_result(&self, result: Value) { | ||
| *self.result.borrow_mut() = Some(result); | ||
| } | ||
| } |
There was a problem hiding this comment.
I dont think this test is actually testing something besides the rpc args parsing which is also very shallow
There was a problem hiding this comment.
Yeah, the tests are simple because these functions are simple, but they verify that the function is calling the method correctly, passing the correct information, and returning it properly as well.
Description and Notes
Transfers the responsibility for deciding default values from the CLI and RPC clients to the server, so the logic is centralized in one place instead of being duplicated across multiple layers.
In
floresta-cliandfloresta-rpc, client-side defaults forOptionparameters were removed. When a parameter is optional, the client now omits it entirely instead of forcing a default value withunwrap_or(), allowing the server to apply its own configured behavior.The
addnodev2transportdefault was also adjusted to match the node configuration, following Bitcoin Core behavior:trueby default, unless--allow-v1-fallbackis enabledfalsewhen--allow-v1-fallbackis configuredHow to verify the changes you have done?
Check that optional RPC and CLI parameters are no longer defaulted on the client side and are instead handled by the server.
For
addnode, verify that thev2transportbehavior follows the node configuration, matching Bitcoin Core defaults.--allow-v1-fallback, the default should betrue.--allow-v1-fallback, the default should befalse.