mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 18:51:12 +00:00
Relax Slots-based engines from Epochs (#12360)
Remove Epochs reference from slots subsystem
This commit is contained in:
@@ -257,7 +257,7 @@ pub fn build_aura_worker<P, B, C, PF, I, SO, L, BS, Error>(
|
||||
SyncOracle = SO,
|
||||
JustificationSyncLink = L,
|
||||
Claim = P::Public,
|
||||
EpochData = Vec<AuthorityId<P>>,
|
||||
AuxData = Vec<AuthorityId<P>>,
|
||||
>
|
||||
where
|
||||
B: BlockT,
|
||||
@@ -330,7 +330,7 @@ where
|
||||
Pin<Box<dyn Future<Output = Result<E::Proposer, sp_consensus::Error>> + Send + 'static>>;
|
||||
type Proposer = E::Proposer;
|
||||
type Claim = P::Public;
|
||||
type EpochData = Vec<AuthorityId<P>>;
|
||||
type AuxData = Vec<AuthorityId<P>>;
|
||||
|
||||
fn logging_target(&self) -> &'static str {
|
||||
"aura"
|
||||
@@ -340,15 +340,15 @@ where
|
||||
&mut self.block_import
|
||||
}
|
||||
|
||||
fn epoch_data(
|
||||
fn aux_data(
|
||||
&self,
|
||||
header: &B::Header,
|
||||
_slot: Slot,
|
||||
) -> Result<Self::EpochData, sp_consensus::Error> {
|
||||
) -> Result<Self::AuxData, sp_consensus::Error> {
|
||||
authorities(self.client.as_ref(), &BlockId::Hash(header.hash()))
|
||||
}
|
||||
|
||||
fn authorities_len(&self, epoch_data: &Self::EpochData) -> Option<usize> {
|
||||
fn authorities_len(&self, epoch_data: &Self::AuxData) -> Option<usize> {
|
||||
Some(epoch_data.len())
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ where
|
||||
&self,
|
||||
_header: &B::Header,
|
||||
slot: Slot,
|
||||
epoch_data: &Self::EpochData,
|
||||
epoch_data: &Self::AuxData,
|
||||
) -> Option<Self::Claim> {
|
||||
let expected_author = slot_author::<P>(slot, epoch_data);
|
||||
expected_author.and_then(|p| {
|
||||
@@ -382,7 +382,7 @@ where
|
||||
body: Vec<B::Extrinsic>,
|
||||
storage_changes: StorageChanges<<Self::BlockImport as BlockImport<B>>::Transaction, B>,
|
||||
public: Self::Claim,
|
||||
_epoch: Self::EpochData,
|
||||
_epoch: Self::AuxData,
|
||||
) -> Result<
|
||||
sc_consensus::BlockImportParams<B, <Self::BlockImport as BlockImport<B>>::Transaction>,
|
||||
sp_consensus::Error,
|
||||
|
||||
@@ -729,7 +729,6 @@ where
|
||||
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Sync,
|
||||
Error: std::error::Error + Send + From<ConsensusError> + From<I::Error> + 'static,
|
||||
{
|
||||
type EpochData = ViableEpochDescriptor<B::Hash, NumberFor<B>, Epoch>;
|
||||
type Claim = (PreDigest, AuthorityId);
|
||||
type SyncOracle = SO;
|
||||
type JustificationSyncLink = L;
|
||||
@@ -737,6 +736,7 @@ where
|
||||
Pin<Box<dyn Future<Output = Result<E::Proposer, sp_consensus::Error>> + Send + 'static>>;
|
||||
type Proposer = E::Proposer;
|
||||
type BlockImport = I;
|
||||
type AuxData = ViableEpochDescriptor<B::Hash, NumberFor<B>, Epoch>;
|
||||
|
||||
fn logging_target(&self) -> &'static str {
|
||||
"babe"
|
||||
@@ -746,11 +746,7 @@ where
|
||||
&mut self.block_import
|
||||
}
|
||||
|
||||
fn epoch_data(
|
||||
&self,
|
||||
parent: &B::Header,
|
||||
slot: Slot,
|
||||
) -> Result<Self::EpochData, ConsensusError> {
|
||||
fn aux_data(&self, parent: &B::Header, slot: Slot) -> Result<Self::AuxData, ConsensusError> {
|
||||
self.epoch_changes
|
||||
.shared_data()
|
||||
.epoch_descriptor_for_child_of(
|
||||
@@ -763,7 +759,7 @@ where
|
||||
.ok_or(sp_consensus::Error::InvalidAuthoritiesSet)
|
||||
}
|
||||
|
||||
fn authorities_len(&self, epoch_descriptor: &Self::EpochData) -> Option<usize> {
|
||||
fn authorities_len(&self, epoch_descriptor: &Self::AuxData) -> Option<usize> {
|
||||
self.epoch_changes
|
||||
.shared_data()
|
||||
.viable_epoch(epoch_descriptor, |slot| Epoch::genesis(&self.config, slot))
|
||||
@@ -823,7 +819,7 @@ where
|
||||
body: Vec<B::Extrinsic>,
|
||||
storage_changes: StorageChanges<<Self::BlockImport as BlockImport<B>>::Transaction, B>,
|
||||
(_, public): Self::Claim,
|
||||
epoch_descriptor: Self::EpochData,
|
||||
epoch_descriptor: Self::AuxData,
|
||||
) -> Result<
|
||||
sc_consensus::BlockImportParams<B, <Self::BlockImport as BlockImport<B>>::Transaction>,
|
||||
sp_consensus::Error,
|
||||
|
||||
@@ -101,8 +101,8 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
/// Data associated with a slot claim.
|
||||
type Claim: Send + Sync + 'static;
|
||||
|
||||
/// Epoch data necessary for authoring.
|
||||
type EpochData: Send + Sync + 'static;
|
||||
/// Auxiliary data necessary for authoring.
|
||||
type AuxData: Send + Sync + 'static;
|
||||
|
||||
/// The logging target to use when logging messages.
|
||||
fn logging_target(&self) -> &'static str;
|
||||
@@ -110,29 +110,28 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
/// A handle to a `BlockImport`.
|
||||
fn block_import(&mut self) -> &mut Self::BlockImport;
|
||||
|
||||
/// Returns the epoch data necessary for authoring. For time-dependent epochs,
|
||||
/// use the provided slot number as a canonical source of time.
|
||||
fn epoch_data(
|
||||
/// Returns the auxiliary data necessary for authoring.
|
||||
fn aux_data(
|
||||
&self,
|
||||
header: &B::Header,
|
||||
slot: Slot,
|
||||
) -> Result<Self::EpochData, sp_consensus::Error>;
|
||||
) -> Result<Self::AuxData, sp_consensus::Error>;
|
||||
|
||||
/// Returns the number of authorities given the epoch data.
|
||||
/// Returns the number of authorities.
|
||||
/// None indicate that the authorities information is incomplete.
|
||||
fn authorities_len(&self, epoch_data: &Self::EpochData) -> Option<usize>;
|
||||
fn authorities_len(&self, aux_data: &Self::AuxData) -> Option<usize>;
|
||||
|
||||
/// Tries to claim the given slot, returning an object with claim data if successful.
|
||||
async fn claim_slot(
|
||||
&self,
|
||||
header: &B::Header,
|
||||
slot: Slot,
|
||||
epoch_data: &Self::EpochData,
|
||||
aux_data: &Self::AuxData,
|
||||
) -> Option<Self::Claim>;
|
||||
|
||||
/// Notifies the given slot. Similar to `claim_slot`, but will be called no matter whether we
|
||||
/// need to author blocks or not.
|
||||
fn notify_slot(&self, _header: &B::Header, _slot: Slot, _epoch_data: &Self::EpochData) {}
|
||||
fn notify_slot(&self, _header: &B::Header, _slot: Slot, _aux_data: &Self::AuxData) {}
|
||||
|
||||
/// Return the pre digest data to include in a block authored with the given claim.
|
||||
fn pre_digest_data(&self, slot: Slot, claim: &Self::Claim) -> Vec<sp_runtime::DigestItem>;
|
||||
@@ -145,7 +144,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
body: Vec<B::Extrinsic>,
|
||||
storage_changes: StorageChanges<<Self::BlockImport as BlockImport<B>>::Transaction, B>,
|
||||
public: Self::Claim,
|
||||
epoch: Self::EpochData,
|
||||
epoch: Self::AuxData,
|
||||
) -> Result<
|
||||
sc_consensus::BlockImportParams<B, <Self::BlockImport as BlockImport<B>>::Transaction>,
|
||||
sp_consensus::Error,
|
||||
@@ -268,12 +267,12 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
Delay::new(proposing_remaining_duration)
|
||||
};
|
||||
|
||||
let epoch_data = match self.epoch_data(&slot_info.chain_head, slot) {
|
||||
Ok(epoch_data) => epoch_data,
|
||||
let aux_data = match self.aux_data(&slot_info.chain_head, slot) {
|
||||
Ok(aux_data) => aux_data,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
target: logging_target,
|
||||
"Unable to fetch epoch data at block {:?}: {}",
|
||||
"Unable to fetch auxiliary data for block {:?}: {}",
|
||||
slot_info.chain_head.hash(),
|
||||
err,
|
||||
);
|
||||
@@ -290,9 +289,9 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
},
|
||||
};
|
||||
|
||||
self.notify_slot(&slot_info.chain_head, slot, &epoch_data);
|
||||
self.notify_slot(&slot_info.chain_head, slot, &aux_data);
|
||||
|
||||
let authorities_len = self.authorities_len(&epoch_data);
|
||||
let authorities_len = self.authorities_len(&aux_data);
|
||||
|
||||
if !self.force_authoring() &&
|
||||
self.sync_oracle().is_offline() &&
|
||||
@@ -309,7 +308,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
return None
|
||||
}
|
||||
|
||||
let claim = self.claim_slot(&slot_info.chain_head, slot, &epoch_data).await?;
|
||||
let claim = self.claim_slot(&slot_info.chain_head, slot, &aux_data).await?;
|
||||
|
||||
if self.should_backoff(slot, &slot_info.chain_head) {
|
||||
return None
|
||||
@@ -351,7 +350,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
body.clone(),
|
||||
proposal.storage_changes,
|
||||
claim,
|
||||
epoch_data,
|
||||
aux_data,
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user