diff --git a/src/components/abciapp/src/abci/mod.rs b/src/components/abciapp/src/abci/mod.rs index 507078bd1..03e49dc9b 100644 --- a/src/components/abciapp/src/abci/mod.rs +++ b/src/components/abciapp/src/abci/mod.rs @@ -59,6 +59,7 @@ pub fn run() -> Result<()> { let app = server::ABCISubmissionServer::new( basedir, format!("{}:{}", config.tendermint_host, config.tendermint_port), + CFG.enable_eth_api_service, )?; if CFG.enable_query_service { @@ -87,7 +88,7 @@ pub fn run() -> Result<()> { } if CFG.enable_eth_api_service { - let base_app = app.account_base_app.clone(); + let base_app = app.eth_api_base_app.clone().c(d!())?; let evm_http = format!("{}:{}", config.abci_host, config.evm_http_port); let evm_ws = format!("{}:{}", config.abci_host, config.evm_ws_port); let tendermint_rpc = format!( diff --git a/src/components/abciapp/src/abci/server/callback/mod.rs b/src/components/abciapp/src/abci/server/callback/mod.rs index 4a9153377..38ef77556 100644 --- a/src/components/abciapp/src/abci/server/callback/mod.rs +++ b/src/components/abciapp/src/abci/server/callback/mod.rs @@ -613,6 +613,9 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm } IN_SAFE_ITV.store(false, Ordering::Release); + if let Some(eth_api_base_app) = &s.eth_api_base_app { + pnk!(eth_api_base_app.write().secondary_catch_up_primary()); + } if CFG.enable_enterprise_web3 && td_height as u64 > *WEB3_SERVICE_START_HEIGHT { let height = td_height as u32; diff --git a/src/components/abciapp/src/abci/server/mod.rs b/src/components/abciapp/src/abci/server/mod.rs index aa66ce218..cfbe32570 100644 --- a/src/components/abciapp/src/abci/server/mod.rs +++ b/src/components/abciapp/src/abci/server/mod.rs @@ -37,6 +37,7 @@ pub mod tx_sender; pub struct ABCISubmissionServer { pub la: Arc>>, pub account_base_app: Arc>, + pub eth_api_base_app: Option>>, } impl ABCISubmissionServer { @@ -44,6 +45,7 @@ impl ABCISubmissionServer { pub fn new( basedir: Option<&str>, tendermint_reply: String, + enable_eth_api_service: bool, ) -> Result { let ledger_state = match basedir { None => LedgerState::tmp_ledger(), @@ -71,6 +73,30 @@ impl ABCISubmissionServer { } }; let account_base_app = Arc::new(RwLock::new(account_base_app)); + let eth_api_base_app = if enable_eth_api_service { + let eth_api_base_app = Arc::new(RwLock::new(match basedir { + None => { + pnk!(AccountBaseAPP::new_with_secondary( + tempfile::tempdir().unwrap().path(), + CFG.disable_eth_empty_blocks, + CFG.arc_history, + CFG.arc_fresh + )) + } + Some(basedir) => { + pnk!(AccountBaseAPP::new_with_secondary( + Path::new(basedir), + CFG.disable_eth_empty_blocks, + CFG.arc_history, + CFG.arc_fresh + )) + } + })); + Some(eth_api_base_app) + } else { + None + }; + if EVM_STAKING.set(account_base_app.clone()).is_err() { return Err(eg!("Invalid usage.")); } @@ -85,6 +111,7 @@ impl ABCISubmissionServer { .c(d!())?, )), account_base_app, + eth_api_base_app, }) } } diff --git a/src/components/contracts/baseapp/Cargo.toml b/src/components/contracts/baseapp/Cargo.toml index 5a2598c54..a8b54a94a 100644 --- a/src/components/contracts/baseapp/Cargo.toml +++ b/src/components/contracts/baseapp/Cargo.toml @@ -22,8 +22,8 @@ protobuf = "2.16" ruc = "1.0" serde = {version = "1.0.124", features = ["derive"]} serde_json = "1.0.40" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } sha3 = "0.8" zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" } diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index b8d23ad02..a9385d934 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -53,6 +53,8 @@ lazy_static! { const APP_NAME: &str = "findora"; const CHAIN_STATE_PATH: &str = "state.db"; const CHAIN_HISTORY_DATA_PATH: &str = "history.db"; +const CHAIN_STATE_SECONDARY_PATH: &str = "state_secondary.db"; +const CHAIN_HISTORY_SECONDARY_DATA_PATH: &str = "history_secondary.db"; const BLOCKS_IN_DAY: u64 = 4 * 60 * 24; const SNAPSHOT_INTERVAL: u64 = 10 * 24; @@ -205,12 +207,17 @@ impl BaseApp { BLOCKS_IN_DAY * v as u64 }), }; - let chain_state = Arc::new(RwLock::new(ChainState::create_with_opts(fdb, opts))); + let chain_state = + Arc::new(RwLock::new(ChainState::create_with_opts(fdb, opts, false))); let rdb_path = basedir.join(CHAIN_HISTORY_DATA_PATH); let rdb = RocksDB::open(rdb_path.as_path())?; - let chain_db = - Arc::new(RwLock::new(ChainState::new(rdb, "rocks_db".to_owned(), 0))); + let chain_db = Arc::new(RwLock::new(ChainState::new( + rdb, + "rocks_db".to_owned(), + 0, + false, + ))); //Migrate any existing data from one database to the other. BaseApp::migrate_initial_db(chain_state.clone(), chain_db.clone())?; @@ -230,7 +237,76 @@ impl BaseApp { event_notify: Arc::new(Notifications::new()), }) } + pub fn new_with_secondary( + basedir: &Path, + empty_block: bool, + arc_history: (u16, Option), + is_fresh: bool, + ) -> Result { + info!( + target: "baseapp", + "create new baseapp with basedir {:?}, empty_block {}, trace history {:?} days, is_fresh {}", + basedir, empty_block, arc_history, is_fresh + ); + + // Creates a fresh chain state db and history db + let fdb_path = basedir.join(CHAIN_STATE_PATH); + let fdb_secondary_path = basedir.join(CHAIN_STATE_SECONDARY_PATH); + let fdb = + FinDB::open_as_secondary(fdb_path.as_path(), fdb_secondary_path.as_path())?; + + let opts = ChainStateOpts { + name: Some("findora_db".to_owned()), + ver_window: BLOCKS_IN_DAY * arc_history.0 as u64, + cleanup_aux: is_fresh, + interval: arc_history + .1 + .map_or(SNAPSHOT_INTERVAL * arc_history.0 as u64, |v| { + BLOCKS_IN_DAY * v as u64 + }), + }; + let chain_state = + Arc::new(RwLock::new(ChainState::create_with_opts(fdb, opts, true))); + let rdb_path = basedir.join(CHAIN_HISTORY_DATA_PATH); + let rdb_secondary_path = basedir.join(CHAIN_HISTORY_SECONDARY_DATA_PATH); + let rdb = RocksDB::open_as_secondary( + rdb_path.as_path(), + rdb_secondary_path.as_path(), + )?; + + let chain_db = Arc::new(RwLock::new(ChainState::new( + rdb, + "rocks_db".to_owned(), + 0, + true, + ))); + + Ok(BaseApp { + name: APP_NAME.to_string(), + version: "1.0.0".to_string(), + app_version: 1, + chain_state: chain_state.clone(), + chain_db: chain_db.clone(), + check_state: Context::new(chain_state.clone(), chain_db.clone()), + deliver_state: Context::new(chain_state, chain_db), + modules: ModuleManager { + ethereum_module: module_ethereum::App::::new(empty_block), + ..Default::default() + }, + event_notify: Arc::new(Notifications::new()), + }) + } + pub fn secondary_catch_up_primary(&self) -> Result<()> { + self.chain_state + .read() + .secondary_catch_up_primary() + .map_err(|e| eg!("chain_state secondary_catch_up_primary fail:{}", e))?; + self.chain_db + .read() + .secondary_catch_up_primary() + .map_err(|e| eg!("chain_db secondary_catch_up_primary fail:{}", e)) + } pub fn derive_app(&self) -> Self { let chain_state = self.chain_state.clone(); let chain_db = self.chain_db.clone(); diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index 5fedd1cad..25c32db4e 100644 --- a/src/components/contracts/modules/account/Cargo.toml +++ b/src/components/contracts/modules/account/Cargo.toml @@ -15,7 +15,7 @@ primitive-types = { version = "0.11.1", default-features = false, features = ["r ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.64" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } @@ -29,4 +29,4 @@ config = { path = "../../../config"} rand_chacha = "0.2" parking_lot = "0.12" zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } diff --git a/src/components/contracts/modules/account/src/tests.rs b/src/components/contracts/modules/account/src/tests.rs index aa07f72f4..1883edf6c 100644 --- a/src/components/contracts/modules/account/src/tests.rs +++ b/src/components/contracts/modules/account/src/tests.rs @@ -26,6 +26,7 @@ fn setup() -> Context { fdb, "temp_db".to_string(), 100, + false, ))); let mut rocks_path = temp_dir(); @@ -36,6 +37,7 @@ fn setup() -> Context { rdb, "temp_rocks_db".to_string(), 0, + false, ))); Context::new(chain_state, chain_db) diff --git a/src/components/contracts/modules/ethereum/Cargo.toml b/src/components/contracts/modules/ethereum/Cargo.toml index c40e523aa..81a303392 100644 --- a/src/components/contracts/modules/ethereum/Cargo.toml +++ b/src/components/contracts/modules/ethereum/Cargo.toml @@ -37,8 +37,8 @@ enterprise-web3 = { path = "../../primitives/enterprise-web3" } baseapp = { path = "../../baseapp" } fp-mocks = { path = "../../primitives/mocks" } module-account = { path = "../account" } -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } [features] default = [] diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs index 75cd17f48..3bf5ad39d 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs @@ -23,6 +23,7 @@ fn setup() -> Context { fdb, "temp_db".to_string(), 100, + false, ))); let mut rocks_path = temp_dir(); @@ -33,6 +34,7 @@ fn setup() -> Context { rdb, "temp_rocks_db".to_string(), 0, + false, ))); Context::new(chain_state, chain_db) diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index 4f57c3c6e..9e09a61de 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -35,8 +35,8 @@ fp-traits = { path = "../../primitives/traits" } fp-types = { path = "../../primitives/types" } fp-utils = { path = "../../primitives/utils" } config = { path = "../../../config"} -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } ledger = { path = "../../../../ledger" } enterprise-web3 = { path = "../../primitives/enterprise-web3" } module-ethereum = { path = "../ethereum" } diff --git a/src/components/contracts/primitives/core/Cargo.toml b/src/components/contracts/primitives/core/Cargo.toml index e265036a7..30a1ec64c 100644 --- a/src/components/contracts/primitives/core/Cargo.toml +++ b/src/components/contracts/primitives/core/Cargo.toml @@ -16,8 +16,8 @@ parking_lot = "0.12" primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5", optional = true } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5", optional = true } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7", optional = true } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7", optional = true } serde_with = { version = "1.9.4"} # primitives diff --git a/src/components/contracts/primitives/storage/Cargo.toml b/src/components/contracts/primitives/storage/Cargo.toml index bab9bfc4c..5aeaa646d 100644 --- a/src/components/contracts/primitives/storage/Cargo.toml +++ b/src/components/contracts/primitives/storage/Cargo.toml @@ -15,11 +15,11 @@ ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" sha2 = "0.9.5" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } # primitives fp-core = { path = "../core" } config = { path = "../../../config"} [dev-dependencies] -temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.7" } diff --git a/src/components/contracts/primitives/storage/src/tests.rs b/src/components/contracts/primitives/storage/src/tests.rs index f8d306079..1c8d84875 100644 --- a/src/components/contracts/primitives/storage/src/tests.rs +++ b/src/components/contracts/primitives/storage/src/tests.rs @@ -18,6 +18,7 @@ fn setup_temp_db() -> Arc>> { fdb, "temp_db".to_string(), 100, + false, ))); Arc::new(RwLock::new(State::new(chain_state, true))) }