Skip to content

Commit

Permalink
feat: make phase-1 validations optional
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Dec 14, 2023
1 parent 312baad commit 56d4a8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/sync-preview/dolos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 16 additions & 5 deletions src/sync/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +24,8 @@ pub struct Stage {
// HACK: until multi-era genesis
genesis_values: GenesisValues,

phase1_validation_enabled: bool,

pub upstream: UpstreamPort,

#[metric]
Expand All @@ -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(
Expand All @@ -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(),
Expand Down Expand Up @@ -140,10 +148,13 @@ impl gasket::framework::Worker<Stage> 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()?;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::retries::Policy>) -> gasket::runtime::Policy {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 56d4a8e

Please sign in to comment.