Open ZzPoLariszZ opened 3 months ago
These might be related and helpful: ethereum/go-ethereum#22857 and serde-rs/json#509
If you want to deserialize that kind of heavily nested structure, enable the serde_json "disable_recursion_limit" feature yourself. This is not suitable to enable in Alloy itself.
I ran into the same issue not too long ago. The problem with using the disable_recursion_limit
feature of serde is that it needs to be enabled on the Deserializer
itself, which is buried deep inside alloy (the try_deserialize_ok
function that @ZzPoLariszZ has identified).
It would be good if alloy could somehow at least expose the option to the outside without the need of forking the project. After all this effectively currently disables the ability to work with certain transactions on the blockchain.
There is nothing that we need to expose, you have to add serde_json
as a dependency and enable the feature.
The unbounded_depth
feature on serde_json
only exposes the disable_recursion_limit
function that needs to be called on the deserializer itself.
let mut deserializer = serde_json::Deserializer::from_str(&json);
deserializer.disable_recursion_limit();
Since the deserializer is instantiated inside the try_deserialize_ok
, it is not possible to enable this right now.
The possible modification of try_deserialize_ok
/// Attempt to deserialize the `Ok(_)` variant of an [`RpcResult`].
pub fn try_deserialize_ok<'a, J, T, E, ErrResp>(
result: RpcResult<J, E, ErrResp>,
) -> RpcResult<T, E, ErrResp>
where
J: Borrow<RawValue> + 'a,
T: RpcReturn,
ErrResp: RpcReturn,
{
let json = result?;
let json = json.borrow().get();
trace!(ty=%std::any::type_name::<T>(), json, "deserializing response");
let mut deserializer = serde_json::Deserializer::from_str(&json);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
T::deserialize(deserializer)
.inspect(|response| trace!(?response, "deserialized response"))
.inspect_err(|err| trace!(?err, "failed to deserialize response"))
.map_err(|err| RpcError::deser_err(err, json))
}
Ah I see, I thought it would be removed by enabling the feature alone
Component
network, json-rpc
What version of Alloy are you on?
alloy v0.2.1
Operating System
Linux
Describe the bug
The function
try_deserialize_ok
will return a deserialization error when recursion limit exceeded.Reproduce Example
Using
debug_trace_block_by_number
withCallTracer
option to trace Block 15413811Code
Result
Reason
The recursion limit is not large enough to handle call traces of these two transactions tx1 and tx2 inside.