Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename all instances of slot number to slot
  • Loading branch information
andresilva committed Jan 28, 2021
commit 57af1a3f6e204e8f8a7105cb8b85cf23748ece7b
12 changes: 6 additions & 6 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ mod tests {
let chain_spec = crate::chain_spec::tests::integration_test_config_with_single_authority();

// For the block factory
let mut slot_num = 1u64;
let mut slot = 1u64;

// For the extrinsics factory
let bob = Arc::new(AccountKeyring::Bob.pair());
Expand Down Expand Up @@ -575,17 +575,17 @@ mod tests {
descendent_query(&*service.client()),
&parent_hash,
parent_number,
slot_num.into(),
slot.into(),
).unwrap().unwrap();

let mut digest = Digest::<H256>::default();

// even though there's only one authority some slots might be empty,
// so we must keep trying the next slots until we can claim one.
let babe_pre_digest = loop {
inherent_data.replace_data(sp_timestamp::INHERENT_IDENTIFIER, &(slot_num * SLOT_DURATION));
inherent_data.replace_data(sp_timestamp::INHERENT_IDENTIFIER, &(slot * SLOT_DURATION));
if let Some(babe_pre_digest) = sc_consensus_babe::test_helpers::claim_slot(
slot_num.into(),
slot.into(),
&parent_header,
&*service.client(),
keystore.clone(),
Expand All @@ -594,7 +594,7 @@ mod tests {
break babe_pre_digest;
}

slot_num += 1;
slot += 1;
};

digest.push(<DigestItem as CompatibleDigestItem>::babe_pre_digest(babe_pre_digest));
Expand Down Expand Up @@ -625,7 +625,7 @@ mod tests {
let item = <DigestItem as CompatibleDigestItem>::babe_seal(
signature,
);
slot_num += 1;
slot += 1;

let mut params = BlockImportParams::new(BlockOrigin::File, new_header);
params.post_digests.push(item);
Expand Down
6 changes: 3 additions & 3 deletions client/consensus/aura/src/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait CompatibleDigestItem<P: Pair>: Sized {
fn as_aura_seal(&self) -> Option<Signature<P>>;

/// Construct a digest item which contains the slot number
fn aura_pre_digest(slot_num: Slot) -> Self;
fn aura_pre_digest(slot: Slot) -> Self;

/// If this item is an AuRa pre-digest, return the slot number
fn as_aura_pre_digest(&self) -> Option<Slot>;
Expand All @@ -58,8 +58,8 @@ impl<P, Hash> CompatibleDigestItem<P> for DigestItem<Hash> where
self.try_to(OpaqueDigestItemId::Seal(&AURA_ENGINE_ID))
}

fn aura_pre_digest(slot_num: Slot) -> Self {
DigestItem::PreRuntime(AURA_ENGINE_ID, slot_num.encode())
fn aura_pre_digest(slot: Slot) -> Self {
DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())
}

fn as_aura_pre_digest(&self) -> Option<Slot> {
Expand Down
46 changes: 23 additions & 23 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ pub fn slot_duration<A, B, C>(client: &C) -> CResult<SlotDuration> where
}

/// Get slot author for given block along with authorities.
fn slot_author<P: Pair>(slot_num: Slot, authorities: &[AuthorityId<P>]) -> Option<&AuthorityId<P>> {
fn slot_author<P: Pair>(slot: Slot, authorities: &[AuthorityId<P>]) -> Option<&AuthorityId<P>> {
if authorities.is_empty() { return None }

let idx = slot_num.0 % (authorities.len() as u64);
let idx = slot.0 % (authorities.len() as u64);
assert!(
idx <= usize::max_value() as u64,
"It is impossible to have a vector with length beyond the address space; qed",
Expand Down Expand Up @@ -237,7 +237,7 @@ where
fn epoch_data(
&self,
header: &B::Header,
_slot_number: Slot,
_slot: Slot,
) -> Result<Self::EpochData, sp_consensus::Error> {
authorities(self.client.as_ref(), &BlockId::Hash(header.hash()))
}
Expand All @@ -249,10 +249,10 @@ where
fn claim_slot(
&self,
_header: &B::Header,
slot_number: Slot,
slot: Slot,
epoch_data: &Self::EpochData,
) -> Option<Self::Claim> {
let expected_author = slot_author::<P>(slot_number, epoch_data);
let expected_author = slot_author::<P>(slot, epoch_data);
expected_author.and_then(|p| {
if SyncCryptoStore::has_keys(
&*self.keystore,
Expand All @@ -267,11 +267,11 @@ where

fn pre_digest_data(
&self,
slot_number: Slot,
slot: Slot,
_claim: &Self::Claim,
) -> Vec<sp_runtime::DigestItem<B::Hash>> {
vec![
<DigestItemFor<B> as CompatibleDigestItem<P>>::aura_pre_digest(slot_number),
<DigestItemFor<B> as CompatibleDigestItem<P>>::aura_pre_digest(slot),
]
}

Expand Down Expand Up @@ -321,14 +321,14 @@ where
self.force_authoring
}

fn should_backoff(&self, slot_number: Slot, chain_head: &B::Header) -> bool {
fn should_backoff(&self, slot: Slot, chain_head: &B::Header) -> bool {
if let Some(ref strategy) = self.backoff_authoring_blocks {
if let Ok(chain_head_slot) = find_pre_digest::<B, P>(chain_head) {
return strategy.should_backoff(
*chain_head.number(),
chain_head_slot,
self.client.info().finalized_number,
slot_number,
slot,
self.logging_target(),
);
}
Expand Down Expand Up @@ -364,7 +364,7 @@ where
debug!(
target: "aura",
"No block for {} slots. Applying linear lenience of {}s",
slot_info.number.saturating_sub(parent_slot.0 + 1),
slot_info.slot.saturating_sub(parent_slot.0 + 1),
slot_lenience.as_secs(),
);

Expand Down Expand Up @@ -400,7 +400,7 @@ enum Error<B: BlockT> {
DataProvider(String),
Runtime(String),
#[display(fmt = "Slot number must increase: parent slot: {}, this slot: {}", _0, _1)]
SlotNumberMustIncrease(Slot, Slot),
SlotMustIncrease(Slot, Slot),
#[display(fmt = "Parent ({}) of {} unavailable. Cannot import", _0, _1)]
ParentUnavailable(B::Hash, B::Hash),
}
Expand Down Expand Up @@ -458,15 +458,15 @@ fn check_header<C, B: BlockT, P: Pair>(
aura_err(Error::HeaderBadSeal(hash))
})?;

let slot_num = find_pre_digest::<B, _>(&header)?;
let slot = find_pre_digest::<B, _>(&header)?;

if slot_num > slot_now {
if slot > slot_now {
header.digest_mut().push(seal);
Ok(CheckedHeader::Deferred(header, slot_num))
Ok(CheckedHeader::Deferred(header, slot))
} else {
// check the signature is valid under the expected authority and
// chain state.
let expected_author = match slot_author::<P>(slot_num, &authorities) {
let expected_author = match slot_author::<P>(slot, &authorities) {
None => return Err(Error::SlotAuthorNotFound),
Some(author) => author,
};
Expand All @@ -477,19 +477,19 @@ fn check_header<C, B: BlockT, P: Pair>(
if let Some(equivocation_proof) = check_equivocation(
client,
slot_now,
slot_num,
slot,
&header,
expected_author,
).map_err(Error::Client)? {
info!(
"Slot author is equivocating at slot {} with headers {:?} and {:?}",
slot_num,
slot,
equivocation_proof.first_header.hash(),
equivocation_proof.second_header.hash(),
);
}

Ok(CheckedHeader::Checked(header, (slot_num, seal)))
Ok(CheckedHeader::Checked(header, (slot, seal)))
} else {
Err(Error::BadSignature(hash))
}
Expand Down Expand Up @@ -613,12 +613,12 @@ impl<B: BlockT, C, P, CAW> Verifier<B> for AuraVerifier<C, P, CAW> where
&authorities[..],
).map_err(|e| e.to_string())?;
match checked_header {
CheckedHeader::Checked(pre_header, (slot_num, seal)) => {
CheckedHeader::Checked(pre_header, (slot, seal)) => {
// if the body is passed through, we need to use the runtime
// to check that the internally-set timestamp in the inherents
// actually matches the slot set in the seal.
if let Some(inner_body) = body.take() {
inherent_data.aura_replace_inherent_data(slot_num);
inherent_data.aura_replace_inherent_data(slot);
let block = B::new(pre_header.clone(), inner_body);

// skip the inherents verification if the runtime API is old.
Expand Down Expand Up @@ -802,7 +802,7 @@ impl<Block: BlockT, C, I, P> BlockImport<Block> for AuraBlockImport<Block, C, I,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
let hash = block.post_hash();
let slot_number = find_pre_digest::<Block, P>(&block.header)
let slot = find_pre_digest::<Block, P>(&block.header)
.expect("valid Aura headers must contain a predigest; \
header has been already verified; qed");

Expand All @@ -818,10 +818,10 @@ impl<Block: BlockT, C, I, P> BlockImport<Block> for AuraBlockImport<Block, C, I,
parent header has already been verified; qed");

// make sure that slot number is strictly increasing
if slot_number <= parent_slot {
if slot <= parent_slot {
return Err(
ConsensusError::ClientImport(aura_err(
Error::<Block>::SlotNumberMustIncrease(parent_slot, slot_number)
Error::<Block>::SlotMustIncrease(parent_slot, slot)
).into())
);
}
Expand Down
18 changes: 9 additions & 9 deletions client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,19 @@ impl<B, C, SC> BabeApi for BabeRpcHandler<B, C, SC>
.collect::<Vec<_>>()
};

for slot_number in epoch_start.0..epoch_end.0 {
for slot in epoch_start.0..epoch_end.0 {
if let Some((claim, key)) =
authorship::claim_slot_using_keys(slot_number.into(), &epoch, &keystore, &keys)
authorship::claim_slot_using_keys(slot.into(), &epoch, &keystore, &keys)
{
match claim {
PreDigest::Primary { .. } => {
claims.entry(key).or_default().primary.push(slot_number);
claims.entry(key).or_default().primary.push(slot);
}
PreDigest::SecondaryPlain { .. } => {
claims.entry(key).or_default().secondary.push(slot_number);
claims.entry(key).or_default().secondary.push(slot);
}
PreDigest::SecondaryVRF { .. } => {
claims.entry(key).or_default().secondary_vrf.push(slot_number.into());
claims.entry(key).or_default().secondary_vrf.push(slot.into());
},
};
}
Expand All @@ -173,7 +173,7 @@ impl<B, C, SC> BabeApi for BabeRpcHandler<B, C, SC>
}
}

/// Holds information about the `slot_number`'s that can be claimed by a given key.
/// Holds information about the `slot`'s that can be claimed by a given key.
#[derive(Default, Debug, Deserialize, Serialize)]
pub struct EpochAuthorship {
/// the array of primary slots that can be claimed
Expand Down Expand Up @@ -203,12 +203,12 @@ impl From<Error> for jsonrpc_core::Error {
}
}

/// fetches the epoch data for a given slot_number.
/// fetches the epoch data for a given slot.
fn epoch_data<B, C, SC>(
epoch_changes: &SharedEpochChanges<B, Epoch>,
client: &Arc<C>,
babe_config: &Config,
slot_number: u64,
slot: u64,
select_chain: &SC,
) -> Result<Epoch, Error>
where
Expand All @@ -221,7 +221,7 @@ fn epoch_data<B, C, SC>(
descendent_query(&**client),
&parent.hash(),
parent.number().clone(),
slot_number.into(),
slot.into(),
|slot| Epoch::genesis(&babe_config, slot),
)
.map_err(|e| Error::Consensus(ConsensusError::ChainLookup(format!("{:?}", e))))?
Expand Down
Loading