From e711e0ac727eb1ab3384e77230c14f2c2cec93d6 Mon Sep 17 00:00:00 2001 From: Andrew Falaleev Date: Fri, 14 Dec 2018 17:30:58 +0700 Subject: [PATCH 1/5] Fix calculation of pending payouts. #1005 --- libraries/api/discussion_helper.cpp | 47 ++++++++++--------- .../include/golos/api/discussion_helper.hpp | 7 +-- plugins/tags/plugin.cpp | 25 +--------- 3 files changed, 30 insertions(+), 49 deletions(-) diff --git a/libraries/api/discussion_helper.cpp b/libraries/api/discussion_helper.cpp index 59d101a08d..c1fe4b5565 100644 --- a/libraries/api/discussion_helper.cpp +++ b/libraries/api/discussion_helper.cpp @@ -57,6 +57,8 @@ namespace golos { namespace api { discussion get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t offset) const; + void fill_discussion(discussion& d, const comment_object& comment, uint32_t vote_limit, uint32_t offset) const; + void fill_comment_api_object(const comment_object& o, comment_api_object& d) const; private: @@ -136,8 +138,28 @@ namespace golos { namespace api { // get_discussion discussion discussion_helper::impl::get_discussion(const comment_object& comment, uint32_t vote_limit, uint32_t offset) const { discussion d = create_discussion(comment); + fill_discussion(d, comment, vote_limit, offset); + return d; + } + + discussion discussion_helper::get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t offset) const { + return pimpl->get_discussion(c, vote_limit, offset); + } + + void discussion_helper::impl::fill_discussion( + discussion& d, const comment_object& comment, uint32_t vote_limit, uint32_t offset + ) const { set_url(d); + fill_reputation_(database_, d.author, d.author_reputation); + + if (d.body.size() > 1024 * 128) { + d.body = "body pruned due to size"; + } + if (d.parent_author.size() > 0 && d.body.size() > 1024 * 16) { + d.body = "comment pruned due to size"; + } + d.active_votes_count = comment.total_votes; comment_curation_info c{database_, comment, true}; @@ -149,12 +171,12 @@ namespace golos { namespace api { d.active_votes = select_active_votes(c, vote_limit, offset); set_pending_payout(d); - - return d; } - discussion discussion_helper::get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t offset) const { - return pimpl->get_discussion(c, vote_limit, offset); + void discussion_helper::fill_discussion( + discussion& d, const comment_object& comment, uint32_t vote_limit, uint32_t offset + ) const { + pimpl->fill_discussion(d, comment, vote_limit, offset); } // @@ -293,22 +315,8 @@ namespace golos { namespace api { d.total_pending_payout_value = db.to_sbd(asset(static_cast(tpp), pot.symbol)); } - - fill_reputation_(db, d.author, d.author_reputation); - - if (d.body.size() > 1024 * 128) { - d.body = "body pruned due to size"; - } - if (d.parent_author.size() > 0 && d.body.size() > 1024 * 16) { - d.body = "comment pruned due to size"; - } - - set_url(d); } - void discussion_helper::set_pending_payout(discussion& d) const { - pimpl->set_pending_payout(d); - } // // set_url void discussion_helper::impl::set_url(discussion& d) const { @@ -321,9 +329,6 @@ namespace golos { namespace api { } } - void discussion_helper::set_url(discussion& d) const { - pimpl->set_url(d); - } // // create_discussion discussion discussion_helper::impl::create_discussion(const std::string& author) const { diff --git a/libraries/api/include/golos/api/discussion_helper.hpp b/libraries/api/include/golos/api/discussion_helper.hpp index 664f70fed8..c36bc817a6 100644 --- a/libraries/api/include/golos/api/discussion_helper.hpp +++ b/libraries/api/include/golos/api/discussion_helper.hpp @@ -21,11 +21,6 @@ namespace golos { namespace api { ); ~discussion_helper(); - - void set_pending_payout(discussion& d) const; - - void set_url(discussion& d) const; - std::vector select_active_votes( const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset ) const; @@ -38,6 +33,8 @@ namespace golos { namespace api { comment_api_object create_comment_api_object(const comment_object& o) const; + void fill_discussion(discussion&, const comment_object&, uint32_t vote_limit, uint32_t offset) const; + void fill_comment_api_object(const comment_object& o, comment_api_object& d) const; diff --git a/plugins/tags/plugin.cpp b/plugins/tags/plugin.cpp index 3c23c79977..3476014daf 100644 --- a/plugins/tags/plugin.cpp +++ b/plugins/tags/plugin.cpp @@ -51,8 +51,6 @@ namespace golos { namespace plugins { namespace tags { return database_; } - std::vector select_active_votes(const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset) const; - bool filter_tags(const tags::tag_type type, std::set& select_tags) const; bool filter_authors(discussion_query& query) const; @@ -84,10 +82,6 @@ namespace golos { namespace plugins { namespace tags { std::vector> get_tags_used_by_author(const std::string& author) const; - void set_pending_payout(discussion& d) const; - - void set_url(discussion& d) const; - std::vector get_replies_by_last_update( account_name_type start_parent_author, std::string start_permlink, uint32_t limit, uint32_t vote_limit @@ -111,12 +105,6 @@ namespace golos { namespace plugins { namespace tags { std::unique_ptr helper; }; - std::vector tags_plugin::impl::select_active_votes( - const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset - ) const { - return helper->select_active_votes(author, permlink, limit, offset); - } - discussion tags_plugin::impl::get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t votes_offset) const { return helper->get_discussion(c, vote_limit, votes_offset); } @@ -139,9 +127,8 @@ namespace golos { namespace plugins { namespace tags { } void tags_plugin::impl::fill_discussion(discussion& d, const discussion_query& query) const { - set_url(d); - set_pending_payout(d); - d.active_votes = select_active_votes(d.author, d.permlink, query.vote_limit, query.vote_offset); + helper->fill_discussion(d, database_.get_comment(d.author, d.permlink), query.vote_limit, query.vote_offset); + d.body_length = static_cast(d.body.size()); if (query.truncate_body) { if (d.body.size() > query.truncate_body) { @@ -231,10 +218,6 @@ namespace golos { namespace plugins { namespace tags { tags_plugin::~tags_plugin() = default; - void tags_plugin::impl::set_url(discussion& d) const { - helper->set_url( d ); - } - boost::multiprecision::uint256_t to256(const fc::uint128_t& t) { boost::multiprecision::uint256_t result(t.high_bits()); result <<= 65; @@ -242,10 +225,6 @@ namespace golos { namespace plugins { namespace tags { return result; } - void tags_plugin::impl::set_pending_payout(discussion& d) const { - helper->set_pending_payout(d); - } - bool tags_plugin::impl::filter_tags(const tags::tag_type type, std::set& select_tags) const { if (select_tags.empty()) { return true; From 9a7f6a9e118941660d26296168a73ee4687746fe Mon Sep 17 00:00:00 2001 From: Andrew Falaleev Date: Tue, 18 Dec 2018 11:38:25 +0700 Subject: [PATCH 2/5] Add get_transaction_digest to database_api. #823 --- plugins/database_api/api.cpp | 21 ++++++++++++++++--- .../golos/plugins/database_api/plugin.hpp | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/plugins/database_api/api.cpp b/plugins/database_api/api.cpp index 2d5152d44a..8482da862f 100755 --- a/plugins/database_api/api.cpp +++ b/plugins/database_api/api.cpp @@ -97,7 +97,8 @@ struct plugin::api_impl final { uint64_t get_account_count() const; // Authority / validation - std::string get_transaction_hex(const signed_transaction &trx) const; + std::string get_transaction_digest(const transaction &trx) const; + std::string get_transaction_hex(const transaction &trx) const; std::set get_required_signatures(const signed_transaction &trx, const flat_set &available_keys) const; std::set get_potential_signatures(const signed_transaction &trx) const; bool verify_authority(const signed_transaction &trx) const; @@ -572,16 +573,30 @@ DEFINE_API(plugin, get_account_bandwidth) { // // ////////////////////////////////////////////////////////////////////// +DEFINE_API(plugin, get_transaction_digest) { + PLUGIN_API_VALIDATE_ARGS( + (transaction, trx) + ); + return my->database().with_weak_read_lock([&]() { + return my->get_transaction_digest(trx); + }); +} + +std::string plugin::api_impl::get_transaction_digest(const transaction &trx) const { + static const auto chain_id = STEEMIT_CHAIN_ID; + return trx.sig_digest(chain_id).str(); +} + DEFINE_API(plugin, get_transaction_hex) { PLUGIN_API_VALIDATE_ARGS( - (signed_transaction, trx) + (transaction, trx) ); return my->database().with_weak_read_lock([&]() { return my->get_transaction_hex(trx); }); } -std::string plugin::api_impl::get_transaction_hex(const signed_transaction &trx) const { +std::string plugin::api_impl::get_transaction_hex(const transaction &trx) const { return fc::to_hex(fc::raw::pack(trx)); } diff --git a/plugins/database_api/include/golos/plugins/database_api/plugin.hpp b/plugins/database_api/include/golos/plugins/database_api/plugin.hpp index d997db5567..13d7c2c08b 100755 --- a/plugins/database_api/include/golos/plugins/database_api/plugin.hpp +++ b/plugins/database_api/include/golos/plugins/database_api/plugin.hpp @@ -120,6 +120,7 @@ DEFINE_API_ARGS(get_vesting_delegations, msg_pack, vector) DEFINE_API_ARGS(get_conversion_requests, msg_pack, std::vector) +DEFINE_API_ARGS(get_transaction_digest, msg_pack, std::string) DEFINE_API_ARGS(get_transaction_hex, msg_pack, std::string) DEFINE_API_ARGS(get_required_signatures, msg_pack, std::set) DEFINE_API_ARGS(get_potential_signatures, msg_pack, std::set) @@ -284,6 +285,9 @@ class plugin final : public appbase::plugin { // Authority / Validation // //////////////////////////// + /// @brief Get a hexdump of the serialized binary form of a transaction digest + (get_transaction_digest) + /// @brief Get a hexdump of the serialized binary form of a transaction (get_transaction_hex) From 0495af94090a2e2127bebac9927d226513d37f67 Mon Sep 17 00:00:00 2001 From: Andrew Falaleev Date: Tue, 18 Dec 2018 11:54:30 +0700 Subject: [PATCH 3/5] Don't lock database on getting of transaction signature in database_api. #823 --- plugins/database_api/api.cpp | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/plugins/database_api/api.cpp b/plugins/database_api/api.cpp index 8482da862f..f23b117870 100755 --- a/plugins/database_api/api.cpp +++ b/plugins/database_api/api.cpp @@ -97,8 +97,6 @@ struct plugin::api_impl final { uint64_t get_account_count() const; // Authority / validation - std::string get_transaction_digest(const transaction &trx) const; - std::string get_transaction_hex(const transaction &trx) const; std::set get_required_signatures(const signed_transaction &trx, const flat_set &available_keys) const; std::set get_potential_signatures(const signed_transaction &trx) const; bool verify_authority(const signed_transaction &trx) const; @@ -577,12 +575,6 @@ DEFINE_API(plugin, get_transaction_digest) { PLUGIN_API_VALIDATE_ARGS( (transaction, trx) ); - return my->database().with_weak_read_lock([&]() { - return my->get_transaction_digest(trx); - }); -} - -std::string plugin::api_impl::get_transaction_digest(const transaction &trx) const { static const auto chain_id = STEEMIT_CHAIN_ID; return trx.sig_digest(chain_id).str(); } @@ -591,13 +583,8 @@ DEFINE_API(plugin, get_transaction_hex) { PLUGIN_API_VALIDATE_ARGS( (transaction, trx) ); - return my->database().with_weak_read_lock([&]() { - return my->get_transaction_hex(trx); - }); -} - -std::string plugin::api_impl::get_transaction_hex(const transaction &trx) const { return fc::to_hex(fc::raw::pack(trx)); + } DEFINE_API(plugin, get_required_signatures) { From 58742300776389afcd1cfa9708d6b48230a8149b Mon Sep 17 00:00:00 2001 From: Andrew Falaleev Date: Tue, 18 Dec 2018 14:27:21 +0700 Subject: [PATCH 4/5] Fix clearing old data in social_network. #1007 --- plugins/social_network/social_network.cpp | 64 ++++++++++++++--------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/plugins/social_network/social_network.cpp b/plugins/social_network/social_network.cpp index 28c4f21e2a..021bf71454 100644 --- a/plugins/social_network/social_network.cpp +++ b/plugins/social_network/social_network.cpp @@ -230,24 +230,22 @@ namespace golos { namespace plugins { namespace social_network { } void operator()(const delete_comment_operation& o) const { - const auto& comment = impl.db.get_comment(o.author, o.permlink); - const auto content = impl.find_comment_content(comment.id); - - if (content == nullptr) { + const auto* comment = impl.db.find_comment(o.author, o.permlink); + if (comment == nullptr) { return; } - impl.db.remove(*content); + const auto content = impl.find_comment_content(comment->id); - if (impl.db.template has_index()) { - if (comment.net_rshares > 0) { - return; - } + if (content != nullptr) { + impl.db.remove(*content); + } - impl.activate_parent_comments(comment); + if (impl.db.template has_index()) { + impl.activate_parent_comments(*comment); auto& idx = impl.db.template get_index().indices().template get(); - auto itr = idx.find(comment.id); + auto itr = idx.find(comment->id); if (idx.end() != itr) { impl.db.remove(*itr); } @@ -255,7 +253,7 @@ namespace golos { namespace plugins { namespace social_network { if (impl.db.template has_index()) { auto& idx = impl.db.template get_index().indices().template get(); - auto itr = idx.find(comment.id); + auto itr = idx.find(comment->id); if (idx.end() != itr) { impl.db.remove(*itr); } @@ -287,10 +285,14 @@ namespace golos { namespace plugins { namespace social_network { } /// ignore all other ops void operator()(const golos::protocol::comment_operation& o) const { - const auto& comment = db.get_comment(o.author, o.permlink); + const auto* comment = db.find_comment(o.author, o.permlink); + if (nullptr == comment) { + return; + } + const auto& dp = depth_parameters; if (!dp.miss_content()) { - const auto comment_content = impl.find_comment_content(comment.id); + const auto comment_content = impl.find_comment_content(comment->id); if ( comment_content != nullptr) { // Edit case db.modify(*comment_content, [&]( comment_content_object& con ) { @@ -331,7 +333,7 @@ namespace golos { namespace plugins { namespace social_network { } else { // Creation case db.create([&](comment_content_object& con) { - con.comment = comment.id; + con.comment = comment->id; if (!dp.has_comment_title_depth || dp.comment_title_depth > 0) { from_string(con.title, o.title); } @@ -351,8 +353,8 @@ namespace golos { namespace plugins { namespace social_network { if (db.has_index()) { auto now = db.head_block_time(); - if (!impl.set_comment_update(comment, now, true)) { // If create case - impl.activate_parent_comments(comment); + if (!impl.set_comment_update(*comment, now, true)) { // If create case + impl.activate_parent_comments(*comment); } } } @@ -472,10 +474,14 @@ namespace golos { namespace plugins { namespace social_network { auto& content = *itr; ++itr; - auto& comment = db.get_comment(content.comment); + auto* comment = db.find(content.comment); + if (nullptr == comment) { + db.remove(content); + continue; + } auto delta = head_block_num - content.block_number; - if (comment.mode == archived && dp.should_delete_part_of_content_object(delta)) { + if (comment->mode == archived && dp.should_delete_part_of_content_object(delta)) { if (dp.should_delete_whole_content_object(delta)) { db.remove(content); continue; @@ -509,10 +515,14 @@ namespace golos { namespace plugins { namespace social_network { auto& clu = *itr; ++itr; - auto& comment = db.get_comment(clu.comment); + auto* comment = db.find(clu.comment); + if (nullptr == comment) { + db.remove(clu); + continue; + } auto delta = head_block_num - clu.block_number; - if (comment.mode == archived && depth_parameters.should_delete_last_update_object(delta)) { + if (comment->mode == archived && depth_parameters.should_delete_last_update_object(delta)) { db.remove(clu); } else { break; @@ -720,9 +730,12 @@ namespace golos { namespace plugins { namespace social_network { continue; } - const auto& vo = db.get(itr->comment); + const auto* vo = db.find(itr->comment); + if (nullptr == vo) { + continue; + } account_vote avote; - avote.authorperm = vo.author + "/" + to_string(vo.permlink); + avote.authorperm = vo->author + "/" + to_string(vo->permlink); //avote.weight = itr->weight; // TODO: avote.rshares = itr->rshares; avote.percent = itr->vote_percent; @@ -806,7 +819,10 @@ namespace golos { namespace plugins { namespace social_network { result.reserve(limit); while (itr != clu_idx.end() && result.size() < limit && itr->parent_author == *parent_author) { - result.emplace_back(get_discussion(db.get_comment(itr->comment), vote_limit, vote_offset)); + auto* comment = db.find(itr->comment); + if (nullptr != comment) { + result.emplace_back(get_discussion(*comment, vote_limit, vote_offset)); + } ++itr; } From 5893b3a36c9fa6fbcfdcaf59b9745894311cbe30 Mon Sep 17 00:00:00 2001 From: Andrew Falaleev Date: Tue, 18 Dec 2018 14:47:38 +0700 Subject: [PATCH 5/5] Update blockchain version to 0.19.1 --- libraries/protocol/include/golos/protocol/config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/protocol/include/golos/protocol/config.hpp b/libraries/protocol/include/golos/protocol/config.hpp index c3c9c84782..8d06a5f53a 100644 --- a/libraries/protocol/include/golos/protocol/config.hpp +++ b/libraries/protocol/include/golos/protocol/config.hpp @@ -3,7 +3,7 @@ */ #pragma once -#define STEEMIT_BLOCKCHAIN_VERSION (version(0, 19, 0)) +#define STEEMIT_BLOCKCHAIN_VERSION (version(0, 19, 1)) #define STEEMIT_BLOCKCHAIN_HARDFORK_VERSION (hardfork_version(STEEMIT_BLOCKCHAIN_VERSION)) #ifdef STEEMIT_BUILD_TESTNET