Skip to content

Commit

Permalink
solve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
harryliisme3 committed Aug 31, 2022
2 parents b337fcd + f335770 commit a3c61fc
Show file tree
Hide file tree
Showing 45 changed files with 1,612 additions and 359 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ build_release_goleveldb: tendermint_goleveldb
cargo build --release --bins -p abciapp -p finutils
$(call pack,release)

check: tendermint_goleveldb
cargo check --release --bins -p abciapp -p finutils
$(call pack,release)

# Build for goleveldb
build_release_musl_goleveldb: tendermint_goleveldb
cargo build --release --bins -p abciapp -p finutils --target=x86_64-unknown-linux-musl
Expand Down
3 changes: 2 additions & 1 deletion src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ pub fn end_block(
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 _ =
s.account_base_app.write().end_block(req);
}

// mint coinbase, cache system transactions to ledger
Expand Down
34 changes: 16 additions & 18 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
[package]
name = "baseapp"
version = "0.1.0"
authors = ["FindoraNetwork"]
description = "Base application for tendermint abci"
edition = "2021"
homepage = "https://findora.org/technology"
repository = "https://github.com/findoranetwork/platform/"
description = "Base application for tendermint abci"
name = "baseapp"
readme = "README.md"
repository = "https://github.com/findoranetwork/platform/"
version = "0.1.0"

[dependencies]
abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.4" }
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
ethereum-types = { version = "0.13.1", default-features = false }
futures = "0.3.16"
lazy_static = "1.4.0"
ledger = { path = "../../../ledger" }
ledger = {path = "../../../ledger"}
log = "0.4"
parking_lot = "0.12"
primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] }
protobuf = "2.16"
ruc = "1.0"
serde = { version = "1.0.124", features = ["derive"] }
serde = {version = "1.0.124", features = ["derive"]}
serde_json = "1.0.40"
attohttpc = { version = "0.18", default-features = false, features = ["compress", "json", "tls-rustls"] }
base64 = "0.12"
once_cell = "1.10.0"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" }

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

# primitives
fp-core = { path = "../primitives/core" }
fp-evm = { path = "../primitives/evm" }
fp-traits = { path = "../primitives/traits" }
fp-types = { path = "../primitives/types" }
fp-utils = { path = "../primitives/utils" }
fp-core = {path = "../primitives/core"}
fp-evm = {path = "../primitives/evm"}
fp-traits = {path = "../primitives/traits"}
fp-types = {path = "../primitives/types"}
fp-utils = {path = "../primitives/utils"}

# modules
module-account = { path = "../modules/account"}
module-ethereum = { path = "../modules/ethereum"}
module-evm = { path = "../modules/evm"}
module-template = { path = "../modules/template"}
module-xhub = { path = "../modules/xhub"}
module-account = {path = "../modules/account"}
module-ethereum = {path = "../modules/ethereum"}
module-evm = {path = "../modules/evm"}
module-template = {path = "../modules/template"}
module-xhub = {path = "../modules/xhub"}

evm-precompile-basic = { path = "../modules/evm/precompile/basic" }
evm-precompile-frc20 = { path = "../modules/evm/precompile/frc20" }
evm-precompile-modexp = { path = "../modules/evm/precompile/modexp" }
evm-precompile-sha3fips = { path = "../modules/evm/precompile/sha3fips" }
evm-precompile = {path = "../modules/evm/precompile"}


[features]
abci_mock = []
75 changes: 74 additions & 1 deletion src/components/contracts/baseapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod tm_events;

use crate::modules::ModuleManager;
use abci::Header;
use ethereum::BlockV0 as Block;
use ethereum::BlockV2 as Block;
use evm_precompile::{self, FindoraPrecompiles};
use fin_db::{FinDB, RocksDB};
use fp_core::context::Context as Context2;
Expand Down Expand Up @@ -50,6 +50,23 @@ const CHAIN_STATE_PATH: &str = "state.db";
const CHAIN_HISTORY_DATA_PATH: &str = "history.db";
const CHAIN_STATE_MIN_VERSIONS: u64 = 4 * 60 * 24 * 90;

