-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pathfinder/examples): add a
reorg
tool to perform reorgs on a …
…database Usage: `cargo run --example reorg -- --target-block 190000 /path/to/database.sqlite`
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::num::NonZeroU32; | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
use pathfinder_common::BlockNumber; | ||
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::{fmt, EnvFilter}; | ||
|
||
#[derive(Parser)] | ||
#[command(version)] | ||
struct Cli { | ||
#[arg(long_help = "Database path")] | ||
pub database_path: PathBuf, | ||
#[arg(long, long_help = "Roll back state to this block", value_parser = parse_block_number)] | ||
pub target_block: BlockNumber, | ||
} | ||
|
||
fn parse_block_number(s: &str) -> Result<BlockNumber, String> { | ||
let n: u64 = s | ||
.parse() | ||
.map_err(|e| format!("Invalid block number '{s}': {e}"))?; | ||
BlockNumber::new(n).ok_or_else(|| format!("Invalid block number '{s}'")) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let cli = Cli::parse(); | ||
|
||
tracing_subscriber::registry() | ||
.with(fmt::layer()) | ||
.with(EnvFilter::from_default_env()) | ||
.init(); | ||
|
||
let storage = pathfinder_storage::StorageBuilder::file(cli.database_path.into()) | ||
.migrate()? | ||
.create_pool(NonZeroU32::new(10).unwrap()) | ||
.unwrap(); | ||
|
||
let mut connection = storage.connection().unwrap(); | ||
|
||
pathfinder_lib::state::l2_reorg(&mut connection, cli.target_block) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ mod sync; | |
pub use sync::{ | ||
l1, | ||
l2, | ||
l2_reorg, | ||
revert, | ||
sync, | ||
update_starknet_state, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters