Update Substrate to the new TendermintHandle

This commit is contained in:
Luke Parker
2022-11-08 22:51:31 -05:00
parent 1c8192218a
commit f7b1ff9f3b
3 changed files with 23 additions and 19 deletions

View File

@@ -233,6 +233,7 @@ pub async fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceE
tendermint_protocol, tendermint_protocol,
keystore_container.keystore(), keystore_container.keystore(),
Cidp, Cidp,
task_manager.spawn_essential_handle(),
sc_basic_authorship::ProposerFactory::new( sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(), task_manager.spawn_handle(),
client, client,

View File

@@ -12,7 +12,7 @@ use futures::{
channel::mpsc::{self, UnboundedSender}, channel::mpsc::{self, UnboundedSender},
}; };
use sp_core::{Encode, Decode}; use sp_core::{Encode, Decode, traits::SpawnEssentialNamed};
use sp_keystore::CryptoStore; use sp_keystore::CryptoStore;
use sp_runtime::{ use sp_runtime::{
traits::{Header, Block}, traits::{Header, Block},
@@ -33,7 +33,7 @@ use substrate_prometheus_endpoint::Registry;
use tendermint_machine::{ use tendermint_machine::{
ext::{BlockError, BlockNumber, Commit, SignatureScheme, Network}, ext::{BlockError, BlockNumber, Commit, SignatureScheme, Network},
SignedMessage, TendermintMachine, SignedMessage, TendermintMachine, TendermintHandle,
}; };
use crate::{ use crate::{
@@ -140,11 +140,13 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
/// Act as a network authority, proposing and voting on blocks. This should be spawned on a task /// 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. /// as it will not return until the P2P stack shuts down.
#[allow(clippy::too_many_arguments)]
pub async fn authority( pub async fn authority(
mut self, mut self,
protocol: ProtocolName, protocol: ProtocolName,
keys: Arc<dyn CryptoStore>, keys: Arc<dyn CryptoStore>,
providers: T::CIDP, providers: T::CIDP,
spawner: impl SpawnEssentialNamed,
env: T::Environment, env: T::Environment,
network: T::Network, network: T::Network,
registry: Option<&Registry>, registry: Option<&Registry>,
@@ -170,7 +172,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
let (gossip_tx, mut gossip_rx) = mpsc::unbounded(); let (gossip_tx, mut gossip_rx) = mpsc::unbounded();
// Create the Tendermint machine // Create the Tendermint machine
let mut handle = { let TendermintHandle { mut messages, machine } = {
// Set this struct as active // Set this struct as active
*self.import.providers.write().await = Some(providers); *self.import.providers.write().await = Some(providers);
self.active = Some(ActiveAuthority { self.active = Some(ActiveAuthority {
@@ -188,8 +190,9 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
.await; .await;
// We no longer need self, so let TendermintMachine become its owner // 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 // Start receiving messages about the Tendermint process for this block
let mut recv = gossip.messages_for(TendermintGossip::<T>::topic(new_number)); let mut recv = gossip.messages_for(TendermintGossip::<T>::topic(new_number));
@@ -222,19 +225,17 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
// Received a message // Received a message
msg = recv.next() => { msg = recv.next() => {
if let Some(msg) = msg { if let Some(msg) = msg {
handle messages.send(match SignedMessage::decode(&mut msg.message.as_ref()) {
.messages Ok(msg) => msg,
.send(match SignedMessage::decode(&mut msg.message.as_ref()) { Err(e) => {
Ok(msg) => msg, // This is guaranteed to be valid thanks to to the gossip validator, assuming
Err(e) => { // that pipeline is correct. That's why this doesn't panic
// This is guaranteed to be valid thanks to to the gossip validator, assuming error!(target: "tendermint", "Couldn't decode valid message: {}", e);
// that pipeline is correct. That's why this doesn't panic continue;
error!(target: "tendermint", "Couldn't decode valid message: {}", e); }
continue; })
} .await
}) .unwrap()
.await
.unwrap()
} else { } else {
break; break;
} }

View File

@@ -285,7 +285,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
let weights = Arc::new(network.weights()); let weights = Arc::new(network.weights());
let validator_id = signer.validator_id().await; let validator_id = signer.validator_id().await;
// 01-10 // 01-10
TendermintMachine { let mut machine = TendermintMachine {
network, network,
signer, signer,
validators, validators,
@@ -317,7 +317,9 @@ impl<N: Network + 'static> TendermintMachine<N> {
valid: None, valid: None,
timeouts: HashMap::new(), timeouts: HashMap::new(),
} };
machine.round(Round(0));
machine
}, },
} }
} }