From 56d4a8e91bfc2231ea6455260af393c0af63943a Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Thu, 14 Dec 2023 20:30:18 -0300 Subject: [PATCH] feat: make phase-1 validations optional --- examples/sync-preview/dolos.toml | 1 + src/sync/ledger.rs | 21 ++++++++++++++++----- src/sync/mod.rs | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/sync-preview/dolos.toml b/examples/sync-preview/dolos.toml index c9eb2268..96c31b27 100644 --- a/examples/sync-preview/dolos.toml +++ b/examples/sync-preview/dolos.toml @@ -2,6 +2,7 @@ peer_address = "preview-node.world.dev.cardano.org:30002" network_magic = 2 network_id = 0 +phase1_validation_enabled = false [rolldb] path = "./tmp/rolldb" diff --git a/src/sync/ledger.rs b/src/sync/ledger.rs index 1a7d91cc..069ab0ba 100644 --- a/src/sync/ledger.rs +++ b/src/sync/ledger.rs @@ -5,7 +5,7 @@ use pallas::ledger::traverse::wellknown::GenesisValues; use pallas::ledger::traverse::{Era, MultiEraBlock, MultiEraInput, MultiEraOutput}; use std::borrow::Cow; use std::collections::HashMap; -use tracing::{info, warn}; +use tracing::{debug, info, warn}; use crate::prelude::*; use crate::storage::applydb::ApplyDB; @@ -24,6 +24,8 @@ pub struct Stage { // HACK: until multi-era genesis genesis_values: GenesisValues, + phase1_validation_enabled: bool, + pub upstream: UpstreamPort, #[metric] @@ -34,7 +36,12 @@ pub struct Stage { } impl Stage { - pub fn new(ledger: ApplyDB, byron: byron::GenesisFile, shelley: shelley::GenesisFile) -> Self { + pub fn new( + ledger: ApplyDB, + byron: byron::GenesisFile, + shelley: shelley::GenesisFile, + phase1_validation_enabled: bool, + ) -> Self { Self { ledger, genesis_values: pallas::ledger::traverse::wellknown::GenesisValues::from_magic( @@ -44,6 +51,7 @@ impl Stage { byron, shelley, current_pparams: None, + phase1_validation_enabled, upstream: Default::default(), block_count: Default::default(), wal_count: Default::default(), @@ -140,10 +148,13 @@ impl gasket::framework::Worker for Worker { info!(slot, "applying block"); let block = MultiEraBlock::decode(cbor).or_panic()?; - let (epoch, _) = block.epoch(&stage.genesis_values); - stage.ensure_pparams(epoch)?; - stage.execute_phase1_validation(&block)?; + if stage.phase1_validation_enabled { + debug!("performing phase-1 validations"); + let (epoch, _) = block.epoch(&stage.genesis_values); + stage.ensure_pparams(epoch)?; + stage.execute_phase1_validation(&block)?; + } stage.ledger.apply_block(&block).or_panic()?; } diff --git a/src/sync/mod.rs b/src/sync/mod.rs index efa3478b..8839600f 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -21,6 +21,7 @@ pub struct Config { pub peer_address: String, pub network_magic: u64, pub network_id: u8, + pub phase1_validation_enabled: bool, } fn define_gasket_policy(config: &Option) -> gasket::runtime::Policy { @@ -73,7 +74,7 @@ pub fn pipeline( let mut roll = roll::Stage::new(wal, cursor_chain, cursor_ledger); let mut chain = chain::Stage::new(chain); - let mut ledger = ledger::Stage::new(ledger, byron, shelley); + let mut ledger = ledger::Stage::new(ledger, byron, shelley, config.phase1_validation_enabled); let (to_roll, from_pull) = gasket::messaging::tokio::mpsc_channel(50); pull.downstream.connect(to_roll);