Skip to content

Commit

Permalink
issues fixes
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer committed Nov 12, 2024
1 parent 17986df commit 2afee0f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 90 deletions.
1 change: 1 addition & 0 deletions core/common/ref_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <map>
#include <memory>
#include <optional>
#include "outcome/outcome.hpp"

namespace kagome {

Expand Down
3 changes: 1 addition & 2 deletions core/network/impl/protocols/fetch_attested_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ namespace kagome::network {
base().logger()->info(
"Fetching attested candidate request.(candidate={})",
request.candidate_hash);
statement_distribution_->OnFetchAttestedCandidateRequest(
std::move(request), stream);
statement_distribution_->OnFetchAttestedCandidateRequest(request, stream);
return std::nullopt;
}

Expand Down
15 changes: 14 additions & 1 deletion core/parachain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,20 @@ namespace kagome::network {
return hash_.value();
}

SCALE_TIE_ONLY(descriptor, commitments_hash);
inline bool operator==(const CandidateReceipt &other) const {
return descriptor == other.descriptor
and commitments_hash == other.commitments_hash;
}

friend inline scale::ScaleDecoderStream &operator>>(
scale::ScaleDecoderStream &s, CandidateReceipt &cr) {
return s >> cr.descriptor >> cr.commitments_hash;
}

friend inline scale::ScaleEncoderStream &operator<<(
scale::ScaleEncoderStream &s, const CandidateReceipt &cr) {
return s << cr.descriptor << cr.commitments_hash;
}

private:
mutable std::optional<parachain::Hash> hash_{};
Expand Down
55 changes: 30 additions & 25 deletions core/parachain/validator/impl/candidates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <libp2p/peer/peer_info.hpp>
#include "parachain/validator/collations.hpp"
#include "primitives/common.hpp"
#include "utils/map.hpp"
#include "utils/retain_if.hpp"

namespace kagome::parachain {
Expand Down Expand Up @@ -516,32 +517,36 @@ namespace kagome::parachain {
}
};

retain_if(candidates, [&](auto &pair) {
auto &[c_hash, state] = pair;
return visit_in_place(
state,
[&](ConfirmedCandidate &c) {
if (!std::forward<F>(relay_parent_live)(c.relay_parent())) {
remove_parent_claims(
c_hash, c.parent_head_data_hash(), c.para_id());
return false;
}
retain_if(
candidates,
[&remove_parent_claims,
&leaves,
relay_parent_live(std::forward<F>(relay_parent_live))](auto &pair) {
auto &[c_hash, state] = pair;
return visit_in_place(
state,
[&](ConfirmedCandidate &c) {
if (!relay_parent_live(c.relay_parent())) {
remove_parent_claims(
c_hash, c.parent_head_data_hash(), c.para_id());
return false;
}

for (const auto &leaf_hash : leaves) {
c.importable_under.erase(leaf_hash);
}
return true;
},
[&](UnconfirmedCandidate &c) {
c.on_deactivate_leaves(
leaves,
[&](const auto &parent_hash, const auto &id) {
return remove_parent_claims(c_hash, parent_hash, id);
},
std::forward<F>(relay_parent_live));
return c.has_claims();
});
});
for (const auto &leaf_hash : leaves) {
c.importable_under.erase(leaf_hash);
}
return true;
},
[&](UnconfirmedCandidate &c) {
c.on_deactivate_leaves(
leaves,
[&](const auto &parent_hash, const auto &id) {
return remove_parent_claims(c_hash, parent_hash, id);
},
relay_parent_live);
return c.has_claims();
});
});

SL_TRACE(
logger, "Candidates remaining after cleanup: {}", candidates.size());
Expand Down
69 changes: 7 additions & 62 deletions core/parachain/validator/impl/parachain_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ namespace kagome::parachain {
event.view.finalized_number_,
event.view.heads_.size());
broadcastView(event.view);
// broadcastViewToGroup(relay_parent, event.view);

handle_active_leaves_update_for_validator(event, std::move(pruned));
}
Expand Down Expand Up @@ -433,7 +432,6 @@ namespace kagome::parachain {

backing_store_->onDeactivateLeaf(lost.hash);
bitfield_store_->remove(lost.hash);
// av_store_->remove(lost);
}
}

Expand Down Expand Up @@ -496,8 +494,6 @@ namespace kagome::parachain {
network::ViewUpdate{.view = view});
pm_->getStreamEngine()->broadcast(router_->getCollationProtocolVStaging(),
msg);
// pm_->getStreamEngine()->broadcast(router_->getValidationProtocolVStaging(),
// msg);
}

outcome::result<std::optional<ValidatorSigner>>
Expand Down Expand Up @@ -595,9 +591,6 @@ namespace kagome::parachain {
parachain_host_->session_index_for_child(relay_parent));
OUTCOME_TRY(session_info,
parachain_host_->session_info(relay_parent, session_index));
// OUTCOME_TRY(randomness, getBabeRandomness(relay_parent));
// OUTCOME_TRY(disabled_validators_,
// parachain_host_->disabled_validators(relay_parent));
const auto &[validator_groups, group_rotation_info] = groups;

if (!validator) {
Expand Down Expand Up @@ -704,45 +697,6 @@ namespace kagome::parachain {
}
}

