Skip to content

Commit

Permalink
fix check tx size (#1053)
Browse files Browse the repository at this point in the history
* fix check tx size

* fix checkpoint

---------

Co-authored-by: shaorongqiang <[email protected]>
  • Loading branch information
shaorongqiang and shaorongqiang authored Apr 29, 2024
1 parent a209efb commit d90052f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
36 changes: 26 additions & 10 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//! # Impl function of tendermint ABCI
//!
use chrono::Local;
use fp_storage::BorrowMut;

mod utils;

use {
crate::{
abci::{server::ABCISubmissionServer, staking, IN_SAFE_ITV, IS_EXITING, POOL},
abci::{
server::{tx_sender::TX_SIZE, ABCISubmissionServer},
staking, IN_SAFE_ITV, IS_EXITING, POOL,
},
api::{
query_server::BLOCK_CREATED,
submission_server::{convert_tx, try_tx_catalog, TxCatalog},
Expand All @@ -21,12 +21,14 @@ use {
ResponseBeginBlock, ResponseCheckTx, ResponseCommit, ResponseDeliverTx,
ResponseEndBlock, ResponseInfo, ResponseInitChain, ResponseQuery,
},
chrono::Local,
config::abci::global_cfg::CFG,
enterprise_web3::{
Setter, ALLOWANCES, BALANCE_MAP, BLOCK, CODE_MAP, NONCE_MAP, RECEIPTS,
REDIS_CLIENT, STATE_UPDATE_LIST, TOTAL_ISSUANCE, TXS, WEB3_SERVICE_START_HEIGHT,
},
fp_storage::hash::{Sha256, StorageHasher},
fp_storage::BorrowMut,
globutils::wallet,
lazy_static::lazy_static,
ledger::{
Expand Down Expand Up @@ -133,15 +135,21 @@ pub fn init_chain(
/// any new tx will trigger this callback before it can enter the mem-pool of tendermint
pub fn check_tx(s: &mut ABCISubmissionServer, req: &RequestCheckTx) -> ResponseCheckTx {
let mut resp = ResponseCheckTx::new();
let td_height = TENDERMINT_BLOCK_HEIGHT.load(Ordering::Relaxed);

let tx_catalog = try_tx_catalog(req.get_tx(), false);
let tx = req.get_tx();
if td_height > CFG.checkpoint.check_tx_size_height && tx.len() > TX_SIZE {
resp.log = format!("Transaction too large:{}", tx.len());
resp.code = 1;
return resp;
}

let td_height = TENDERMINT_BLOCK_HEIGHT.load(Ordering::Relaxed);
let tx_catalog = try_tx_catalog(tx, false);

match tx_catalog {
TxCatalog::FindoraTx => {
if matches!(req.field_type, CheckTxType::New) {
if let Ok(tx) = convert_tx(req.get_tx()) {
if let Ok(tx) = convert_tx(tx) {
if td_height > CFG.checkpoint.check_signatures_num {
for op in tx.body.operations.iter() {
if let Operation::TransferAsset(op) = op {
Expand Down Expand Up @@ -271,13 +279,21 @@ pub fn deliver_tx(
req: &RequestDeliverTx,
) -> ResponseDeliverTx {
let mut resp = ResponseDeliverTx::new();

let tx_catalog = try_tx_catalog(req.get_tx(), true);
let td_height = TENDERMINT_BLOCK_HEIGHT.load(Ordering::Relaxed);

let tx = req.get_tx();

if td_height > CFG.checkpoint.check_tx_size_height && tx.len() > TX_SIZE {
resp.log = format!("Transaction too large:{}", tx.len());
resp.code = 1;
return resp;
}

let tx_catalog = try_tx_catalog(tx, true);

match tx_catalog {
TxCatalog::FindoraTx => {
if let Ok(tx) = convert_tx(req.get_tx()) {
if let Ok(tx) = convert_tx(tx) {
if td_height > CFG.checkpoint.check_signatures_num {
for op in tx.body.operations.iter() {
if let Operation::TransferAsset(op) = op {
Expand Down
5 changes: 2 additions & 3 deletions src/components/abciapp/src/abci/server/tx_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
use {
crate::{abci::POOL, api::submission_server::TxnForward},
config::abci::global_cfg::CFG,
ledger::data_model::Transaction,
ruc::*,
std::sync::atomic::{AtomicU16, Ordering},
};

static TX_PENDING_CNT: AtomicU16 = AtomicU16::new(0);

pub static TX_SIZE: usize = 8192;
pub struct TendermintForward {
pub tendermint_reply: String,
}
Expand All @@ -38,7 +37,7 @@ pub fn forward_txn_with_mode(

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

Expand Down
21 changes: 15 additions & 6 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ pub struct CheckPointConfig {
#[serde(default = "def_evm_staking_address")]
pub evm_staking_address: String,

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

pub tx_size: u32,
#[serde(default = "def_check_tx_size_height")]
pub check_tx_size_height: i64,
}

fn def_fix_check_replay() -> u64 {
Expand Down Expand Up @@ -232,6 +233,14 @@ fn def_evm_staking_address() -> String {
DEFAULT_CHECKPOINT_CONFIG.evm_staking_address.clone()
}

fn def_utxo_fee_height() -> i64 {
DEFAULT_CHECKPOINT_CONFIG.utxo_fee_height
}

fn def_check_tx_size_height() -> i64 {
DEFAULT_CHECKPOINT_CONFIG.check_tx_size_height
}

#[cfg(feature = "debug_env")]
lazy_static! {
static ref DEFAULT_CHECKPOINT_CONFIG: CheckPointConfig = CheckPointConfig {
Expand Down Expand Up @@ -276,8 +285,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
utxo_fee_height: 0,
check_tx_size_height: 0
};
}

Expand Down Expand Up @@ -612,8 +621,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
utxo_fee_height: 5671678,
check_tx_size_height: 5671678
};
}

Expand Down

0 comments on commit d90052f

Please sign in to comment.