Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix ship big vector serialization #9880

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,6 @@ ST& operator<<(ST& ds, const eosio::state_history::big_vector_wrapper<T>& obj) {
return ds;
}

template <typename ST>
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 <typename ST>
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 <typename ST>
void history_pack_big_bytes(ST& ds, const std::optional<eosio::chain::bytes>& v) {
fc::raw::pack(ds, v.has_value());
if (v)
history_pack_big_bytes(ds, *v);
}

template <typename ST, typename T>
ST& operator<<(ST& ds, const history_serial_wrapper<std::vector<T>>& obj) {
return history_serialize_container(ds, obj.db, obj.obj);
Expand Down Expand Up @@ -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;
}

Expand Down
28 changes: 27 additions & 1 deletion libraries/state_history/include/eosio/state_history/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ struct big_vector_wrapper {
T obj;
};

template <typename ST>
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 <typename ST>
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 <typename ST>
void pack_big_bytes(ST& ds, const std::optional<eosio::chain::bytes>& v) {
fc::raw::pack(ds, v.has_value());
if (v)
pack_big_bytes(ds, *v);
}

template <typename T>
class opaque {
std::vector<char> data;
Expand All @@ -41,7 +65,9 @@ class opaque {

template <typename ST>
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);
}
};

Expand Down