Relax Slots-based engines from Epochs (#12360)

Remove Epochs reference from slots subsystem
This commit is contained in:
Davide Galassi
2022-09-27 13:16:30 +02:00
committed by GitHub
parent 96c1f8bcf0
commit 499ca74afe
3 changed files with 28 additions and 33 deletions
+17 -18
View File
@@ -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
{