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

Enforce string limits for deserialization #4567

Merged
merged 9 commits into from
Jun 12, 2024
32 changes: 14 additions & 18 deletions crates/bin/pd/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod testnet72;
mod testnet74;
mod testnet76;
mod testnet77;
mod testnet78;

use anyhow::{ensure, Context};
use penumbra_governance::StateReadExt;
Expand Down Expand Up @@ -47,6 +48,9 @@ pub enum Migration {
/// Testnet-77 migration:
/// - Reset the halt bit
Testnet77,
/// Testnet-78 migration:
/// - Truncate various user-supplied `String` fields to a maximum length.
Testnet78,
}

impl Migration {
Expand All @@ -72,30 +76,22 @@ impl Migration {
);
tracing::info!("started migration");

// If this is `ReadyToStart`, we need to reset the halt bit and return early.
if let Migration::ReadyToStart = self {
reset_halt_bit::migrate(storage, pd_home, genesis_start).await?;
return Ok(());
}

match self {
Migration::ReadyToStart => {
reset_halt_bit::migrate(storage, pd_home, genesis_start).await?;
return Ok(());
}
Migration::SimpleMigration => {
simple::migrate(storage, pd_home.clone(), genesis_start).await?
}

Migration::Testnet72 => {
testnet72::migrate(storage, pd_home.clone(), genesis_start).await?
}

Migration::Testnet74 => {
testnet74::migrate(storage, pd_home.clone(), genesis_start).await?
Migration::Testnet78 => {
testnet78::migrate(storage, pd_home.clone(), genesis_start).await?
}

Migration::Testnet76 => {
testnet76::migrate(storage, pd_home.clone(), genesis_start).await?
}
Migration::Testnet77 => {
testnet77::migrate(storage, pd_home.clone(), genesis_start).await?
}
};
_ => unreachable!(),
}

if let Some(comet_home) = comet_home {
// TODO avoid this when refactoring to clean up migrations
Expand Down
1 change: 1 addition & 0 deletions crates/bin/pd/src/migrate/reset_halt_bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ pub async fn migrate(
let _ = storage.commit_in_place(delta).await?;
storage.release().await;
tracing::info!("migration completed: halt bit is turned off, chain is ready to start");

Ok(())
}
2 changes: 1 addition & 1 deletion crates/bin/pd/src/migrate/testnet72.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Contains functions related to the migration script of Testnet72

#![allow(dead_code)]
use anyhow;
use cnidarium::{Snapshot, StateDelta, StateRead, StateWrite, Storage};
use futures::StreamExt as _;
Expand Down
1 change: 1 addition & 0 deletions crates/bin/pd/src/migrate/testnet74.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Contains functions related to the migration script of Testnet74
#![allow(dead_code)]

use anyhow;
use cnidarium::{EscapedByteSlice, Snapshot, StateDelta, StateRead, StateWrite, Storage};
Expand Down
1 change: 1 addition & 0 deletions crates/bin/pd/src/migrate/testnet76.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Contains functions related to the migration script of Testnet74
#![allow(dead_code)]

use anyhow;
use cnidarium::{Snapshot, StateDelta, Storage};
Expand Down
Loading
Loading