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

Ship: port #7383 and #7384 to develop #7385

Merged
merged 1 commit into from
May 20, 2019
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 @@ -89,10 +89,19 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_big_vector_w
return ds;
}

template <typename ST>
inline void history_pack_varuint64(datastream<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(datastream<ST>& 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());
}
Expand Down
19 changes: 15 additions & 4 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
bool include_delta(const T& old, const T& curr) {
return true;
Expand Down Expand Up @@ -126,10 +136,10 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
auto& stream = log.get_entry(block_num, header);
uint32_t s;
stream.read((char*)&s, sizeof(s));
result.emplace();
result->resize(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<bytes>& result) {
Expand All @@ -139,7 +149,8 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
} catch (...) {
return;
}
result = fc::raw::pack(*p);
if (p)
result = fc::raw::pack(*p);
}

fc::optional<chain::block_id_type> get_block_id(uint32_t block_num) {
Expand Down