Skip to content

Commit

Permalink
fix: compute epoch directly from Shelley genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Mar 30, 2024
1 parent 83e03b4 commit 10f94f9
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/sync/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub struct Stage {

current_pparams: Option<(u64, Environment)>,

// HACK: until multi-era genesis
genesis_values: GenesisValues,

phase1_validation_enabled: bool,

pub upstream: UpstreamPort,
Expand All @@ -44,10 +41,6 @@ impl Stage {
) -> Self {
Self {
ledger,
genesis_values: pallas::ledger::traverse::wellknown::GenesisValues::from_magic(
byron.protocol_consts.protocol_magic as u64,
)
.unwrap(),
byron,
shelley,
current_pparams: None,
Expand All @@ -58,7 +51,24 @@ impl Stage {
}
}

fn ensure_pparams(&mut self, epoch: u64) -> Result<(), WorkerError> {
// Temporal workaround while we fix the GenesisValues mess we have in Pallas.
fn compute_epoch(&mut self, block: &MultiEraBlock) -> u64 {
let slot_length = self
.shelley
.slot_length
.expect("shelley genesis didn't provide a slot length");

let epoch_length = self
.shelley
.epoch_length
.expect("shelley genesis didn't provide an epoch lenght");

(block.slot() * slot_length as u64) / epoch_length as u64
}

fn ensure_pparams(&mut self, block: &MultiEraBlock) -> Result<(), WorkerError> {
let epoch = self.compute_epoch(block);

if self
.current_pparams
.as_ref()
Expand Down Expand Up @@ -151,8 +161,7 @@ impl gasket::framework::Worker<Stage> for Worker {

if stage.phase1_validation_enabled {
debug!("performing phase-1 validations");
let (epoch, _) = block.epoch(&stage.genesis_values);
stage.ensure_pparams(epoch)?;
stage.ensure_pparams(&block)?;
stage.execute_phase1_validation(&block)?;
}

Expand Down

0 comments on commit 10f94f9

Please sign in to comment.