Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent multiple observer calls for confirmed block #2082

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,33 @@ TEST (confirmation_height, conflict_rollback_cemented)
ASSERT_FALSE (node2.store.block_exists (transaction2, publish1.block->hash ()));
}

TEST (confirmation_height, observers)
{
auto amount (std::numeric_limits<nano::uint128_t>::max ());
nano::system system (24000, 1);
auto node1 (system.nodes[0]);
nano::keypair key1;
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
nano::block_hash latest1 (node1->latest (nano::test_genesis_key.pub));
auto send1 (std::make_shared<nano::send_block> (latest1, key1.pub, amount - node1->config.receive_minimum.number (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (latest1)));

node1->observers.blocks.add ([node1](nano::election_status const & status_a, nano::account const &, nano::amount const &, bool) {
node1->stats.inc (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out);
});

node1->process_active (send1);
node1->block_processor.flush ();
bool confirmed (false);
system.deadline_set (10s);
while (!confirmed)
{
auto transaction = node1->store.tx_begin_read ();
confirmed = node1->ledger.block_confirmed (transaction, send1->hash ());
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (1, node1->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
}

TEST (bootstrap, tcp_listener_timeout_empty)
{
nano::system system (24000, 1);
Expand Down
5 changes: 4 additions & 1 deletion nano/node/confirmation_height_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ void nano::confirmation_height_processor::collect_unconfirmed_receive_and_source
auto block (store.block_get (transaction_a, hash, &sideband));
if (block)
{
active.confirm_block (transaction_a, block, sideband);
if (!pending_confirmations.is_processing_block (hash))
{
active.confirm_block (transaction_a, block, sideband);
}
auto source (block->source ());
if (source.is_zero ())
{
Expand Down