Starts an in-process consensus node with the given configuration.
(config: InProcessConsensusConfig)
| 96 | impl InProcessConsensus { |
| 97 | /// Starts an in-process consensus node with the given configuration. |
| 98 | pub async fn start(config: InProcessConsensusConfig) -> Result<Self> { |
| 99 | let rollup_config = config.rollup_config; |
| 100 | let l1_chain_config = config.l1_chain_config; |
| 101 | |
| 102 | let rpc_port = config.rpc_port.unwrap_or_else(get_available_port); |
| 103 | let p2p_tcp_port = config.p2p_tcp_port.unwrap_or_else(get_available_port); |
| 104 | let p2p_udp_port = config.p2p_udp_port.unwrap_or_else(get_available_port); |
| 105 | let listen_ip = IpAddr::V4(Ipv4Addr::LOCALHOST); |
| 106 | |
| 107 | // Build keypair from P2P key or generate a random one. |
| 108 | let keypair = if let Some(mut p2p_key) = config.p2p_key { |
| 109 | SecretKeyLoader::parse(&mut p2p_key.0).wrap_err("Failed to parse P2P key")? |
| 110 | } else { |
| 111 | libp2p::identity::Keypair::generate_secp256k1() |
| 112 | }; |
| 113 | |
| 114 | let peer_id = keypair.public().to_peer_id().to_string(); |
| 115 | |
| 116 | // Build the signing key for discv5 from the same P2P key material. |
| 117 | let signing_key = extract_signing_key(&keypair)?; |
| 118 | |
| 119 | let local_node = LocalNode::new(signing_key, listen_ip, p2p_tcp_port, p2p_udp_port); |
| 120 | |
| 121 | let gossip_address: libp2p::Multiaddr = format!("/ip4/{listen_ip}/tcp/{p2p_tcp_port}") |
| 122 | .parse() |
| 123 | .wrap_err("Failed to parse gossip multiaddr")?; |
| 124 | |
| 125 | let mut net_config = NetworkConfig::new( |
| 126 | rollup_config.clone(), |
| 127 | local_node, |
| 128 | gossip_address, |
| 129 | config.unsafe_block_signer, |
| 130 | ); |
| 131 | net_config.scoring = PeerScoreLevel::Off; |
| 132 | net_config.keypair = keypair; |
| 133 | // Use flood_publish since the mesh may not fully form with only two peers. |
| 134 | net_config.gossip_config = base_consensus_gossip::default_config_builder() |
| 135 | .flood_publish(true) |
| 136 | .build() |
| 137 | .expect("valid gossip config"); |
| 138 | |
| 139 | // For sequencer mode, attach a gossip signer. |
| 140 | if config.mode == NodeMode::Sequencer { |
| 141 | let seq_key = config |
| 142 | .sequencer_key |
| 143 | .ok_or_else(|| eyre::eyre!("sequencer_key is required for Sequencer mode"))?; |
| 144 | let signer = PrivateKeySigner::from_bytes(&seq_key) |
| 145 | .wrap_err("Failed to create sequencer signer")?; |
| 146 | net_config.gossip_signer = Some(BlockSigner::Local(signer)); |
| 147 | } |
| 148 | |
| 149 | let l1_config = L1ConfigBuilder { |
| 150 | chain_config: l1_chain_config, |
| 151 | trust_rpc: true, |
| 152 | beacon: config.l1_beacon_url, |
| 153 | rpc_url: config.l1_rpc_url.clone(), |
| 154 | slot_duration_override: config.l1_slot_duration_override, |
| 155 | verifier_l1_confs: config.verifier_l1_confs, |
nothing calls this directly
no test coverage detected