From 10f94f9098e9813174ee32dde2498422614410e6 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Sat, 30 Mar 2024 18:01:22 -0300 Subject: [PATCH] fix: compute epoch directly from Shelley genesis --- src/sync/ledger.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/sync/ledger.rs b/src/sync/ledger.rs index 069ab0ba..479f0437 100644 --- a/src/sync/ledger.rs +++ b/src/sync/ledger.rs @@ -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, @@ -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, @@ -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() @@ -151,8 +161,7 @@ impl gasket::framework::Worker 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)?; }