Skip to content

Commit

Permalink
Merge develop into main (#994)
Browse files Browse the repository at this point in the history
* Evm staking (#966)

* evm staking

* add EVM_SYSTEM_ADDR

* add getValidatorsLimit

* fix

* fix mint pay

* add max_gas_price_limit

* update api

* Judging the caller

* rm RPCNodeRelease.yml

* cliam add validator

* fix build

* update import

* fix decimals

* fix fn staker update

* fix claim

* parse MintOps

* parse CoinbaseMint

* fix clim

* add import_reward

* update gas_limit

* store trigger transaction

* fix evm init

* add transaction

* fix lint

* fix build wasm (#989)

* add system replace staker (#988)

* add systemReplaceDelegator

* add checkpoint

* claim remove amount

* fix max_gas_price

* update log

* Add new precompile (#986)

* add blake2f precompile

* add bn128 precompile

* delete add conflict precompile

* fix build

---------

Co-authored-by: harry <harry@findora.org>
Co-authored-by: shaorongqiang <shaorongqiang@gmail.com>

* fix macos fn path isuse (#990)

* add importCoinBase (#991)

* add importCoinBase

* update CoinbaseMint

* update abi

* fix build

* fix code

* fix clippy

* Lock rust version

* update docker file

* fix rust-toolchain

---------

Co-authored-by: shaorongqiang <26101255+shaorongqiang@users.noreply.github.com>
Co-authored-by: HarryLiIsMe <42673017+HarryLiIsMe@users.noreply.github.com>
Co-authored-by: harry <harry@findora.org>
Co-authored-by: shaorongqiang <shaorongqiang@gmail.com>
Co-authored-by: Jimmy Sun <75454104+jimmysun0815@users.noreply.github.com>
Co-authored-by: Ubuntu <ubuntu@ip-10-20-156-0.us-west-2.compute.internal>
  • Loading branch information
7 people authored Jul 28, 2023
1 parent a6a69da commit a4a157e
Show file tree
Hide file tree
Showing 60 changed files with 3,915 additions and 330 deletions.
92 changes: 0 additions & 92 deletions .github/workflows/RPCNodeRelease.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ members = [
"src/components/contracts/modules/evm/precompile/modexp",
"src/components/contracts/modules/evm/precompile/sha3fips",
"src/components/contracts/modules/evm/precompile/anemoi",
"src/components/contracts/modules/evm/precompile/blake2",
"src/components/contracts/modules/evm/precompile/bn128",
"src/components/contracts/modules/evm/precompile/utils",
"src/components/contracts/modules/evm/precompile/utils/macro",
"src/components/contracts/modules/xhub",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ build_musl_fn_macos_base:
build_musl_fn_macos:
docker build -t musl_fn_macos -f container/Dockerfile-fn-musl-macos .
docker run -d --rm --name fn_macos musl_fn_macos
docker cp fn_macos:/volume/target/x86_64-apple-darwin/release/fn fn
docker cp fn_macos:/platform/target/x86_64-apple-darwin/release/fn fn
tar -czvf fn_macos.tar.gz fn
rm fn

Expand Down
6 changes: 3 additions & 3 deletions container/Dockerfile-binary-image-dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ENV PATH=$PATH:/root/.cargo/bin/
COPY . $WORK_DIR
WORKDIR $WORK_DIR

RUN rustup toolchain install stable && \
rustup component add clippy --toolchain stable && \
rustup component add rustfmt
RUN rustup toolchain install 1.70 && \
rustup component add clippy --toolchain 1.70 && \
rustup component add rustfmt --toolchain 1.70

RUN mkdir /binary
RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb
Expand Down
8 changes: 4 additions & 4 deletions container/Dockerfile-binary-image-release
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ENV PATH=$PATH:/root/.cargo/bin/
COPY . $WORK_DIR
WORKDIR $WORK_DIR

RUN rustup toolchain install stable && \
rustup component add clippy --toolchain stable && \
rustup component add rustfmt
RUN rustup toolchain install 1.70 && \
rustup component add clippy --toolchain 1.70 && \
rustup component add rustfmt --toolchain 1.70

RUN mkdir /binary
RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb
Expand Down Expand Up @@ -48,4 +48,4 @@ RUN git clone https://github.com/FindoraNetwork/findora-rosetta.git \
&& go build \
&& cp findora-rosetta /binary/

CMD ["sleep", "999999"]
CMD ["sleep", "999999"]
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
stable
1.70
93 changes: 78 additions & 15 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
//! # Impl function of tendermint ABCI
//!

use globutils::wallet;
use ledger::{
data_model::ASSET_TYPE_FRA,
staking::{FF_ADDR_EXTRA_120_0000, FF_ADDR_LIST},
};
use zei::xfr::asset_record::AssetRecordType;

mod utils;

use {
Expand Down Expand Up @@ -29,7 +36,7 @@ use {
ledger::{
converter::is_convert_account,
data_model::Operation,
staking::KEEP_HIST,
staking::{evm::EVM_STAKING, KEEP_HIST, VALIDATOR_UPDATE_BLOCK_ITV},
store::{
api_cache,
fbnc::{new_mapx, Mapx},
Expand Down Expand Up @@ -470,6 +477,33 @@ pub fn end_block(

let mut la = s.la.write();

if header.height == CFG.checkpoint.evm_staking_inital_height {
let ledger_state = la.get_committed_state().read();
let staking = ledger_state.get_staking();
let validators = staking
.validator_get_current()
.map(|v| v.get_validators().values().cloned().collect::<Vec<_>>())
.unwrap_or_default();

let delegations = staking
.get_global_delegation_records()
.values()
.map(|v| (v.id, v.clone()))
.collect();
let coinbase_balance = staking.coinbase_balance();

if let Err(e) = EVM_STAKING.get().c(d!()).and_then(|staking| {
staking.write().import_validators(
&validators,
&delegations,
coinbase_balance,
)
}) {
tracing::error!(target: "evm staking", "import_validators error:{:?}", e);
panic!()
};
}

// mint coinbase, cache system transactions to ledger
{
let laa = la.get_committed_state().read();
Expand All @@ -485,25 +519,54 @@ pub fn end_block(
if !la.all_commited() && la.block_txn_count() != 0 {
pnk!(la.end_block());
}
if td_height <= CFG.checkpoint.evm_staking_inital_height {
if let Ok(Some(vs)) = ruc::info!(staking::get_validators(
la.get_committed_state().read().get_staking().deref(),
begin_block_req.last_commit_info.as_ref()
)) {
resp.set_validator_updates(RepeatedField::from_vec(vs));
}

if let Ok(Some(vs)) = ruc::info!(staking::get_validators(
la.get_committed_state().read().get_staking().deref(),
begin_block_req.last_commit_info.as_ref()
)) {
resp.set_validator_updates(RepeatedField::from_vec(vs));
staking::system_ops(
&mut la.get_committed_state().write(),
&header,
begin_block_req.last_commit_info.as_ref(),
&begin_block_req.byzantine_validators.as_slice(),
);
}

staking::system_ops(
&mut la.get_committed_state().write(),
&header,
begin_block_req.last_commit_info.as_ref(),
&begin_block_req.byzantine_validators.as_slice(),
);

if td_height <= CFG.checkpoint.disable_evm_block_height
let evm_resp = if td_height <= CFG.checkpoint.disable_evm_block_height
|| td_height >= CFG.checkpoint.enable_frc20_height
{
let _ = s.account_base_app.write().end_block(req);
let mut sum = 0;
let ledger = la.get_committed_state().read();
let mut addrs = FF_ADDR_LIST.to_vec();
addrs.push(FF_ADDR_EXTRA_120_0000);
for fra_addr in addrs.iter() {
for (_, (utxo, _)) in pnk!(wallet::public_key_from_bech32(fra_addr)
.and_then(|pub_key| ledger.get_owned_utxos(&pub_key)))
{
if AssetRecordType::NonConfidentialAmount_NonConfidentialAssetType
== utxo.0.record.get_record_type()
&& Some(ASSET_TYPE_FRA) == utxo.0.record.asset_type.get_asset_type()
{
if let Some(v) = utxo.0.record.amount.get_amount() {
sum += v;
};
}
}
}

s.account_base_app.write().end_block(req, sum)
} else {
Default::default()
};

if td_height > CFG.checkpoint.evm_staking_inital_height
&& 0 == TENDERMINT_BLOCK_HEIGHT.load(Ordering::Relaxed)
% VALIDATOR_UPDATE_BLOCK_ITV
{
resp.validator_updates = evm_resp.validator_updates;
}

resp
Expand Down
9 changes: 6 additions & 3 deletions src/components/abciapp/src/abci/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
},
baseapp::BaseApp as AccountBaseAPP,
config::abci::global_cfg::CFG,
ledger::store::LedgerState,
ledger::{staking::evm::EVM_STAKING, store::LedgerState},
parking_lot::RwLock,
rand_chacha::ChaChaRng,
rand_core::SeedableRng,
Expand Down Expand Up @@ -70,7 +70,10 @@ impl ABCISubmissionServer {
))
}
};

let account_base_app = Arc::new(RwLock::new(account_base_app));
if EVM_STAKING.set(account_base_app.clone()).is_err() {
return Err(eg!("Invalid usage."));
}
let prng = rand_chacha::ChaChaRng::from_entropy();
Ok(ABCISubmissionServer {
la: Arc::new(RwLock::new(
Expand All @@ -81,7 +84,7 @@ impl ABCISubmissionServer {
)
.c(d!())?,
)),
account_base_app: Arc::new(RwLock::new(account_base_app)),
account_base_app,
})
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/abciapp/src/abci/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! Business logic based on [**Ledger Staking**](ledger::staking).
//!

use ledger::staking::evm::EVM_STAKING_MINTS;

mod whoami;

#[cfg(test)]
Expand Down Expand Up @@ -468,6 +470,13 @@ pub fn system_mint_pay(

mint_entries.append(&mut mints);

//Mints from evm staking
for mint in EVM_STAKING_MINTS.lock().drain(..).map(|(pk, amount)| {
MintEntry::new(MintKind::Other, pk, None, amount, ASSET_TYPE_FRA)
}) {
mint_entries.push(mint)
}

if mint_entries.is_empty() {
None
} else {
Expand Down
28 changes: 28 additions & 0 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ pub struct CheckPointConfig {

#[serde(default = "def_validator_whitelist_v3")]
pub validator_whitelist_v3: Vec<String>,

#[serde(default = "def_max_gas_price_limit")]
pub max_gas_price_limit: i64,

#[serde(default = "def_evm_staking_inital_height")]
pub evm_staking_inital_height: i64,

#[serde(default = "def_evm_staking_address")]
pub evm_staking_address: String,
}

fn def_fix_check_replay() -> u64 {
Expand Down Expand Up @@ -205,6 +214,19 @@ fn def_validator_whitelist_v3_height() -> u64 {
fn def_validator_whitelist_v3() -> Vec<String> {
DEFAULT_CHECKPOINT_CONFIG.validator_whitelist_v3.clone()
}

fn def_max_gas_price_limit() -> i64 {
DEFAULT_CHECKPOINT_CONFIG.max_gas_price_limit
}

fn def_evm_staking_inital_height() -> i64 {
DEFAULT_CHECKPOINT_CONFIG.evm_staking_inital_height
}

fn def_evm_staking_address() -> String {
DEFAULT_CHECKPOINT_CONFIG.evm_staking_address.clone()
}

#[cfg(feature = "debug_env")]
lazy_static! {
static ref DEFAULT_CHECKPOINT_CONFIG: CheckPointConfig = CheckPointConfig {
Expand Down Expand Up @@ -246,6 +268,9 @@ lazy_static! {
validator_whitelist_v2: vec![],
validator_whitelist_v3_height: 0,
validator_whitelist_v3: vec![],
max_gas_price_limit: 0,
evm_staking_inital_height: 128,
evm_staking_address: "0x84db796A3F8F02396f82219e3197933d15960771".to_owned(),
};
}

Expand Down Expand Up @@ -577,6 +602,9 @@ lazy_static! {
"37D3228A650F591522698BECDF42DCE5D1113D88".to_string(),
"577F8548D8F834D39D26350D2A3A928F478AF5FD".to_string(),
],
max_gas_price_limit: 5000000,
evm_staking_inital_height: 5000000,
evm_staking_address: "".to_owned(),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde_json = "1.0.40"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" }
sha3 = "0.8"
zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" }

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

Expand Down
Loading

0 comments on commit a4a157e

Please sign in to comment.