From 1ef4d0c12373b77d6a65003ac4175dc4a3d45175 Mon Sep 17 00:00:00 2001 From: Maico Leberle Date: Tue, 20 Feb 2024 20:55:24 -0300 Subject: [PATCH] feat: integrate Babbage phase-1 validations (#169) Co-authored-by: Santiago Carmuega --- Cargo.lock | 28 ++++++++--------- Cargo.toml | 2 +- examples/sync-preprod/dolos.toml | 1 + src/storage/applydb/mod.rs | 54 ++++++++++++++++---------------- src/sync/pparams.rs | 40 ++++++++++++++++++++--- 5 files changed, 78 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6432ebd6..c4010647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1904,7 +1904,7 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" [[package]] name = "pallas" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "pallas-addresses", "pallas-applying", @@ -1924,7 +1924,7 @@ dependencies = [ [[package]] name = "pallas-addresses" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "base58", "bech32 0.9.1", @@ -1939,7 +1939,7 @@ dependencies = [ [[package]] name = "pallas-applying" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "hex", "pallas-addresses", @@ -1965,7 +1965,7 @@ dependencies = [ [[package]] name = "pallas-codec" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "hex", "minicbor", @@ -1976,7 +1976,7 @@ dependencies = [ [[package]] name = "pallas-configs" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "base64 0.21.7", "hex", @@ -2004,7 +2004,7 @@ dependencies = [ [[package]] name = "pallas-crypto" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "cryptoxide", "hex", @@ -2017,7 +2017,7 @@ dependencies = [ [[package]] name = "pallas-hardano" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "binary-layout", "pallas-network 0.23.0", @@ -2048,7 +2048,7 @@ dependencies = [ [[package]] name = "pallas-network" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "byteorder", "hex", @@ -2065,7 +2065,7 @@ dependencies = [ [[package]] name = "pallas-primitives" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "base58", "bech32 0.9.1", @@ -2080,7 +2080,7 @@ dependencies = [ [[package]] name = "pallas-rolldb" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "async-stream", "bincode", @@ -2097,7 +2097,7 @@ dependencies = [ [[package]] name = "pallas-traverse" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "hex", "pallas-addresses", @@ -2112,7 +2112,7 @@ dependencies = [ [[package]] name = "pallas-txbuilder" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "hex", "pallas-addresses", @@ -2129,7 +2129,7 @@ dependencies = [ [[package]] name = "pallas-utxorpc" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "pallas-codec 0.23.0", "pallas-primitives", @@ -2140,7 +2140,7 @@ dependencies = [ [[package]] name = "pallas-wallet" version = "0.23.0" -source = "git+https://github.com/txpipe/pallas.git#ab1fd882d6394ffd3bd90250a64a9b234a6a033e" +source = "git+https://github.com/txpipe/pallas.git?branch=feat/babbage-phase-1-validations#282f2ea57d212495faf78945c5ef2b48d4c5a6a8" dependencies = [ "bech32 0.9.1", "bip39", diff --git a/Cargo.toml b/Cargo.toml index 998eb2cc..479e1b3a 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/babbage-phase-1-validations", features = ["unstable"] } # pallas = { version = "^0.23", features = ["unstable"] } # pallas = { path = "../pallas/pallas", features = ["unstable"] } diff --git a/examples/sync-preprod/dolos.toml b/examples/sync-preprod/dolos.toml index f9739e24..c9e2c908 100644 --- a/examples/sync-preprod/dolos.toml +++ b/examples/sync-preprod/dolos.toml @@ -2,6 +2,7 @@ peer_address = "preprod-node.world.dev.cardano.org:30000" network_magic = 1 network_id = 0 +phase1_validation_enabled = false [rolldb] path = "./tmp/rolldb" diff --git a/src/storage/applydb/mod.rs b/src/storage/applydb/mod.rs index e17ca12d..14308576 100644 --- a/src/storage/applydb/mod.rs +++ b/src/storage/applydb/mod.rs @@ -375,36 +375,36 @@ impl ApplyDB { let txs = block.txs(); for tx in txs.iter() { - for (idx, produced) in tx.produces() { - let body = produced.encode(); - let era = tx.era().into(); - batch.insert_utxo(tx.hash(), idx as u64, (era, body)); - } - } - - for tx in txs.iter() { - for consumed in tx.consumes() { - let hash = *consumed.hash(); - let idx = consumed.index(); + // Update the database UTxO only if the transaction is valid. + if tx.is_valid() { + for (idx, produced) in tx.produces() { + let body = produced.encode(); + let era = tx.era().into(); + batch.insert_utxo(tx.hash(), idx as u64, (era, body)); + } + for consumed in tx.consumes() { + let hash = *consumed.hash(); + let idx = consumed.index(); - if batch.contains_utxo(hash, idx) { - batch.spend_utxo_same_block(hash, idx); - } else { - let utxo = self - .get_utxo(hash, idx)? - .ok_or(Error::MissingUtxo(hash, idx))?; + if batch.contains_utxo(hash, idx) { + batch.spend_utxo_same_block(hash, idx); + } else { + let utxo = self + .get_utxo(hash, idx)? + .ok_or(Error::MissingUtxo(hash, idx))?; - batch.spend_utxo(hash, idx, utxo); - }; - } + batch.spend_utxo(hash, idx, utxo); + }; + } - if let Some(update) = tx.update() { - batch.update_pparams( - update.epoch(), - block.era().into(), - block.hash(), - update.encode(), - ); + if let Some(update) = tx.update() { + batch.update_pparams( + update.epoch(), + block.era().into(), + block.hash(), + update.encode(), + ); + } } } diff --git a/src/sync/pparams.rs b/src/sync/pparams.rs index e984eca1..1cb8a421 100644 --- a/src/sync/pparams.rs +++ b/src/sync/pparams.rs @@ -1,8 +1,8 @@ use gasket::framework::{AsWorkError, WorkerError}; use pallas::{ applying::utils::{ - AlonzoProtParams, ByronProtParams, Environment, FeePolicy, MultiEraProtParams, - ShelleyProtParams, + AlonzoProtParams, BabbageProtParams, ByronProtParams, Environment, FeePolicy, + MultiEraProtParams, ShelleyProtParams, }, ledger::{ configs::{byron, shelley}, @@ -173,7 +173,7 @@ pub fn compute_pparams( max_collateral_inputs: 3, coins_per_utxo_word: 34482, }; - let res: Environment = Environment { + Ok(Environment { block_slot: 0, prot_magic: genesis.byron.protocol_consts.protocol_magic, network_id: match genesis.shelley.network_id.as_deref() { @@ -181,10 +181,40 @@ pub fn compute_pparams( _ => 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 + } else { + 20000000000 }; - Ok(res) + 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 other than Alonzo + // Eras prior to Alonzo and Babbage let mut out = Environment { block_slot: 0, prot_magic: genesis.byron.protocol_consts.protocol_magic,