Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ header_states CLASS::get_validated_fork(size_t& fork_point,
code ec{};

// Disable filter constraint if filtering is disabled.
////const auto filter = filter_enabled();
const auto filter = filter_enabled();

///////////////////////////////////////////////////////////////////////////
std::shared_lock interlock{ candidate_reorganization_mutex_ };
Expand All @@ -134,9 +134,10 @@ header_states CLASS::get_validated_fork(size_t& fork_point,
auto height = add1(fork_point);
auto link = to_candidate(height);

// Filter body always written before validated, so the check is redundant.
while (is_block_validated(ec, link, height, top_checkpoint)
/*&& (!filter || is_filtered_body(link))*/)
// Checkpoint and milestone bypass considers association sufficient, but
// filter bodies are generated asynchronously and must precede confirmation.
while (is_block_validated(ec, link, height, top_checkpoint) &&
(!filter || ec != error::bypassed || is_filtered_body(link)))
Comment thread
evoskuil marked this conversation as resolved.
{
out.emplace_back(link, ec);
link = to_candidate(++height);
Expand Down
90 changes: 90 additions & 0 deletions test/query/consensus/consensus_forks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,94 @@

BOOST_FIXTURE_TEST_SUITE(query_consensus_tests, test::directory_setup_fixture)

BOOST_AUTO_TEST_CASE(query_consensus__get_validated_fork__bypassed_filters_pending__stops_at_first_missing)
{
settings settings{};
settings.path = TEST_DIRECTORY;
test::chunk_store store{ settings };
test::query_accessor query{ store };
BOOST_REQUIRE(!store.create(test::events_handler));
BOOST_REQUIRE(query.initialize(test::genesis));
BOOST_REQUIRE(query.filter_enabled());
BOOST_REQUIRE(query.set(test::block1,
database::context{ 0, 1, 0 }, false, false));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

style, don't wrap parameters in text cases (more below)

BOOST_REQUIRE(query.set(test::block2,
database::context{ 0, 2, 0 }, false, false));

const auto link1 = query.to_header(test::block1_hash);
const auto link2 = query.to_header(test::block2_hash);
BOOST_REQUIRE(query.push_candidate(link1));
BOOST_REQUIRE(query.push_candidate(link2));

size_t fork_point{};
auto fork = query.get_validated_fork(fork_point, 2);
BOOST_REQUIRE_EQUAL(fork_point, 0u);
BOOST_REQUIRE(fork.empty());

BOOST_REQUIRE(query.set_filter_body(link1, test::block1));
fork = query.get_validated_fork(fork_point, 2);
BOOST_REQUIRE_EQUAL(fork.size(), 1u);
BOOST_REQUIRE(fork.front().link == link1);
BOOST_REQUIRE(fork.front().ec == error::bypassed);

BOOST_REQUIRE(query.set_filter_body(link2, test::block2));
fork = query.get_validated_fork(fork_point, 2);
BOOST_REQUIRE_EQUAL(fork.size(), 2u);
BOOST_REQUIRE(fork.front().link == link1);
BOOST_REQUIRE(fork.back().link == link2);
BOOST_REQUIRE(fork.front().ec == error::bypassed);
BOOST_REQUIRE(fork.back().ec == error::bypassed);
}

BOOST_AUTO_TEST_CASE(query_consensus__get_validated_fork__filters_disabled__bypass_unchanged)
{
settings settings{};
settings.path = TEST_DIRECTORY;
settings.filter_tx.buckets = 0;
test::chunk_store store{ settings };
test::query_accessor query{ store };
BOOST_REQUIRE(!store.create(test::events_handler));
BOOST_REQUIRE(query.initialize(test::genesis));
BOOST_REQUIRE(!query.filter_enabled());
BOOST_REQUIRE(query.set(test::block1,
database::context{ 0, 1, 0 }, false, false));
BOOST_REQUIRE(query.set(test::block2,
database::context{ 0, 2, 0 }, false, false));

const auto link1 = query.to_header(test::block1_hash);
const auto link2 = query.to_header(test::block2_hash);
BOOST_REQUIRE(query.push_candidate(link1));
BOOST_REQUIRE(query.push_candidate(link2));

size_t fork_point{};
const auto fork = query.get_validated_fork(fork_point, 2);
BOOST_REQUIRE_EQUAL(fork_point, 0u);
BOOST_REQUIRE_EQUAL(fork.size(), 2u);
BOOST_REQUIRE(fork.front().link == link1);
BOOST_REQUIRE(fork.back().link == link2);
BOOST_REQUIRE(fork.front().ec == error::bypassed);
BOOST_REQUIRE(fork.back().ec == error::bypassed);
}

BOOST_AUTO_TEST_CASE(query_consensus__get_validated_fork__milestone_filter_pending__empty)
{
settings settings{};
settings.path = TEST_DIRECTORY;
test::chunk_store store{ settings };
test::query_accessor query{ store };
BOOST_REQUIRE(!store.create(test::events_handler));
BOOST_REQUIRE(query.initialize(test::genesis));
BOOST_REQUIRE(query.filter_enabled());
BOOST_REQUIRE(query.set(test::block1,
database::context{ 0, 1, 0 }, true, false));

const auto link = query.to_header(test::block1_hash);
BOOST_REQUIRE(query.push_candidate(link));

size_t fork_point{};
const auto fork = query.get_validated_fork(fork_point);
BOOST_REQUIRE_EQUAL(fork_point, 0u);
BOOST_REQUIRE(fork.empty());
}

BOOST_AUTO_TEST_SUITE_END()
Loading