MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / create_node

Method create_node

fendermint/testing/materializer/src/testnet.rs:288–360  ·  view source on GitHub ↗

Create the configuration of a node. Fails if the genesis hasn't been created yet.

(
        &mut self,
        m: &mut R,
        subnet_name: &SubnetName,
        node_id: &NodeId,
        node: &Node,
        env: &EnvMap,
        peer_count: usize,
    )

Source from the content-addressed store, hash-verified

286 ///
287 /// Fails if the genesis hasn't been created yet.
288 async fn create_node(
289 &mut self,
290 m: &mut R,
291 subnet_name: &SubnetName,
292 node_id: &NodeId,
293 node: &Node,
294 env: &EnvMap,
295 peer_count: usize,
296 ) -> anyhow::Result<()> {
297 let genesis = self.genesis(subnet_name)?;
298 let network = self.network();
299 let node_name = subnet_name.node(node_id);
300
301 let parent_node = match (subnet_name.parent(), &node.parent_node) {
302 (Some(ps), Some(ParentNode::Internal(id))) => {
303 let tc = TargetConfig::<M>::Internal(
304 self.node(&ps.node(id))
305 .with_context(|| format!("invalid parent node in {node_name:?}"))?,
306 );
307 let deployment = self.deployment(&ps)?;
308 Some(ParentConfig {
309 node: tc,
310 deployment,
311 })
312 }
313 (Some(ps), Some(ParentNode::External(url))) if ps.is_root() => {
314 let tc = TargetConfig::External(url.clone());
315 let deployment = self.deployment(&ps)?;
316 Some(ParentConfig {
317 node: tc,
318 deployment,
319 })
320 }
321 (Some(_), Some(ParentNode::External(_))) => {
322 bail!("node {node_name:?} specifies external URL for parent, but it's on a non-root subnet")
323 }
324 (None, Some(_)) => {
325 bail!("node {node_name:?} specifies parent node, but there is no parent subnet")
326 }
327 (Some(_), None) => {
328 bail!("node {node_name:?} is on a subnet, but doesn't specify a parent node")
329 }
330 _ => None,
331 };
332
333 let node_config = NodeConfig {
334 network,
335 genesis,
336 validator: match &node.mode {
337 NodeMode::Full => None,
338 NodeMode::Validator { validator } => {
339 let validator = self
340 .account(validator)
341 .with_context(|| format!("invalid validator in {node_name:?}"))?;
342 Some(validator)
343 }
344 },
345 parent_node,

Callers 1

Calls 11

genesisMethod · 0.80
with_contextMethod · 0.80
deploymentMethod · 0.80
contextMethod · 0.80
networkMethod · 0.45
nodeMethod · 0.45
parentMethod · 0.45
is_rootMethod · 0.45
accountMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected