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

Commit

Permalink
Merge pull request #7385 from EOSIO/update-ship
Browse files Browse the repository at this point in the history
Ship: port #7383 and #7384 to develop
  • Loading branch information
tbfleming committed May 20, 2019
2 parents 63e6324 + 1a86660 commit 42c5f7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
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

0 comments on commit 42c5f7d

Please sign in to comment.