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

Sassafras Prototype 2.2 #12314

Merged
merged 27 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e4364e3
First experiments with Sassafras equivocations report
davxy Sep 12, 2022
b267418
Preparation for sassafras client tests
davxy Sep 20, 2022
1292e86
Cleanup and first working client test with multiple peers
davxy Sep 23, 2022
d0c8bc2
Merge branch 'davxy-sassafras-protocol' into davxy/sassafras-protocol…
davxy Sep 24, 2022
0a20351
Dummy commit
davxy Sep 24, 2022
326ac44
Conflicts resolution
davxy Sep 24, 2022
5b43f28
Test code refactory
davxy Sep 27, 2022
2dd6086
Better submit-tickets extrinsic tag
davxy Sep 27, 2022
829b90b
Refactory of client tests
davxy Oct 6, 2022
a2d66b6
Aux data revert implementation
davxy Oct 6, 2022
ca4b563
Handle skipped epochs on block-import
davxy Oct 7, 2022
e7be289
Skipped epoch test and fix
davxy Oct 11, 2022
7690a5c
Fix to epoch start slot computation
davxy Oct 14, 2022
6c20538
Minor tweaks
davxy Oct 17, 2022
2361064
Trivial comments refactory
davxy Oct 24, 2022
a26a31e
Do not alter original epoch changes node on epoch skip
davxy Oct 24, 2022
f3ebc2b
Insert tickets aux data after block import
davxy Oct 24, 2022
84bfdff
Tests environment refactory
davxy Oct 24, 2022
cfe639e
Use in-memory keystore for tests
davxy Oct 24, 2022
51e81a2
Push lock file
davxy Oct 24, 2022
04e92f6
Use test accounts keyring
davxy Oct 24, 2022
193134a
Test for secondary slots claims
davxy Oct 24, 2022
8bd8aed
Improved tests after epoch changes tree fix
davxy Oct 25, 2022
76c24bd
Tests for blocks verification
davxy Oct 29, 2022
950020b
Next epoch tickets incremental sort
davxy Oct 29, 2022
94e9ee8
Incremental sortition test
davxy Oct 29, 2022
d1a7edd
Set proper tickets tx longevity
davxy Oct 29, 2022
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
Fix to epoch start slot computation
  • Loading branch information
davxy committed Oct 14, 2022
commit 7690a5c5683a75a47725016dc9f2a5045662572d
18 changes: 11 additions & 7 deletions client/consensus/sassafras/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,21 @@ where
ConsensusError::ClientImport(Error::<Block>::FetchEpoch(parent_hash).into())
})?;

// TODO-SASS-P2: test me
if viable_epoch.as_ref().end_slot() <= slot {
// Some epochs were skipped, reuse the configuration of the first skipped epoch.
// The headers in the epoch changes tree is left untouched even if the slots
// are not updated.
// Some epochs were skipped, reuse part of the configuration from the first
// skipped epoch.
let epoch_data = viable_epoch.as_mut();
epoch_data.start_slot = slot;
epoch_data.epoch_index = u64::from(slot) / self.genesis_config.epoch_duration;
let slot_idx = u64::from(slot) - u64::from(epoch_data.start_slot);
let skipped_epochs = slot_idx / self.genesis_config.epoch_duration;
epoch_data.epoch_index += skipped_epochs;
epoch_data.start_slot = Slot::from(
u64::from(epoch_data.start_slot) +
skipped_epochs * self.genesis_config.epoch_duration,
);
log::warn!(
target: "sassafras",
"🌳 Detected skipped epochs, starting recovery epoch"
"🌳 Detected {} skipped epochs, starting recovery epoch {}",
skipped_epochs, epoch_data.epoch_index
);
}

Expand Down
15 changes: 8 additions & 7 deletions client/consensus/sassafras/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,10 @@ fn allows_to_skip_epochs() {
//
// Block# : [ 1 2 3 4 5 6 ][ 7 - - - - - ][ - - - - - - ][ 8 ... ]
// Slot# : [ 1 2 3 4 5 6 ][ 7 8 9 10 11 12 ][ 13 14 15 16 17 18 ][ 19 ... ]
// Epoch# : [ 0 ][ 1 ][ skipped ][ 2 ]
// Epoch# : [ 0 ][ 1 ][ skipped ][ 3 ]
//
// As a recovery strategy, a fallback epoch 2 is created by reusing the configuration
// meant to be used by the "real" epoch 2 but with start slot set to the slot
// of the first block after the skipped epoch.
// As a recovery strategy, a fallback epoch 3 is created by reusing part of the
// configuration created for epoch 2.

let blocks = env.propose_and_import_blocks(BlockId::Number(0), 7);

Expand All @@ -375,8 +374,7 @@ fn allows_to_skip_epochs() {
assert_eq!(*epochs[2].0, block);
assert_eq!(*epochs[2].1, 8);

println!("{:#?}", epochs);

// Fist block in E0 (B1)) announces E0 (this is special)
let data = epoch_changes
.epoch(&EpochIdentifier {
position: EpochIdentifierPosition::Genesis0,
Expand All @@ -387,6 +385,7 @@ fn allows_to_skip_epochs() {
assert_eq!(data.epoch_index, 0);
assert_eq!(data.start_slot, Slot::from(1));

// First block in E0 (B1) also announces E1
let data = epoch_changes
.epoch(&EpochIdentifier {
position: EpochIdentifierPosition::Genesis1,
Expand All @@ -397,6 +396,7 @@ fn allows_to_skip_epochs() {
assert_eq!(data.epoch_index, 1);
assert_eq!(data.start_slot, Slot::from(7));

// First block in E1 (B7) announces E2 (config then stolen by E3)
let data = epoch_changes
.epoch(&EpochIdentifier {
position: EpochIdentifierPosition::Regular,
Expand All @@ -407,11 +407,12 @@ fn allows_to_skip_epochs() {
assert_eq!(data.epoch_index, 3);
assert_eq!(data.start_slot, Slot::from(19));

// First block in E3 (B8) announced E4.
let data = epoch_changes
.epoch(&EpochIdentifier {
position: EpochIdentifierPosition::Regular,
hash: block,
number: 19,
number: 8,
})
.unwrap();
assert_eq!(data.epoch_index, 4);
Expand Down
6 changes: 2 additions & 4 deletions frame/sassafras/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,9 @@ impl<T: Config> Pallet<T> {

let slot_idx = CurrentSlot::<T>::get().saturating_sub(Self::epoch_start(epoch_idx));
if slot_idx >= T::EpochDuration::get() {
// Detected one or more skipped epochs, kill tickets and recompute the `epoch_index`.
// Detected one or more skipped epochs, kill tickets and recompute epoch index.
TicketsMeta::<T>::kill();
// TODO-SASS-P2: adjust epoch index accordingly (TEST ME)
let idx: u64 = slot_idx.into();
epoch_idx += idx / T::EpochDuration::get();
epoch_idx += u64::from(slot_idx) / T::EpochDuration::get();
}
EpochIndex::<T>::put(epoch_idx);

Expand Down