Missing new serialization for legacy_comment_options_extensions
Currently hive nodes support two types of serialization in API responses: the old one (that with arrays, e.g. [ "op_name", { /* data */ } ]
used by the condenser API) and the new one (as a more intuitive object type, e.g. { "type": "op_name", "value": { /* data */ } }
used by the block API). As far as I know serialization works as intended for the majority of operations, but that is not a case with the comment_options operation, where in the comment_options_extensions serialization, there is currently only one type of it implemented (the old one):
Expected Behavior
comment_options_extensions being properly serialized from the output of the block API. Example comment_options operation from block 54837076:
{
"type": "comment_options_operation",
"value": {
...,
"extensions": [
{
"type": "comment_payout_beneficiaries",
"value": { "beneficiaries": [ ... ] }
}
]
}
}
Current Behavior
Bad cast exception in variant holding legacy_comment_options_extensions (trying to retrieve array type from an object type in old_sv_from_variant):
7 bad_cast_exception: Bad Cast
Invalid cast from object_type to Array
{"type":"object_type"}
variant.cpp:537 get_array
Possible Solution
Implement something similar to the legacy check in the extended_serialization_functor in the legacy_comment_options_extensions serialization:
(array check in variant)
Update: Since @Trela moved legacy serialization to hive::protocol about a month ago, "user-defined" pow2_work
and comment_options_extension
serialization is now redundant and we can leave from_variant
and to_variant
function overloads generation to the fc reflect. The reason why this was happening was because of the user-defined serialization function overloads for pow2_work and comment_options_extension. Same applies to the legacy_operation
. Quick fix would be to add serialization functors
Steps to Reproduce
- Send request to the
block_api.get_block
endpoint with params:{ "block_num": 54837076 }
- Construct new
fc::variant_object
from the jsonresult
string - Access
block
and try to serialize it to thehive::protocol::signed_block
,hive::plugins::condenser_api::legacy_signed_block
orhive::plugins::block_api::api_signed_block_object
type (v.as< type >
)
Context (Environment)
Bug encountered while working on the "blockchain converter" tool that sends multiple requests to the block_api.get_block_range
endpoint.
Built on Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-154-generic x86_64)
CMake options: -DCMAKE_BUILD_TYPE=Release -DBUILD_HIVE_TESTNET=OFF -DENABLE_SMT_SUPPORT=ON -DHIVE_STATIC_BUILD=ON -DHIVE_CONVERTER_BUILD=ON