diff --git a/libraries/state_history/include/eosio/state_history/serialization.hpp b/libraries/state_history/include/eosio/state_history/serialization.hpp index f2e41814f97..280d5c44543 100644 --- a/libraries/state_history/include/eosio/state_history/serialization.hpp +++ b/libraries/state_history/include/eosio/state_history/serialization.hpp @@ -91,30 +91,6 @@ ST& operator<<(ST& ds, const eosio::state_history::big_vector_wrapper& obj) { return ds; } -template -inline void history_pack_varuint64(ST& ds, uint64_t val) { - do { - uint8_t b = uint8_t(val) & 0x7f; - val >>= 7; - b |= ((val > 0) << 7); - ds.write((char*)&b, 1); - } while (val); -} - -template -void history_pack_big_bytes(ST& ds, const eosio::chain::bytes& v) { - history_pack_varuint64(ds, v.size()); - if (v.size()) - ds.write(&v.front(), (uint32_t)v.size()); -} - -template -void history_pack_big_bytes(ST& ds, const std::optional& v) { - fc::raw::pack(ds, v.has_value()); - if (v) - history_pack_big_bytes(ds, *v); -} - template ST& operator<<(ST& ds, const history_serial_wrapper>& obj) { return history_serialize_container(ds, obj.db, obj.obj); @@ -738,9 +714,9 @@ ST& operator<<(ST& ds, const eosio::state_history::get_blocks_result_v0& obj) { fc::raw::pack(ds, obj.last_irreversible); fc::raw::pack(ds, obj.this_block); fc::raw::pack(ds, obj.prev_block); - history_pack_big_bytes(ds, obj.block); - history_pack_big_bytes(ds, obj.traces); - history_pack_big_bytes(ds, obj.deltas); + eosio::state_history::pack_big_bytes(ds, obj.block); + eosio::state_history::pack_big_bytes(ds, obj.traces); + eosio::state_history::pack_big_bytes(ds, obj.deltas); return ds; } diff --git a/libraries/state_history/include/eosio/state_history/types.hpp b/libraries/state_history/include/eosio/state_history/types.hpp index 7ca88ac3be7..3a15d856036 100644 --- a/libraries/state_history/include/eosio/state_history/types.hpp +++ b/libraries/state_history/include/eosio/state_history/types.hpp @@ -20,6 +20,30 @@ struct big_vector_wrapper { T obj; }; +template +inline void pack_varuint64(ST& ds, uint64_t val) { + do { + uint8_t b = uint8_t(val) & 0x7f; + val >>= 7; + b |= ((val > 0) << 7); + ds.write((char*)&b, 1); + } while (val); +} + +template +void pack_big_bytes(ST& ds, const eosio::chain::bytes& v) { + pack_varuint64(ds, v.size()); + if (v.size()) + ds.write(&v.front(), v.size()); +} + +template +void pack_big_bytes(ST& ds, const std::optional& v) { + fc::raw::pack(ds, v.has_value()); + if (v) + pack_big_bytes(ds, *v); +} + template class opaque { std::vector data; @@ -41,7 +65,9 @@ class opaque { template void pack_to(ST& ds) const { - fc::raw::pack(ds, this->data); + // we need to pack as big vector because it can be used to hold the state delta object + // which would be as large as the eos snapshot when the nodeos restarted from a snapshot. + pack_big_bytes(ds, this->data); } };