Skip to content

Commit

Permalink
Relax Slots-based engines from Epochs (paritytech#12360)
Browse files Browse the repository at this point in the history
Remove Epochs reference from slots subsystem
  • Loading branch information
davxy authored and ark0f committed Feb 27, 2023
1 parent 84ab960 commit d633948
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
14 changes: 7 additions & 7 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand All @@ -340,23 +340,23 @@ 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())
}

async fn claim_slot(
&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| {
Expand All @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,14 +729,14 @@ 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;
type CreateProposer =
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"
Expand All @@ -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(
Expand All @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 17 additions & 18 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,37 @@ 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;

/// 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>;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
);
Expand All @@ -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() &&
Expand All @@ -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
Expand Down Expand Up @@ -351,7 +350,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
body.clone(),
proposal.storage_changes,
claim,
epoch_data,
aux_data,
)
.await
{
Expand Down

0 comments on commit d633948

Please sign in to comment.