From 8f6f9fbd8e4fa46f1240f8ff2af1ee4796bbc853 Mon Sep 17 00:00:00 2001 From: iceseer Date: Wed, 9 Oct 2024 20:16:44 +0300 Subject: [PATCH] tests + statement_filter check Signed-off-by: iceseer --- .../validator/impl/parachain_processor.cpp | 6 +- test/core/parachain/grid_tracker.cpp | 116 ++++++++++++++++++ 2 files changed, 118 insertions(+), 4 deletions(-) diff --git a/core/parachain/validator/impl/parachain_processor.cpp b/core/parachain/validator/impl/parachain_processor.cpp index e23b1b6124..31ab6ce3af 100644 --- a/core/parachain/validator/impl/parachain_processor.cpp +++ b/core/parachain/validator/impl/parachain_processor.cpp @@ -2614,7 +2614,7 @@ namespace kagome::parachain { "Enumerate peers. (relay_parent={}, candidate_hash={})", relay_parent, candidate_hash); - std::optional target; + std::optional target; auto audi = query_audi_->get(peer); if (!audi) { SL_TRACE(logger_, @@ -2665,8 +2665,7 @@ namespace kagome::parachain { if (!backing_threshold || (filter->has_seconded() && filter->backing_validators() >= *backing_threshold)) { - network::vstaging::StatementFilter f(group->size()); - target.emplace(std::move(f)); + target.emplace(peer); } else { SL_TRACE( logger_, @@ -2684,7 +2683,6 @@ namespace kagome::parachain { return; } - const auto &um = *target; SL_TRACE(logger_, "Requesting. (peer={}, relay_parent={}, candidate_hash={})", peer, diff --git a/test/core/parachain/grid_tracker.cpp b/test/core/parachain/grid_tracker.cpp index 91135d94f2..bc08b633e9 100644 --- a/test/core/parachain/grid_tracker.cpp +++ b/test/core/parachain/grid_tracker.cpp @@ -391,3 +391,119 @@ TEST_F(GridTrackerTest, pending_communication_is_cleared) { ASSERT_FALSE( tracker.is_manifest_pending_for(validator_index, candidate_hash)); } + + TEST_F(GridTrackerTest, pending_statements_are_updated_after_manifest_exchange) { + const ValidatorIndex send_to(0); + const ValidatorIndex receive_from(1); + + GridTracker tracker; + SessionTopologyView session_topology = {View{ + .sending = {send_to}, + .receiving = {receive_from}, + }}; + + const auto candidate_hash = fromNumber(42); + const GroupIndex group_index(0); + const size_t group_size(3); + + const StatementFilter local_knowledge(group_size); + const auto groups = dummy_groups(group_size); + + // Confirm the candidate. + const auto receivers = tracker.add_backed_candidate( + session_topology, + candidate_hash, + group_index, + local_knowledge + ); + ASSERT_EQ(receivers.size(), 1); + ASSERT_EQ(receivers[0].first, send_to); + ASSERT_EQ(receivers[0].second, ManifestKind::Full); + + // Learn a statement from a different validator. + tracker.learned_fresh_statement( + groups, + session_topology, + ValidatorIndex(2), + kagome::network::vstaging::SecondedCandidateHash { + .hash = candidate_hash, + } + ); + + // Test receiving followed by sending an ack. + { + // Should start with no pending statements. + ASSERT_FALSE(tracker.pending_statements_for(receive_from, candidate_hash)); + ASSERT_TRUE(tracker.all_pending_statements_for(receive_from).empty()); + const auto ack = tracker.import_manifest( + session_topology, + groups, + candidate_hash, + 3, + ManifestSummary { + .claimed_parent_hash = fromNumber(0), + .claimed_group_index = group_index, + .statement_knowledge = + create_filter({{false, true, false}, {true, false, true}}), + }, + ManifestKind::Full, + receive_from + ); + ASSERT_TRUE(ack.has_value() && ack.value() == true); + + // Send ack now. + tracker.manifest_sent_to( + groups, + receive_from, + candidate_hash, + local_knowledge + ); + + // There should be pending statements now. + ASSERT_EQ( + tracker.pending_statements_for(receive_from, candidate_hash), + create_filter({{false, false, true}, {false, false, false}}) + ); + + const auto res = tracker.all_pending_statements_for(receive_from); + ASSERT_EQ(res.size(), 1); + ASSERT_EQ(res[0], std::make_pair(ValidatorIndex(2), kagome::network::vstaging::CompactStatement(kagome::network::vstaging::SecondedCandidateHash { + .hash = candidate_hash, + }))); + } + + // Test sending followed by receiving an ack. + { + // Should start with no pending statements. + ASSERT_FALSE(tracker.pending_statements_for(send_to, candidate_hash)); + ASSERT_TRUE(tracker.all_pending_statements_for(send_to).empty()); + + tracker.manifest_sent_to(groups, send_to, candidate_hash, local_knowledge); + const auto ack = tracker.import_manifest( + session_topology, + groups, + candidate_hash, + 3, + ManifestSummary { + .claimed_parent_hash = fromNumber(0), + .claimed_group_index = group_index, + .statement_knowledge = + create_filter({{false, true, false}, {false, false, true}}), + }, + ManifestKind::Acknowledgement, + send_to + ); + ASSERT_TRUE(ack.has_value() && ack.value() == false); + + // There should be pending statements now. + ASSERT_EQ( + tracker.pending_statements_for(send_to, candidate_hash), + create_filter({{false, false, true}, {false, false, false}}) + ); + const auto res = tracker.all_pending_statements_for(send_to); + ASSERT_EQ(res.size(), 1); + ASSERT_EQ(res[0], std::make_pair(ValidatorIndex(2), kagome::network::vstaging::CompactStatement(kagome::network::vstaging::SecondedCandidateHash { + .hash = candidate_hash, + }))); + } + }