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
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
Do not alter original epoch changes node on epoch skip
  • Loading branch information
davxy committed Oct 24, 2022
commit a26a31e90b43b1b5a442f01634032d78aa1c9ca1
18 changes: 10 additions & 8 deletions client/consensus/sassafras/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,23 @@ where
old_epoch_changes = Some((*epoch_changes).clone());

let mut viable_epoch = epoch_changes
.viable_epoch_mut(&epoch_descriptor, |slot| {
.viable_epoch(&epoch_descriptor, |slot| {
Epoch::genesis(&self.genesis_config, slot)
})
.ok_or_else(|| {
ConsensusError::ClientImport(Error::<Block>::FetchEpoch(parent_hash).into())
})?;
})?
.into_cloned();

if viable_epoch.as_ref().end_slot() <= slot {
// Some epochs must have been skipped as our current slot fits outside the
// current epoch. We will figure out which is the first skipped epoch and we
// will partially re-use its data for this "recovery" epoch.
let epoch_data = viable_epoch.as_mut();
let slot_idx = u64::from(slot) - u64::from(epoch_data.start_slot);
let skipped_epochs = slot_idx / self.genesis_config.epoch_duration;
let skipped_epochs =
(*slot - *epoch_data.start_slot) / epoch_data.config.epoch_duration;
let original_epoch_idx = epoch_data.epoch_index;

// NOTE: notice that we are only updating a local copy of the `Epoch`, this
// makes it so that when we insert the next epoch into `EpochChanges` below
// (after incrementing it), it will use the correct epoch index and start slot.
Expand All @@ -190,13 +193,12 @@ where
// requiring to update `start_slot` to the correct value.
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,
*epoch_data.start_slot + skipped_epochs * epoch_data.config.epoch_duration,
);
log::warn!(
target: "sassafras",
"🌳 Detected {} skipped epochs, starting recovery epoch {}",
skipped_epochs, epoch_data.epoch_index
"🌳 Epoch(s) skipped from {} to {}",
original_epoch_idx, epoch_data.epoch_index
);
}

Expand Down
9 changes: 6 additions & 3 deletions client/consensus/sassafras/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,19 @@ 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)
// First block in E1 (B7) announces E2
// NOTE: config has been "magically" used by E3 without altering epoch node values.
// This will break as soon as our assumptions about how fork-tree works are not met anymore
// (and this is a good thing)
let data = epoch_changes
.epoch(&EpochIdentifier {
position: EpochIdentifierPosition::Regular,
hash: blocks[6],
number: 7,
})
.unwrap();
assert_eq!(data.epoch_index, 3);
assert_eq!(data.start_slot, Slot::from(19));
assert_eq!(data.epoch_index, 2);
assert_eq!(data.start_slot, Slot::from(13));

// First block in E3 (B8) announced E4.
let data = epoch_changes
Expand Down