Remove HeaderBackend requirement from AuthorityDiscovery and NetworkWorker (#13730)

* Remove `HeaderBackend` requirement from `NetworkWorker`

* Remove HeaderBackend from authority-discovery
This commit is contained in:
Sebastian Kunert
2023-03-28 09:10:50 +02:00
committed by GitHub
parent 551367d4cb
commit c41eadc090
8 changed files with 43 additions and 30 deletions
@@ -23,6 +23,7 @@ pub type Result<T> = std::result::Result<T, Error>;
/// Error type for the authority discovery module.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Received dht value found event with records with different keys.")]
ReceivingDhtValueFoundEventWithDifferentKeys,
@@ -71,4 +72,7 @@ pub enum Error {
#[error("Received authority record without a valid signature for the remote peer id.")]
MissingPeerIdSignature,
#[error("Unable to fetch best block.")]
BestBlockFetchingError,
}
@@ -28,6 +28,7 @@
//! See [`Worker`] and [`Service`] for more documentation.
pub use crate::{
error::Error,
service::Service,
worker::{AuthorityDiscovery, NetworkProvider, Role, Worker},
};
@@ -148,7 +149,7 @@ pub fn new_worker_and_service_with_config<Client, Network, Block, DhtEventStream
where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: AuthorityDiscovery<Block> + HeaderBackend<Block> + 'static,
Client: AuthorityDiscovery<Block> + 'static,
DhtEventStream: Stream<Item = DhtEvent> + Unpin,
{
let (to_worker, from_service) = mpsc::channel(0);
@@ -157,12 +157,15 @@ pub trait AuthorityDiscovery<Block: BlockT> {
/// Retrieve authority identifiers of the current and next authority set.
async fn authorities(&self, at: Block::Hash)
-> std::result::Result<Vec<AuthorityId>, ApiError>;
/// Retrieve best block hash
async fn best_hash(&self) -> std::result::Result<Block::Hash, Error>;
}
#[async_trait::async_trait]
impl<Block, T> AuthorityDiscovery<Block> for T
where
T: ProvideRuntimeApi<Block> + Send + Sync,
T: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync,
T::Api: AuthorityDiscoveryApi<Block>,
Block: BlockT,
{
@@ -172,13 +175,17 @@ where
) -> std::result::Result<Vec<AuthorityId>, ApiError> {
self.runtime_api().authorities(at)
}
async fn best_hash(&self) -> std::result::Result<Block::Hash, Error> {
Ok(self.info().best_hash)
}
}
impl<Client, Network, Block, DhtEventStream> Worker<Client, Network, Block, DhtEventStream>
where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: AuthorityDiscovery<Block> + HeaderBackend<Block> + 'static,
Client: AuthorityDiscovery<Block> + 'static,
DhtEventStream: Stream<Item = DhtEvent> + Unpin,
{
/// Construct a [`Worker`].
@@ -376,7 +383,7 @@ where
}
async fn refill_pending_lookups_queue(&mut self) -> Result<()> {
let best_hash = self.client.info().best_hash;
let best_hash = self.client.best_hash().await?;
let local_keys = match &self.role {
Role::PublishAndDiscover(key_store) => key_store
@@ -594,7 +601,7 @@ where
.into_iter()
.collect::<HashSet<_>>();
let best_hash = client.info().best_hash;
let best_hash = client.best_hash().await?;
let authorities = client
.authorities(best_hash)
.await