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: timeout for rpc server #1060

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
151 changes: 85 additions & 66 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/autorocks/autorocks-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn build_snappy() {

fn try_to_find_and_link_lib(lib_name: &str) -> bool {
println!("cargo:rerun-if-env-changed={}_COMPILE", lib_name);
if let Ok(v) = env::var(&format!("{}_COMPILE", lib_name)) {
if let Ok(v) = env::var(format!("{}_COMPILE", lib_name)) {
if v.to_lowercase() == "true" || v == "1" {
return false;
}
Expand All @@ -377,8 +377,8 @@ fn try_to_find_and_link_lib(lib_name: &str) -> bool {
println!("cargo:rerun-if-env-changed={}_LIB_DIR", lib_name);
println!("cargo:rerun-if-env-changed={}_STATIC", lib_name);

if let Ok(lib_dir) = env::var(&format!("{}_LIB_DIR", lib_name)) {
let mode = match env::var_os(&format!("{}_STATIC", lib_name)) {
if let Ok(lib_dir) = env::var(format!("{}_LIB_DIR", lib_name)) {
let mode = match env::var_os(format!("{}_STATIC", lib_name)) {
Some(_) => "static",
None => "dylib",
};
Expand Down
2 changes: 1 addition & 1 deletion crates/autorocks/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.63.0
1.68.2
4 changes: 2 additions & 2 deletions crates/benches/benches/benchmarks/smt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ impl BenchExecutionEnvironment {
let configs = vec![
BackendConfig {
generator: Resource::file_system(META_GENERATOR_PATH.into()),
generator_checksum: file_checksum(&META_GENERATOR_PATH).unwrap().into(),
generator_checksum: file_checksum(META_GENERATOR_PATH).unwrap().into(),
validator_script_type_hash: META_VALIDATOR_SCRIPT_TYPE_HASH.into(),
backend_type: gw_config::BackendType::Meta,
},
BackendConfig {
generator: Resource::file_system(SUDT_GENERATOR_PATH.into()),
generator_checksum: file_checksum(&SUDT_GENERATOR_PATH).unwrap().into(),
generator_checksum: file_checksum(SUDT_GENERATOR_PATH).unwrap().into(),
validator_script_type_hash: SUDT_VALIDATOR_SCRIPT_TYPE_HASH.into(),
backend_type: gw_config::BackendType::Sudt,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/benches/benches/benchmarks/sudt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ fn build_backend_manage(rollup_config: &RollupConfig) -> BackendManage {
let configs = vec![
BackendConfig {
generator: Resource::file_system(META_GENERATOR_PATH.into()),
generator_checksum: file_checksum(&META_GENERATOR_PATH).unwrap().into(),
generator_checksum: file_checksum(META_GENERATOR_PATH).unwrap().into(),
validator_script_type_hash: META_VALIDATOR_SCRIPT_TYPE_HASH.into(),
backend_type: gw_config::BackendType::Meta,
},
BackendConfig {
generator: Resource::file_system(SUDT_GENERATOR_PATH.into()),
generator_checksum: file_checksum(&SUDT_GENERATOR_PATH).unwrap().into(),
generator_checksum: file_checksum(SUDT_GENERATOR_PATH).unwrap().into(),
validator_script_type_hash: sudt_validator_script_type_hash.into(),
backend_type: gw_config::BackendType::Sudt,
},
Expand Down
2 changes: 0 additions & 2 deletions crates/block-producer/src/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ impl BlockProducer {
if input_len != witness_len {
// append dummy witness args to align our reverted deposit witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down Expand Up @@ -475,7 +474,6 @@ impl BlockProducer {
if input_len != witness_len {
// append dummy witness args to align our reverted withdrawal witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down
1 change: 0 additions & 1 deletion crates/block-producer/src/challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ impl Challenger {
if input_len != witness_len {
// append dummy witness args to align our reverted deposit witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/psc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ async fn submit_block(
global_state,
since,
withdrawal_extras,
local_cells_manager: &*local_cells_manager,
local_cells_manager: &local_cells_manager,
fee_rate,
};
let tx = ctx
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub async fn dump_transaction<P: AsRef<Path>>(dir: P, rpc_client: &RPCClient, tx
if let Err(err) = debugger::dump_transaction(dir, rpc_client, tx).await {
log::error!(
"Failed to dump transaction {} error: {}",
hex::encode(&tx.hash()),
hex::encode(tx.hash()),
err
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ impl Chain {

// check consistency of account SMT
let expected_account = match self.challenge_target {
Some(_) => (&db).get_last_valid_tip_block()?.raw().post_account(),
Some(_) => db.get_last_valid_tip_block()?.raw().post_account(),
None => self.local_state.tip.raw().post_account(),
};

Expand Down
11 changes: 3 additions & 8 deletions crates/challenge/src/cancel_challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,13 @@ impl CancelChallengeOutput {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Default)]
pub enum LoadDataStrategy {
#[default]
Witness,
CellDep,
}

impl Default for LoadDataStrategy {
fn default() -> Self {
LoadDataStrategy::Witness
}
}

#[allow(clippy::too_many_arguments)]
pub fn build_output(
rollup_context: &RollupContext,
Expand Down Expand Up @@ -192,7 +187,7 @@ pub fn build_output(
load_builtin.iter().map(to_dep).collect()
};

let load_data: Vec<Bytes> = load_data.into_iter().map(|(_, v)| v.unpack()).collect();
let load_data: Vec<Bytes> = load_data.into_values().map(|v| v.unpack()).collect();
let (witness, load_data_cells) = match load_data_strategy.unwrap_or_default() {
LoadDataStrategy::Witness => {
let witness = witness.as_builder().load_data(load_data.pack()).build();
Expand Down
2 changes: 1 addition & 1 deletion crates/challenge/src/offchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ fn dump_tx_to_file(
let dump = || -> Result<_> {
let debug_config = &validator_context.debug_config;
let dir = debug_config.debug_tx_dump_path.as_path();
create_dir_all(&dir)?;
create_dir_all(dir)?;

let mut dump_path = PathBuf::new();
dump_path.push(dir);
Expand Down
1 change: 0 additions & 1 deletion crates/challenge/src/offchain/mock_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ pub fn mock_cancel_challenge_tx(
if input_len != witness_len {
// append dummy witness args to align our reverted deposit witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down
22 changes: 6 additions & 16 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,15 @@ impl Default for MemBlockConfig {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum NodeMode {
FullNode,
Test,
#[default]
ReadOnly,
}

impl Default for NodeMode {
fn default() -> Self {
NodeMode::ReadOnly
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DBBlockValidatorConfig {
Expand Down Expand Up @@ -506,19 +501,14 @@ pub struct GithubConfigUrl {
pub token: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
pub enum ContractLogConfig {
#[default]
Verbose,
Error,
}

impl Default for ContractLogConfig {
fn default() -> Self {
ContractLogConfig::Verbose
}
}

// Cycles config for all db related syscalls
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct SyscallCyclesConfig {
Expand All @@ -539,8 +529,8 @@ pub struct SyscallCyclesConfig {
pub sys_revert_cycles: u64,
}

impl SyscallCyclesConfig {
pub fn default() -> Self {
impl Default for SyscallCyclesConfig {
fn default() -> Self {
SyscallCyclesConfig {
sys_store_cycles: 50000,
sys_load_cycles: 5000,
Expand Down
9 changes: 2 additions & 7 deletions crates/config/src/fork_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ use crate::constants::{
MAX_WITHDRAWAL_SIZE, MAX_WRITE_DATA_BYTES,
};

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum BackendType {
Meta,
Sudt,
Polyjuice,
EthAddrReg,
#[default]
Unknown,
}

impl Default for BackendType {
fn default() -> Self {
BackendType::Unknown
}
}

/// SUDT Proxy config
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
6 changes: 3 additions & 3 deletions crates/generator/src/account_lock_manage/eip712/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ pub trait EIP712Encode {
buf
};
let mut hasher = Keccak256::new();
hasher.update(&type_hash);
hasher.update(type_hash);
hasher.update(&encoded_data);
hasher.finalize().into()
}

fn eip712_message(&self, domain_separator: [u8; 32]) -> [u8; 32] {
let mut hasher = Keccak256::new();
hasher.update(b"\x19\x01");
hasher.update(&domain_separator);
hasher.update(&self.hash_struct());
hasher.update(domain_separator);
hasher.update(self.hash_struct());
hasher.finalize().into()
}
}
8 changes: 4 additions & 4 deletions crates/generator/src/backend_manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ mod tests {
let sudt_v1 = dir.join("sudt_v1");
let meta_v0 = dir.join("meta_v0");
let addr_v0 = dir.join("addr_v0");
std::fs::write(&sudt_v0, "sudt_v0").unwrap();
std::fs::write(&sudt_v1, "sudt_v1").unwrap();
std::fs::write(&meta_v0, "meta_v0").unwrap();
std::fs::write(&addr_v0, "addr_v0").unwrap();
std::fs::write(sudt_v0, "sudt_v0").unwrap();
std::fs::write(sudt_v1, "sudt_v1").unwrap();
std::fs::write(meta_v0, "meta_v0").unwrap();
std::fs::write(addr_v0, "addr_v0").unwrap();

let config = BackendForkConfig {
fork_height: 1,
Expand Down
4 changes: 1 addition & 3 deletions crates/generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl Generator {
log::warn!(
"skip the checkpoint check of block: #{} {}",
block_number,
hex::encode(&block_hash)
hex::encode(block_hash)
);
}
let max_cycles = self
Expand Down Expand Up @@ -891,15 +891,13 @@ impl Generator {
.lock()
.unwrap()
.keys()
.into_iter()
.cloned()
.collect(),
write_data_hashes: state_tracker
.write_data()
.lock()
.unwrap()
.keys()
.into_iter()
.cloned()
.collect(),
debug_log_buf: run_context.debug_log_buf,
Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn load_bytes<Mac: SupportMachine>(
addr: u64,
len: usize,
) -> Result<Vec<u8>, VMError> {
if len > MAX_BUF_SIZE as usize {
if len > MAX_BUF_SIZE {
return Err(VMError::MemOutOfBound);
}
let mut data = vec![0; len];
Expand Down
10 changes: 5 additions & 5 deletions crates/godwoken-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async fn run_cli() -> Result<()> {
match matches.subcommand() {
Some((COMMAND_RUN, m)) => {
let config_path = m.value_of(ARG_CONFIG).unwrap();
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init()?;
gw_metrics::init(&config);
runner::run(config, m.is_present(ARG_SKIP_CONFIG_CHECK)).await?;
Expand All @@ -229,15 +229,15 @@ async fn run_cli() -> Result<()> {
}
Some((COMMAND_VERIFY_DB_BLOCK, m)) => {
let config_path = m.value_of(ARG_CONFIG).unwrap();
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init()?;
let from_block: Option<u64> = m.value_of(ARG_FROM_BLOCK).map(str::parse).transpose()?;
let to_block: Option<u64> = m.value_of(ARG_TO_BLOCK).map(str::parse).transpose()?;
db_block_validator::verify(config, from_block, to_block).await?;
}
Some((COMMAND_EXPORT_BLOCK, m)) => {
let config_path = m.value_of(ARG_CONFIG).unwrap();
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init()?;
let output = m.value_of(ARG_OUTPUT_PATH).unwrap().into();
let from_block: Option<u64> = m.value_of(ARG_FROM_BLOCK).map(str::parse).transpose()?;
Expand All @@ -255,7 +255,7 @@ async fn run_cli() -> Result<()> {
}
Some((COMMAND_IMPORT_BLOCK, m)) => {
let config_path = m.value_of(ARG_CONFIG).unwrap();
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init()?;
let source = m.value_of(ARG_SOURCE_PATH).unwrap().into();
let read_batch: Option<usize> =
Expand Down Expand Up @@ -286,7 +286,7 @@ async fn run_cli() -> Result<()> {
_ => {
// default command: start a Godwoken node
let config_path = "./config.toml";
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init()?;
gw_metrics::init(&config);
runner::run(config, false).await?;
Expand Down
6 changes: 2 additions & 4 deletions crates/godwoken-bin/src/subcommand/db_block_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ impl DBBlockCancelChallengeValidator {
.into_par_iter()
.try_for_each(|block_number| self.verify_block(block_number))?;
} else {
(from_block..=to_block)
.into_iter()
.try_for_each(|block_number| self.verify_block(block_number))?;
(from_block..=to_block).try_for_each(|block_number| self.verify_block(block_number))?;
}

Ok(())
Expand Down Expand Up @@ -312,7 +310,7 @@ impl DBBlockCancelChallengeValidator {
let dump = || -> Result<_> {
let debug_config = &self.debug_config;
let dir = debug_config.debug_tx_dump_path.as_path();
create_dir_all(&dir)?;
create_dir_all(dir)?;

let mut dump_path = PathBuf::new();
dump_path.push(dir);
Expand Down
4 changes: 2 additions & 2 deletions crates/godwoken-bin/src/subcommand/import_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ImportBlock {

let progress_bar = if args.show_progress {
let metadata = fs::metadata(&args.source)?;
let bar = ProgressBar::new(metadata.len() as u64);
let bar = ProgressBar::new(metadata.len());
bar.set_style(
ProgressStyle::default_bar()
.template("[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}")
Expand Down Expand Up @@ -151,7 +151,7 @@ impl ImportBlock {
}

if let Some(ref progress_bar) = self.progress_bar {
progress_bar.inc(size as u64)
progress_bar.inc(size)
}
}

Expand Down
Loading