Skip to content

Commit

Permalink
GH-529 If an existing handler with the same priority exists for a non…
Browse files Browse the repository at this point in the history
…-unique id then do not post it
  • Loading branch information
heifner committed Sep 25, 2024
1 parent 4763f13 commit fd21a45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
14 changes: 4 additions & 10 deletions libraries/custom_appbase/include/eosio/chain/exec_pri_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,10 @@ class exec_pri_queue : public boost::asio::execution_context
auto i = std::lower_bound(que.ordered_begin(), end, priority, [](const auto& h, int priority) {
return h->priority() > priority;
});
if (i != end) {
// ordered iterator appears to only be a forward iterator
// find last posted handler with same priority
auto p = i;
for (; i != end; p = i, ++i) {
if ((*i)->priority() != priority)
break;
}
// if last posted handler with the same priority is same id then do not post it
if ((*p)->priority() == priority && (*p)->id() == id)
// boost::heap ordered iterator is a forward iterator
// if an existing handler with the id exists within the same priority then do not post
for (; i != end && (*i)->priority() == priority; ++i) {
if ((*i)->id() == id)
return;
}
}
Expand Down
20 changes: 12 additions & 8 deletions libraries/custom_appbase/tests/custom_appbase_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,19 @@ BOOST_AUTO_TEST_CASE( exec_with_handler_id ) {
BOOST_REQUIRE_EQUAL( app->executor().read_write_queue_empty(), true);

// does not post if one already exists at the same priority
BOOST_TEST( rslts.size() == 8u );

BOOST_TEST(!rslts.contains(1)); // not added to execute
BOOST_TEST(!rslts.contains(3)); // not added to execute
BOOST_TEST(!rslts.contains(5)); // not added to execute
BOOST_TEST(!rslts.contains(7)); // not added to execute
BOOST_TEST(rslts.contains(9));
BOOST_TEST( rslts.size() == 6u );

BOOST_TEST(!rslts.contains(1));
BOOST_TEST(rslts.contains(2));
BOOST_TEST(!rslts.contains(3));
BOOST_TEST(rslts.contains(4));
BOOST_TEST(!rslts.contains(5));
BOOST_TEST(rslts.contains(6));
BOOST_TEST(!rslts.contains(7));
BOOST_TEST(rslts.contains(8));
BOOST_TEST(!rslts.contains(9));
BOOST_TEST(rslts.contains(10));
BOOST_TEST(rslts.contains(11));
BOOST_TEST(!rslts.contains(11));
}

// verify functions only from read_only queue are processed during read window on the main thread
Expand Down

0 comments on commit fd21a45

Please sign in to comment.