Skip to content

Commit

Permalink
add coninbase mint 、remove importCoinBase、remove coinbasemintevent、fi…
Browse files Browse the repository at this point in the history
…x decimal (#999)

* evm staking update

* update systemReplaceDelegator

* fix td_addr len error

* remove replaceDelegator

---------

Co-authored-by: Your Name <[email protected]>
  • Loading branch information
shaorongqiang and Your Name authored Sep 7, 2023
1 parent f5ab725 commit fdbbd75
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 700 deletions.
52 changes: 25 additions & 27 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,32 @@ pub fn end_block(
panic!()
};
}
let evm_resp = if td_height <= CFG.checkpoint.disable_evm_block_height
|| td_height >= CFG.checkpoint.enable_frc20_height
{
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()
};
// mint coinbase, cache system transactions to ledger
{
let laa = la.get_committed_state().read();
Expand Down Expand Up @@ -533,33 +558,6 @@ pub fn end_block(
);
}

let evm_resp = if td_height <= CFG.checkpoint.disable_evm_block_height
|| td_height >= CFG.checkpoint.enable_frc20_height
{
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
Expand Down
3 changes: 1 addition & 2 deletions src/components/abciapp/src/abci/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! Business logic based on [**Ledger Staking**](ledger::staking).
//!
use ledger::staking::evm::EVM_STAKING_MINTS;

mod whoami;

#[cfg(test)]
Expand All @@ -18,6 +16,7 @@ use {
config::abci::global_cfg::CFG,
fp_types::actions::xhub::NonConfidentialOutput,
lazy_static::lazy_static,
ledger::staking::evm::EVM_STAKING_MINTS,
ledger::{
data_model::{
AssetType, AssetTypeCode, IssuerPublicKey, Operation, Transaction,
Expand Down
2 changes: 1 addition & 1 deletion src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ lazy_static! {
validator_whitelist_v3: vec![],
max_gas_price_limit: 0,
evm_staking_inital_height: 128,
evm_staking_address: "0x84db796A3F8F02396f82219e3197933d15960771".to_owned(),
evm_staking_address: "0x321DF28026D01858906D322533900aD3435eE964".to_owned(),
};
}

Expand Down
192 changes: 23 additions & 169 deletions src/components/contracts/baseapp/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{extensions::SignedExtra, BaseApp};
use crate::extensions::SignedExtra;
use abci::*;
use config::abci::global_cfg::CFG;
use enterprise_web3::{
Expand All @@ -7,25 +7,14 @@ use enterprise_web3::{
};
use fp_core::context::RunTxMode;
use fp_evm::BlockId;
use fp_traits::account::AccountAsset;
use fp_types::{
actions::xhub::NonConfidentialOutput, assemble::convert_unchecked_transaction,
crypto::Address,
};
use fp_utils::tx::EvmRawTxWrapper;
use ledger::data_model::ASSET_TYPE_FRA;
use module_evm::{
get_claim_on_contract_address,
system_contracts::SYSTEM_ADDR,
utils::{
coinbase_mint_event, coinbase_mint_event_topic_str,
deposit_asset_event_topic_str, parse_deposit_asset_event,
parse_evm_staking_coinbase_mint_event,
},
};
use primitive_types::{H160, H256, U256};
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, str::FromStr};
use std::{mem::take, ops::DerefMut};
use tracing::{debug, error, info};
impl crate::BaseApp {
/// info implements the ABCI interface.
Expand Down Expand Up @@ -294,40 +283,12 @@ impl crate::BaseApp {
if td_height > CFG.checkpoint.prismxx_inital_height && 0 == resp.code
{
let deposit_asset_topic = deposit_asset_event_topic_str();
let coinbase_mint_event_topic = coinbase_mint_event_topic_str();

for evt in resp.events.iter() {
if evt.field_type == *"ethereum_ContractLog" {
let mut bridge_contract_found = false;
let mut deposit_asset_foud = false;

let mut staking_contract_found = false;
let mut coinbase_mint_foud = false;
let mut validator = H256::zero();
let mut delegator = H256::zero();

let claim_on_contract_address = if td_height
> CFG.checkpoint.evm_staking_inital_height
{
match H160::from_str(SYSTEM_ADDR).c(d!()).and_then(
|from| {
get_claim_on_contract_address::<BaseApp>(
&self.modules.evm_module.contracts,
&self.deliver_state,
from,
)
},
) {
Ok(v) => v,
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
return (resp, vec![]);
}
}
} else {
Default::default()
};
for pair in evt.attributes.iter() {
let key = String::from_utf8(pair.key.clone())
.unwrap_or_default();
Expand All @@ -341,11 +302,6 @@ impl crate::BaseApp {
.to_lowercase()
{
bridge_contract_found = true
} else if addr
== format!("{:?}", claim_on_contract_address)
.to_lowercase()
{
staking_contract_found = true;
}
}
if key == *"topics" {
Expand All @@ -354,130 +310,28 @@ impl crate::BaseApp {
.unwrap_or_default();
if topic == deposit_asset_topic {
deposit_asset_foud = true;
} else if td_height
> CFG.checkpoint.evm_staking_inital_height
&& topic.starts_with(
&coinbase_mint_event_topic[0
..coinbase_mint_event_topic.len()
- 1],
)
{
let hashes = topic
.strip_prefix('[')
.and_then(|v| v.strip_suffix(']'))
.unwrap_or(&topic)
.split(", ")
.collect::<Vec<_>>();

let mut validator_flag = false;
if let Some(v) = hashes.get(1) {
validator_flag = true;

let s = v
.strip_prefix(' ')
.and_then(|v| v.strip_suffix(' '))
.unwrap_or(v);
validator = match H256::from_str(s) {
Ok(v) => v,
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
return (resp, vec![]);
}
};
};
let mut delegator_flag = false;
if let Some(v) = hashes.get(2) {
delegator_flag = true;

let s = v
.strip_prefix(' ')
.and_then(|v| v.strip_suffix(' '))
.unwrap_or(v);
delegator = match H256::from_str(s) {
Ok(v) => v,
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
return (resp, vec![]);
}
};
};
coinbase_mint_foud =
validator_flag && delegator_flag;
}
}
if key == *"data" {
if bridge_contract_found && deposit_asset_foud {
let data =
String::from_utf8(pair.value.clone())
.unwrap_or_default();

let data_vec =
serde_json::from_str(&data).unwrap();

let deposit_asset =
parse_deposit_asset_event(data_vec);

match deposit_asset {
Ok(deposit) => non_confidential_outputs
.push(deposit),
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
}
if key == *"data"
&& bridge_contract_found
&& deposit_asset_foud
{
let data = String::from_utf8(pair.value.clone())
.unwrap_or_default();

let data_vec =
serde_json::from_str(&data).unwrap();

let deposit_asset =
parse_deposit_asset_event(data_vec);

match deposit_asset {
Ok(deposit) => {
non_confidential_outputs.push(deposit)
}
} else if td_height
> CFG.checkpoint.evm_staking_inital_height
&& staking_contract_found
&& coinbase_mint_foud
{
let data =
String::from_utf8(pair.value.clone())
.unwrap_or_default();

let data_vec: Vec<u8> =
serde_json::from_str(&data).unwrap();

let event = coinbase_mint_event();
let ret =
parse_evm_staking_coinbase_mint_event(
&event,
vec![
event.signature(),
validator,
delegator,
],
data_vec,
);

match ret {
Ok((addr, pub_key, amount)) => {
if let Some(pk) = pub_key {
non_confidential_outputs.push(
NonConfidentialOutput {
asset: ASSET_TYPE_FRA,
amount,
target: pk,
decimal: 0,
max_supply: 0,
},
);
} else if let Err(e) = module_account::App::<
BaseApp,
>::mint(
&self.deliver_state,
&Address::from(addr),
U256::from(amount),
) {
resp.code = 2;
resp.log = e.to_string();
}
}
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
}
Err(e) => {
resp.code = 1;
resp.log = e.to_string();
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/components/contracts/baseapp/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,11 @@ impl ModuleManager {
let mut resp: ResponseEndBlock = Default::default();
// Note: adding new modules need to be updated.
self.account_module.end_block(ctx, req, ff_addr_balance);
let (mresp, burn_amount) = self.evm_module.end_block(ctx, req, 0);
let mresp = self.evm_module.end_block(ctx, req, 0);
if !mresp.validator_updates.is_empty() {
resp.validator_updates = mresp.validator_updates;
}
if let Err(e) = module_account::App::<BaseApp>::burn(
ctx,
&Address::from(self.evm_module.contracts.staking_address),
burn_amount,
) {
tracing::warn!("module_account::App::<BaseApp>::burn error: {:?}", e)
}

self.ethereum_module.end_block(ctx, req, 0);
self.xhub_module.end_block(ctx, req, 0);
self.template_module.end_block(ctx, req, 0);
Expand Down
Loading

0 comments on commit fdbbd75

Please sign in to comment.