Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evm staking init data. #731

Open
wants to merge 6 commits into
base: feat-evm-staking
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ members = [
"src/components/contracts/primitives/rpc-server",
"src/components/contracts/primitives/utils",
"src/components/contracts/primitives/wasm",
"src/components/contracts/primitives/enterprise-web3",
"src/components/contracts/rpc",
]

Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ build_release_debug: tendermint_goleveldb
cargo build --features debug_env --release --bins -p abciapp -p finutils
$(call pack,release)

build_release_web3_goleveldb: tendermint_goleveldb
cargo build --features="web3_service 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)

tendermint_cleveldb:
bash tools/download_tendermint.sh 'tools/tendermint'
mkdir -p $(shell go env GOPATH)/bin
Expand Down
30 changes: 30 additions & 0 deletions container/Dockerfile-enterprise-web3
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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

CMD ["sleep", "999999"]
6 changes: 5 additions & 1 deletion src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ fc-rpc = { path = "../contracts/rpc" }
fp-storage = { path = "../contracts/primitives/storage" }
fp-utils = { path = "../contracts/primitives/utils" }


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


[target.'cfg(target_os= "linux")'.dependencies]
btm = "0.1.6"

Expand All @@ -72,4 +76,4 @@ vergen = "=3.1.0"
default = ["diskcache"]
diskcache = ["ledger/diskcache"]
debug_env = ["ledger/debug_env", "config/debug_env"]

web3_service = ["enterprise-web3", "baseapp/web3_service"]
118 changes: 118 additions & 0 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,124 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
}

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

#[cfg(feature = "web3_service")]
{
use enterprise_web3::{
BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS, STATE_UPDATE_LIST, TXS,
WEB3_SERVICE_START_HEIGHT,
};
use std::collections::HashMap;
use std::mem::replace;

let height = state.get_tendermint_height() as u32;
if height as u64 > *WEB3_SERVICE_START_HEIGHT {
let mut setter = enterprise_web3::setter().expect("connection redis failed");

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

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

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

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

let block = if let Ok(mut block) = BLOCK.lock() {
block.take()
} else {
None
};

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

let receipts = if let Ok(mut receipts) = RECEIPTS.lock() {
replace(&mut *receipts, vec![])
} else {
tracing::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| tracing::error!("{:?}", e))
.unwrap_or(());

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

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

for (addr, balance) in balance_map.iter() {
setter
.set_balance(height, *addr, *balance)
.map_err(|e| tracing::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| tracing::error!("{:?}", e))
.unwrap_or(());
}

if let Some(block) = block {
setter
.set_block_info(block, receipts, txs)
.map_err(|e| tracing::error!("{:?}", e))
.unwrap_or(());
}
}
}
}

r
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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" }
sha3 = "0.8"

config = { path = "../../config"}

Expand All @@ -36,6 +37,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 }

# modules
module-account = {path = "../modules/account"}
Expand All @@ -54,3 +56,4 @@ evm-precompile = {path = "../modules/evm/precompile"}

[features]
abci_mock = []
web3_service = ["enterprise-web3", "module-account/web3_service", "module-ethereum/web3_service", "module-evm/web3_service"]
113 changes: 112 additions & 1 deletion src/components/contracts/baseapp/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ impl crate::BaseApp {
};

if let Ok(tx) = convert_unchecked_transaction::<SignedExtra>(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();
Expand All @@ -83,6 +85,57 @@ impl crate::BaseApp {
let result = self.modules.process_tx::<SignedExtra>(ctx, tx);
match result {
Ok(ar) => {
#[cfg(feature = "enterprise-web3")]
{
use enterprise_web3::{
PENDING_CODE_MAP, PENDING_STATE_UPDATE_LIST,
};
use std::{collections::HashMap, mem::replace};
let code_map =
if let Ok(mut code_map) = PENDING_CODE_MAP.lock() {
replace(&mut *code_map, HashMap::new())
} else {
tracing::error!("{}", "");
Default::default()
};
let state_list = if let Ok(mut state_list) =
PENDING_STATE_UPDATE_LIST.lock()
{
replace(&mut *state_list, vec![])
} else {
tracing::error!("{}", "");
Default::default()
};
if 0 == ar.code {
if let fp_types::actions::Action::Ethereum(
fp_types::actions::ethereum::Action::Transact(tx),
) = tmp_tx.function
{
let mut setter = enterprise_web3::setter()
.expect("connection redis failed");
setter
.set_pending_tx(tx)
.map_err(|e| tracing::error!("{:?}", e))
.unwrap_or(());
for (addr, code) in code_map.iter() {
setter
.set_pending_code(*addr, code.clone())
.map_err(|e| tracing::error!("{:?}", e))
.unwrap_or(());
}
for state in state_list.iter() {
setter
.set_pending_state(
state.address.clone(),
state.index.clone(),
state.value.clone(),
)
.map_err(|e| tracing::error!("{:?}", e))
.unwrap_or(());
}
}
}
}
resp.code = ar.code;
if ar.code != 0 {
info!(target: "baseapp", "Transaction check error, action result {:?}", ar);
Expand Down Expand Up @@ -153,10 +206,68 @@ impl crate::BaseApp {

if let Ok(tx) = convert_unchecked_transaction::<SignedExtra>(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::<SignedExtra>(ctx, tx);
match ret {
Ok(ar) => {
#[cfg(feature = "enterprise-web3")]
{
use enterprise_web3::{
REMOVE_PENDING_CODE_MAP, REMOVE_PENDING_STATE_UPDATE_LIST,
};
use std::{mem::replace, ops::DerefMut};
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()
} else {
tracing::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()
} else {
tracing::error!("{}", "");
Default::default()
};
if 0 == ar.code {
if let fp_types::actions::Action::Ethereum(
fp_types::actions::ethereum::Action::Transact(tx),
) = tmp_tx.function
{
let mut setter = enterprise_web3::setter()
.expect("connection redis failed");
setter
.remove_pending_tx(tx)
.map_err(|e| tracing::error!("{:?}", e))
.unwrap_or(());

for addr in code_map.iter() {
setter
.remove_pending_code(*addr)
.map_err(|e| tracing::error!("{:?}", e))
.unwrap_or(());
}

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

if ar.code != 0 {
info!(target: "baseapp", "deliver tx with result: {:?}", ar);
} else {
Expand Down
Loading