Skip to content

Commit

Permalink
fix utxo fee (#1050)
Browse files Browse the repository at this point in the history
* Limit utxo transaction size

* add memo

* fix lint

* feat utxo fee

---------

Co-authored-by: shaorongqiang <[email protected]>
  • Loading branch information
shaorongqiang and shaorongqiang authored Apr 15, 2024
1 parent ff1759e commit 664b561
Show file tree
Hide file tree
Showing 40 changed files with 279 additions and 1,081 deletions.
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 1.70 && \
rustup component add clippy --toolchain 1.70 && \
rustup component add rustfmt --toolchain 1.70
RUN rustup toolchain install stable && \
rustup component add clippy --toolchain stable && \
rustup component add rustfmt --toolchain stable

RUN mkdir /binary
RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb
Expand Down
6 changes: 3 additions & 3 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 1.70 && \
rustup component add clippy --toolchain 1.70 && \
rustup component add rustfmt --toolchain 1.70
RUN rustup toolchain install stable && \
rustup component add clippy --toolchain stable && \
rustup component add rustfmt --toolchain stable

RUN mkdir /binary
RUN mkdir -p /binary/cleveldb && mkdir -p /binary/goleveldb
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.70
stable
15 changes: 7 additions & 8 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ use {
std::{
fs,
mem::take,
ops::Deref,
sync::{
atomic::{AtomicI64, Ordering},
Arc,
Expand Down Expand Up @@ -569,7 +568,7 @@ pub fn 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(),
la.get_committed_state().read().get_staking(),
begin_block_req.last_commit_info.as_ref()
)) {
resp.set_validator_updates(RepeatedField::from_vec(vs));
Expand Down Expand Up @@ -691,13 +690,13 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
Default::default()
};

let total_issuance = if let Ok(mut receipts) = TOTAL_ISSUANCE.lock() {
take(&mut *receipts)
let total_issuance = if let Ok(mut total_issuance) = TOTAL_ISSUANCE.lock() {
take(&mut *total_issuance)
} else {
Default::default()
};
let allowances = if let Ok(mut receipts) = ALLOWANCES.lock() {
take(&mut *receipts)
let allowances = if let Ok(mut allowances) = ALLOWANCES.lock() {
take(&mut *allowances)
} else {
Default::default()
};
Expand All @@ -706,9 +705,9 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
.set_total_issuance(height, v)
.map_err(|e| eg!("set redis error: {:?}", e)));
}
for ((owner, spender), amount) in allowances.iter() {
for (key, amount) in allowances.iter() {
pnk!(setter
.set_allowances(height, *owner, *spender, *amount)
.set_allowances(height, key.owner_address, key.spender_address, *amount)
.map_err(|e| eg!("set redis error: {:?}", e)));
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/abciapp/src/abci/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use {
tx_sender::TendermintForward,
};

pub use tx_sender::forward_txn_with_mode;

pub mod callback;
pub mod tx_sender;

Expand Down
6 changes: 5 additions & 1 deletion src/components/abciapp/src/abci/server/tx_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use {
crate::{abci::POOL, api::submission_server::TxnForward},
config::abci::global_cfg::CFG,
ledger::data_model::Transaction,
ruc::*,
std::sync::atomic::{AtomicU16, Ordering},
Expand Down Expand Up @@ -36,7 +37,10 @@ pub fn forward_txn_with_mode(
const ASYNC_API: &str = "broadcast_tx_async";

let txn_json = serde_json::to_string(&txn).c(d!())?;
let txn_b64 = base64::encode_config(&txn_json.as_str(), base64::URL_SAFE);
let txn_b64 = base64::encode_config(txn_json, base64::URL_SAFE);
if txn_b64.len() > CFG.checkpoint.tx_size as usize {
return Err(eg!("Transaction too large"));
}

let json_rpc = if async_mode {
format!(
Expand Down
9 changes: 4 additions & 5 deletions src/components/abciapp/src/abci/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use {
serde::Serialize,
std::{
collections::{BTreeMap, BTreeSet},
ops::{Deref, DerefMut},
ops::DerefMut,
sync::atomic::Ordering,
},
};
Expand Down Expand Up @@ -283,10 +283,9 @@ pub fn system_ops(
}

if online_list.len() != lci.votes.len() {
if let Ok(pl) = ruc::info!(gen_offline_punish_list(
la.get_staking().deref(),
&online_list
)) {
if let Ok(pl) =
ruc::info!(gen_offline_punish_list(la.get_staking(), &online_list))
{
pl.into_iter().for_each(|v| {
let bz = ByzantineInfo {
addr: &td_addr_to_string(&v),
Expand Down
6 changes: 3 additions & 3 deletions src/components/abciapp/src/abci/staking/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
ledger::{
data_model::{
Transaction, TransferType, TxnEffect, TxoRef, ASSET_TYPE_FRA,
BLACK_HOLE_PUBKEY, TX_FEE_MIN,
BLACK_HOLE_PUBKEY, TX_FEE_MIN_V0,
},
staking::{FF_PK_LIST, FRA_PRE_ISSUE_AMOUNT},
store::{utils::fra_gen_initial_tx, LedgerState},
Expand Down Expand Up @@ -99,7 +99,7 @@ fn gen_transfer_tx(
) -> Result<Transaction> {
let mut tx_builder = TransactionBuilder::from_seq_id(seq_id);

let target_list = vec![(target_pk, am), (&*BLACK_HOLE_PUBKEY, TX_FEE_MIN)];
let target_list = vec![(target_pk, am), (&*BLACK_HOLE_PUBKEY, TX_FEE_MIN_V0)];

let mut trans_builder = TransferOperationBuilder::new();

Expand Down Expand Up @@ -159,5 +159,5 @@ fn gen_transfer_tx(
.c(d!())?;

tx_builder.add_operation(op);
Ok(tx_builder.take_transaction().into())
Ok(tx_builder.take_transaction())
}
2 changes: 1 addition & 1 deletion src/components/abciapp/src/abci/staking/whoami.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn from_config_file() -> Result<Vec<u8>> {
.unwrap_or(CFG_PATH_FF);
}

fs::read_to_string(&*CFG_PATH)
fs::read_to_string(*CFG_PATH)
.c(d!())
.and_then(|cfg| serde_json::from_str::<SelfAddr>(&cfg).c(d!()))
.and_then(|sa| td_addr_to_bytes(&sa.address).c(d!()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl SubmissionApi {
web::get().to(txn_status::<RNG, TF>),
)
})
.bind(&format!("{host}:{port}"))
.bind(format!("{host}:{port}"))
.c(d!())?
.run();

Expand Down
9 changes: 9 additions & 0 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub struct CheckPointConfig {

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

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

pub tx_size: u32,
}

fn def_fix_check_replay() -> u64 {
Expand Down Expand Up @@ -271,6 +276,8 @@ lazy_static! {
max_gas_price_limit: 0,
evm_staking_inital_height: 128,
evm_staking_address: "0x321DF28026D01858906D322533900aD3435eE964".to_owned(),
utxo_fee_height: 128,
tx_size: 8192
};
}

Expand Down Expand Up @@ -605,6 +612,8 @@ lazy_static! {
max_gas_price_limit: 4636000,
evm_staking_inital_height: 4636000,
evm_staking_address: "0x38d49e3bd5144059c9f3bA10CF7306E84155B603".to_owned(),
utxo_fee_height: 50000000,
tx_size: 8192
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/baseapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub struct StableTxFee;

impl FeeCalculator for StableTxFee {
fn min_fee() -> U256 {
// TX_FEE_MIN
// TX_FEE_MIN_V0
U256::from(1_0000_0000_0000_0000_u64)
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/components/contracts/modules/account/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{storage::*, App, Config};
use config::abci::global_cfg::CFG;
use enterprise_web3::{
ALLOWANCES, BALANCE_MAP, TOTAL_ISSUANCE, WEB3_SERVICE_START_HEIGHT,
AllowancesKey, ALLOWANCES, BALANCE_MAP, TOTAL_ISSUANCE, WEB3_SERVICE_START_HEIGHT,
};
use fp_core::{account::SmartAccount, context::Context};
use fp_storage::BorrowMut;
Expand Down Expand Up @@ -211,9 +211,9 @@ impl<C: Config> AccountAsset<Address> for App<C> {
fn approve(
ctx: &Context,
owner: &Address,
owner_addr: H160,
owner_address: H160,
spender: &Address,
spender_addr: H160,
spender_address: H160,
amount: U256,
) -> Result<()> {
Allowances::insert(ctx.state.write().borrow_mut(), owner, spender, &amount)?;
Expand All @@ -222,7 +222,13 @@ impl<C: Config> AccountAsset<Address> for App<C> {
{
let mut allowances = ALLOWANCES.lock().c(d!())?;

allowances.push(((owner_addr, spender_addr), amount));
allowances.push((
AllowancesKey {
owner_address,
spender_address,
},
amount,
));
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<C: Config> App<C> {
if log.address != addr {
continue;
}
match log.topics.get(0).cloned() {
match log.topics.first().cloned() {
Some(v) => {
if v != signature {
continue;
Expand Down Expand Up @@ -871,7 +871,7 @@ impl<C: Config> App<C> {
if log.address != addr {
continue;
}
match log.topics.get(0).cloned() {
match log.topics.first().cloned() {
Some(v) => {
if v != signature {
continue;
Expand Down Expand Up @@ -1137,7 +1137,7 @@ pub fn get_claim_on_contract_address<C: Config>(
)?;
let ret = function.decode_output(&data).c(d!())?;

if let Some(Token::Address(addr)) = ret.get(0) {
if let Some(Token::Address(addr)) = ret.first() {
Ok(*addr)
} else {
Err(eg!("address not found"))
Expand Down
8 changes: 4 additions & 4 deletions src/components/contracts/modules/evm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn build_update_info(tk: &Token) -> Result<abci::ValidatorUpdate> {

let mut pub_key = abci::PubKey::default();

if let Token::Bytes(pk) = v.get(0).ok_or(eg!("update info 0 must bytes"))? {
if let Token::Bytes(pk) = v.first().ok_or(eg!("update info 0 must bytes"))? {
pub_key.set_data(pk.clone());
} else {
return Err(eg!("Error type of public key"));
Expand Down Expand Up @@ -210,7 +210,7 @@ pub fn build_validator_updates(
let func = sc.staking.function("getValidatorsList").c(d!())?;
let dp = func.decode_output(data).c(d!())?;

if let Token::Array(output) = dp.get(0).c(d!())? {
if let Token::Array(output) = dp.first().c(d!())? {
let mut res = Vec::with_capacity(output.len());

for o in output.iter() {
Expand All @@ -227,7 +227,7 @@ pub fn build_validator_updates(
fn build_claim_info(tk: &Token) -> Result<(H160, U256)> {
if let Token::Tuple(v) = tk {
let addr = if let Token::Address(addr) =
v.get(0).ok_or(eg!("update info 0 must bytes"))?
v.first().ok_or(eg!("update info 0 must bytes"))?
{
*addr
} else {
Expand All @@ -254,7 +254,7 @@ pub fn build_claim_ops(sc: &SystemContracts, data: &[u8]) -> Result<Vec<(H160, U
let func = sc.staking.function("getClaimOps").c(d!())?;
let dp = func.decode_output(data).c(d!())?;

if let Token::Array(output) = dp.get(0).c(d!())? {
if let Token::Array(output) = dp.first().c(d!())? {
let mut res = Vec::with_capacity(output.len());

for o in output.iter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ pub type Block = EnterpriseBlock;
pub type Receipt = EnterpriseReceipt;
pub type TxState = EnterpriseTxState;

pub struct AllowancesKey {
pub owner_address: H160,
pub spender_address: H160,
}

lazy_static! {
pub static ref STATE_UPDATE_LIST: Arc<Mutex<Vec<State>>> =
Arc::new(Mutex::new(vec![]));
Expand All @@ -40,8 +45,8 @@ lazy_static! {
pub static ref REMOVE_PENDING_STATE_UPDATE_LIST: Arc<Mutex<Vec<(H160, H256)>>> =
Arc::new(Mutex::new(vec![]));
pub static ref TOTAL_ISSUANCE: Arc<Mutex<Option<U256>>> = Arc::new(Mutex::new(None));
pub static ref ALLOWANCES: Arc<Mutex<Vec<((H160, H160), U256)>>> =
Arc::new(Mutex::new(vec![]));
pub static ref ALLOWANCES: Arc<Mutex<Vec<(AllowancesKey, U256)>>> =
Arc::new(Mutex::new(Vec::new()));
}

fn gen_redis_client() -> r2d2::Pool<Client> {
Expand Down
9 changes: 4 additions & 5 deletions src/components/contracts/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ impl SubscriptionResult {
receipts: Vec<Receipt>,
params: &FilteredParams,
) -> Vec<Log> {
let block_hash = Some(H256::from_slice(
Keccak256::digest(&rlp::encode(&block.header)).as_slice(),
));
let block_hash =
H256::from_slice(Keccak256::digest(&rlp::encode(&block.header)).as_slice());
let mut logs: Vec<Log> = vec![];
let mut log_index: u32 = 0;
for (receipt_index, receipt) in receipts.into_iter().enumerate() {
Expand All @@ -234,12 +233,12 @@ impl SubscriptionResult {
None
};
for (transaction_log_index, log) in receipt.logs.into_iter().enumerate() {
if self.add_log(block_hash.unwrap(), &log, &block, params) {
if self.add_log(block_hash, &log, &block, params) {
logs.push(Log {
address: log.address,
topics: log.topics,
data: Bytes(log.data),
block_hash,
block_hash: Some(block_hash),
block_number: Some(block.header.number),
transaction_hash,
transaction_index: Some(U256::from(receipt_index)),
Expand Down
2 changes: 1 addition & 1 deletion src/components/finutils/src/bins/cfg_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn gen() -> Result<()> {
cfg_template
.valiators
.iter_mut()
.zip(id_list.into_iter())
.zip(id_list)
.for_each(|(v, id)| {
v.id = id;
});
Expand Down
Loading

0 comments on commit 664b561

Please sign in to comment.