Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1332 from GolosChain/1331-serialize-state-store-r…
Browse files Browse the repository at this point in the history
…eputation

Store reputation in serialized state #1331
  • Loading branch information
afalaleev authored Jun 15, 2019
2 parents 8f6c8fd + 1d41693 commit e9a5f5e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions plugins/chain/serialize_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <golos/chain/steem_objects.hpp>
#include <golos/chain/account_object.hpp>
#include <golos/chain/comment_object.hpp>
#include "../follow/include/golos/plugins/follow/follow_objects.hpp"
#include <boost/filesystem/fstream.hpp>
#include <fc/crypto/sha256.hpp>

Expand Down Expand Up @@ -184,15 +185,18 @@ struct table_header {
};

template<typename Idx, typename Lambda1, typename Lambda2>
void serialize_table(const database& db, ofstream_sha256& out, Lambda1&& fix_hdr, Lambda2&& check_item) {
void serialize_table(const database& db, ofstream_sha256& out, uint32_t type_id, Lambda1&& fix_hdr, Lambda2&& check_item) {
auto start = fc::time_point::now();
size_t n = 0, l = 0;
uint32_t min = -1, max = 0;

const auto& generic = db.get_index<Idx>();
const auto& indices = generic.indicies();
const auto& idx = indices.template get<by_id>();
table_header hdr({chainbase::generic_index<Idx>::value_type::type_id, static_cast<uint32_t>(indices.size())});
if (type_id == 0) {
type_id = chainbase::generic_index<Idx>::value_type::type_id;
}
table_header hdr({type_id, static_cast<uint32_t>(indices.size())});
fix_hdr(hdr, idx);
wlog("Saving ${name}, ${n} record(s), type: ${t}",
("name", generic.name())("n", hdr.records_count)("t", hdr.type_id));
Expand All @@ -219,7 +223,7 @@ void serialize_table(const database& db, ofstream_sha256& out, Lambda1&& fix_hdr
}

void serialize_vote_table(const database& db, ofstream_sha256& out) {
serialize_table<comment_vote_index>(db, out, [](auto& hdr, auto& idx) {
serialize_table<comment_vote_index>(db, out, 0, [](auto& hdr, auto& idx) {
auto itr = idx.begin();
auto etr = idx.end();
int bad = 0;
Expand Down Expand Up @@ -257,7 +261,7 @@ void plugin::serialize_state(const bfs::path& output) {
out.write(hdr);
ilog("---------------------------------------------------------------------------");

#define STORE(T) serialize_table<T>(db_, out, [](auto& h, auto& i){}, [](const auto& i){return true;});
#define STORE(T) serialize_table<T>(db_, out, 0, [](auto& h, auto& i){}, [](const auto& i){return true;});
STORE(account_index);
STORE(account_authority_index);
STORE(account_bandwidth_index);
Expand Down Expand Up @@ -290,13 +294,27 @@ void plugin::serialize_state(const bfs::path& output) {
// custom_pack::_current_str_type = custom_pack::other;
// STORE(proposal_index); // not supported
// STORE(required_approval_index); // not supported

// if adding new objects, do not forgot update type ids in optional state parts
#undef STORE

auto end = fc::time_point::now();
wlog("Done in ${t} sec.", ("t", double((end - start).count()) / 1000000.0));
wlog("Data SHA256 hash: ${h}", ("h", out.hash().str()));
out.close();

auto rep_file = output;
rep_file += ".reputation";
if (db_.has_index<golos::plugins::follow::reputation_index>()) {
ofstream_sha256 rep_out(rep_file);
rep_out.write(hdr);
serialize_table<golos::plugins::follow::reputation_index>(db_, rep_out, required_approval_object_type+1, [](auto& h, auto& i){}, [](const auto& i){return true;});
wlog("Reputation SHA256 hash: ${h}", ("h", rep_out.hash().str()));
rep_out.close();
} else {
bfs::remove(rep_file);
}

auto map_file = output;
map_file += ".map";
ofstream_sha256 om(map_file);
Expand Down

0 comments on commit e9a5f5e

Please sign in to comment.