Skip to content

Commit

Permalink
feat(applying): add prot params for Alonzo
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicoLeberle committed Jan 17, 2024
1 parent eaf0cef commit aac19f7
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 100 deletions.
29 changes: 15 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 <santiago@carmuega.me>"]


[dependencies]
pallas = { git = "https://github.com/txpipe/pallas.git", features = ["unstable"] }
pallas = { git = "https://github.com/txpipe/pallas.git", branch = "feat/alonzo-phase-1-validations", features = ["unstable"] }
# pallas = { path = "../pallas/pallas", features = ["unstable"] }

gasket = { version = "^0.5", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions examples/sync-mainnet/dolos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
peer_address = "relays-new.cardano-mainnet.iohk.io:3001"
network_magic = 764824073
network_id = 1
phase1_validation_enabled = false

[rolldb]
path = "./tmp/rolldb"
Expand Down
39 changes: 0 additions & 39 deletions src/sync/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,6 @@ use tracing::{debug, info, warn};
use crate::prelude::*;
use crate::storage::applydb::ApplyDB;

pub fn execute_phase1_validation(
ledger: &ApplyDB,
block: &MultiEraBlock<'_>,
) -> Result<(), WorkerError> {
let mut utxos = HashMap::new();
ledger
.resolve_inputs_for_block(block, &mut utxos)
.or_panic()?;

let mut utxos2 = UTxOs::new();

for (ref_, output) in utxos.iter() {
let txin = pallas::ledger::primitives::byron::TxIn::Variant0(
pallas::codec::utils::CborWrap((ref_.0, ref_.1 as u32)),
);

let key = MultiEraInput::Byron(
<Box<Cow<'_, pallas::ledger::primitives::byron::TxIn>>>::from(Cow::Owned(txin)),
);

let era = Era::try_from(output.0).or_panic()?;
let value = MultiEraOutput::decode(era, &output.1).or_panic()?;

utxos2.insert(key, value);
}

let env = ledger.get_active_pparams(block.slot()).or_panic()?;

for tx in block.txs().iter() {
let res = validate(tx, &utxos2, &env);

if let Err(err) = res {
warn!(?err, "validation error");
}
}

Ok(())
}

pub type UpstreamPort = gasket::messaging::tokio::InputPort<RollEvent>;

#[derive(Stage)]
Expand Down
136 changes: 90 additions & 46 deletions src/sync/pparams.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use gasket::framework::{AsWorkError, WorkerError};
use pallas::{
applying::{Environment, MultiEraProtParams},
applying::utils::{
AlonzoProtParams, ByronProtParams, Environment, FeePolicy, MultiEraProtParams,
ShelleyProtParams,
},
ledger::{
configs::{byron, shelley},
traverse::{Era, MultiEraUpdate},
Expand All @@ -18,40 +21,38 @@ pub struct Genesis<'a> {
fn pparams_from_byron_genesis(
byron: &byron::GenesisFile,
) -> Result<MultiEraProtParams, WorkerError> {
let out =
pallas::applying::MultiEraProtParams::Byron(pallas::applying::types::ByronProtParams {
fee_policy: pallas::applying::types::FeePolicy {
summand: byron
.block_version_data
.tx_fee_policy
.summand
.parse()
.or_panic()?,
multiplier: byron
.block_version_data
.tx_fee_policy
.multiplier
.parse()
.or_panic()?,
},
max_tx_size: byron.block_version_data.max_tx_size.parse().or_panic()?,
});
let out = pallas::applying::MultiEraProtParams::Byron(ByronProtParams {
fee_policy: FeePolicy {
summand: byron
.block_version_data
.tx_fee_policy
.summand
.parse()
.or_panic()?,
multiplier: byron
.block_version_data
.tx_fee_policy
.multiplier
.parse()
.or_panic()?,
},
max_tx_size: byron.block_version_data.max_tx_size.parse().or_panic()?,
});

Ok(out)
}

fn pparams_from_shelley_genesis(
shelley: &shelley::GenesisFile,
) -> Result<MultiEraProtParams, WorkerError> {
let out =
pallas::applying::MultiEraProtParams::Shelley(pallas::applying::types::ShelleyProtParams {
fee_policy: pallas::applying::types::FeePolicy {
summand: shelley.protocol_params.min_fee_a,
multiplier: shelley.protocol_params.min_fee_b,
},
max_tx_size: shelley.protocol_params.max_tx_size,
min_lovelace: shelley.protocol_params.min_u_tx_o_value,
});
let out = pallas::applying::MultiEraProtParams::Shelley(ShelleyProtParams {
fee_policy: FeePolicy {
summand: shelley.protocol_params.min_fee_a,
multiplier: shelley.protocol_params.min_fee_b,
},
max_tx_size: shelley.protocol_params.max_tx_size,
min_lovelace: shelley.protocol_params.min_u_tx_o_value,
});

Ok(out)
}
Expand Down Expand Up @@ -90,7 +91,7 @@ fn apply_param_update(
warn!("found new byron fee policy update proposal");

let new = new.unwrap();
pparams.fee_policy = pallas::applying::types::FeePolicy {
pparams.fee_policy = FeePolicy {
summand: new.0 as u64,
multiplier: new.1 as u64,
};
Expand Down Expand Up @@ -140,25 +141,68 @@ pub fn compute_pparams(
ledger: &ApplyDB,
epoch: u64,
) -> Result<Environment, WorkerError> {
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)?,
};
if epoch >= 290 && epoch <= 364 {

Check failure on line 144 in src/sync/pparams.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

manual `RangeInclusive::contains` implementation
// Alonzo era
let max_tx_ex_mem: u32 = if epoch < 306 {
10000000
} else if epoch >= 306 && epoch < 319 {

Check failure on line 148 in src/sync/pparams.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

manual `Range::contains` implementation
11250000
} else {
14000000
};
let max_block_ex_mem: u64 = if epoch < 321 {
50000000
} else if epoch >= 321 && epoch < 328 {

Check failure on line 155 in src/sync/pparams.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

manual `Range::contains` implementation
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_mem,

Check failure on line 166 in src/sync/pparams.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

redundant field names in struct initialization
max_block_ex_steps: 40000000000,
max_tx_ex_mem: max_tx_ex_mem,

Check failure on line 168 in src/sync/pparams.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

redundant field names in struct initialization
max_tx_ex_steps: 10000000000,
max_val_size: 5000,
collateral_percent: 150,
max_collateral_inputs: 3,
coins_per_utxo_word: 34482,
};
let res: Environment = 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),
};
Ok(res)
} else {
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()?;
let updates = ledger.get_pparams_updates(epoch).or_panic()?;

info!(epoch, updates = updates.len(), "computing pparams");
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)?;
}
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)
Ok(out)
}
}

0 comments on commit aac19f7

Please sign in to comment.