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 #1286 from GolosChain/golos-transit-new
Browse files Browse the repository at this point in the history
Merge golos-transit, operation dump and fix tests #1287 #1288
  • Loading branch information
zxcat committed May 7, 2019
2 parents acf36c2 + e9c143d commit ac40e8a
Show file tree
Hide file tree
Showing 23 changed files with 568 additions and 28 deletions.
5 changes: 5 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,11 @@ namespace golos { namespace chain {
modify(get_account(comment.author), [&](account_object &a) {
a.posting_rewards += author_tokens;
});

auto author_golos = asset(author_tokens, STEEM_SYMBOL);
auto benefactor_golos = asset(total_beneficiary, STEEM_SYMBOL);
auto curator_golos = asset(reward_tokens.to_uint64() - (author_tokens + total_beneficiary), STEEM_SYMBOL);
push_virtual_operation(total_comment_reward_operation(comment.author, to_string(comment.permlink), author_golos, benefactor_golos, curator_golos, comment.net_rshares.value));
}

fc::uint128_t old_rshares2 = calculate_vshares(comment.net_rshares.value);
Expand Down
3 changes: 2 additions & 1 deletion libraries/protocol/include/golos/protocol/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ namespace golos { namespace protocol {
return_vesting_delegation_operation,
producer_reward_operation,
delegation_reward_operation,
auction_window_reward_operation
auction_window_reward_operation,
total_comment_reward_operation
> operation;

/*void operation_get_required_authorities( const operation& op,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ namespace golos { namespace protocol {
account_name_type account;
asset vesting_shares;
};

struct total_comment_reward_operation : public virtual_operation {
total_comment_reward_operation() {
}

total_comment_reward_operation(const account_name_type& a, const string &p, const asset& ar, const asset& br, const asset& cr, int64_t nr)
: author(a), permlink(p), author_reward(ar), benefactor_reward(br), curator_reward(cr), net_rshares(nr) {
}

account_name_type author;
string permlink;
asset author_reward;
asset benefactor_reward;
asset curator_reward;
int64_t net_rshares;
};
} } //golos::protocol

FC_REFLECT((golos::protocol::author_reward_operation), (author)(permlink)(sbd_payout)(steem_payout)(vesting_payout))
Expand All @@ -251,3 +267,4 @@ FC_REFLECT((golos::protocol::comment_benefactor_reward_operation), (benefactor)(
FC_REFLECT((golos::protocol::return_vesting_delegation_operation), (account)(vesting_shares))
FC_REFLECT((golos::protocol::producer_reward_operation), (producer)(vesting_shares))
FC_REFLECT((golos::protocol::delegation_reward_operation), (delegator)(delegatee)(payout_strategy)(vesting_shares))
FC_REFLECT((golos::protocol::total_comment_reward_operation), (author)(permlink)(author_reward)(benefactor_reward)(curator_reward)(net_rshares))
4 changes: 4 additions & 0 deletions plugins/account_history/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ if (options.count(name)) { \
insert_receiver(op.account);
}

void operator()(const total_comment_reward_operation& op) {
insert_dual(op.author);
}

// todo: proposal tx signers are receivers
void operator()(const proposal_create_operation& op) {
insert_dual(op.author);
Expand Down
3 changes: 1 addition & 2 deletions plugins/json_rpc/include/golos/plugins/json_rpc/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ namespace golos {
APPBASE_PLUGIN_REQUIRES();

void set_program_options(boost::program_options::options_description &,
boost::program_options::options_description &) override {
}
boost::program_options::options_description &);

static const std::string &name() {
static std::string name = STEEM_JSON_RPC_PLUGIN_NAME;
Expand Down
44 changes: 37 additions & 7 deletions plugins/json_rpc/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace golos {
namespace plugins {
namespace json_rpc {

namespace bpo = boost::program_options;

struct json_rpc_error {
json_rpc_error() : code(0) {
}
Expand Down Expand Up @@ -273,24 +276,41 @@ namespace golos {
}

struct dump_rpc_time {
dump_rpc_time(const fc::variant& data)
: data_(data) {
dump_rpc_time(const fc::variant& data, uint64_t log_rpc_calls_slower_msec)
: data_(data), log_rpc_calls_slower_msec_(log_rpc_calls_slower_msec) {

dlog("data: ${data}", ("data", fc::json::to_string(data_)));
}

~dump_rpc_time() {
auto msecs = (fc::time_point::now() - start_).count() / 1000;

if (error_.empty()) {
dlog(
"elapsed: ${time} sec, data: ${data}",
"elapsed: ${time} msec, data: ${data}",
("data", fc::json::to_string(data_))
("time", double((fc::time_point::now() - start_).count()) / 1000000.0));
("time", msecs));
} else {
dlog(
"elapsed: ${time} sec, error: '${error}', data: ${data}",
"elapsed: ${time} msec, error: '${error}', data: ${data}",
("data", fc::json::to_string(data_))
("error", error_)
("time", double((fc::time_point::now() - start_).count()) / 1000000.0));
("time", msecs));
}

if (uint64_t(msecs) > log_rpc_calls_slower_msec_) {
if (error_.empty()) {
wlog(
"Too slow RPC call: ${time} msec, data: ${data}",
("data", fc::json::to_string(data_))
("time", msecs));
} else {
wlog(
"Too slow RPC call: ${time} msec, error: '${error}', data: ${data}",
("data", fc::json::to_string(data_))
("error", error_)
("time", msecs));
}
}
}

Expand All @@ -302,10 +322,11 @@ namespace golos {
fc::time_point start_ = fc::time_point::now();
std::string error_;
const fc::variant& data_;
uint64_t log_rpc_calls_slower_msec_;
};

void rpc(const fc::variant& data, msg_pack& msg) {
dump_rpc_time dump(data);
dump_rpc_time dump(data, _log_rpc_calls_slower_msec);

try {
rpc_jsonrpc(data, msg);
Expand Down Expand Up @@ -406,6 +427,7 @@ namespace golos {
map<string, api_description> _registered_apis;
vector<string> _methods;
map<string, map<string, api_method_signature> > _method_sigs;
uint64_t _log_rpc_calls_slower_msec = UINT64_MAX;
private:
// This is a reindex which allows to get parent plugin by method
// unordered_map[method] -> plugin
Expand All @@ -422,10 +444,18 @@ namespace golos {
plugin::~plugin() {
}

void plugin::set_program_options(bpo::options_description& cli, bpo::options_description& cfg) {
cfg.add_options() (
"log-rpc-calls-slower-msec", bpo::value<uint64_t>()->default_value(UINT64_MAX),
"Maximal milliseconds of RPC call or dump it as too slow. If not set, do not dump"
);
}

void plugin::plugin_initialize(const boost::program_options::variables_map &options) {
ilog("json_rpc plugin: plugin_initialize() begin");
pimpl = std::make_unique<impl>();
pimpl->initialize();
pimpl->_log_rpc_calls_slower_msec = options.at("log-rpc-calls-slower-msec").as<uint64_t>();
ilog("json_rpc plugin: plugin_initialize() end");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace mongo_db {
result_type operator()(const chain_properties_update_operation& op);
result_type operator()(const delegation_reward_operation& op);
result_type operator()(const auction_window_reward_operation& op);
result_type operator()(const total_comment_reward_operation& op);
};

}}} // golos::plugins::mongo_db
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace mongo_db {
result_type operator()(const chain_properties_update_operation& op);
result_type operator()(const delegation_reward_operation& op);
result_type operator()(const auction_window_reward_operation& op);
result_type operator()(const total_comment_reward_operation& op);

void write_global_property_object(const dynamic_global_property_object& dgpo, bool history);

Expand Down
5 changes: 5 additions & 0 deletions plugins/mongo_db/mongo_db_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,9 @@ namespace mongo_db {
return body;
}

auto operation_writer::operator()(const total_comment_reward_operation& op) -> result_type {
result_type body;
return body;
}

}}}
4 changes: 4 additions & 0 deletions plugins/mongo_db/mongo_db_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,4 +1927,8 @@ namespace mongo_db {

}

auto state_writer::operator()(const total_comment_reward_operation& op) -> result_type {

}

}}}
44 changes: 44 additions & 0 deletions plugins/operation_dump/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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
)

list(APPEND CURRENT_TARGET_SOURCES
operation_dump_plugin.cpp
)

if(BUILD_SHARED_LIBRARIES)
add_library(golos_${CURRENT_TARGET} SHARED
${CURRENT_TARGET_HEADERS}
${CURRENT_TARGET_SOURCES}
)
else()
add_library(golos_${CURRENT_TARGET} STATIC
${CURRENT_TARGET_HEADERS}
${CURRENT_TARGET_SOURCES}
)
endif()

add_library(golos::${CURRENT_TARGET} ALIAS golos_${CURRENT_TARGET})
set_property(TARGET golos_${CURRENT_TARGET} PROPERTY EXPORT_NAME ${CURRENT_TARGET})

target_link_libraries(
golos_${CURRENT_TARGET}
golos::chain_plugin
golos::follow
golos::tags
appbase
)

target_include_directories(golos_${CURRENT_TARGET}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

install(TARGETS
golos_${CURRENT_TARGET}

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <boost/filesystem/fstream.hpp>

namespace golos { namespace plugins { namespace operation_dump {

namespace bfs = boost::filesystem;

// Structure size can differ - uses sizeof
struct dump_header {
char magic[13] = "Golos\adumpOP";
uint32_t version = 1;
};

using operation_number = std::pair<uint32_t, uint16_t>;

class dump_buffer : public std::stringstream {
public:
dump_buffer() {
}

using std::stringstream::write;

void write(const operation_number& op_num) {
fc::raw::pack(*this, op_num);
}
};

using dump_buffers = std::map<std::string, dump_buffer>;

class dump_file : public bfs::ofstream {
public:
dump_file(const bfs::path& p): bfs::ofstream(p, std::ios_base::binary | std::ios_base::app) {
bfs::ofstream::exceptions(std::ofstream::failbit | std::ofstream::badbit);
}

void write(const dump_header& hdr) {
bfs::ofstream::write((const char*)&hdr, sizeof(dump_header));
}
};

} } } // golos::plugins::operation_dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <appbase/plugin.hpp>
#include <golos/chain/database.hpp>
#include <golos/chain/operation_notification.hpp>
#include <golos/plugins/chain/plugin.hpp>

namespace golos { namespace plugins { namespace operation_dump {

namespace bpo = boost::program_options;
using namespace golos::chain;

class operation_dump_plugin final : public appbase::plugin<operation_dump_plugin> {
public:
APPBASE_PLUGIN_REQUIRES((chain::plugin))

operation_dump_plugin();

~operation_dump_plugin();

void set_program_options(bpo::options_description& cli, bpo::options_description& cfg) override;

void plugin_initialize(const bpo::variables_map& options) override;

void plugin_startup() override;

void plugin_shutdown() override;

static const std::string& name();

private:
class operation_dump_plugin_impl;

std::unique_ptr<operation_dump_plugin_impl> my;
};

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

0 comments on commit ac40e8a

Please sign in to comment.