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

Commit

Permalink
Not write follow operations dump in wrong cases #1333
Browse files Browse the repository at this point in the history
  • Loading branch information
soft-bagel-93 committed Jun 18, 2019
1 parent e9a5f5e commit 2a6002a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 25 deletions.
2 changes: 2 additions & 0 deletions plugins/operation_dump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ set(CURRENT_TARGET operation_dump)
list(APPEND CURRENT_TARGET_HEADERS
include/golos/plugins/operation_dump/operation_dump_plugin.hpp
include/golos/plugins/operation_dump/operation_dump_container.hpp
include/golos/plugins/operation_dump/operation_dump_visitor.hpp
)

list(APPEND CURRENT_TARGET_SOURCES
operation_dump_plugin.cpp
operation_dump_visitor.cpp
)

if(BUILD_SHARED_LIBRARIES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class operation_dump_plugin final : public appbase::plugin<operation_dump_plugin
dump_buffers buffers;
clarifications<int64_t> vote_rshares;
clarifications<bool> not_deleted_comments;
clarifications<bool> not_exist_accounts;
private:
class operation_dump_plugin_impl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ using namespace golos::plugins::follow;
#define TAGS_NUMBER 15
#define TAG_MAX_LENGTH 512

template<typename OperationType>
std::vector<OperationType> get_custom_ops(const custom_json_operation& op);

std::vector<follow_plugin_operation> get_follow_ops(const custom_json_operation& op, const database& _db);

class operation_dump_visitor {
public:
using result_type = void;
Expand Down Expand Up @@ -122,37 +127,18 @@ class operation_dump_visitor {
fc::raw::pack(b, _block.timestamp);
}

// Not logs if operation failed in plugin, but logs if plugin not exists
// Not logs if operation failed in plugin or if plugin not exists and cannot check operation
auto operator()(const custom_json_operation& op) -> result_type {
if (op.id != "follow") { // follows, reblogs, delete_reblogs
return;
}

std::vector<follow_plugin_operation> fpops;

auto v = fc::json::from_string(op.json);
try {
if (v.is_array() && v.size() > 0 && v.get_array()[0].is_array()) {
fc::from_variant(v, fpops);
} else {
fpops.emplace_back();
fc::from_variant(v, fpops[0]);
}
} catch (...) {
// Normal cases failed, try this strange case from follow-plugin
try {
auto fop = v.as<follow_operation>();
fpops.emplace_back(fop);
} catch (...) {
}
}

for (const follow_plugin_operation& fpop : fpops) {
for (const follow_plugin_operation& fpop : get_follow_ops(op, _db)) {
fpop.visit(*this);
}
}

auto operator()(const follow_operation& op) -> result_type {
if (pop_clarification(_plugin.not_exist_accounts)) {
return;
}

auto& b = write_op_header("follows", std::string(op.follower) + "/" + op.following);

fc::raw::pack(b, op.follower);
Expand Down
13 changes: 13 additions & 0 deletions plugins/operation_dump/operation_dump_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ struct post_operation_clarifier {

add_clarification(_plugin.not_deleted_comments, not_deleted);
}

auto operator()(const custom_json_operation& op) -> result_type {
for (const follow_plugin_operation& fpop : get_follow_ops(op, _db)) {
fpop.visit(*this);
}
}

result_type operator()(const follow_operation& op) const {
auto not_exist = (!_db.find_account(op.follower) || _db.find_account(op.following));

add_clarification(_plugin.not_exist_accounts, not_exist);
}
};

class operation_dump_plugin::operation_dump_plugin_impl final {
Expand All @@ -62,6 +74,7 @@ class operation_dump_plugin::operation_dump_plugin_impl final {
virtual_ops.erase(block_num);
_plugin.vote_rshares.erase(block_num);
_plugin.not_deleted_comments.erase(block_num);
_plugin.not_exist_accounts.erase(block_num);
}

void on_block(const signed_block& block) {
Expand Down
45 changes: 45 additions & 0 deletions plugins/operation_dump/operation_dump_visitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <golos/plugins/operation_dump/operation_dump_visitor.hpp>

namespace golos { namespace plugins { namespace operation_dump {

template<typename OperationType>
std::vector<OperationType> get_custom_ops(const custom_json_operation& op) {
std::vector<OperationType> ops;

auto v = fc::json::from_string(op.json);
if (v.is_array() && v.size() > 0 && v.get_array()[0].is_array()) {
fc::from_variant(v, ops);
} else {
ops.emplace_back();
fc::from_variant(v, ops[0]);
}

return ops;
}

std::vector<follow_plugin_operation> get_follow_ops(const custom_json_operation& op, const database& _db) {
std::vector<follow_plugin_operation> fpops;

if (op.id != "follow") { // follows, reblogs, delete_reblogs
return fpops;
}

if (!_db.has_index<follow_index>()) {
return fpops;
}

try {
fpops = get_custom_ops<follow_plugin_operation>(op);
} catch (...) {
// Normal cases failed, try this strange case from follow-plugin
try {
auto fop = fc::json::from_string(op.json).as<follow_operation>();
fpops.emplace_back(fop);
} catch (...) {
}
}

return fpops;
}

} } } // golos::plugins::operation_dump

0 comments on commit 2a6002a

Please sign in to comment.