Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 7022acb

Browse files
author
Andronik Ordian
committed
resolve slots renaming fallout
1 parent 43187c4 commit 7022acb

File tree

7 files changed

+39
-37
lines changed

7 files changed

+39
-37
lines changed

node/core/approval-voting/src/aux_schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl CandidateEntry {
220220
pub(crate) struct BlockEntry {
221221
pub block_hash: Hash,
222222
pub session: SessionIndex,
223-
pub slot: SlotNumber,
223+
pub slot: Slot,
224224
pub relay_vrf_story: RelayVRFStory,
225225
// The candidates included as-of this block and the index of the core they are
226226
// leaving. Sorted ascending by core index.

node/core/approval-voting/src/aux_schema/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn make_block_entry(
6161
BlockEntry {
6262
block_hash,
6363
session: 1,
64-
slot: 1,
64+
slot: Slot::from(1),
6565
relay_vrf_story: RelayVRFStory([0u8; 32]),
6666
approved_bitfield: make_bitvec(candidates.len()),
6767
candidates,

node/core/approval-voting/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use polkadot_node_primitives::approval::{
4444
};
4545
use parity_scale_codec::Encode;
4646
use sc_keystore::LocalKeystore;
47-
use sp_consensus_slots::SlotNumber;
47+
use sp_consensus_slots::Slot;
4848
use sc_client_api::backend::AuxStore;
4949
use sp_runtime::traits::AppVerify;
5050
use sp_application_crypto::Pair;
@@ -71,7 +71,7 @@ mod time;
7171
mod tests;
7272

7373
const APPROVAL_SESSIONS: SessionIndex = 6;
74-
const LOG_TARGET: &str = "approval-voting";
74+
const LOG_TARGET: &str = "approval_voting";
7575

7676
/// The approval voting subsystem.
7777
pub struct ApprovalVotingSubsystem<T> {
@@ -663,7 +663,7 @@ struct ImportedBlockInfo {
663663
assignments: HashMap<CoreIndex, OurAssignment>,
664664
n_validators: usize,
665665
relay_vrf_story: RelayVRFStory,
666-
slot: SlotNumber,
666+
slot: Slot,
667667
}
668668

669669
// Computes information about the imported block. Returns `None` if the info couldn't be extracted -
@@ -755,7 +755,7 @@ async fn imported_block_info(
755755

756756
match unsafe_vrf {
757757
Some(unsafe_vrf) => {
758-
let slot = unsafe_vrf.slot_number();
758+
let slot = unsafe_vrf.slot();
759759

760760
match unsafe_vrf.compute_randomness(
761761
&babe_epoch.authorities,
@@ -887,7 +887,7 @@ async fn handle_new_head(
887887
number: block_header.number,
888888
parent_hash: block_header.parent_hash,
889889
candidates: included_candidates.iter().map(|(hash, _, _, _)| *hash).collect(),
890-
slot_number: slot,
890+
slot,
891891
});
892892

893893
let (block_tick, no_show_duration) = {
@@ -897,7 +897,7 @@ async fn handle_new_head(
897897
let block_tick = slot_number_to_tick(state.slot_duration_millis, slot);
898898
let no_show_duration = slot_number_to_tick(
899899
state.slot_duration_millis,
900-
session_info.no_show_slots as _,
900+
Slot::from(u64::from(session_info.no_show_slots)),
901901
);
902902

903903
(block_tick, no_show_duration)
@@ -934,7 +934,7 @@ fn check_and_import_assignment(
934934
assignment: IndirectAssignmentCert,
935935
candidate_index: CandidateIndex,
936936
) -> SubsystemResult<AssignmentCheckResult> {
937-
const TOO_FAR_IN_FUTURE: SlotNumber = 5;
937+
const SLOT_TOO_FAR_IN_FUTURE: u64 = 5;
938938

939939
let tick_now = state.clock.tick_now();
940940

@@ -1004,7 +1004,7 @@ fn check_and_import_assignment(
10041004
Ok(tranche) => {
10051005
let tranche_now_of_prev_slot = state.clock.tranche_now(
10061006
state.slot_duration_millis,
1007-
block_entry.slot.saturating_sub(TOO_FAR_IN_FUTURE),
1007+
block_entry.slot.saturating_sub(SLOT_TOO_FAR_IN_FUTURE),
10081008
);
10091009

10101010
if tranche >= tranche_now_of_prev_slot {
@@ -1029,7 +1029,7 @@ fn check_and_import_assignment(
10291029
let block_tick = slot_number_to_tick(state.slot_duration_millis, block_entry.slot);
10301030
let no_show_duration = slot_number_to_tick(
10311031
state.slot_duration_millis,
1032-
session_info.no_show_slots as _,
1032+
Slot::from(u64::from(session_info.no_show_slots)),
10331033
);
10341034

10351035
(block_tick, no_show_duration)
@@ -1211,7 +1211,7 @@ fn check_full_approvals(
12111211
&candidate_entry.approvals,
12121212
tranche_now,
12131213
slot_number_to_tick(state.slot_duration_millis, block_entry.slot),
1214-
slot_number_to_tick(state.slot_duration_millis, session_info.no_show_slots as _),
1214+
slot_number_to_tick(state.slot_duration_millis, Slot::from(u64::from(session_info.no_show_slots))),
12151215
session_info.needed_approvals as _
12161216
);
12171217

@@ -1467,7 +1467,7 @@ async fn process_wakeup(
14671467
let block_tick = slot_number_to_tick(state.slot_duration_millis, block_entry.slot);
14681468
let no_show_duration = slot_number_to_tick(
14691469
state.slot_duration_millis,
1470-
session_info.no_show_slots as _,
1470+
Slot::from(u64::from(session_info.no_show_slots)),
14711471
);
14721472

14731473
let should_broadcast = {

node/core/approval-voting/src/tests.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,20 @@ impl AuxStore for TestStore {
130130

131131
fn blank_state() -> (State<TestStore>, mpsc::Receiver<BackgroundRequest>) {
132132
let (tx, rx) = mpsc::channel(1024);
133-
State {
134-
earliest_session: None,
135-
session_info: Vec::new(),
136-
keystore: LocalKeystore::in_memory(),
137-
wakeups: Wakeups::default(),
138-
slot_duration_millis: SLOT_DURATION_MILLIS,
139-
db: Arc::new(TestStore::default()),
140-
background_tx: tx,
141-
clock: Box::new(MockClock::default()),
142-
assignment_criteria: unimplemented!(),
143-
}
133+
(
134+
State {
135+
earliest_session: None,
136+
session_info: Vec::new(),
137+
keystore: LocalKeystore::in_memory(),
138+
wakeups: Wakeups::default(),
139+
slot_duration_millis: SLOT_DURATION_MILLIS,
140+
db: Arc::new(TestStore::default()),
141+
background_tx: tx,
142+
clock: Box::new(MockClock::default()),
143+
assignment_criteria: unimplemented!(),
144+
},
145+
rx,
146+
)
144147
}
145148

146149
fn single_session_state(index: SessionIndex, info: SessionInfo)
@@ -154,14 +157,14 @@ fn single_session_state(index: SessionIndex, info: SessionInfo)
154157

155158
#[test]
156159
fn rejects_bad_assignment() {
157-
let state = single_session_state(1, unimplemented!());
160+
let (mut state, rx) = single_session_state(1, unimplemented!());
158161
let assignment = unimplemented!();
159162
let candidate_index = unimplemented!();
160163

161164
// TODO [now]: instantiate test store with block data.
162165

163166
check_and_import_assignment(
164-
state,
167+
&mut state,
165168
assignment,
166169
candidate_index,
167170
).unwrap();

node/core/approval-voting/src/time.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! Time utilities for approval voting.
1818
1919
use polkadot_node_primitives::approval::DelayTranche;
20-
use sp_consensus_slots::SlotNumber;
20+
use sp_consensus_slots::Slot;
2121
use futures::prelude::*;
2222
use std::time::{Duration, SystemTime};
2323
use std::pin::Pin;
@@ -39,11 +39,11 @@ pub(crate) trait Clock {
3939

4040
/// Extension methods for clocks.
4141
pub(crate) trait ClockExt {
42-
fn tranche_now(&self, slot_duration_millis: u64, base_slot: SlotNumber) -> DelayTranche;
42+
fn tranche_now(&self, slot_duration_millis: u64, base_slot: Slot) -> DelayTranche;
4343
}
4444

4545
impl<C: Clock + ?Sized> ClockExt for C {
46-
fn tranche_now(&self, slot_duration_millis: u64, base_slot: SlotNumber) -> DelayTranche {
46+
fn tranche_now(&self, slot_duration_millis: u64, base_slot: Slot) -> DelayTranche {
4747
self.tick_now()
4848
.saturating_sub(slot_number_to_tick(slot_duration_millis, base_slot)) as u32
4949
}
@@ -82,7 +82,7 @@ fn tick_to_time(tick: Tick) -> SystemTime {
8282
}
8383

8484
/// assumes `slot_duration_millis` evenly divided by tick duration.
85-
pub(crate) fn slot_number_to_tick(slot_duration_millis: u64, slot: SlotNumber) -> Tick {
85+
pub(crate) fn slot_number_to_tick(slot_duration_millis: u64, slot: Slot) -> Tick {
8686
let ticks_per_slot = slot_duration_millis / TICK_DURATION_MILLIS;
87-
slot * ticks_per_slot
87+
u64::from(slot) * ticks_per_slot
8888
}

node/primitives/src/approval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! Types relevant for approval.
1818
1919
pub use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof, Randomness};
20-
pub use sp_consensus_babe::SlotNumber;
20+
pub use sp_consensus_babe::Slot;
2121

2222
use polkadot_primitives::v1::{
2323
CandidateHash, Hash, ValidatorIndex, ValidatorSignature, CoreIndex,
@@ -147,13 +147,13 @@ pub enum ApprovalError {
147147
/// An unsafe VRF output. Provide BABE Epoch info to create a `RelayVRFStory`.
148148
pub struct UnsafeVRFOutput {
149149
vrf_output: VRFOutput,
150-
slot: SlotNumber,
150+
slot: Slot,
151151
authority_index: u32,
152152
}
153153

154154
impl UnsafeVRFOutput {
155-
/// Get the slot number.
156-
pub fn slot_number(&self) -> SlotNumber {
155+
/// Get the slot.
156+
pub fn slot(&self) -> Slot {
157157
self.slot
158158
}
159159

@@ -194,7 +194,7 @@ pub fn babe_unsafe_vrf_info(header: &Header) -> Option<UnsafeVRFOutput> {
194194

195195
for digest in &header.digest.logs {
196196
if let Some(pre) = digest.as_babe_pre_digest() {
197-
let slot = pre.slot_number();
197+
let slot = pre.slot();
198198
let authority_index = pre.authority_index();
199199

200200
// exhaustive match to defend against upstream variant changes.

node/subsystem/src/messages.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use polkadot_node_network_protocol::{
3030
use polkadot_node_primitives::{
3131
CollationGenerationConfig, SignedFullStatement, ValidationResult,
3232
approval::{BlockApprovalMeta, IndirectAssignmentCert, IndirectSignedApprovalVote},
33-
CollationGenerationConfig, MisbehaviorReport, SignedFullStatement, ValidationResult,
3433
BabeEpoch,
3534
};
3635
use polkadot_primitives::v1::{

0 commit comments

Comments
 (0)