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

feat: export and import block #754

Merged
merged 21 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0466c49
feat(block-producer): import/export blocks
zeroqn Jul 1, 2022
7f258f1
perf(export-block): molecule encode
zeroqn Jul 4, 2022
792d1de
feat(export-block): append rollup script hash and block range to fname
zeroqn Jul 4, 2022
e0625d9
feat(export-block): support export block from readonly database
zeroqn Jul 5, 2022
8b63603
refactor(import-block): skip to new block
zeroqn Jul 5, 2022
79cb1ed
feat(import-block): read blocks in background
zeroqn Jul 5, 2022
ee62c4b
feat(import-block): add to block argument
zeroqn Jul 5, 2022
bb97fd9
refactor(import-block): use peek_block func instead
zeroqn Jul 6, 2022
07b1460
fix(export-block): no tip bad block check
zeroqn Jul 6, 2022
b8b9aeb
feat(export-block): support get reverted block hashes from readonly db
zeroqn Jul 6, 2022
11a7109
fix(import-block): no block import if to is none
zeroqn Jul 6, 2022
fa71b65
fix(import-block): process_block result isn't checked
zeroqn Jul 6, 2022
717c2d7
test: export and import block
zeroqn Jul 6, 2022
85d2760
feat(export/import): add long name to args
zeroqn Jul 6, 2022
7bed239
feat(import-block): add rewind to last valid tip arg
zeroqn Jul 6, 2022
b1b9ce2
doc: add export import block subcommand
zeroqn Jul 6, 2022
d3fb6ae
fix(export_block): no error on corrupted block size header
zeroqn Jul 11, 2022
68595a7
fix(export_block): reverted block hashes iter out of order
zeroqn Jul 11, 2022
30ddb0d
refactor(block-producer): extract main.rs to godwoken-bin crate
zeroqn Jul 11, 2022
2779903
refactor(block-producer): move db_block_validator to godwoken-bin
zeroqn Jul 11, 2022
59f7848
refactor(store): get_reverted_block_hashes func return sig
zeroqn Jul 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 78 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"crates/dynamic-config",
"crates/p2p-network",
"crates/polyjuice-sender-recover",
"crates/godwoken-bin",
]

[profile.release]
Expand Down
18 changes: 0 additions & 18 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ version = "1.3.0"
authors = ["Nervos Network"]
edition = "2021"

[lib]
path = "src/lib.rs"

[[bin]]
name = "godwoken"
path = "src/main.rs"

[dependencies]
gw-challenge = { path = "../challenge" }
gw-common = { path = "../common" }
Expand All @@ -25,20 +18,17 @@ gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-rpc-server = { path = "../rpc-server" }
gw-rpc-client = { path = "../rpc-client" }
gw-utils = { path = "../utils" }
gw-version = { path = "../version" }
gw-ckb-hardfork = { path = "../ckb-hardfork" }
gw-dynamic-config = { path = "../dynamic-config"}
gw-polyjuice-sender-recover = { path = "../polyjuice-sender-recover" }
ckb-crypto = "0.100.0"
ckb-fixed-hash = "0.100.0"
ckb-types = "0.100.0"
ckb-chain-spec = "0.100.0"
toml = "0.5"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
async-channel = "1.4.2"
async-jsonrpc-client = { version = "0.3.0", default-features = false, features = ["http-tokio"] }
clap = "2.33.3"
futures = "0.3.13"
log = "0.4.14"
serde_json = "1.0"
Expand All @@ -48,7 +38,6 @@ openssl = { version = "0.10", features = ["vendored"] }
hex = "0.4"
async-trait = "0.1"
semver = "1.0"
rayon = "1.5"
thiserror = "1.0"
# For latest tracing
sentry = { git = "https://github.com/getsentry/sentry-rust", rev = "df694a49595d6890c510d80b85cfbb4b5ae6159a" }
Expand All @@ -63,10 +52,3 @@ tokio-metrics = "0.1.0"
console-subscriber = "0.1.3"
tentacle = "0.4.0"
gw-p2p-network = { path = "../p2p-network" }
num_cpus = "1.13.1"

[target.'cfg(all(not(target_env = "msvc"), not(target_os="macos")))'.dependencies]
tikv-jemallocator = { version = "0.4.0", features = ["unprefixed_malloc_on_supported_platforms"] }