const INITIAL_BASE_FEE: u64 = 1000000000;
const ELASTICITY_MULTIPLIER: u64 = 2;
const BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 8;

#[inline(always)]
pub fn get_initial_base_fee() -> U256 {
U256::from(INITIAL_BASE_FEE)
}
#[inline(always)]
pub fn get_elasticity_multiplier() -> U256 {
U256::from(ELASTICITY_MULTIPLIER)
}
#[inline(always)]
pub fn get_base_fee_max_change_denominator() -> U256 {
U256::from(BASE_FEE_MAX_CHANGE_DENOMINATOR)
}

#[derive(Clone)]
pub struct BaseApp {
/// application name from abci.Info
Expand Down Expand Up @@ -444,4 +461,60 @@ impl BaseProvider for BaseApp {
None
}
}

/// Return the base fee at the given height.
#[allow(clippy::comparison_chain, clippy::question_mark)]
fn base_fee(&self, id: Option<BlockId>) -> Option<U256> {
let mut comp_gas = std::vec::Vec::new();
let block = self.current_block(id)?;
let mut parent_block =
self.current_block(Some(BlockId::Hash(block.header.parent_hash)));
if parent_block.is_none() {
return None;
}
let parent_gas_used = parent_block.as_ref().unwrap().header.gas_used;
let parent_gas_target = parent_block.as_ref().unwrap().header.gas_limit
/ get_elasticity_multiplier();
comp_gas.push((parent_gas_used, parent_gas_target));

while parent_block.as_ref().is_some() {
parent_block = self.current_block(Some(BlockId::Hash(
parent_block.as_ref().unwrap().header.parent_hash,
)));
let parent_gas_used = parent_block.as_ref().unwrap().header.gas_used;
let parent_gas_target = parent_block.as_ref().unwrap().header.gas_limit
/ get_elasticity_multiplier();
comp_gas.push((parent_gas_used, parent_gas_target));
}

let mut base_fee = get_initial_base_fee();
comp_gas.pop();
while !comp_gas.is_empty() {
let (parent_gas_used, parent_gas_target) = comp_gas.pop().unwrap();
if parent_gas_used > parent_gas_target {
let gas_used_delta = parent_gas_used - parent_gas_target;
let base_fee_delta = std::cmp::max(
base_fee * gas_used_delta
/ parent_gas_target
/ get_base_fee_max_change_denominator(),
U256::from(1),
);
base_fee += base_fee_delta;
} else if parent_gas_used < parent_gas_target {
let gas_used_delta = parent_gas_target - parent_gas_used;
let base_fee_delta = base_fee * gas_used_delta
/ parent_gas_target
/ get_base_fee_max_change_denominator();
base_fee -= base_fee_delta;
}
}

Some(base_fee)
}

/// Return `true` if the request BlockId is post-eip1559.
/// Do not be used.
fn is_eip1559(&self, _id: Option<BlockId>) -> bool {
false
}
}
10 changes: 10 additions & 0 deletions src/components/contracts/modules/account/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,14 @@ impl<C: Config> AccountAsset<Address> for App<C> {
) -> Result<()> {
Allowances::insert(ctx.state.write().borrow_mut(), owner, spender, &amount)
}

fn income(ctx: &Context, who: &Address, value: U256) -> Result<()> {
if value.is_zero() {
return Ok(());
}

let mut sa = Self::account_of(ctx, who, None).c(d!("account does not exist"))?;
sa.balance = sa.balance.checked_add(value).c(d!("balance overflow"))?;
AccountStore::insert(ctx.state.write().borrow_mut(), who, &sa)
}
}
Loading

0 comments on commit a3c61fc

Please sign in to comment.