Skip to content

Commit

Permalink
Enforce string limits for deserialization (#4567)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc authored Jun 12, 2024
1 parent 757d42d commit defd51b
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 33 deletions.
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

0 comments on commit defd51b

Please sign in to comment.