Skip to content

Commit

Permalink
feat: integrate Babbage phase-1 validations (#169)
Browse files Browse the repository at this point in the history
Co-authored-by: Santiago Carmuega <[email protected]>
  • Loading branch information
MaicoLeberle and scarmuega authored Feb 20, 2024
1 parent b3f8eb9 commit 1ef4d0c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 47 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = ["Santiago Carmuega <[email protected]>"]


[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"] }

Expand Down
1 change: 1 addition & 0 deletions examples/sync-preprod/dolos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
54 changes: 27 additions & 27 deletions src/storage/applydb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
}
}

Expand Down
40 changes: 35 additions & 5 deletions src/sync/pparams.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -173,18 +173,48 @@ 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() {
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
} 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,
Expand Down

0 comments on commit 1ef4d0c

Please sign in to comment.