Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1adf4c8

Browse files
committed
begin fragment graph API
1 parent 7d0cdca commit 1adf4c8

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

node/core/prospective-parachains/src/fragment_graph.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
//! A graph utility for managing fragments
17+
//! A graph utility for managing unbacked parachain fragments.
1818
//!
1919
//! Each node in the graph represents a candidate. Nodes do not uniquely refer to a parachain
2020
//! block for two reasons.
@@ -32,7 +32,10 @@
3232
//! attribute of a path, not a candidate.
3333
//!
3434
//! We also need to handle cycles, including nodes for candidates which produce a header
35-
//! which is the same as the parent's.
35+
//! which is the same as its parent's.
36+
//!
37+
//! The graph exposes a 'frontier' of nodes which appear to be the best to build upon
38+
//! and is the primary means for higher-level code to select candidates to build upon.
3639
3740
use std::{
3841
collections::{hash_map::Entry as HEntry, HashMap, HashSet},
@@ -54,18 +57,19 @@ use polkadot_primitives::vstaging::{
5457
GroupIndex, GroupRotationInfo, Hash, Header, Id as ParaId, SessionIndex, ValidatorIndex,
5558
};
5659

60+
// TODO [now]: separate graph per relay-parent (constraints)?
61+
// TODO [now]: keep nodes and graphs separate? recompute / prune graphs
62+
// on every new relay parent?
63+
// TODO [now]: API for selecting backed candidates
5764
pub(crate) struct FragmentGraph {
5865
para: ParaId,
59-
// Fragment nodes based on fragment head-data.
60-
nodes: HashMap<Hash, FragmentNode>,
66+
relay_parent: RelayChainBlockInfo,
67+
base_constraints: Constraints,
6168
}
6269

63-
impl FragmentGraph {
64-
fn is_empty(&self) -> bool {
65-
self.nodes.is_empty()
66-
}
67-
68-
// TODO [now]: pruning
70+
struct CandidateGraph {
71+
// TODO [now]: semi-ordered pile of candidates.
72+
// we'll need to support some kinds of traversal and insertions
6973
}
7074

7175
enum FragmentState {
@@ -76,24 +80,21 @@ enum FragmentState {
7680
}
7781

7882
struct FragmentNode {
79-
// Head-data of the parent node.
80-
parent_fragment: CandidateHash,
83+
// The hash of the head-data of the parent node
84+
parent: Hash,
8185
// Candidate hashes of children.
8286
children: Vec<CandidateHash>,
8387
fragment: Fragment,
8488
erasure_root: Hash,
8589
state: FragmentState,
86-
depth: usize,
8790
}
8891

8992
impl FragmentNode {
9093
fn relay_parent(&self) -> Hash {
9194
self.fragment.relay_parent().hash
9295
}
9396

94-
fn depth(&self) -> usize {
95-
self.depth
96-
}
97+
9798

9899
/// Produce a candidate receipt from this fragment node.
99100
fn produce_candidate_receipt(&self, para_id: ParaId) -> CommittedCandidateReceipt {

0 commit comments

Comments
 (0)