From 1a86660efa5c3e26cc13d700b89c6a660440ae03 Mon Sep 17 00:00:00 2001 From: Todd Fleming Date: Mon, 20 May 2019 14:00:24 -0400 Subject: [PATCH] Ship: port #7383 and #7384 to develop --- .../state_history_serialization.hpp | 13 +++++++++++-- .../state_history_plugin.cpp | 19 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/plugins/state_history_plugin/include/eosio/state_history_plugin/state_history_serialization.hpp b/plugins/state_history_plugin/include/eosio/state_history_plugin/state_history_serialization.hpp index 07b241aeec6..6685eadadd5 100644 --- a/plugins/state_history_plugin/include/eosio/state_history_plugin/state_history_serialization.hpp +++ b/plugins/state_history_plugin/include/eosio/state_history_plugin/state_history_serialization.hpp @@ -89,10 +89,19 @@ datastream& operator<<(datastream& ds, const history_serial_big_vector_w return ds; } +template +inline void history_pack_varuint64(datastream& 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(datastream& ds, const eosio::chain::bytes& v) { - FC_ASSERT(v.size() <= 1024 * 1024 * 1024); - fc::raw::pack(ds, unsigned_int((uint32_t)v.size())); + history_pack_varuint64(ds, v.size()); if (v.size()) ds.write(&v.front(), (uint32_t)v.size()); } diff --git a/plugins/state_history_plugin/state_history_plugin.cpp b/plugins/state_history_plugin/state_history_plugin.cpp index 0d6d33fb34a..27ace9718d3 100644 --- a/plugins/state_history_plugin/state_history_plugin.cpp +++ b/plugins/state_history_plugin/state_history_plugin.cpp @@ -53,6 +53,16 @@ static bytes zlib_compress_bytes(bytes in) { return out; } +static bytes zlib_decompress(const bytes& in) { + bytes out; + bio::filtering_ostream decomp; + decomp.push(bio::zlib_decompressor()); + decomp.push(bio::back_inserter(out)); + bio::write(decomp, in.data(), in.size()); + bio::close(decomp); + return out; +} + template bool include_delta(const T& old, const T& curr) { return true; @@ -126,10 +136,10 @@ struct state_history_plugin_impl : std::enable_shared_from_thisresize(s); + bytes compressed(s); if (s) - stream.read(result->data(), s); + stream.read(compressed.data(), s); + result = zlib_decompress(compressed); } void get_block(uint32_t block_num, fc::optional& result) { @@ -139,7 +149,8 @@ struct state_history_plugin_impl : std::enable_shared_from_this get_block_id(uint32_t block_num) {