// std::optional<StatementStore> statement_store;
// std::optional<LocalValidatorState> local_validator;
// if (mode) {
// //statement_store.emplace(per_session_state->value().groups);
// auto maybe_claim_queue =
// [&]() -> std::optional<runtime::ClaimQueueSnapshot> {
// auto r = fetch_claim_queue(relay_parent);
// if (r.has_value()) {
// return r.value();
// }
// return std::nullopt;
// }();
//
// const auto seconding_limit = mode->max_candidate_depth + 1;
// local_validator = [&]() -> std::optional<LocalValidatorState> {
// if (!global_v_index) {
// return std::nullopt;
// }
// if (validator_index) {
// return find_active_validator_state(*validator_index,
// per_session_state->value().groups,
// cores,
// group_rotation_info,
// maybe_claim_queue,
// seconding_limit,
// mode->max_candidate_depth);
// }
// return LocalValidatorState{};
// }();
// }

// std::unordered_set<ValidatorIndex> disabled_validators{
// disabled_validators_.begin(), disabled_validators_.end()};
// if (!disabled_validators.empty()) {
// SL_TRACE(logger_,
// "Disabled validators detected. (relay parent={})",
// relay_parent);
// }

SL_VERBOSE(logger_,
"Inited new backing task v3.(assigned_para={}, "
"assigned_core={}, our index={}, relay parent={})",
Expand Down Expand Up @@ -771,7 +725,6 @@ namespace kagome::parachain {
.peers_advertised = {},
.fallbacks = {},
.backed_hashes = {},
// .disabled_validators = std::move(disabled_validators),
.inject_core_index = inject_core_index,
.per_session_state = per_session_state,
};
Expand Down Expand Up @@ -914,10 +867,7 @@ namespace kagome::parachain {
const Hash &head_data_hash) {
auto unblocked_collations_it =
our_current_state_.validator_side.blocked_from_seconding.find(
BlockedCollationId{
.para_id = para_id,
.parent_head_data_hash = head_data_hash,
});
BlockedCollationId(para_id, head_data_hash));

if (unblocked_collations_it
!= our_current_state_.validator_side.blocked_from_seconding.end()) {
Expand Down Expand Up @@ -2537,11 +2487,8 @@ namespace kagome::parachain {
*main_pool_handler_, notifyInvalid, parent, candidate_receipt);

our_current_state_.validator_side.blocked_from_seconding.erase(
BlockedCollationId{
.para_id = candidate_receipt.descriptor.para_id,
.parent_head_data_hash =
candidate_receipt.descriptor.para_head_hash,
});
BlockedCollationId(candidate_receipt.descriptor.para_id,
candidate_receipt.descriptor.para_head_hash));

auto fetched_collation =
network::FetchedCollation::from(candidate_receipt, *hasher_);
Expand Down Expand Up @@ -3114,8 +3061,7 @@ namespace kagome::parachain {
} else if (!maybe_pvd && !maybe_parent_head && maybe_parent_head_hash) {
const network::PendingCollationFetch blocked_collation{
.collation_event = std::move(collation_event),
.candidate_receipt =
std::move(pending_collation_fetch.candidate_receipt),
.candidate_receipt = pending_collation_fetch.candidate_receipt,
.pov = std::move(pending_collation_fetch.pov),
.maybe_parent_head_data = std::nullopt,
};
Expand All @@ -3127,10 +3073,9 @@ namespace kagome::parachain {
blocked_collation.candidate_receipt.hash(*hasher_),
blocked_collation.candidate_receipt.descriptor.relay_parent);
our_current_state_.validator_side
.blocked_from_seconding[BlockedCollationId{
.para_id = blocked_collation.candidate_receipt.descriptor.para_id,
.parent_head_data_hash = *maybe_parent_head_hash,
}]
.blocked_from_seconding[BlockedCollationId(
blocked_collation.candidate_receipt.descriptor.para_id,
*maybe_parent_head_hash)]
.emplace_back(blocked_collation);

return outcome::success(false);
Expand Down
6 changes: 6 additions & 0 deletions core/parachain/validator/parachain_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ namespace kagome::parachain {
/// Hash of the parent head data.
Hash parent_head_data_hash;

BlockedCollationId(ParachainId pid, const Hash &h)
: para_id(pid), parent_head_data_hash(h) {}
constexpr auto operator<=>(const BlockedCollationId &) const = default;
};
} // namespace kagome::parachain
Expand Down Expand Up @@ -372,6 +374,9 @@ namespace kagome::parachain {
struct PerSessionState final {
SessionIndex session;
runtime::SessionInfo session_info;

PerSessionState(SessionIndex s, runtime::SessionInfo si)
: session(s), session_info(std::move(si)) {}
};

struct RelayParentState {
Expand Down Expand Up @@ -853,6 +858,7 @@ namespace kagome::parachain {

/// Handle a fetched collation result.
/// polkadot/node/network/collator-protocol/src/validator_side/mod.rs
/// Returns `true` if seconding started.
outcome::result<bool> kick_off_seconding(
network::PendingCollationFetch &&pending_collation_fetch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <libp2p/peer/peer_info.hpp>

#include "network/types/collator_messages_vstaging.hpp"
#include "parachain/validator/backing_implicit_view.hpp"
#include "utils/pool_handler_ready_make.hpp"

namespace kagome::parachain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include <unordered_map>

#include <libp2p/peer/peer_id.hpp>
#include "parachain/backing/grid.hpp"
#include "parachain/groups.hpp"
#include "parachain/types.hpp"
#include "runtime/runtime_api/parachain_host_types.hpp"
#include "utils/safe_object.hpp"

namespace kagome::parachain::statement_distribution {
Expand Down

0 comments on commit 2afee0f

Please sign in to comment.