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

Commit

Permalink
Merge branch 'master' into golos-v0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
afalaleev committed Aug 24, 2018
2 parents dda652f + 9ee5f5f commit 6b19a3c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ namespace golos { namespace chain {

signed_block pending_block;

with_strong_write_lock([&]() {
with_strong_write_lock([&]() { detail::with_generating(*this, [&]() {
//
// The following code throws away existing pending_tx_session and
// rebuilds it by re-applying pending transactions.
Expand Down Expand Up @@ -1198,7 +1198,7 @@ namespace golos { namespace chain {
}

_pending_tx_session.reset();
});
}); });

// We have temporarily broken the invariant that
// _pending_tx_session is the result of applying _pending_tx, as
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/golos/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ namespace golos { namespace chain {
_is_producing = p;
}

bool is_generating() const {
return _is_generating;
}

void set_generating(bool p) {
_is_generating = p;
}

bool _is_producing = false;
bool _is_generating = false;
bool _is_testing = false; ///< set for tests to avoid low free memory spam
bool _log_hardforks = true;

Expand Down
28 changes: 28 additions & 0 deletions libraries/chain/include/golos/chain/db_with.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ namespace golos {
database &_db;
};

/**
* Class is used to help the with_generating implementation
*/
struct generating_helper final {
generating_helper(database& db): _db(db) {
_db.set_generating(true);
}

~generating_helper() {
_db.set_generating(false);
}

database &_db;
};

/**
* Empty pending_transactions, call callback,
* then reset pending_transactions after callback is done.
Expand Down Expand Up @@ -111,6 +126,19 @@ namespace golos {
producing_helper restorer(db);
callback();
}

/**
* Set generating flag to true, call callback, then set generating flag to false
*/
template <typename Lambda>
void with_generating(
database& db,
Lambda callback
) {
generating_helper restorer(db);
callback();
}

}
}
} // golos::chain::detail
7 changes: 4 additions & 3 deletions plugins/private_message/private_message_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ namespace golos { namespace plugins { namespace private_message {
}

bool private_message_plugin::private_message_plugin_impl::can_call_callbacks() const {
return !db_.is_producing() && !callbacks_.empty();
return !db_.is_producing() && !db_.is_generating() && !callbacks_.empty();
}

void private_message_plugin::private_message_plugin_impl::call_callbacks(
Expand All @@ -300,8 +300,9 @@ namespace golos { namespace plugins { namespace private_message {
(!info.query.select_events.empty() && !info.query.select_events.count(event)) ||
info.query.filter_accounts.count(from) ||
info.query.filter_accounts.count(to) ||
(to.size() && !info.query.select_accounts.empty() && !info.query.select_accounts.count(to)) ||
(from.size() && !info.query.select_accounts.empty() && !info.query.select_accounts.count(from))
(!info.query.select_accounts.empty() &&
!info.query.select_accounts.count(to) &&
!info.query.select_accounts.count(from))
) {
++itr;
continue;
Expand Down

0 comments on commit 6b19a3c

Please sign in to comment.