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: support switch backend binaries by height #713

Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions crates/benches/benches/benchmarks/smt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use gw_common::{
state::State,
H256,
};
use gw_config::{BackendConfig, GenesisConfig, StoreConfig};
use gw_config::{BackendConfig, BackendSwitchConfig, GenesisConfig, StoreConfig};
use gw_db::{schema::COLUMNS, RocksDB};
use gw_generator::{
account_lock_manage::{always_success::AlwaysSuccess, AccountLockManage},
Expand Down Expand Up @@ -160,7 +160,11 @@ impl BenchExecutionEnvironment {
backend_type: gw_config::BackendType::Sudt,
},
];
BackendManage::from_config(configs).expect("bench backend")
BackendManage::from_config(vec![BackendSwitchConfig {
switch_height: 0,
backends: configs,
}])
.expect("bench backend")
};

let account_lock_manage = {
Expand Down
8 changes: 6 additions & 2 deletions crates/benches/benches/benchmarks/sudt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use criterion::*;
use gw_common::{
builtins::ETH_REGISTRY_ACCOUNT_ID, registry_address::RegistryAddress, state::State, H256,
};
use gw_config::BackendConfig;
use gw_config::{BackendConfig, BackendSwitchConfig};
use gw_generator::{
account_lock_manage::AccountLockManage, backend_manage::BackendManage,
constants::L2TX_MAX_CYCLES, dummy_state::DummyState, error::TransactionError, traits::StateExt,
Expand Down Expand Up @@ -47,7 +47,11 @@ fn build_backend_manage(rollup_config: &RollupConfig) -> BackendManage {
backend_type: gw_config::BackendType::Sudt,
},
];
BackendManage::from_config(configs).expect("default backend")
BackendManage::from_config(vec![BackendSwitchConfig {
switch_height: 0,
backends: configs,
}])
.expect("default backend")
}

struct DummyChainStore;
Expand Down
7 changes: 5 additions & 2 deletions crates/block-producer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ static GLOBAL_ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
use anyhow::{Context, Result};
use clap::{App, Arg, SubCommand};
use gw_block_producer::{db_block_validator, runner, trace};
use gw_config::Config;
use gw_config::{BackendSwitchConfig, Config};
use gw_version::Version;
use std::{env, fs, path::Path};

Expand All @@ -27,7 +27,10 @@ fn read_config<P: AsRef<Path>>(path: P) -> Result<Config> {

fn generate_example_config<P: AsRef<Path>>(path: P) -> Result<()> {
let mut config = Config::default();
config.backends.push(Default::default());
config.backend_switches.push(BackendSwitchConfig {
switch_height: 0,
backends: Default::default(),
});
config.block_producer = Some(Default::default());
let content = toml::to_string_pretty(&config)?;
fs::write(path, content)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl BaseInitComponents {
}
let rollup_config_hash: H256 = rollup_config.hash().into();
let generator = {
let backend_manage = BackendManage::from_config(config.backends.clone())
let backend_manage = BackendManage::from_config(config.backend_switches.clone())
.with_context(|| "config backends")?;
let mut account_lock_manage = AccountLockManage::default();
let allowed_eoa_type_hashes = rollup_config.as_reader().allowed_eoa_type_hashes();
Expand Down
8 changes: 7 additions & 1 deletion crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Trace {
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Config {
pub node_mode: NodeMode,
pub backends: Vec<BackendConfig>,
pub backend_switches: Vec<BackendSwitchConfig>,
pub genesis: GenesisConfig,
pub chain: ChainConfig,
pub rpc_client: RPCClientConfig,
Expand Down Expand Up @@ -196,6 +196,12 @@ impl Default for BackendType {
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BackendSwitchConfig {
pub switch_height: u64,
pub backends: Vec<BackendConfig>,
}

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct BackendConfig {
pub validator_path: PathBuf,
Expand Down
1 change: 1 addition & 0 deletions crates/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ tracing = { version = "0.1", features = ["attributes"] }

[dev-dependencies]
gw-utils = {path = "../utils" }
tempfile = "3"
Loading