From 322787b160c95cc3b9e42fab0f1469f6ddf11875 Mon Sep 17 00:00:00 2001 From: shaorongqiang <26101255+shaorongqiang@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:00:11 +0800 Subject: [PATCH] remove web3 feature (#947) * remove web3 feature * clean Makefile * fix lint --- Makefile | 25 ---- container/Dockerfile-enterprise-web3 | 52 -------- .../abciapp/src/abci/server/callback/mod.rs | 6 - src/components/contracts/baseapp/src/app.rs | 60 +++------ .../modules/evm/src/runtime/stack.rs | 118 ++++++++---------- 5 files changed, 72 insertions(+), 189 deletions(-) delete mode 100644 container/Dockerfile-enterprise-web3 diff --git a/Makefile b/Makefile index 127010b16..fee913886 100644 --- a/Makefile +++ b/Makefile @@ -90,10 +90,6 @@ build_release_debug: tendermint_goleveldb cargo build --features="debug_env" --release --bins -p abciapp -p finutils $(call pack,release) -build_release_web3: tendermint_cleveldb - cargo build --features="web3_service debug_env" --release --bins -p abciapp -p finutils - $(call pack,release) - build_bench_release: tendermint_goleveldb cargo build --features="debug_env benchmark" --release --bins -p abciapp -p finutils $(call pack,release) @@ -320,27 +316,6 @@ ci_build_image_dockerhub_arm: @ docker run --rm --privileged tonistiigi/binfmt:latest --install all @ docker buildx build --platform linux/arm64/v8 -t $(DOCKERHUB_URL)/findorad:$(IMAGE_TAG) -f container/Dockerfile-goleveldb-arm . --push - -# ========================== build RPC node=========================== - -build_release_web3_goleveldb: tendermint_goleveldb - cargo build --features="web3_service debug_env" --release --bins -p abciapp -p finutils - $(call pack,release) - -ci_build_release_web3_binary_image: - sed -i "s/^ENV VERGEN_SHA_EXTERN .*/ENV VERGEN_SHA_EXTERN ${VERGEN_SHA_EXTERN}/g" container/Dockerfile-enterprise-web3 - docker build -t findorad-binary-image:$(IMAGE_TAG) -f container/Dockerfile-enterprise-web3 . - -ci_build_image_web3: - @ if [ -d "./binary" ]; then \ - rm -rf ./binary || true; \ - fi - @ docker run --rm -d --name findorad-binary findorad-binary-image:$(IMAGE_TAG) - @ docker cp findorad-binary:/binary ./binary - @ docker rm -f findorad-binary - @ docker build -t $(PUBLIC_ECR_URL)/$(ENV)/findorad:$(IMAGE_TAG) -f container/Dockerfile-goleveldb . - - # ========================== push image and clean up=========================== ci_push_image: diff --git a/container/Dockerfile-enterprise-web3 b/container/Dockerfile-enterprise-web3 deleted file mode 100644 index 76210e632..000000000 --- a/container/Dockerfile-enterprise-web3 +++ /dev/null @@ -1,52 +0,0 @@ -FROM binary-rust-base -ENV WORK_DIR /platform -ENV WASM_DIR /tmp/wasm-js-bindings -ENV VERGEN_SHA_EXTERN web3_service_build -ENV PATH=$PATH:/root/.cargo/bin/ -ENV REDIS_ADDR=redis://127.0.0.1 - -COPY . $WORK_DIR -WORKDIR $WORK_DIR - -RUN rustup toolchain install stable && \ - rustup component add clippy --toolchain stable && \ - rustup component add rustfmt - -RUN mkdir /binary -RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb - -RUN make fmt -RUN make lint -RUN make test - -# RUN mkdir -p /root/.cargo/bin/ && \ -# make build_release_web3 && \ -# if [ -d /platform/release/bin ] ; then mv /platform/release/bin/* /binary/cleveldb ; rm -rf /platform/release/; else mv /platform/debug/bin/* /binary/cleveldb ; rm -rf /platform/debug/ ;fi - -RUN mkdir -p /root/.cargo/bin/ && \ - make build_release_web3_goleveldb && \ - if [ -d /platform/release/bin ] ; then mv /platform/release/bin/* /binary/goleveldb ; rm -rf /platform/release/; else mv /platform/debug/bin/* /binary/goleveldb ; rm -rf /platform/debug/ ;fi - -# Rosetta -ENV GOLANG_VERSION 1.16.8 -ENV GOLANG_DOWNLOAD_SHA256 f32501aeb8b7b723bc7215f6c373abb6981bbc7e1c7b44e9f07317e1a300dce2 -ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz - -RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ - && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ - && tar -C /usr/local -xzf golang.tar.gz \ - && rm golang.tar.gz - -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH -RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" - -RUN update-ca-certificates - -RUN git clone https://github.com/FindoraNetwork/findora-rosetta.git \ - && cd findora-rosetta \ - && go get \ - && go build \ - && cp findora-rosetta /binary/ - -CMD ["sleep", "999999"] \ No newline at end of file diff --git a/src/components/abciapp/src/abci/server/callback/mod.rs b/src/components/abciapp/src/abci/server/callback/mod.rs index d0747bcf2..0cbcec7d6 100644 --- a/src/components/abciapp/src/abci/server/callback/mod.rs +++ b/src/components/abciapp/src/abci/server/callback/mod.rs @@ -549,28 +549,24 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm let nonce_map = if let Ok(mut nonce_map) = NONCE_MAP.lock() { take(&mut *nonce_map) } 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 balance_map = if let Ok(mut balance_map) = BALANCE_MAP.lock() { take(&mut *balance_map) } else { - error!("{}", ""); Default::default() }; let state_list = if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() { take(&mut *state_list) } else { - error!("{}", ""); Default::default() }; @@ -583,14 +579,12 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm 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() }; diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index ecf2d53d4..e810172f2 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -1,6 +1,10 @@ use crate::extensions::SignedExtra; use abci::*; use config::abci::global_cfg::CFG; +use enterprise_web3::{ + Setter, PENDING_CODE_MAP, PENDING_STATE_UPDATE_LIST, REDIS_CLIENT, + REMOVE_PENDING_CODE_MAP, REMOVE_PENDING_STATE_UPDATE_LIST, +}; use fp_core::context::RunTxMode; use fp_evm::BlockId; use fp_types::{ @@ -10,8 +14,8 @@ use fp_utils::tx::EvmRawTxWrapper; use module_evm::utils::{deposit_asset_event_topic_str, parse_deposit_asset_event}; use primitive_types::U256; use ruc::*; +use std::{mem::take, ops::DerefMut}; use tracing::{debug, error, info}; - impl crate::BaseApp { /// info implements the ABCI interface. /// - Returns chain info (las height and hash where the node left off) @@ -78,43 +82,33 @@ impl crate::BaseApp { }; if let Ok(tx) = convert_unchecked_transaction::(raw_tx) { - #[cfg(feature = "enterprise-web3")] - let tmp_tx = tx.clone(); let check_fn = |mode: RunTxMode| { let ctx = { let mut ctx = self.check_state.clone(); ctx.run_mode = mode; ctx }; - let result = self.modules.process_tx::(ctx, tx); + let result = self.modules.process_tx::(ctx, tx.clone()); match result { Ok(ar) => { - #[cfg(feature = "enterprise-web3")] - { - use enterprise_web3::{ - Setter, PENDING_CODE_MAP, PENDING_STATE_UPDATE_LIST, - REDIS_CLIENT, - }; - use std::{collections::HashMap, mem::replace}; + if CFG.enable_enterprise_web3 { let code_map = if let Ok(mut code_map) = PENDING_CODE_MAP.lock() { - replace(&mut *code_map, HashMap::new()) + take(&mut *code_map) } else { - error!("{}", ""); Default::default() }; let state_list = if let Ok(mut state_list) = PENDING_STATE_UPDATE_LIST.lock() { - replace(&mut *state_list, vec![]) + take(&mut *state_list) } else { - error!("{}", ""); Default::default() }; if 0 == ar.code { if let fp_types::actions::Action::Ethereum( fp_types::actions::ethereum::Action::Transact(tx), - ) = tmp_tx.function + ) = tx.function { let redis_pool = REDIS_CLIENT.lock().expect("REDIS_CLIENT error"); @@ -136,9 +130,9 @@ impl crate::BaseApp { for state in state_list.iter() { setter .set_pending_state( - state.address.clone(), - state.index.clone(), - state.value.clone(), + state.address, + state.index, + state.value, ) .map_err(|e| error!("{e:?}")) .unwrap_or(()); @@ -220,41 +214,30 @@ impl crate::BaseApp { if let Ok(tx) = convert_unchecked_transaction::(raw_tx) { let ctx = self.retrieve_context(RunTxMode::Deliver).clone(); - #[cfg(feature = "enterprise-web3")] - let tmp_tx = tx.clone(); - let ret = self.modules.process_tx::(ctx, tx); + + let ret = self.modules.process_tx::(ctx, tx.clone()); match ret { Ok(ar) => { - #[cfg(feature = "enterprise-web3")] - { - use enterprise_web3::{ - Setter, REDIS_CLIENT, REMOVE_PENDING_CODE_MAP, - REMOVE_PENDING_STATE_UPDATE_LIST, - }; - use std::{mem::replace, ops::DerefMut}; + if CFG.enable_enterprise_web3 { let code_map = if let Ok(mut code_map) = REMOVE_PENDING_CODE_MAP.lock() { let m = code_map.deref_mut(); - let map = replace(m, vec![]); - map.clone() + take(m) } else { - error!("{}", ""); Default::default() }; let state_list = if let Ok(mut state_list) = REMOVE_PENDING_STATE_UPDATE_LIST.lock() { let v = state_list.deref_mut(); - let v2 = replace(v, vec![]); - v2.clone() + take(v) } else { - error!("{}", ""); Default::default() }; if 0 == ar.code { if let fp_types::actions::Action::Ethereum( fp_types::actions::ethereum::Action::Transact(tx), - ) = tmp_tx.function + ) = tx.function { let redis_pool = REDIS_CLIENT.lock().expect("REDIS_CLIENT error"); @@ -277,10 +260,7 @@ impl crate::BaseApp { for (address, index) in state_list.iter() { setter - .remove_pending_state( - address.clone(), - index.clone(), - ) + .remove_pending_state(*address, *index) .map_err(|e| error!("{:?}", e)) .unwrap_or(()); } diff --git a/src/components/contracts/modules/evm/src/runtime/stack.rs b/src/components/contracts/modules/evm/src/runtime/stack.rs index 0a6de5546..70e25dbed 100644 --- a/src/components/contracts/modules/evm/src/runtime/stack.rs +++ b/src/components/contracts/modules/evm/src/runtime/stack.rs @@ -1,5 +1,10 @@ use crate::{storage::*, AddressMapping, App, Config}; use config::abci::global_cfg::CFG; +use enterprise_web3::{ + State as Web3State, CODE_MAP, NONCE_MAP, PENDING_CODE_MAP, + PENDING_STATE_UPDATE_LIST, REMOVE_PENDING_CODE_MAP, + REMOVE_PENDING_STATE_UPDATE_LIST, STATE_UPDATE_LIST, WEB3_SERVICE_START_HEIGHT, +}; use ethereum_types::{H160, H256, U256}; use evm::{ backend::Backend, @@ -7,6 +12,7 @@ use evm::{ ExitError, Transfer, }; use fin_db::FinDB; +use fp_core::context::RunTxMode; use fp_core::{context::Context, macros::Get}; use fp_evm::{Log, Vicinity}; use fp_storage::{BorrowMut, DerefMut}; @@ -18,7 +24,6 @@ use fp_utils::timestamp_converter; use std::{collections::btree_set::BTreeSet, marker::PhantomData, mem}; use storage::state::State; use tracing::{debug, error, info}; - pub struct FindoraStackSubstate<'context, 'config> { pub ctx: &'context Context, pub metadata: StackSubstateMetadata<'config>, @@ -312,14 +317,12 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> let account_id = C::AddressMapping::convert_to_account_id(address); let _nonce = C::AccountAsset::inc_nonce(self.ctx, &account_id); - #[cfg(feature = "enterprise-web3")] + if CFG.enable_enterprise_web3 + && self.ctx.header.height as u64 > *WEB3_SERVICE_START_HEIGHT { - use enterprise_web3::{NONCE_MAP, WEB3_SERVICE_START_HEIGHT}; - if self.ctx.header.height as u64 > *WEB3_SERVICE_START_HEIGHT { - let mut nonce_map = NONCE_MAP.lock().expect("get nonce map error"); - if let Ok(nonce) = _nonce { - nonce_map.insert(address, nonce); - } + let mut nonce_map = NONCE_MAP.lock().expect("get nonce map error"); + if let Ok(nonce) = _nonce { + nonce_map.insert(address, nonce); } } } @@ -362,46 +365,40 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> } } - #[cfg(feature = "enterprise-web3")] + if CFG.enable_enterprise_web3 + && self.ctx.header.height as u64 > *WEB3_SERVICE_START_HEIGHT { - use enterprise_web3::{ - State, PENDING_STATE_UPDATE_LIST, REMOVE_PENDING_STATE_UPDATE_LIST, - STATE_UPDATE_LIST, WEB3_SERVICE_START_HEIGHT, - }; - use fp_core::context::RunTxMode; - if self.ctx.header.height as u64 > *WEB3_SERVICE_START_HEIGHT { - if RunTxMode::Deliver == self.ctx.run_mode { - let mut remove_pending_state_list = REMOVE_PENDING_STATE_UPDATE_LIST - .lock() - .expect("get code map fail"); - remove_pending_state_list.push((address, index)); - - if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() { - state_list.push(State { - height: self.ctx.header.height as u32, - address, - index, - value, - }); - } else { - error!( - target: "evm", - "Failed push state update to STATE_UPDATE_LIST for {:?} [index: {:?}, value: {:?}]", - address, - index, - value, - ) - } - } else { - let mut state_list = - PENDING_STATE_UPDATE_LIST.lock().expect("get code map fail"); - state_list.push(State { - height: 0, + if RunTxMode::Deliver == self.ctx.run_mode { + let mut remove_pending_state_list = REMOVE_PENDING_STATE_UPDATE_LIST + .lock() + .expect("get code map fail"); + remove_pending_state_list.push((address, index)); + + if let Ok(mut state_list) = STATE_UPDATE_LIST.lock() { + state_list.push(Web3State { + height: self.ctx.header.height as u32, address, index, value, }); + } else { + error!( + target: "evm", + "Failed push state update to STATE_UPDATE_LIST for {:?} [index: {:?}, value: {:?}]", + address, + index, + value, + ) } + } else { + let mut state_list = + PENDING_STATE_UPDATE_LIST.lock().expect("get code map fail"); + state_list.push(Web3State { + height: 0, + address, + index, + value, + }); } } } @@ -434,10 +431,8 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> code_len, address ); - #[cfg(feature = "enterprise-web3")] - let code_clone = code.clone(); - let result = App::::create_account(self.ctx, address.into(), code); + let result = App::::create_account(self.ctx, address.into(), code.clone()); if let Err(e) = result { error!( @@ -447,27 +442,18 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> address, e ); - } else { - #[cfg(feature = "enterprise-web3")] - { - use enterprise_web3::{ - CODE_MAP, PENDING_CODE_MAP, REMOVE_PENDING_CODE_MAP, - WEB3_SERVICE_START_HEIGHT, - }; - use fp_core::context::RunTxMode; - if self.ctx.header.height as u64 > *WEB3_SERVICE_START_HEIGHT { - if RunTxMode::Deliver == self.ctx.run_mode { - let mut code_map = CODE_MAP.lock().expect("get code map fail"); - code_map.insert(address, code_clone.clone()); - let mut remove_pending_code_map = - REMOVE_PENDING_CODE_MAP.lock().expect("get code map fail"); - remove_pending_code_map.push(address); - } else { - let mut code_map = - PENDING_CODE_MAP.lock().expect("get code map fail"); - code_map.insert(address, code_clone); - } - } + } else if CFG.enable_enterprise_web3 + && self.ctx.header.height as u64 > *WEB3_SERVICE_START_HEIGHT + { + if RunTxMode::Deliver == self.ctx.run_mode { + let mut code_map = CODE_MAP.lock().expect("get code map fail"); + code_map.insert(address, code); + let mut remove_pending_code_map = + REMOVE_PENDING_CODE_MAP.lock().expect("get code map fail"); + remove_pending_code_map.push(address); + } else { + let mut code_map = PENDING_CODE_MAP.lock().expect("get code map fail"); + code_map.insert(address, code); } } }