Skip to content

Commit

Permalink
Merge branch 'develop_eip1559' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
harryliisme3 committed Dec 6, 2022
2 parents 6fd5ede + 32ae058 commit a43f0e4
Show file tree
Hide file tree
Showing 50 changed files with 1,786 additions and 357 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/RPCNode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: RpcNode
on:
push:
tags:
- '*-RPCNode'
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
matrix:
platform: [scalable]
runs-on: ${{ matrix.platform }}
env:
ENV: release
PRIVATE_ECR_URL: 358484141435.dkr.ecr.us-west-2.amazonaws.com
PUBLIC_ECR_URL: public.ecr.aws/k6m5b6e2
DOCKERHUB_URL: findoranetwork
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt


- name: Prepare key
shell: bash
run: |
tar -C ~/.ssh -zcf key.tar.gz ./
- name: Clean garbage containers and images
shell: bash
run: |
docker rm $(docker ps -a | grep -v "^CONTAINER" | awk '{print $1}') || true
docker rmi -f $(docker images -f "dangling=true" -q) || true
- name: Build rust base image
shell: bash
run: |
make ci_build_binary_rust_base
- name: Build binary image
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
shell: bash
run: |
echo "REF: ${GITHUB_REF}"
TAGS=$(grep "refs/tags" <<< ${GITHUB_REF}) || true
TAGV="${TAGS#refs/tags/}"
export IMAGE_TAG="${TAGV:-main}"
export VERGEN_SHA_EXTERN="${IMAGE_TAG}"
echo "Image tag: ${IMAGE_TAG}"
make ci_build_release_web3_binary_image
- name: Build images
env:
PRIVATE_ECR_URL: ${{ env.PRIVATE_ECR_URL }}
PUBLIC_ECR_URL: ${{ env.PUBLIC_ECR_URL }}
ENV: release
shell: bash
run: |
echo "REF: ${GITHUB_REF}"
TAGS=$(grep "refs/tags" <<< ${GITHUB_REF}) || true
TAGV="${TAGS#refs/tags/}"
export IMAGE_TAG="${TAGV:-main}"
echo "Image tag: ${IMAGE_TAG}"
make ci_build_image_web3
- name: Login ECR
env:
PUBLIC_ECR_URL: ${{ env.PUBLIC_ECR_URL }}
shell: bash
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${PUBLIC_ECR_URL}
- name: Push images
env:
PRIVATE_ECR_URL: ${{ env.PRIVATE_ECR_URL }}
PUBLIC_ECR_URL: ${{ env.PUBLIC_ECR_URL }}
ENV: release
shell: bash
run: |
echo "REF: ${GITHUB_REF}"
TAGS=$(grep "refs/tags" <<< ${GITHUB_REF}) || true
TAGV="${TAGS#refs/tags/}"
export IMAGE_TAG="${TAGV:-main}"
echo "Image tag: ${IMAGE_TAG}"
make ci_push_image
- name: Clean images
env:
PRIVATE_ECR_URL: ${{ env.PRIVATE_ECR_URL }}
PUBLIC_ECR_URL: ${{ env.PUBLIC_ECR_URL }}
ENV: release
shell: bash
run: |
echo "REF: ${GITHUB_REF}"
TAGS=$(grep "refs/tags" <<< ${GITHUB_REF}) || true
TAGV="${TAGS#refs/tags/}"
export IMAGE_TAG="${TAGV:-main}"
echo "Image tag: ${IMAGE_TAG}"
make clean_image
- name: Clean binary images
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
shell: bash
run: |
echo "REF: ${GITHUB_REF}"
TAGS=$(grep "refs/tags" <<< ${GITHUB_REF}) || true
TAGV="${TAGS#refs/tags/}"
export IMAGE_TAG="${TAGV:-main}"
echo "Image tag: ${IMAGE_TAG}"
make clean_binary_dockerhub
- name: Clean garbage
shell: bash
run: |
rm -rf /tmp/*>/dev/null 2>&1 || true
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,29 @@ ci_build_image_dockerhub_arm:
# # docker tag $(DOCKERHUB_URL)/findorad:$(IMAGE_TAG) $(DOCKERHUB_URL)/findorad:latest
# endif

# ========================== 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 .

ifeq ($(ENV),release)
docker tag $(PUBLIC_ECR_URL)/$(ENV)/findorad:$(IMAGE_TAG) $(PUBLIC_ECR_URL)/$(ENV)/findorad:latest
endif

# ========================== push image and clean up===========================

ci_push_image:
Expand Down
13 changes: 7 additions & 6 deletions container/Dockerfile-enterprise-web3
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ RUN rustup toolchain install stable && \
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 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 && \
Expand Down
2 changes: 1 addition & 1 deletion src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ 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);
s.account_base_app.write().end_block(req);
}

// mint coinbase, cache system transactions to ledger
Expand Down
8 changes: 8 additions & 0 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ pub struct CheckPointConfig {
pub nonce_bug_fix_height: u64,
pub proper_gas_set_height: u64,


// https://github.com/FindoraNetwork/platform/pull/434
// Fix the amount in the delegators that staking did not modify when it punished the validator.
pub fix_delegators_am_height: u64,
pub validators_limit_v2_height: u64,
// Note: This field only used to qa02.
pub qa02_prismxx_asset: i64,
pub enable_eip1559_height: u64,
}

impl CheckPointConfig {
Expand Down Expand Up @@ -127,6 +131,8 @@ impl CheckPointConfig {
proper_gas_set_height: 0,
fix_delegators_am_height: 0,
validators_limit_v2_height: 0,
qa02_prismxx_asset: 0,
enable_eip1559_height: 0,
};
#[cfg(not(feature = "debug_env"))]
let config = CheckPointConfig {
Expand Down Expand Up @@ -156,6 +162,8 @@ impl CheckPointConfig {
fix_undelegation_missing_reward_height: 3000000,
fix_delegators_am_height: 30000000,
validators_limit_v2_height: 30000000,
qa02_prismxx_asset: 30000000,
enable_eip1559_height: 40000000,
};
let content = toml::to_string(&config).unwrap();
file.write_all(content.as_bytes()).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ 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" }
sha3 = "0.8"

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


# primitives
fp-core = {path = "../primitives/core"}
fp-evm = {path = "../primitives/evm"}
Expand All @@ -53,7 +55,6 @@ evm-precompile-sha3fips = { path = "../modules/evm/precompile/sha3fips" }
evm-precompile-eth-pairings = { path = "../modules/evm/precompile/eth-pairings" }
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"]
37 changes: 36 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 All @@ -24,6 +24,7 @@ use fp_core::{
transaction::{ActionResult, Executable, ValidateUnsigned},
};
use fp_evm::BlockId;
use fp_traits::evm::FeeCalculator as FeeCalculator2;
use fp_traits::{
account::{AccountAsset, FeeCalculator},
base::BaseProvider,
Expand Down Expand Up @@ -54,6 +55,23 @@ const CHAIN_STATE_PATH: &str = "state.db";
const CHAIN_HISTORY_DATA_PATH: &str = "history.db";
const BLOCKS_IN_DAY: u64 = 4 * 60 * 24;

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 @@ -467,4 +485,21 @@ 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 _ = id;
Some(
<BaseApp as module_evm::Config>::FeeCalculator::min_gas_price(
self.current_block_number()?.as_u64(),
),
)
}

/// Return `true` if the request BlockId is post-eip1559.
/// Do not be used.
fn is_eip1559(&self, _id: Option<BlockId>) -> bool {
false
}
}
2 changes: 1 addition & 1 deletion src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0"
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" }

[features]
web3_service = ["enterprise-web3"]
web3_service = ["enterprise-web3"]
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 @@ -242,4 +242,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 a43f0e4

Please sign in to comment.