Skip to content

Commit

Permalink
Fo 1159 main (#772)
Browse files Browse the repository at this point in the history
* honor block_number in call rpc

* replace crate log with tracing

* add clean_aux()

fmerk update

* update logging and enable snapshot

* avoid overflow

* update storage version to v1.1.4

* rename trace/fresh options

Co-authored-by: simonjiao <[email protected]>
Co-authored-by: harry <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2023
1 parent 57d97f0 commit baa3665
Show file tree
Hide file tree
Showing 41 changed files with 253 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "src/bins/abcid.rs"
parking_lot = "0.12"
base64 = "0.12"
bincode = "1.3.1"
log = "0.4.8"
tracing = "0.1"
rand = "0.8"
rand_chacha = "0.2"
rand_core = { version = "0.5", default-features = false, features = ["alloc"] }
Expand Down
36 changes: 19 additions & 17 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use {
Arc,
},
},
tracing::info
};

#[cfg(feature = "web3_service")]
Expand Down Expand Up @@ -95,7 +96,7 @@ pub fn info(s: &mut ABCISubmissionServer, req: &RequestInfo) -> ResponseInfo {

drop(state);

log::info!(target: "abciapp", "======== Last committed height: {} ========", h);
info!(target: "abciapp", "======== Last committed height: {} ========", h);

if la.all_commited() {
la.begin_block();
Expand Down Expand Up @@ -242,7 +243,7 @@ pub fn deliver_tx(
if tx.valid_in_abci() {
// Log print for monitor purpose
if td_height < EVM_FIRST_BLOCK_HEIGHT {
log::info!(target: "abciapp",
info!(target: "abciapp",
"EVM transaction(FindoraTx) detected at early height {}: {:?}",
td_height, tx
);
Expand Down Expand Up @@ -271,7 +272,7 @@ pub fn deliver_tx(
if let Err(err) =
s.account_base_app.write().deliver_findora_tx(&tx)
{
log::info!(target: "abciapp", "deliver convert account tx failed: {:?}", err);
info!(target: "abciapp", "deliver convert account tx failed: {:?}", err);

resp.code = 1;
resp.log =
Expand Down Expand Up @@ -348,7 +349,7 @@ pub fn deliver_tx(
} else {
// Log print for monitor purpose
if td_height < EVM_FIRST_BLOCK_HEIGHT {
log::info!(
info!(
target:
"abciapp",
"EVM transaction(EvmTx) detected at early height {}: {:?}",
Expand Down Expand Up @@ -456,6 +457,7 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
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 {
Expand All @@ -466,28 +468,28 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
let nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() {
replace(&mut *nonce_map, HashMap::new())
} else {
log::error!("{}", "");
error!("{}", "");
Default::default()
};

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

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

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

Expand All @@ -500,14 +502,14 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
let txs = if let Ok(mut txs) = TXS.lock() {
replace(&mut *txs, vec![])
} else {
log::error!("{}", "");
error!("{}", "");
Default::default()
};

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

Expand All @@ -521,27 +523,27 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
{
setter
.set_height(height)
.map_err(|e| log::error!("{:?}", e))
.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| log::error!("{:?}", e))
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

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

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

Expand All @@ -553,14 +555,14 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
state.index.clone(),
state.value.clone(),
)
.map_err(|e| log::error!("{:?}", e))
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}

if let Some(block) = block {
setter
.set_block_info(block, receipts, txs)
.map_err(|e| log::error!("{:?}", e))
.map_err(|e| error!("{:?}", e))
.unwrap_or(());
}
}
Expand All @@ -578,7 +580,7 @@ fn app_hash(
mut la_hash: Vec<u8>,
mut cs_hash: Vec<u8>,
) -> Vec<u8> {
log::info!(target: "abciapp",
info!(target: "abciapp",
"app_hash_{}: {}_{}, height: {}",
when,
hex::encode(la_hash.clone()),
Expand Down
8 changes: 6 additions & 2 deletions src/components/abciapp/src/abci/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ impl ABCISubmissionServer {
None => {
pnk!(AccountBaseAPP::new(
tempfile::tempdir().unwrap().path(),
CFG.disable_eth_empty_blocks
CFG.disable_eth_empty_blocks,
CFG.arc_history,
CFG.arc_fresh
))
}
Some(basedir) => {
pnk!(AccountBaseAPP::new(
Path::new(basedir),
CFG.disable_eth_empty_blocks
CFG.disable_eth_empty_blocks,
CFG.arc_history,
CFG.arc_fresh
))
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use {
},
},
ledger_api::*,
log::info,
tracing::info,
parking_lot::RwLock,
ruc::*,
serde::{Deserialize, Serialize},
Expand Down
2 changes: 1 addition & 1 deletion src/components/abciapp/src/api/submission_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub enum TxCatalog {
pub fn try_tx_catalog(tx: &[u8], log: bool) -> TxCatalog {
// print tx
if log {
log::info!(target: "abciapp", "try_tx_catalog: {:?}", base64::encode(tx));
tracing::info!(target: "abciapp", "try_tx_catalog: {:?}", base64::encode(tx));
}

let len = EVM_TX_TAG.len();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
actix_web::{error, middleware, web, App, HttpServer},
finutils::api::NetworkRoute,
ledger::data_model::Transaction,
log::info,
tracing::info,
parking_lot::RwLock,
rand_core::{CryptoRng, RngCore},
ruc::*,
Expand Down
2 changes: 1 addition & 1 deletion src/components/abciapp/src/bins/abcid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {

fn main() {
globutils::logging::init_logging(None);
log::info!(concat!(
tracing::info!(target: "abciapp", concat!(
"Build: ",
env!("VERGEN_SHA"),
" ",
Expand Down
12 changes: 11 additions & 1 deletion src/components/abciapp/src/bins/findorad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ fn node_command() -> Result<()> {
.checkpoint_file
.clone()
.unwrap_or_else(|| String::from("./checkpoint.toml"));
let arc_history_arg = {
if let Some(interval) = CFG.arc_history.1 {
format!("{},{}", CFG.arc_history.0, interval)
} else {
format!("{}", CFG.arc_history.0)
}
};

abcid
.arg("--submission-service-port")
Expand All @@ -60,7 +67,9 @@ fn node_command() -> Result<()> {
.arg("--checkpoint-file")
.arg(&checkpoint_file)
.arg("--ledger-dir")
.arg(&CFG.ledger_dir);
.arg(&CFG.ledger_dir)
.arg("--arc-history")
.arg(&arc_history_arg);

for (condition, action) in [
(CFG.enable_query_service, "--enable-query-service"),
Expand All @@ -69,6 +78,7 @@ fn node_command() -> Result<()> {
(CFG.enable_snapshot, "--enable-snapshot"),
(CFG.snapshot_list, "--snapshot-list"),
(CFG.snapshot_rollback, "--snapshot-rollback"),
(CFG.arc_fresh, "--arc-fresh"),
] {
if condition {
abcid.arg(action);
Expand Down
39 changes: 39 additions & 0 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ pub mod global_cfg {
pub struct Config {
pub abci_host: String,
pub abci_port: u16,
pub arc_history: (u16, Option<u16>),
pub arc_fresh: bool,
pub tendermint_host: String,
pub tendermint_port: u16,
pub submission_service_port: u16,
Expand Down Expand Up @@ -321,6 +323,8 @@ 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("--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]")
.arg_from_usage("--tendermint-port=[Tendermint Port]")
.arg_from_usage("--submission-service-port=[Submission Service Port]")
Expand Down Expand Up @@ -364,6 +368,39 @@ pub mod global_cfg {
.unwrap_or_else(|| "26658".to_owned())
.parse::<u16>()
.c(d!())?;
let arh = {
let trace = m
.value_of("arc-history")
.map(|v| v.to_owned())
.or_else(|| env::var("ARC_HISTORY").ok())
.unwrap_or_else(|| "90,10".to_string())
.trim()
.to_owned();
if trace.is_empty() {
return Err(eg!("empty trace"));
}
if trace.contains(',') {
let t = trace.split(',').collect::<Vec<_>>();
let trace = t
.first()
.expect("missing trace period")
.parse::<u16>()
.c(d!("invalid trace period"))?;
let interval = Some(
t.get(1)
.expect("missing trace interval")
.parse::<u16>()
.c(d!("invalid trace interval"))?,
);
(trace, interval)
} else if !trace.is_empty() {
let trace = trace.parse::<u16>().c(d!("invalid trace period"))?;
(trace, None)
} else {
return Err(eg!("invalid trace"));
}
};
let arf = m.is_present("arc-fresh");
let th = m
.value_of("tendermint-host")
.map(|v| v.to_owned())
Expand Down Expand Up @@ -434,6 +471,8 @@ pub mod global_cfg {
let res = Config {
abci_host: ah,
abci_port: ap,
arc_history: arh,
arc_fresh: arf,
tendermint_host: th,
tendermint_port: tp,
submission_service_port: ssp,
Expand Down
39 changes: 39 additions & 0 deletions src/components/config/src/findora/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ pub mod config {
pub struct Config {
pub tendermint_host: String,
pub tendermint_port: u16,
pub arc_history: (u16, Option<u16>),
pub arc_fresh: bool,
pub submission_service_port: u16,
pub ledger_service_port: u16,
pub enable_query_service: bool,
Expand Down Expand Up @@ -182,6 +184,8 @@ pub mod config {
let node = SubCommand::with_name("node")
.about("Start findora node.")
.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'")
.arg_from_usage("-H, --tendermint-host=[Tendermint Node IP]")
.arg_from_usage("-P, --tendermint-port=[Tendermint Node Port]")
.arg_from_usage("--submission-service-port=[Submission Service Port]")
Expand Down Expand Up @@ -276,6 +280,39 @@ pub mod config {
.unwrap_or_else(|| "26657".to_owned())
.parse::<u16>()
.c(d!())?;
let arh = {
let trace = m
.value_of("arc-history")
.map(|v| v.to_owned())
.or_else(|| env::var("ARC_HISTORY").ok())
.unwrap_or_else(|| "90,10".to_string())
.trim()
.to_owned();
if trace.is_empty() {
return Err(eg!("empty trace"));
}
if trace.contains(',') {
let t = trace.split(',').collect::<Vec<_>>();
let trace = t
.first()
.expect("missing trace period")
.parse::<u16>()
.c(d!("invalid trace period"))?;
let interval = Some(
t.get(1)
.expect("missing trace interval")
.parse::<u16>()
.c(d!("invalid trace interval"))?,
);
(trace, interval)
} else if !trace.is_empty() {
let trace = trace.parse::<u16>().c(d!("invalid trace period"))?;
(trace, None)
} else {
return Err(eg!("invalid trace"));
}
};
let arf = m.is_present("arc-fresh");
let ssp = m
.value_of("submission-service-port")
.map(|v| v.to_owned())
Expand Down Expand Up @@ -336,6 +373,8 @@ pub mod config {
let res = Config {
tendermint_host: th,
tendermint_port: tp,
arc_history: arh,
arc_fresh: arf,
submission_service_port: ssp,
ledger_service_port: lsp,
enable_query_service: eqs,
Expand Down
Loading

0 comments on commit baa3665

Please sign in to comment.