diff --git a/substrate/node/src/service.rs b/substrate/node/src/service.rs index 1de4e6ed..7d35507d 100644 --- a/substrate/node/src/service.rs +++ b/substrate/node/src/service.rs @@ -233,6 +233,7 @@ pub async fn new_full(mut config: Configuration) -> Result TendermintAuthority { /// Act as a network authority, proposing and voting on blocks. This should be spawned on a task /// as it will not return until the P2P stack shuts down. + #[allow(clippy::too_many_arguments)] pub async fn authority( mut self, protocol: ProtocolName, keys: Arc, providers: T::CIDP, + spawner: impl SpawnEssentialNamed, env: T::Environment, network: T::Network, registry: Option<&Registry>, @@ -170,7 +172,7 @@ impl TendermintAuthority { let (gossip_tx, mut gossip_rx) = mpsc::unbounded(); // Create the Tendermint machine - let mut handle = { + let TendermintHandle { mut messages, machine } = { // Set this struct as active *self.import.providers.write().await = Some(providers); self.active = Some(ActiveAuthority { @@ -188,8 +190,9 @@ impl TendermintAuthority { .await; // We no longer need self, so let TendermintMachine become its owner - TendermintMachine::new(self, last, proposal) + TendermintMachine::new(self, last, proposal).await }; + spawner.spawn_essential("machine", Some("tendermint"), Box::pin(machine.run())); // Start receiving messages about the Tendermint process for this block let mut recv = gossip.messages_for(TendermintGossip::::topic(new_number)); @@ -222,19 +225,17 @@ impl TendermintAuthority { // Received a message msg = recv.next() => { if let Some(msg) = msg { - handle - .messages - .send(match SignedMessage::decode(&mut msg.message.as_ref()) { - Ok(msg) => msg, - Err(e) => { - // This is guaranteed to be valid thanks to to the gossip validator, assuming - // that pipeline is correct. That's why this doesn't panic - error!(target: "tendermint", "Couldn't decode valid message: {}", e); - continue; - } - }) - .await - .unwrap() + messages.send(match SignedMessage::decode(&mut msg.message.as_ref()) { + Ok(msg) => msg, + Err(e) => { + // This is guaranteed to be valid thanks to to the gossip validator, assuming + // that pipeline is correct. That's why this doesn't panic + error!(target: "tendermint", "Couldn't decode valid message: {}", e); + continue; + } + }) + .await + .unwrap() } else { break; } diff --git a/substrate/tendermint/machine/src/lib.rs b/substrate/tendermint/machine/src/lib.rs index d3fbd74a..8b20536a 100644 --- a/substrate/tendermint/machine/src/lib.rs +++ b/substrate/tendermint/machine/src/lib.rs @@ -285,7 +285,7 @@ impl TendermintMachine { let weights = Arc::new(network.weights()); let validator_id = signer.validator_id().await; // 01-10 - TendermintMachine { + let mut machine = TendermintMachine { network, signer, validators, @@ -317,7 +317,9 @@ impl TendermintMachine { valid: None, timeouts: HashMap::new(), - } + }; + machine.round(Round(0)); + machine }, } }