Skip to content

Commit

Permalink
Feature/fragment chain (#2207)
Browse files Browse the repository at this point in the history
* candidate storage

Signed-off-by: iceseer <[email protected]>

* candidate storage tests

Signed-off-by: iceseer <[email protected]>

* fragment

Signed-off-by: iceseer <[email protected]>

* constraints

Signed-off-by: iceseer <[email protected]>

* backed chain

Signed-off-by: iceseer <[email protected]>

* scope

Signed-off-by: iceseer <[email protected]>

* fragment node

Signed-off-by: iceseer <[email protected]>

* fragment chain

Signed-off-by: iceseer <[email protected]>

* scope tests

Signed-off-by: iceseer <[email protected]>

* fragment chain test

Signed-off-by: iceseer <[email protected]>

* backing implicit view fixup

Signed-off-by: iceseer <[email protected]>

* prospective parachains

Signed-off-by: iceseer <[email protected]>

* backing implicit view reqork

Signed-off-by: iceseer <[email protected]>

* parachain core

Signed-off-by: iceseer <[email protected]>

* fragment chain errors

Signed-off-by: iceseer <[email protected]>

* remove fragment tree

Signed-off-by: iceseer <[email protected]>

* remove redundant logs

Signed-off-by: iceseer <[email protected]>

---------

Signed-off-by: turuslan <[email protected]>
Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer authored Oct 7, 2024
1 parent 33364be commit 6df4d6e
Show file tree
Hide file tree
Showing 37 changed files with 5,366 additions and 5,590 deletions.
1 change: 1 addition & 0 deletions core/log/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace kagome::log {
- name: parachain
children:
- name: pvf_executor
- name: fragment_chain
- name: dispute
- name: runtime
children:
Expand Down
11 changes: 7 additions & 4 deletions core/network/peer_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "consensus/grandpa/common.hpp"
#include "network/types/collator_messages_vstaging.hpp"
#include "network/types/roles.hpp"
#include "outcome/outcome.hpp"
#include "parachain/validator/backing_implicit_view.hpp"
#include "primitives/common.hpp"
Expand Down Expand Up @@ -70,8 +71,11 @@ namespace kagome::network {
const View &new_view, const parachain::ImplicitView &local_implicit) {
std::unordered_set<common::Hash256> next_implicit;
for (const auto &x : new_view.heads_) {
auto t = local_implicit.knownAllowedRelayParentsUnder(x, std::nullopt);
next_implicit.insert(t.begin(), t.end());
auto t =
local_implicit.known_allowed_relay_parents_under(x, std::nullopt);
if (t) {
next_implicit.insert(t->begin(), t->end());
}
}

std::vector<common::Hash256> fresh_implicit;
Expand Down Expand Up @@ -156,8 +160,7 @@ namespace kagome::network {

template <>
struct std::hash<kagome::network::FetchedCollation> {
size_t operator()(
const kagome::network::FetchedCollation &value) const {
size_t operator()(const kagome::network::FetchedCollation &value) const {
using CollatorId = kagome::parachain::CollatorId;
using CandidateHash = kagome::parachain::CandidateHash;
using RelayHash = kagome::parachain::RelayHash;
Expand Down
4 changes: 3 additions & 1 deletion core/parachain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#

add_subdirectory(validator/prospective_parachains)

add_library(grid_tracker
backing/grid_tracker.cpp
)
Expand Down Expand Up @@ -38,7 +40,6 @@ add_library(validator_parachain
approval/approval.cpp
backing/store_impl.cpp
backing/cluster.cpp
validator/impl/fragment_tree.cpp
validator/backing_implicit_view.cpp
)

Expand All @@ -52,6 +53,7 @@ target_link_libraries(validator_parachain
waitable_timer
kagome_pvf_worker
runtime_common
prospective_parachains
)

add_library(kagome_pvf_worker
Expand Down
24 changes: 15 additions & 9 deletions core/parachain/backing/grid_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
OUTCOME_CPP_DEFINE_CATEGORY(kagome::parachain::grid, GridTracker::Error, e) {
using E = kagome::parachain::grid::GridTracker::Error;
switch (e) {
case E::DISALLOWED:
return "Manifest disallowed";
case E::MALFORMED:
return "Malformed";
case E::DISALLOWED_GROUP_INDEX:
return "Manifest disallowed group index";
case E::DISALLOWED_DIRECTION:
return "Manifest disallowed direction";
case E::MALFORMED_BACKING_THRESHOLD:
return "Malformed backing threshold";
case E::MALFORMED_REMOTE_KNOWLEDGE_LEN:
return "Malformed remote knowledge len";
case E::MALFORMED_HAS_SECONDED:
return "Malformed has seconded";
case E::INSUFFICIENT:
return "Insufficient";
case E::CONFLICTING:
Expand Down Expand Up @@ -115,7 +121,7 @@ namespace kagome::parachain::grid {
ValidatorIndex sender) {
const auto claimed_group_index = manifest.claimed_group_index;
if (claimed_group_index >= session_topology.size()) {
return Error::DISALLOWED;
return Error::DISALLOWED_GROUP_INDEX;
}

const auto &group_topology = session_topology[manifest.claimed_group_index];
Expand All @@ -131,22 +137,22 @@ namespace kagome::parachain::grid {
&& it->second.has_sent_manifest_to(sender);
}
if (!manifest_allowed) {
return Error::DISALLOWED;
return Error::DISALLOWED_DIRECTION;
}

auto group_size_backing_threshold =
groups.get_size_and_backing_threshold(manifest.claimed_group_index);
if (!group_size_backing_threshold) {
return Error::MALFORMED;
return Error::MALFORMED_BACKING_THRESHOLD;
}

const auto [group_size, backing_threshold] = *group_size_backing_threshold;
auto remote_knowledge = manifest.statement_knowledge;
if (!remote_knowledge.has_len(group_size)) {
return Error::MALFORMED;
return Error::MALFORMED_REMOTE_KNOWLEDGE_LEN;
}
if (!remote_knowledge.has_seconded()) {
return Error::MALFORMED;
return Error::MALFORMED_HAS_SECONDED;
}

const auto votes = remote_knowledge.backing_validators();
Expand Down
7 changes: 5 additions & 2 deletions core/parachain/backing/grid_tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ namespace kagome::parachain::grid {
/// relay-parent.
struct GridTracker {
enum class Error {
DISALLOWED = 1,
MALFORMED,
DISALLOWED_GROUP_INDEX = 1,
DISALLOWED_DIRECTION,
MALFORMED_BACKING_THRESHOLD,
MALFORMED_REMOTE_KNOWLEDGE_LEN,
MALFORMED_HAS_SECONDED,
INSUFFICIENT,
CONFLICTING,
SECONDING_OVERFLOW
Expand Down
15 changes: 10 additions & 5 deletions core/parachain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ namespace kagome::network {
struct OutboundHorizontal {
SCALE_TIE(2);

parachain::ParachainId para_id; /// Parachain Id is recepient id
parachain::UpwardMessage
upward_msg; /// upward message for parallel parachain
/// The para that will get this message in its downward message queue.
parachain::ParachainId recipient;

/// The message payload.
common::Buffer data;
};

struct InboundDownwardMessage {
Expand Down Expand Up @@ -324,10 +326,11 @@ namespace kagome::parachain::fragment {
std::optional<std::pair<BlockNumber, ValidationCodeHash>>
future_validation_code;

outcome::result<Constraints> applyModifications(
outcome::result<Constraints> apply_modifications(
const ConstraintModifications &modifications) const;

bool checkModifications(const ConstraintModifications &modifications) const;
outcome::result<void> check_modifications(
const ConstraintModifications &modifications) const;
};

struct BackingState {
Expand Down Expand Up @@ -357,3 +360,5 @@ namespace kagome::parachain::fragment {
};

} // namespace kagome::parachain::fragment

OUTCOME_HPP_DECLARE_ERROR(kagome::parachain::fragment, Constraints::Error);
Loading

0 comments on commit 6df4d6e

Please sign in to comment.