Skip to content

Commit

Permalink
tests + statement_filter check
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer committed Oct 9, 2024
1 parent ca9d59c commit 8f6f9fb
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 4 deletions.
6 changes: 2 additions & 4 deletions core/parachain/validator/impl/parachain_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ namespace kagome::parachain {
"Enumerate peers. (relay_parent={}, candidate_hash={})",
relay_parent,
candidate_hash);
std::optional<network::vstaging::StatementFilter> target;
std::optional<libp2p::peer::PeerId > target;
auto audi = query_audi_->get(peer);
if (!audi) {
SL_TRACE(logger_,
Expand Down Expand Up @@ -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_,
Expand All @@ -2684,7 +2683,6 @@ namespace kagome::parachain {
return;
}

const auto &um = *target;
SL_TRACE(logger_,
"Requesting. (peer={}, relay_parent={}, candidate_hash={})",
peer,
Expand Down
116 changes: 116 additions & 0 deletions test/core/parachain/grid_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})));
}
}

0 comments on commit 8f6f9fb

Please sign in to comment.