Skip to content

Commit

Permalink
update enterprise_web3 feature to cli (#929)
Browse files Browse the repository at this point in the history
* update enterprise_web3 feature to cli

* fix lint

---------

Co-authored-by: shaorongqiang <[email protected]>
  • Loading branch information
shaorongqiang and shiran555 authored Apr 21, 2023
1 parent d497465 commit 0e2508d
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 217 deletions.
3 changes: 1 addition & 2 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fp-storage = { path = "../contracts/primitives/storage" }
fp-utils = { path = "../contracts/primitives/utils" }
fp-types = {path = "../contracts/primitives/types"}

enterprise-web3 = { path = "../contracts/primitives/enterprise-web3", optional = true }
enterprise-web3 = { path = "../contracts/primitives/enterprise-web3" }
module-evm = { path = "../contracts/modules/evm"}

[target.'cfg(target_os= "linux")'.dependencies]
Expand All @@ -74,5 +74,4 @@ vergen = "=3.1.0"
default = ["diskcache"]
diskcache = ["ledger/diskcache"]
debug_env = ["ledger/debug_env", "config/debug_env", "baseapp/debug_env"]
web3_service = ["enterprise-web3", "baseapp/web3_service"]
benchmark = ["baseapp/benchmark"]
201 changes: 94 additions & 107 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ use {
ResponseEndBlock, ResponseInfo, ResponseInitChain, ResponseQuery,
},
config::abci::global_cfg::CFG,
cryptohash::sha256,
enterprise_web3::{
Setter, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS, REDIS_CLIENT,
STATE_UPDATE_LIST, TXS, WEB3_SERVICE_START_HEIGHT,
},
fp_storage::hash::{Sha256, StorageHasher},
lazy_static::lazy_static,
ledger::{
Expand All @@ -35,19 +40,14 @@ use {
ruc::*,
std::{
fs,
mem::take,
ops::Deref,
sync::{
atomic::{AtomicI64, Ordering},
Arc,
},
},
tracing::info,
};

use cryptohash::sha256;
#[cfg(feature = "web3_service")]
use enterprise_web3::{
BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS, STATE_UPDATE_LIST, TXS,
tracing::{error, info},
};

pub(crate) static TENDERMINT_BLOCK_HEIGHT: AtomicI64 = AtomicI64::new(0);
Expand Down Expand Up @@ -537,119 +537,106 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm

IN_SAFE_ITV.store(false, Ordering::Release);

#[cfg(feature = "web3_service")]
{
use enterprise_web3::{Setter, REDIS_CLIENT, WEB3_SERVICE_START_HEIGHT};
use std::collections::HashMap;
use std::mem::replace;
use tracing::error;

let height = state.get_tendermint_height() as u32;
if height as u64 > *WEB3_SERVICE_START_HEIGHT {
let redis_pool = REDIS_CLIENT.lock().expect("REDIS_CLIENT error");
let mut conn = redis_pool.get().expect("get redis connect");
let mut setter = Setter::new(&mut *conn, "evm".to_string());

let nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() {
replace(&mut *nonce_map, HashMap::new())
} else {
error!("{}", "");
Default::default()
};
if CFG.enable_enterprise_web3 && td_height as u64 > *WEB3_SERVICE_START_HEIGHT {
let height = td_height as u32;
let redis_pool = REDIS_CLIENT.lock().expect("REDIS_CLIENT error");
let mut conn = redis_pool.get().expect("get redis connect");
let mut setter = Setter::new(&mut *conn, "evm".to_string());

let code_map = if let Ok(mut code_map) = CODE_MAP.lock() {
replace(&mut *code_map, HashMap::new())
} else {
error!("{}", "");
Default::default()
};
let nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() {
take(&mut *nonce_map)
} else {
error!("{}", "");
Default::default()
};

let balance_map = if let Ok(mut balance_map) = BALANCE_MAP.lock() {
replace(&mut *balance_map, HashMap::new())
} else {
error!("{}", "");
Default::default()
};
let code_map = if let Ok(mut code_map) = CODE_MAP.lock() {
take(&mut *code_map)
} else {
error!("{}", "");
Default::default()
};

let state_list = if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() {
replace(&mut *state_list, vec![])
} else {
error!("{}", "");
Default::default()
};
let balance_map = if let Ok(mut balance_map) = BALANCE_MAP.lock() {
take(&mut *balance_map)
} else {
error!("{}", "");
Default::default()
};

let block = if let Ok(mut block) = BLOCK.lock() {
block.take()
} else {
None
};
let state_list = if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() {
take(&mut *state_list)
} else {
error!("{}", "");
Default::default()
};

let txs = if let Ok(mut txs) = TXS.lock() {
replace(&mut *txs, vec![])
} else {
error!("{}", "");
Default::default()
};
let block = if let Ok(mut block) = BLOCK.lock() {
block.take()
} else {
None
};

let receipts = if let Ok(mut receipts) = RECEIPTS.lock() {
replace(&mut *receipts, vec![])
} else {
error!("{}", "");
Default::default()
};

if !code_map.is_empty()
|| !nonce_map.is_empty()
|| !balance_map.is_empty()
|| !state_list.is_empty()
|| !txs.is_empty()
|| !receipts.is_empty()
|| block.is_some()
{
let txs = if let Ok(mut txs) = TXS.lock() {
take(&mut *txs)
} else {
error!("{}", "");
Default::default()
};

let receipts = if let Ok(mut receipts) = RECEIPTS.lock() {
take(&mut *receipts)
} else {
error!("{}", "");
Default::default()
};

if !code_map.is_empty()
|| !nonce_map.is_empty()
|| !balance_map.is_empty()
|| !state_list.is_empty()
|| !txs.is_empty()
|| !receipts.is_empty()
|| block.is_some()
{
setter
.set_height(height)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());

for (addr, code) in code_map.iter() {
setter
.set_height(height)
.set_byte_code(height, *addr, code.clone())
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

for (addr, code) in code_map.iter() {
setter
.set_byte_code(height, *addr, code.clone())
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

for (addr, nonce) in nonce_map.iter() {
setter
.set_nonce(height, *addr, *nonce)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}
for (addr, nonce) in nonce_map.iter() {
setter
.set_nonce(height, *addr, *nonce)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

for (addr, balance) in balance_map.iter() {
setter
.set_balance(height, *addr, *balance)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}
for (addr, balance) in balance_map.iter() {
setter
.set_balance(height, *addr, *balance)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

for state in state_list.iter() {
setter
.set_state(
height,
state.address.clone(),
state.index.clone(),
state.value.clone(),
)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}
for state in state_list.iter() {
setter
.set_state(height, state.address, state.index, state.value)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

if let Some(block) = block {
setter
.set_block_info(block, receipts, txs)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}
if let Some(block) = block {
setter
.set_block_info(block, receipts, txs)
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/abciapp/src/bins/findorad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ fn node_command() -> Result<()> {
.arg("--arc-history")
.arg(&arc_history_arg);

if CFG.enable_enterprise_web3 {
abcid.arg("--enable-enterprise-web3");
}

for (condition, action) in [
(CFG.enable_query_service, "--enable-query-service"),
(CFG.enable_eth_api_service, "--enable-eth-api-service"),
Expand Down
4 changes: 4 additions & 0 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ pub mod global_cfg {
pub struct Config {
pub abci_host: String,
pub abci_port: u16,
pub enable_enterprise_web3: bool,
pub arc_history: (u16, Option<u16>),
pub arc_fresh: bool,
pub tendermint_host: String,
Expand Down Expand Up @@ -396,6 +397,7 @@ pub mod global_cfg {
.about("An ABCI node implementation of FindoraNetwork.")
.arg_from_usage("--abcid-host=[ABCId IP]")
.arg_from_usage("--abcid-port=[ABCId Port]")
.arg_from_usage("--enable-enterprise-web3 'enable enterprise-web3'")
.arg_from_usage("--arc-history=[EVM archive node tracing history, format \"PERIOD,INTERVAL\" in days]")
.arg_from_usage("--arc-fresh 'EVM archive node with fresh tracing history'")
.arg_from_usage("--tendermint-host=[Tendermint IP]")
Expand Down Expand Up @@ -441,6 +443,7 @@ pub mod global_cfg {
.unwrap_or_else(|| "26658".to_owned())
.parse::<u16>()
.c(d!())?;
let enable_enterprise_web3 = m.is_present("enable-enterprise-web3");
let arh = {
let trace = m
.value_of("arc-history")
Expand Down Expand Up @@ -544,6 +547,7 @@ pub mod global_cfg {
let res = Config {
abci_host: ah,
abci_port: ap,
enable_enterprise_web3,
arc_history: arh,
arc_fresh: arf,
tendermint_host: th,
Expand Down
5 changes: 5 additions & 0 deletions src/components/config/src/findora/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub mod config {

#[derive(Default)]
pub struct Config {
pub enable_enterprise_web3: bool,
pub tendermint_host: String,
pub tendermint_port: u16,
pub arc_history: (u16, Option<u16>),
Expand Down Expand Up @@ -183,6 +184,7 @@ pub mod config {
let matches = {
let node = SubCommand::with_name("node")
.about("Start findora node.")
.arg_from_usage("--enable-enterprise-web3 'enable enterprise-web3'")
.arg_from_usage("-c, --config=[FILE] 'Path to $TMHOM/config/config.toml'")
.arg_from_usage("--arc-history=[EVM archive node tracing history, format \"PERIOD,INTERVAL\" in days]")
.arg_from_usage("--arc-fresh 'EVM archive node with fresh tracing history'")
Expand Down Expand Up @@ -255,6 +257,8 @@ pub mod config {
return Err(eg!("no this command"));
};

let enable_enterprise_web3 = m.is_present("enable-enterprise-web3");

let tcfg = m
.value_of("config")
.map(|v| v.to_owned())
Expand Down Expand Up @@ -371,6 +375,7 @@ pub mod config {
};

let res = Config {
enable_enterprise_web3,
tendermint_host: th,
tendermint_port: tp,
arc_history: arh,
Expand Down
3 changes: 1 addition & 2 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fp-evm = {path = "../primitives/evm"}
fp-traits = {path = "../primitives/traits"}
fp-types = {path = "../primitives/types"}
fp-utils = {path = "../primitives/utils"}
enterprise-web3 = { path = "../primitives/enterprise-web3", optional = true }
enterprise-web3 = { path = "../primitives/enterprise-web3" }

# modules
module-account = {path = "../modules/account"}
Expand All @@ -51,6 +51,5 @@ evm-precompile-sha3fips = {path = "../modules/evm/precompile/sha3fips"}

[features]
abci_mock = []
web3_service = ["enterprise-web3", "module-account/web3_service", "module-ethereum/web3_service", "module-evm/web3_service"]
benchmark = ["module-evm/benchmark","module-ethereum/benchmark"]
debug_env = []
6 changes: 2 additions & 4 deletions src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ fp-core = { path = "../../primitives/core" }
fp-storage = { path = "../../primitives/storage" }
fp-traits = { path = "../../primitives/traits" }
fp-types = { path = "../../primitives/types" }
enterprise-web3 = { path = "../../primitives/enterprise-web3", optional = true }
enterprise-web3 = { path = "../../primitives/enterprise-web3" }
config = { path = "../../../config"}

[dev-dependencies]
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.4" }

[features]
web3_service = ["enterprise-web3"]
Loading

0 comments on commit 0e2508d

Please sign in to comment.