Skip to content

Commit

Permalink
updated saving "plugin state"
Browse files Browse the repository at this point in the history
  • Loading branch information
coodi committed Feb 12, 2019
1 parent af34577 commit e080915
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 6 additions & 3 deletions uos_blocks_exporter/mongo_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace uos{
)
);
return bool(
mongo_conn[connection_name][db_action_traces].find_one_and_update( //todo
mongo_conn[connection_name][db_action_traces].update_many(
make_document(kvp("$and",
make_array(make_document(kvp("blocknum", static_cast<int64_t>(blocknum))),
make_document(kvp("blockid",block_id)),
Expand Down Expand Up @@ -220,7 +220,9 @@ namespace uos{
if(!connected)
connect();
try{
mongo_conn[connection_name]["last_state"].update_one(
mongocxx::v_noabi::options::update opt;
opt.upsert(true);
auto ret = mongo_conn[connection_name]["last_state"].update_one(
make_document(kvp("last_state",1)),
make_document(
kvp("$set",
Expand All @@ -231,8 +233,9 @@ namespace uos{
kvp("irrblocknum",state.mongo_irrblocknum),
kvp("irrblockid",state.mongo_irrblockid))
)
)
),opt
);

}
catch(mongocxx::exception &ex){
elog(ex.what());
Expand Down
22 changes: 16 additions & 6 deletions uos_blocks_exporter/uos_blocks_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ namespace uos_plugins{
}

void uos_BE_impl::irreversible_block_catcher(const eosio::chain::block_state_ptr &bsp) {
auto ret = mongo->set_irreversible_block(bsp->block_num,bsp->block->id());
mongo->set_irreversible_block(bsp->block_num,bsp->block->id());
last_state.mongo_irrblockid = bsp->block->id();
last_state.mongo_irrblocknum = bsp->block_num;
mongo->set_last_state(last_state);
// elog(std::string("-"+std::string(bsp->block->id())+" "+std::to_string(bsp->block_num)));
}

Expand All @@ -84,6 +87,17 @@ namespace uos_plugins{

void uos_BE_impl::applied_transaction_catcher(const eosio::chain::transaction_trace_ptr &att) {
fc::variants actions;
try{
last_state.mongo_blockid = fc::variant(att->producer_block_id).as_string();
last_state.mongo_blocknum = att->block_num;
mongo->set_last_state(last_state);
}
catch (mongocxx::exception &ex){
elog(ex.what());
}
catch(...){

}
for(auto item : att->action_traces){
if( black_list->size() > 0 ){
if ( black_list->find(item.act.account.to_string()+"."+item.act.name.to_string()) !=black_list->end()){
Expand All @@ -98,9 +112,6 @@ namespace uos_plugins{
else{
wlog("whitelist is empty");
}
// if(item.act.account==N(eosio) && item.act.name==N(onblock)){
// continue;
// }
actions.emplace_back(fill_inline_traces(item));
}
if(actions.size()>0){
Expand All @@ -113,8 +124,6 @@ namespace uos_plugins{
break;
}
}
// if(consists_inlines)
// std::this_thread::sleep_for(std::chrono::seconds(10));
fc::mutable_variant_object mblock;
mblock["blocknum"] = att->block_num;
mblock["blockid"] = att->producer_block_id;
Expand All @@ -125,6 +134,7 @@ namespace uos_plugins{

try {
mongo->put_action_traces(fc::json::to_string(mblock));

}
catch (mongocxx::exception &ex){
elog(ex.what());
Expand Down

1 comment on commit e080915

@coodi
Copy link
Member Author

@coodi coodi commented on e080915 Feb 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2

Please sign in to comment.