Skip to content

Commit

Permalink
trace 2
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
trace

Signed-off-by: iceseer <[email protected]>
Revert "[fix] prune"

This reverts commit 3ad4f47.
[fix] prune

Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer committed Dec 7, 2024
1 parent e6c78b6 commit 6863fbe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
39 changes: 37 additions & 2 deletions core/parachain/validator/backing_implicit_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ namespace kagome::parachain {
std::weak_ptr<IProspectiveParachains> prospective_parachains,
std::shared_ptr<runtime::ParachainHost> parachain_host_,
std::shared_ptr<blockchain::BlockTree> block_tree,
std::optional<ParachainId> collating_for_)
std::optional<ParachainId> collating_for_, bool trace_insertions)
: parachain_host(std::move(parachain_host_)),
collating_for{collating_for_},
prospective_parachains_{std::move(prospective_parachains)},
block_tree_{std::move(block_tree)} {
block_tree_{std::move(block_tree)}, trace_insertions_(trace_insertions) {
BOOST_ASSERT(!prospective_parachains_.expired());
BOOST_ASSERT(parachain_host);
BOOST_ASSERT(block_tree_);
Expand Down Expand Up @@ -87,6 +87,9 @@ namespace kagome::parachain {
ancestors.size());

for (const auto &ancestor : ancestors) {
if (trace_insertions_) {
SL_TRACE(logger, "activate_leaf_from_prospective_parachains(ancestors): {}", ancestor.hash);
}
block_info_storage.insert_or_assign(
ancestor.hash,
BlockInfo{
Expand All @@ -98,6 +101,9 @@ namespace kagome::parachain {
ancestor.hash);
}

if (trace_insertions_) {
SL_TRACE(logger, "activate_leaf_from_prospective_parachains: {} {}", leaf.hash, retain_minimum);
}
block_info_storage.insert_or_assign(
leaf.hash,
BlockInfo{
Expand All @@ -123,6 +129,9 @@ namespace kagome::parachain {

std::vector<Hash> ImplicitView::deactivate_leaf(const Hash &leaf_hash) {
std::vector<Hash> removed;
if (trace_insertions_) {
SL_TRACE(logger, "deactivate_leaf(leaves): {}", leaf_hash);
}
if (leaves.erase(leaf_hash) == 0ull) {
return removed;
}
Expand All @@ -133,14 +142,28 @@ namespace kagome::parachain {
minimum ? std::min(*minimum, l.retain_minimum) : l.retain_minimum;
}

if (trace_insertions_) {
if (minimum) {
SL_TRACE(logger, "deactivate_leaf(--): {}", *minimum);
} else {
SL_TRACE(logger, "deactivate_leaf(--): no");
}
}

for (auto it = block_info_storage.begin();
it != block_info_storage.end();) {
const auto &[hash, i] = *it;
const bool keep = minimum && i.block_number >= *minimum;
if (keep) {
if (trace_insertions_) {
SL_TRACE(logger, "deactivate_leaf(-): {}", i.block_number);
}
++it;
} else {
removed.emplace_back(hash);
if (trace_insertions_) {
SL_TRACE(logger, "deactivate_leaf: {}", hash);
}
it = block_info_storage.erase(it);
}
}
Expand All @@ -157,6 +180,9 @@ namespace kagome::parachain {
fetched.minimum_ancestor_number,
math::sat_sub_unsigned(fetched.leaf_number, MINIMUM_RETAIN_LENGTH));

if (trace_insertions_) {
SL_TRACE(logger, "activate_leaf(-): {} {}", fetched.minimum_ancestor_number, math::sat_sub_unsigned(fetched.leaf_number, MINIMUM_RETAIN_LENGTH));
}
leaves.insert_or_assign(
leaf_hash, ActiveLeafPruningInfo{.retain_minimum = retain_minimum});
return outcome::success();
Expand Down Expand Up @@ -232,6 +258,9 @@ namespace kagome::parachain {
min_min = std::min(x, min_min);
}
}
if (trace_insertions_) {
SL_TRACE(logger, "fetch_fresh_leaf_and_insert_ancestry(-): {} {}", min_min, leaf_header.number);
}

const size_t expected_ancestry_len =
math::sat_sub_unsigned(leaf_header.number, min_min) + 1ull;
Expand All @@ -250,6 +279,9 @@ namespace kagome::parachain {
parent_hash = it->second.parent_hash;
} else {
OUTCOME_TRY(header, block_tree->getBlockHeader(next_ancestor_hash));
if (trace_insertions_) {
SL_TRACE(logger, "activate_leaf(next_ancestor_number): {}", next_ancestor_hash);
}
block_info_storage.emplace(
next_ancestor_hash,
BlockInfo{
Expand All @@ -272,6 +304,9 @@ namespace kagome::parachain {
ancestry.emplace_back(leaf_hash);
}

if (trace_insertions_) {
SL_TRACE(logger, "activate_leaf: {}", leaf_hash);
}
block_info_storage.emplace(
leaf_hash,
BlockInfo{
Expand Down
3 changes: 2 additions & 1 deletion core/parachain/validator/backing_implicit_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace kagome::parachain {
ImplicitView(std::weak_ptr<IProspectiveParachains> prospective_parachains,
std::shared_ptr<runtime::ParachainHost> parachain_host_,
std::shared_ptr<blockchain::BlockTree> block_tree,
std::optional<ParachainId> collating_for_);
std::optional<ParachainId> collating_for_, bool trace_insertions = false);

private:
struct ActiveLeafPruningInfo {
Expand Down Expand Up @@ -163,6 +163,7 @@ namespace kagome::parachain {

std::weak_ptr<IProspectiveParachains> prospective_parachains_;
std::shared_ptr<blockchain::BlockTree> block_tree_;
bool trace_insertions_;
log::Logger logger = log::createLogger("BackingImplicitView", "parachain");
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ namespace kagome::parachain {

auto r = view().implicit_view.all_allowed_relay_parents();
std::unordered_set<Hash> remaining{r.begin(), r.end()};
SL_TRACE(logger, "Remains RP in PP: {}", remaining.size());

for (auto it = view().per_relay_parent.begin();
it != view().per_relay_parent.end();) {
Expand All @@ -619,7 +620,7 @@ namespace kagome::parachain {
.per_relay_parent = {},
.active_leaves = {},
.implicit_view = ImplicitView(
weak_from_this(), parachain_host_, block_tree_, std::nullopt),
weak_from_this(), parachain_host_, block_tree_, std::nullopt, true),
});
}
return *view_;
Expand Down

0 comments on commit 6863fbe

Please sign in to comment.