Skip to content

Commit

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

* add clean_aux()

fmerk update

* enable snapshot

* update storage version

* rename trace/fresh options

* update noah version

* fix build error

---------

Co-authored-by: simonjiao <[email protected]>
Co-authored-by: harry <[email protected]>
  • Loading branch information
3 people committed Feb 7, 2023
1 parent c2b27c5 commit b602137
Show file tree
Hide file tree
Showing 29 changed files with 237 additions and 117 deletions.
4 changes: 2 additions & 2 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] }
module-evm = { path = "../contracts/modules/evm"}
ethereum-types = { version = "0.13.1", default-features = false }

noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }

abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" }
config = { path = "../config"}
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
3 changes: 1 addition & 2 deletions src/components/abciapp/src/bins/abcid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use {

fn main() {
globutils::logging::init_logging(None);

tracing::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 @@ -49,6 +49,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 @@ -58,7 +65,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 @@ -67,6 +76,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 @@ -318,6 +318,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 @@ -351,6 +353,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 @@ -394,6 +398,39 @@ pub mod global_cfg {
.unwrap_or_else(|| "26658".to_owned())
.parse::<u16>()
.c(d!("Invalid `abcid-port`."))?;
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 @@ -465,6 +502,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
4 changes: 2 additions & 2 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ serde_json = "1.0.40"
attohttpc = { version = "0.18", default-features = false, features = ["compress", "json", "tls-rustls"] }
base64 = "0.13"
once_cell = "1.10.0"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
sha3 = "0.8"

config = { path = "../../config"}
Expand Down
44 changes: 29 additions & 15 deletions src/components/contracts/baseapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,21 @@ use parking_lot::RwLock;
use primitive_types::{H160, H256, U256};
use ruc::{eg, Result};
use std::{borrow::BorrowMut, path::Path, sync::Arc};
use storage::state::ChainState;
use storage::state::{ChainState, ChainStateOpts};
use tracing::info;

lazy_static! {
/// An identifier that distinguishes different EVM chains.
static ref EVM_CAHIN_ID: u64 = std::env::var("EVM_CHAIN_ID").map(
|id| id.as_str().parse::<u64>().unwrap()).unwrap_or(2152);

static ref CHAIN_STATE_MIN_VERSIONS: u64 = BLOCKS_IN_DAY * std::env::var("CHAIN_STATE_VERSIONS").map(
|ver|ver.as_str().parse::<u64>().expect("chainstate versions should be a valid integer")
).unwrap_or(90);
}

const APP_NAME: &str = "findora";
const CHAIN_STATE_PATH: &str = "state.db";
const CHAIN_HISTORY_DATA_PATH: &str = "history.db";
const BLOCKS_IN_DAY: u64 = 4 * 60 * 24;
const SNAPSHOT_INTERVAL: u64 = 10 * 24;

#[derive(Clone)]
pub struct BaseApp {
Expand Down Expand Up @@ -161,22 +160,33 @@ impl module_xhub::Config for BaseApp {
}

impl BaseApp {
pub fn new(basedir: &Path, empty_block: bool) -> Result<Self> {
tracing::info!(
"create new baseapp with basedir {:?}, empty_block {}, history {} blocks",
basedir,
empty_block,
*CHAIN_STATE_MIN_VERSIONS
pub fn new(
basedir: &Path,
empty_block: bool,
arc_history: (u16, Option<u16>),
is_fresh: bool,
) -> Result<Self> {
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 = FinDB::open(fdb_path.as_path())?;
let chain_state = Arc::new(RwLock::new(ChainState::new(
fdb,
"findora_db".to_owned(),
*CHAIN_STATE_MIN_VERSIONS,
)));

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)));

let rdb_path = basedir.join(CHAIN_HISTORY_DATA_PATH);
let rdb = RocksDB::open(rdb_path.as_path())?;
Expand Down Expand Up @@ -298,6 +308,10 @@ impl BaseApp {
}
}

pub fn create_context_at(&self, height: u64) -> Option<Context> {
self.check_state.state_at(height)
}

/// retrieve the context for the txBytes and other memoized values.
pub fn retrieve_context(&mut self, mode: RunTxMode) -> &mut Context {
let ctx = if mode == RunTxMode::Deliver {
Expand Down
10 changes: 5 additions & 5 deletions src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }

# primitives, don't depend on any modules
fp-core = { path = "../../primitives/core" }
Expand All @@ -28,9 +28,9 @@ config = {path = "../../../config"}
[dev-dependencies]
parking_lot = "0.12"
rand_chacha = "0.3"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }

[features]
web3_service = ["enterprise-web3"]
web3_service = ["enterprise-web3"]
4 changes: 2 additions & 2 deletions src/components/contracts/modules/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ enterprise-web3 = { path = "../../primitives/enterprise-web3", optional = true
baseapp = { path = "../../baseapp" }
fp-mocks = { path = "../../primitives/mocks" }
module-account = { path = "../account" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }

[features]
default = []
Expand Down
10 changes: 5 additions & 5 deletions src/components/contracts/modules/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ serde_json = "1.0.64"
sha3 = { version = "0.10", default-features = false }
hex = "0.4.2"
ethabi = "17.1.0"
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }

# primitives, don't depend on any modules
fp-core = { path = "../../primitives/core" }
Expand All @@ -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.0.0" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
ledger = { path = "../../../../ledger" }
enterprise-web3 = { path = "../../primitives/enterprise-web3", optional = true }

Expand All @@ -49,4 +49,4 @@ module-ethereum = { path = "../ethereum" }
serde_json = "1.0.64"

[features]
web3_service = ["enterprise-web3"]
web3_service = ["enterprise-web3"]
4 changes: 2 additions & 2 deletions src/components/contracts/modules/evm/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ evm-precompile-sha3fips = {path = "./sha3fips" }
evm-precompile-modexp = { path = "./modexp" }
evm-precompile-frc20 = { path = "./frc20" }
evm-precompile-eth-pairings = { path = "./eth-pairings" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" }
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
fp-core = { path = "../../../primitives/core" }
parking_lot = "0.12"
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
Loading

0 comments on commit b602137

Please sign in to comment.