[features]
profiling = ["tikv-jemallocator/profiling"]
1 change: 0 additions & 1 deletion crates/block-producer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod block_producer;
pub mod challenger;
pub mod cleaner;
pub mod custodian;
pub mod db_block_validator;
pub mod debugger;
pub mod deposit;
pub mod poller;
Expand Down
8 changes: 6 additions & 2 deletions crates/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,15 @@ impl Chain {
assert_eq!(local_slice, submit_slice);

// Revert bad blocks
let prev_reverted_block_root = db.get_reverted_block_smt_root()?;
db.revert_bad_blocks(&local_reverted_blocks)?;
log::debug!("bad blocks reverted");

let reverted_block_hashes =
local_reverted_blocks.iter().map(|b| b.hash().into());
db.set_reverted_block_hashes(
&db.get_reverted_block_smt_root()?,
prev_reverted_block_root,
reverted_block_hashes.collect(),
)?;

Expand Down Expand Up @@ -703,7 +705,8 @@ impl Chain {

let reverted_block_hashes = db
.get_reverted_block_hashes_by_root(&current_reverted_block_root)?
.expect("reverted block hashes should exists");
.expect("reverted block hashes should exists")
.block_hashes;

db.rewind_reverted_block_smt(reverted_block_hashes)?;
current_reverted_block_root = db.get_reverted_block_smt_root()?;
Expand Down Expand Up @@ -768,7 +771,8 @@ impl Chain {

let reverted_block_hashes = db
.get_reverted_block_hashes_by_root(&current_reverted_block_root)?
.expect("reverted block hashes should exists");
.expect("reverted block hashes should exists")
.block_hashes;

db.rewind_reverted_block_smt(reverted_block_hashes)?;
current_reverted_block_root = db.get_reverted_block_smt_root()?;
Expand Down
14 changes: 14 additions & 0 deletions crates/db/src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! TODO(doc): @quake
use crate::db::cf_handle;
use crate::read_only_db::ReadOnlyDB;
use crate::schema::Col;
use crate::{
internal_error, Result, RocksDB, RocksDBSnapshot, RocksDBTransaction,
RocksDBTransactionSnapshot,
};
use rocksdb::ops::GetColumnFamilys;
use rocksdb::{ops::IterateCF, ReadOptions};
pub use rocksdb::{DBIterator as DBIter, Direction, IteratorMode};

Expand Down Expand Up @@ -57,3 +59,15 @@ impl DBIterator for RocksDBSnapshot {
.map_err(internal_error)
}
}

impl DBIterator for ReadOnlyDB {
fn iter_opt(&self, col: Col, mode: IteratorMode, readopts: &ReadOptions) -> Result<DBIter> {
let cf = self
.inner
.cf_handle(&col.to_string())
.ok_or_else(|| internal_error(format!("column {} not found", col)))?;
self.inner
.iterator_cf_opt(cf, mode, readopts)
.map_err(internal_error)
}
}
1 change: 1 addition & 0 deletions crates/db/src/read_only_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::Path;
use std::sync::Arc;

/// ReadOnlyDB wrapper
#[derive(Clone)]
pub struct ReadOnlyDB {
pub(crate) inner: Arc<RawReadOnlyDB>,
}
Expand Down
44 changes: 44 additions & 0 deletions crates/godwoken-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "godwoken-bin"
version = "1.3.0"
authors = ["Nervos Network"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0"
ckb-types = "0.100.0"
clap = "2.33.3"
indicatif = "0.16"
gw-block-producer = { path = "../block-producer" }
gw-chain = { path = "../chain" }
gw-challenge = { path = "../challenge" }
gw-common = { path = "../common" }
gw-config = { path = "../config" }
gw-db = { path = "../db" }
gw-generator = { path = "../generator" }
gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-store = { path = "../store" }
gw-types = { path = "../types" }
gw-utils = { path = "../utils" }
gw-version = { path = "../version" }
log = "0.4.14"
num_cpus = "1.13.1"
rayon = "1.5"
serde_json = "1.0"
tokio = { version = "1.17", features = ["full", "tracing"] }
toml = "0.5"

[target.'cfg(all(not(target_env = "msvc"), not(target_os="macos")))'.dependencies]
tikv-jemallocator = { version = "0.4.0", features = ["unprefixed_malloc_on_supported_platforms"] }

[features]
profiling = ["tikv-jemallocator/profiling"]

[lib]
path = "src/lib.rs"

[[bin]]
name = "godwoken"
path = "src/main.rs"
1 change: 1 addition & 0 deletions crates/godwoken-bin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod subcommand;
Loading