-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Implementation of the state rewind feature for the RocksDB #1996
Changes from 40 commits
fea24a3
4c20273
5119dbe
4b3aecb
b06c622
61f1059
c5ec5bf
db90520
2b9eadc
c61477f
c3d6f66
29d543e
682d256
11d1d28
187ec91
ec86d61
22f6a63
46d0eca
19f7433
f642a4a
c9f4ca2
7ad0907
58c698e
e06ca6e
e6a02d6
d5b6535
0bf402b
ffc6481
97983c5
ccc0a2c
8513901
f4e8bbf
c733a48
eeb75ac
c43006a
f06508c
5bd9e44
0020b2f
af88cc9
4d56031
c466c13
ee634e7
2633cec
562171c
6885cb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use crate::cli::default_db_path; | ||
use anyhow::Context; | ||
use clap::Parser; | ||
use fuel_core::{ | ||
combined_database::CombinedDatabase, | ||
service::genesis::NotifyCancel, | ||
state::historical_rocksdb::StateRewindPolicy, | ||
}; | ||
use std::path::PathBuf; | ||
|
||
/// Rollbacks the state of the blockchain to a specific block height. | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct Command { | ||
/// The path to the database. | ||
#[clap( | ||
name = "DB_PATH", | ||
long = "db-path", | ||
value_parser, | ||
default_value = default_db_path().into_os_string() | ||
)] | ||
pub database_path: PathBuf, | ||
|
||
/// The path to the database. | ||
#[clap(long = "target-block-height")] | ||
pub target_block_height: u32, | ||
} | ||
|
||
pub async fn exec(command: Command) -> anyhow::Result<()> { | ||
use crate::cli::ShutdownListener; | ||
|
||
let path = command.database_path.as_path(); | ||
let db = CombinedDatabase::open( | ||
path, | ||
64 * 1024 * 1024, | ||
StateRewindPolicy::RewindFullRange, | ||
) | ||
.map_err(Into::<anyhow::Error>::into) | ||
.context(format!("failed to open combined database at path {path:?}"))?; | ||
|
||
let shutdown_listener = ShutdownListener::spawn(); | ||
let target_block_height = command.target_block_height.into(); | ||
|
||
while !shutdown_listener.is_cancelled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "While not
|
||
let on_chain_height = db | ||
.on_chain() | ||
.latest_height()? | ||
.ok_or(anyhow::anyhow!("on-chain database doesn't have height"))?; | ||
|
||
let off_chain_height = db | ||
.off_chain() | ||
.latest_height()? | ||
.ok_or(anyhow::anyhow!("on-chain database doesn't have height"))?; | ||
|
||
if on_chain_height == target_block_height | ||
&& off_chain_height == target_block_height | ||
{ | ||
break; | ||
} | ||
|
||
if off_chain_height == target_block_height | ||
&& on_chain_height < target_block_height | ||
{ | ||
return Err(anyhow::anyhow!( | ||
"on-chain database height is less than target height" | ||
)); | ||
} | ||
|
||
if on_chain_height == target_block_height | ||
&& off_chain_height < target_block_height | ||
{ | ||
return Err(anyhow::anyhow!( | ||
"off-chain database height is less than target height" | ||
)); | ||
} | ||
|
||
if on_chain_height > target_block_height { | ||
db.on_chain().rollback_last_block()?; | ||
tracing::info!( | ||
"Rolled back on-chain database to height {:?}", | ||
on_chain_height.pred() | ||
); | ||
} | ||
|
||
if off_chain_height > target_block_height { | ||
db.off_chain().rollback_last_block()?; | ||
tracing::info!( | ||
"Rolled back off-chain database to height {:?}", | ||
on_chain_height.pred() | ||
); | ||
} | ||
} | ||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ | |
# - `cargo install cargo-insta` | ||
# - `npm install prettier prettier-plugin-toml` | ||
|
||
npx prettier --check "**/Cargo.toml" && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we rename |
||
cargo +nightly fmt --all -- --check && | ||
npx prettier --write "**/Cargo.toml" && | ||
cargo +nightly fmt --all && | ||
cargo sort -w --check && | ||
source .github/workflows/scripts/verify_openssl.sh && | ||
cargo clippy -p fuel-core-wasm-executor --target wasm32-unknown-unknown --no-default-features && | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this might also have breaking changes, at least some
pub
fields were madepub(crate)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they were added since the last release, then it should be fine.