diff --git a/Cargo.lock b/Cargo.lock index 8836559d..13bfe5d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1903,7 +1903,7 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "pallas" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "pallas-addresses", "pallas-applying", @@ -1923,7 +1923,7 @@ dependencies = [ [[package]] name = "pallas-addresses" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "base58", "bech32 0.9.1", @@ -1938,7 +1938,7 @@ dependencies = [ [[package]] name = "pallas-applying" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "hex", "pallas-addresses", @@ -1964,7 +1964,7 @@ dependencies = [ [[package]] name = "pallas-codec" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "hex", "minicbor", @@ -1975,7 +1975,7 @@ dependencies = [ [[package]] name = "pallas-configs" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "base64 0.21.7", "hex", @@ -2003,7 +2003,7 @@ dependencies = [ [[package]] name = "pallas-crypto" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "cryptoxide", "hex", @@ -2016,7 +2016,7 @@ dependencies = [ [[package]] name = "pallas-hardano" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "binary-layout", "pallas-network 0.23.0", @@ -2047,7 +2047,7 @@ dependencies = [ [[package]] name = "pallas-network" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "byteorder", "hex", @@ -2064,7 +2064,7 @@ dependencies = [ [[package]] name = "pallas-primitives" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "base58", "bech32 0.9.1", @@ -2079,7 +2079,7 @@ dependencies = [ [[package]] name = "pallas-rolldb" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "async-stream", "bincode", @@ -2096,7 +2096,7 @@ dependencies = [ [[package]] name = "pallas-traverse" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "hex", "pallas-addresses", @@ -2111,7 +2111,7 @@ dependencies = [ [[package]] name = "pallas-txbuilder" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "hex", "pallas-addresses", @@ -2128,7 +2128,7 @@ dependencies = [ [[package]] name = "pallas-utxorpc" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "pallas-codec 0.23.0", "pallas-primitives", @@ -2139,7 +2139,7 @@ dependencies = [ [[package]] name = "pallas-wallet" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#edbf4461880291edb25dbf76997d64dfb1e4ffd4" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/protocol-parameters-preprod-and-preview#83b5cb3def4102ff74dafda850a7cc7b51a34974" dependencies = [ "bech32 0.9.1", "bip39", diff --git a/Cargo.toml b/Cargo.toml index 071fd1f6..f7e2228e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ authors = ["Santiago Carmuega "] [dependencies] -pallas = { git = "https://github.com/txpipe/pallas.git", features = ["unstable"] } +pallas = { git = "https://github.com/txpipe/pallas.git", branch = "feat/protocol-parameters-preprod-and-preview", features = ["unstable"] } # pallas = { version = "^0.23", features = ["unstable"] } # pallas = { path = "../pallas/pallas", features = ["unstable"] } diff --git a/src/bin/dolos/eval.rs b/src/bin/dolos/eval.rs index e37094e3..83bf7714 100644 --- a/src/bin/dolos/eval.rs +++ b/src/bin/dolos/eval.rs @@ -16,6 +16,9 @@ pub struct Args { #[arg(long, short)] epoch: u64, + #[arg(long, short)] + block_slot: u64, + #[arg(long, short)] network_id: u8, } @@ -82,6 +85,9 @@ pub fn run(config: &super::Config, args: &Args) -> miette::Result<()> { }, &ledger, args.epoch, + args.block_slot, + config.upstream.network_magic as u32, + config.upstream.network_id, ) .into_diagnostic() .context("computing protocol params")?; diff --git a/src/sync/ledger.rs b/src/sync/ledger.rs index 069ab0ba..be438868 100644 --- a/src/sync/ledger.rs +++ b/src/sync/ledger.rs @@ -18,6 +18,8 @@ pub struct Stage { ledger: ApplyDB, byron: byron::GenesisFile, shelley: shelley::GenesisFile, + network_magic: u64, + network_id: u8, current_pparams: Option<(u64, Environment)>, @@ -41,6 +43,8 @@ impl Stage { byron: byron::GenesisFile, shelley: shelley::GenesisFile, phase1_validation_enabled: bool, + network_magic: u64, + network_id: u8, ) -> Self { Self { ledger, @@ -50,6 +54,8 @@ impl Stage { .unwrap(), byron, shelley, + network_magic, + network_id, current_pparams: None, phase1_validation_enabled, upstream: Default::default(), @@ -58,7 +64,7 @@ impl Stage { } } - fn ensure_pparams(&mut self, epoch: u64) -> Result<(), WorkerError> { + fn ensure_pparams(&mut self, epoch: u64, block_slot: u64) -> Result<(), WorkerError> { if self .current_pparams .as_ref() @@ -74,6 +80,9 @@ impl Stage { }, &self.ledger, epoch, + block_slot, + self.network_magic as u32, + self.network_id, )?; warn!(?pparams, "pparams for new epoch"); @@ -152,7 +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(epoch, block.slot())?; stage.execute_phase1_validation(&block)?; } diff --git a/src/sync/mod.rs b/src/sync/mod.rs index fb562a81..1fbcbbcd 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -74,7 +74,14 @@ 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, config.phase1_validation_enabled); + let mut ledger = ledger::Stage::new( + ledger, + byron, + shelley, + config.phase1_validation_enabled, + config.network_magic, + config.network_id, + ); let (to_roll, from_pull) = gasket::messaging::tokio::mpsc_channel(50); pull.downstream.connect(to_roll); diff --git a/src/sync/pparams.rs b/src/sync/pparams.rs index 0a17b456..728b3ef6 100644 --- a/src/sync/pparams.rs +++ b/src/sync/pparams.rs @@ -143,100 +143,233 @@ pub fn compute_pparams( genesis: Genesis, ledger: &ApplyDB, epoch: u64, + block_slot: u64, + prot_magic: u32, + network_id: u8, ) -> Result { - if (290..=364).contains(&epoch) { - // Alonzo era - let max_tx_ex_mem: u32 = if (..306).contains(&epoch) { - 10000000 - } else if (306..319).contains(&epoch) { - 11250000 + if prot_magic == 1 && network_id == 0 { + // Preprod + if (7..=11).contains(&epoch) { + // Alonzo era + Ok(Environment { + block_slot, + prot_magic, + network_id, + prot_params: MultiEraProtParams::Alonzo(AlonzoProtParams { + fee_policy: FeePolicy { + summand: 155381, + multiplier: 44, + }, + max_tx_size: 16384, + max_block_ex_mem: 50000000, + max_block_ex_steps: 40000000000, + max_tx_ex_mem: 10000000, + max_tx_ex_steps: 10000000000, + max_val_size: 5000, + collateral_percent: 150, + max_collateral_inputs: 3, + coins_per_utxo_word: 34482, + }), + }) + } else if 12 >= epoch { + // Babbage era + Ok(Environment { + block_slot, + prot_magic, + network_id, + prot_params: MultiEraProtParams::Babbage(BabbageProtParams { + fee_policy: FeePolicy { + summand: 155381, + multiplier: 44, + }, + max_tx_size: 16384, + max_block_ex_mem: if (12..=27).contains(&epoch) { + 50000000 + } else { + 62000000 + }, + max_block_ex_steps: if (12..=50).contains(&epoch) { + 40000000000 + } else { + 20000000000 + }, + max_tx_ex_mem: if (12..=27).contains(&epoch) { + 10000000 + } else { + 14000000 + }, + max_tx_ex_steps: 10000000000, + max_val_size: 5000, + collateral_percent: 150, + max_collateral_inputs: 3, + coins_per_utxo_word: 4310, + }), + }) } else { - 14000000 - }; - let max_block_ex_mem: u64 = if (290..321).contains(&epoch) { - 50000000 - } else if (321..328).contains(&epoch) { - 56000000 - } else { - 62000000 - }; - let prot_pps: AlonzoProtParams = AlonzoProtParams { - fee_policy: FeePolicy { - summand: 155381, - multiplier: 44, - }, - max_tx_size: 16384, - max_block_ex_mem, - max_block_ex_steps: 40000000000, - max_tx_ex_mem, - max_tx_ex_steps: 10000000000, - max_val_size: 5000, - collateral_percent: 150, - max_collateral_inputs: 3, - coins_per_utxo_word: 34482, - }; - Ok(Environment { - block_slot: 0, - prot_magic: genesis.byron.protocol_consts.protocol_magic, - network_id: match genesis.shelley.network_id.as_deref() { - Some("Mainnet") => 0, - _ => 1, - }, - prot_params: MultiEraProtParams::Alonzo(prot_pps), - }) - } else if epoch >= 365 { - // Babbage era - let max_block_ex_steps: u64 = if (365..=393).contains(&epoch) { - 40000000000 + // Eras prior to Alonzo and Babbage (Byron and ShelleyMA) + let mut out = Environment { + block_slot, + prot_magic, + network_id, + prot_params: apply_era_hardfork(&genesis, 1)?, + }; + + let updates = ledger.get_pparams_updates(epoch).or_panic()?; + + info!(epoch, updates = updates.len(), "computing pparams"); + + for (era, _, cbor) in updates { + let era = Era::try_from(era).or_panic()?; + let update = MultiEraUpdate::decode_for_era(era, &cbor).or_panic()?; + out.prot_params = apply_param_update(&genesis, era, out.prot_params, update)?; + } + + Ok(out) + } + } else if prot_magic == 2 && network_id == 0 { + // Preview + if (1..=2).contains(&epoch) { + // Alonzo era + Ok(Environment { + block_slot, + prot_magic, + network_id, + prot_params: MultiEraProtParams::Alonzo(AlonzoProtParams { + fee_policy: FeePolicy { + summand: 155381, + multiplier: 44, + }, + max_tx_size: 16384, + max_block_ex_mem: 50000000, + max_block_ex_steps: 40000000000, + max_tx_ex_mem: 10000000, + max_tx_ex_steps: 10000000000, + max_val_size: 5000, + collateral_percent: 150, + max_collateral_inputs: 3, + coins_per_utxo_word: 34482, + }), + }) + } else if 3 >= epoch { + // Babbage era + Ok(Environment { + block_slot, + prot_magic, + network_id, + prot_params: MultiEraProtParams::Babbage(BabbageProtParams { + fee_policy: FeePolicy { + summand: 155381, + multiplier: 44, + }, + max_tx_size: 16384, + max_block_ex_mem: if (3..=8).contains(&epoch) { + 50000000 + } else { + 62000000 + }, + max_block_ex_steps: if (3..=106).contains(&epoch) { + 40000000000 + } else { + 20000000000 + }, + max_tx_ex_mem: if (3..=8).contains(&epoch) { + 10000000 + } else { + 14000000 + }, + max_tx_ex_steps: 10000000000, + max_val_size: 5000, + collateral_percent: 150, + max_collateral_inputs: 3, + coins_per_utxo_word: 4310, + }), + }) } else { - 20000000000 - }; - let prot_pps: BabbageProtParams = BabbageProtParams { - fee_policy: FeePolicy { - summand: 155381, - multiplier: 44, - }, - max_tx_size: 16384, - max_block_ex_mem: 62000000, - max_block_ex_steps, - max_tx_ex_mem: 14000000, - max_tx_ex_steps: 10000000000, - max_val_size: 5000, - collateral_percent: 150, - max_collateral_inputs: 3, - coins_per_utxo_word: 4310, - }; - Ok(Environment { - block_slot: 0, - prot_magic: genesis.byron.protocol_consts.protocol_magic, - network_id: match genesis.shelley.network_id.as_deref() { - Some("Mainnet") => 0, - _ => 1, - }, - prot_params: MultiEraProtParams::Babbage(prot_pps), - }) - } else { - // Eras prior to Alonzo and Babbage - let mut out = Environment { - block_slot: 0, - prot_magic: genesis.byron.protocol_consts.protocol_magic, - network_id: match genesis.shelley.network_id.as_deref() { - Some("Mainnet") => 0, - _ => 1, - }, - prot_params: apply_era_hardfork(&genesis, 1)?, - }; - - let updates = ledger.get_pparams_updates(epoch).or_panic()?; - - info!(epoch, updates = updates.len(), "computing pparams"); - - for (era, _, cbor) in updates { - let era = Era::try_from(era).or_panic()?; - let update = MultiEraUpdate::decode_for_era(era, &cbor).or_panic()?; - out.prot_params = apply_param_update(&genesis, era, out.prot_params, update)?; + // Preview networks do not have Byron nor ShelleyMA + Err(WorkerError::Panic) } + } else { + // All other cases are assumed to require a mainnet environment + if (290..=364).contains(&epoch) { + // Alonzo era + Ok(Environment { + block_slot, + prot_magic, + network_id, + prot_params: MultiEraProtParams::Alonzo(AlonzoProtParams { + fee_policy: FeePolicy { + summand: 155381, + multiplier: 44, + }, + max_tx_size: 16384, + max_block_ex_mem: if (290..=321).contains(&epoch) { + 50000000 + } else if (321..328).contains(&epoch) { + 56000000 + } else { + 62000000 + }, + max_block_ex_steps: 40000000000, + max_tx_ex_mem: if (..=306).contains(&epoch) { + 10000000 + } else if (306..319).contains(&epoch) { + 11250000 + } else { + 14000000 + }, + max_tx_ex_steps: 10000000000, + max_val_size: 5000, + collateral_percent: 150, + max_collateral_inputs: 3, + coins_per_utxo_word: 34482, + }), + }) + } else if epoch >= 365 { + // Babbage era + Ok(Environment { + block_slot, + prot_magic, + network_id, + prot_params: MultiEraProtParams::Babbage(BabbageProtParams { + fee_policy: FeePolicy { + summand: 155381, + multiplier: 44, + }, + max_tx_size: 16384, + max_block_ex_mem: 62000000, + max_block_ex_steps: if (365..=393).contains(&epoch) { + 40000000000 + } else { + 20000000000 + }, + max_tx_ex_mem: 14000000, + max_tx_ex_steps: 10000000000, + max_val_size: 5000, + collateral_percent: 150, + max_collateral_inputs: 3, + coins_per_utxo_word: 4310, + }), + }) + } else { + // Eras prior to Alonzo and Babbage (Byron and ShelleyMA) + let mut out = Environment { + block_slot, + prot_magic, + network_id, + prot_params: apply_era_hardfork(&genesis, 1)?, + }; + + let updates = ledger.get_pparams_updates(epoch).or_panic()?; + + info!(epoch, updates = updates.len(), "computing pparams"); - Ok(out) + for (era, _, cbor) in updates { + let era = Era::try_from(era).or_panic()?; + let update = MultiEraUpdate::decode_for_era(era, &cbor).or_panic()?; + out.prot_params = apply_param_update(&genesis, era, out.prot_params, update)?; + } + + Ok(out) + } } }