-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1854 from eqlabs/krisztian/reverse-state-update
feat: revert Merkle trie changes upon reorg
- Loading branch information
Showing
16 changed files
with
869 additions
and
83 deletions.
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
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
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
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
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
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,59 @@ | ||
use std::{num::NonZeroU32, time::Instant}; | ||
|
||
use anyhow::Context; | ||
use pathfinder_common::BlockNumber; | ||
use pathfinder_storage::{BlockId, JournalMode, Storage}; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
tracing_subscriber::fmt() | ||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | ||
.compact() | ||
.init(); | ||
|
||
let database_path = std::env::args().nth(1).unwrap(); | ||
let storage = Storage::migrate(database_path.into(), JournalMode::WAL, 1)? | ||
.create_pool(NonZeroU32::new(10).unwrap())?; | ||
let mut db = storage | ||
.connection() | ||
.context("Opening database connection")?; | ||
|
||
let latest_block = { | ||
let tx = db.transaction().unwrap(); | ||
let (latest_block, _) = tx.block_id(BlockId::Latest)?.unwrap(); | ||
latest_block.get() | ||
}; | ||
let from: u64 = std::env::args() | ||
.nth(2) | ||
.map(|s| str::parse(&s).unwrap()) | ||
.unwrap(); | ||
let to: u64 = std::env::args() | ||
.nth(3) | ||
.map(|s| str::parse(&s).unwrap()) | ||
.unwrap(); | ||
assert!(from <= latest_block); | ||
assert!(from > to); | ||
let from = BlockNumber::new_or_panic(from); | ||
let to = BlockNumber::new_or_panic(to); | ||
|
||
tracing::info!(%from, %to, "Testing state rollback"); | ||
|
||
let started = Instant::now(); | ||
|
||
let tx = db.transaction()?; | ||
|
||
let to_header = tx.block_header(to.into()).unwrap().unwrap(); | ||
|
||
pathfinder_lib::state::revert::revert_starknet_state(&tx, from, to, to_header, true)?; | ||
|
||
tracing::info!( | ||
from=%from, | ||
to=%to, | ||
total=?started.elapsed(), | ||
"Finished state rollback" | ||
); | ||
|
||
// Explicitly do _not_ commit transaction | ||
drop(tx); | ||
|
||
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod block_hash; | ||
mod sync; | ||
|
||
pub use sync::{l1, l2, sync, Gossiper, SyncContext}; | ||
pub use sync::{l1, l2, revert, sync, Gossiper, SyncContext}; |
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
Oops, something went wrong.