Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use hacks to keep gov action pparams updated #436

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions src/ledger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use pallas::ledger::primitives::conway::GovAction;

Check warning on line 1 in src/ledger/mod.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

unused import: `pallas::ledger::primitives::conway::GovAction`

Check failure on line 1 in src/ledger/mod.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

unused import: `pallas::ledger::primitives::conway::GovAction`

Check warning on line 1 in src/ledger/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `pallas::ledger::primitives::conway::GovAction`

Check warning on line 1 in src/ledger/mod.rs

View workflow job for this annotation

GitHub Actions / Check (macOS-latest, stable)

unused import: `pallas::ledger::primitives::conway::GovAction`
use pallas::ledger::traverse::{Era, MultiEraBlock, MultiEraInput, MultiEraUpdate};
use pallas::{crypto::hash::Hash, ledger::traverse::MultiEraOutput};
use pparams::Genesis;
Expand Down Expand Up @@ -119,8 +120,8 @@
/// higher-layers to retry the logic if required.
///
/// This method assumes that the block has already been validated, it will
/// return an error if any of the assumed invariant have been broken in the
/// process of computing the delta, but it own't provide a comprehensive
/// return an error if any of the assumed invariants have been broken in the
/// process of computing the delta, but it doesn't provide a comprehensive
/// validation of the ledger rules.
pub fn compute_delta(
block: &MultiEraBlock,
Expand Down
34 changes: 34 additions & 0 deletions src/ledger/pparams/hacks/mainnet_epoch526.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::ledger::pparams::EraSummary;

pub const SLOT: u64 = 141868807;

pub fn change(era: &mut EraSummary) {
let costs = vec![
100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, 16000,
100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, 16000, 100,
94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, 4, 2, 85848,
123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 1000, 42921, 4, 2, 24548, 29498, 38, 1,
898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32,
76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, 1,
33852, 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, 11546, 32, 85848, 123203, 7305, -900,
1716, 549, 57, 85848, 0, 1, 90434, 519, 0, 1, 74433, 32, 85848, 123203, 7305, -900, 1716,
549, 57, 85848, 0, 1, 1, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 955506,
213312, 0, 2, 270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420,
1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32,
43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, 16000, 100, 16000, 100, 962335, 18,
2780678, 6, 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006, 8868, 18, 52948122, 18,
1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, 36, 284546, 36, 158221314, 26549, 36,
74698472, 36, 333849714, 1, 254006273, 72, 2174038, 72, 2261318, 64571, 4, 207616, 8310, 4,
1293828, 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 100181, 726, 719, 0, 1, 100181, 726,
719, 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, 1, 281145, 18848, 0, 1,
180194, 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, 0, 1, 107490, 3298, 1, 106057, 655, 1,
1964219, 24520, 3,
];

match &mut era.pparams {

Check failure on line 28 in src/ledger/pparams/hacks/mainnet_epoch526.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
pallas::applying::MultiEraProtocolParameters::Conway(x) => {
x.cost_models_for_script_languages.plutus_v3 = Some(costs)
}
_ => (),
}
}
23 changes: 23 additions & 0 deletions src/ledger/pparams/hacks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::ChainSummary;

mod mainnet_epoch526;
mod preprod_epoch191;
mod preview_epoch736;

pub fn mainnet(eras: &mut ChainSummary, current_slot: u64) {
if current_slot >= mainnet_epoch526::SLOT {
eras.apply_hacks(mainnet_epoch526::SLOT, mainnet_epoch526::change);
}
}

pub fn preprod(eras: &mut ChainSummary, current_slot: u64) {
if current_slot >= preprod_epoch191::SLOT {
eras.apply_hacks(preprod_epoch191::SLOT, preprod_epoch191::change);
}
}

pub fn preview(eras: &mut ChainSummary, current_slot: u64) {
if current_slot >= preview_epoch736::SLOT {
eras.apply_hacks(preview_epoch736::SLOT, preview_epoch736::change);
}
}
34 changes: 34 additions & 0 deletions src/ledger/pparams/hacks/preprod_epoch191.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::ledger::pparams::EraSummary;

pub const SLOT: u64 = 80870419;

pub fn change(era: &mut EraSummary) {
let costs = vec![
100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, 16000,
100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, 16000, 100,
94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, 4, 2, 85848,
123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 1000, 42921, 4, 2, 24548, 29498, 38, 1,
898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32,
76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, 1,
33852, 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, 11546, 32, 85848, 123203, 7305, -900,
1716, 549, 57, 85848, 0, 1, 90434, 519, 0, 1, 74433, 32, 85848, 123203, 7305, -900, 1716,
549, 57, 85848, 0, 1, 1, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 955506,
213312, 0, 2, 270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420,
1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32,
43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, 16000, 100, 16000, 100, 962335, 18,
2780678, 6, 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006, 8868, 18, 52948122, 18,
1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, 36, 284546, 36, 158221314, 26549, 36,
74698472, 36, 333849714, 1, 254006273, 72, 2174038, 72, 2261318, 64571, 4, 207616, 8310, 4,
1293828, 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 100181, 726, 719, 0, 1, 100181, 726,
719, 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, 1, 281145, 18848, 0, 1,
180194, 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, 0, 1, 107490, 3298, 1, 106057, 655, 1,
1964219, 24520, 3,
];

match &mut era.pparams {

Check failure on line 28 in src/ledger/pparams/hacks/preprod_epoch191.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
pallas::applying::MultiEraProtocolParameters::Conway(x) => {
x.cost_models_for_script_languages.plutus_v3 = Some(costs)
}
_ => (),
}
}
34 changes: 34 additions & 0 deletions src/ledger/pparams/hacks/preview_epoch736.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::ledger::pparams::EraSummary;

pub const SLOT: u64 = 63590427;

pub fn change(era: &mut EraSummary) {
let costs = vec![
100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, 16000,
100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, 16000, 100,
94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, 4, 2, 85848,
123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 1000, 42921, 4, 2, 24548, 29498, 38, 1,
898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32,
76049, 1, 13169, 4, 22100, 10, 28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, 1,
33852, 32, 68246, 32, 72362, 32, 7243, 32, 7391, 32, 11546, 32, 85848, 123203, 7305, -900,
1716, 549, 57, 85848, 0, 1, 90434, 519, 0, 1, 74433, 32, 85848, 123203, 7305, -900, 1716,
549, 57, 85848, 0, 1, 1, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 955506,
213312, 0, 2, 270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420,
1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32,
43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, 16000, 100, 16000, 100, 962335, 18,
2780678, 6, 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006, 8868, 18, 52948122, 18,
1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, 36, 284546, 36, 158221314, 26549, 36,
74698472, 36, 333849714, 1, 254006273, 72, 2174038, 72, 2261318, 64571, 4, 207616, 8310, 4,
1293828, 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 100181, 726, 719, 0, 1, 100181, 726,
719, 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, 1, 281145, 18848, 0, 1,
180194, 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, 0, 1, 107490, 3298, 1, 106057, 655, 1,
1964219, 24520, 3,
];

match &mut era.pparams {

Check failure on line 28 in src/ledger/pparams/hacks/preview_epoch736.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
pallas::applying::MultiEraProtocolParameters::Conway(x) => {
x.cost_models_for_script_languages.plutus_v3 = Some(costs)
}
_ => (),
}
}
25 changes: 25 additions & 0 deletions src/ledger/pparams/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
traverse::MultiEraUpdate,
},
};
use tracing::{debug, trace, warn};

Check warning on line 12 in src/ledger/pparams/mod.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

unused import: `trace`

Check failure on line 12 in src/ledger/pparams/mod.rs

View workflow job for this annotation

GitHub Actions / Lint Rust

unused import: `trace`

Check warning on line 12 in src/ledger/pparams/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `trace`

Check warning on line 12 in src/ledger/pparams/mod.rs

View workflow job for this annotation

GitHub Actions / Check (macOS-latest, stable)

unused import: `trace`

mod hacks;
mod summary;

pub use summary::*;
Expand Down Expand Up @@ -522,6 +523,30 @@
summary
}

/// Fold pparams, applying hacks as necessary
///
/// Until we have all of the governance-related logic in place, there's no way
/// to keep pparams updated. While we implement this, we'll just apply the hacks
/// manually. Hacks are available in `hacks` folder.
pub fn fold_with_hacks(
genesis: &Genesis,
updates: &[MultiEraUpdate],
current_slot: u64,
) -> ChainSummary {
let mut summary = fold(genesis, updates);

let network_magic = genesis.shelley.network_magic.unwrap_or_default();

match network_magic {
764824073 => hacks::mainnet(&mut summary, current_slot),
1 => hacks::preprod(&mut summary, current_slot),
2 => hacks::preview(&mut summary, current_slot),
_ => (),
}

summary
}

#[cfg(test)]
mod tests {
use std::{io::Read, path::Path};
Expand Down
18 changes: 18 additions & 0 deletions src/ledger/pparams/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,22 @@ impl ChainSummary {
.find(|e| slot >= e.start.slot && e.end.as_ref().unwrap().slot > slot)
.unwrap()
}

pub(crate) fn apply_hacks<F>(&mut self, epoch: u64, change: F)
where
F: Fn(&mut EraSummary),
{
if epoch >= self.edge().start.epoch {
change(self.edge.as_mut().unwrap());
}

let era = self
.past
.iter_mut()
.find(|e| epoch >= e.start.epoch && e.end.as_ref().unwrap().epoch > epoch);

if let Some(era) = era {
change(era);
}
}
}
12 changes: 10 additions & 2 deletions src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ impl Mempool {

let updates: Vec<_> = updates.into_iter().map(TryInto::try_into).try_collect()?;

let eras = crate::ledger::pparams::fold(&self.genesis, &updates);
let eras = crate::ledger::pparams::fold_with_hacks(
&self.genesis,
&updates,
tip.as_ref().unwrap().0,
);

let era = eras.era_for_slot(tip.as_ref().unwrap().0);

Expand Down Expand Up @@ -187,7 +191,11 @@ impl Mempool {

let updates: Vec<_> = updates.into_iter().map(TryInto::try_into).try_collect()?;

let eras = crate::ledger::pparams::fold(&self.genesis, &updates);
let eras = crate::ledger::pparams::fold_with_hacks(
&self.genesis,
&updates,
tip.as_ref().unwrap().0,
);

let slot_config = SlotConfig {
slot_length: eras.edge().pparams.slot_length(),
Expand Down
2 changes: 1 addition & 1 deletion src/serve/grpc/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl u5c::query::query_service_server::QueryService for QueryServiceImpl {
.try_collect::<_, _, pallas::codec::minicbor::decode::Error>()
.map_err(|e| Status::internal(e.to_string()))?;

let summary = pparams::fold(&self.genesis, &updates);
let summary = pparams::fold_with_hacks(&self.genesis, &updates, tip.as_ref().unwrap().0);

let era = summary.era_for_slot(tip.as_ref().unwrap().0);

Expand Down
Loading