Skip to content

Commit 4ee95b3

Browse files
sienivenprasannavl
andauthored
Remove eth call on miner pipeline (#2541)
Co-authored-by: Prasanna Loganathar <pvl@prasannavl.com>
1 parent 5c084e6 commit 4ee95b3

5 files changed

Lines changed: 2 additions & 68 deletions

File tree

lib/ain-rs-exports/src/evm.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use ain_contracts::{
33
get_transferdomain_native_transfer_function, FixedContract,
44
};
55
use ain_evm::{
6-
core::{EthCallArgs, TransferDomainTxInfo, XHash},
6+
core::{TransferDomainTxInfo, XHash},
77
evm::FinalizedBlockInfo,
8-
executor::TxResponse,
98
fee::calculate_max_tip_gas_fee,
109
services::SERVICES,
1110
storage::traits::{BlockStorage, Rollback, TransactionStorage},
@@ -868,36 +867,14 @@ fn get_tx_info_from_raw_tx(raw_tx: &str) -> Result<TxInfo> {
868867
.try_get_or_create(raw_tx)?;
869868

870869
let nonce = u64::try_from(signed_tx.nonce())?;
871-
872-
let (parent_hash, parent_number) = SERVICES
873-
.evm
874-
.block
875-
.get_latest_block_hash_and_number()?
876-
.unwrap_or_default();
877-
878870
let initial_base_fee = SERVICES.evm.block.calculate_base_fee(H256::zero())?;
879871
let tip_fee = calculate_max_tip_gas_fee(&signed_tx, initial_base_fee)?;
880872
let tip_fee = u64::try_from(tip_fee)?;
881873

882-
let base_fee = SERVICES.evm.block.calculate_base_fee(parent_hash)?;
883-
let TxResponse { used_gas, .. } = SERVICES.evm.core.call(EthCallArgs {
884-
caller: Some(signed_tx.sender),
885-
to: signed_tx.to(),
886-
value: signed_tx.value(),
887-
data: signed_tx.data(),
888-
gas_limit: u64::try_from(signed_tx.gas_limit()).unwrap_or(u64::MAX),
889-
gas_price: Some(signed_tx.effective_gas_price(base_fee)),
890-
max_fee_per_gas: signed_tx.max_fee_per_gas(),
891-
access_list: signed_tx.access_list(),
892-
block_number: parent_number,
893-
transaction_type: Some(signed_tx.get_tx_type()),
894-
})?;
895-
896874
Ok(TxInfo {
897875
nonce,
898876
address: format!("{:?}", signed_tx.sender),
899877
tip_fee,
900-
used_gas,
901878
})
902879
}
903880

lib/ain-rs-exports/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub mod ffi {
4646
pub address: String,
4747
pub nonce: u64,
4848
pub tip_fee: u64,
49-
pub used_gas: u64,
5049
}
5150

5251
// ========== Governance Variable ==========

src/miner.cpp

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ struct EvmTxPreApplyContext {
4747
std::multimap<uint64_t, CTxMemPool::txiter>& failedNonces;
4848
std::map<uint256, CTxMemPool::FailedNonceIterator>& failedNoncesLookup;
4949
CTxMemPool::setEntries& failedTxEntries;
50-
arith_uint256& sortedGasUsed;
51-
arith_uint256& blockGasUsed;
52-
arith_uint256& blockGasLimit;
5350
};
5451

5552
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
@@ -627,9 +624,6 @@ bool BlockAssembler::EvmTxPreapply(EvmTxPreApplyContext& ctx)
627624
auto& failedNonces = ctx.failedNonces;
628625
auto& failedNoncesLookup = ctx.failedNoncesLookup;
629626
auto& [txNonce, txSender] = txIter->GetEVMAddrAndNonce();
630-
const auto& sortedGasUsed = ctx.sortedGasUsed;
631-
const auto& blockGasUsed = ctx.blockGasUsed;
632-
const auto& blockGasLimit = ctx.blockGasLimit;
633627

634628
CrossBoundaryResult result;
635629
const auto expectedNonce = evm_try_unsafe_get_next_valid_nonce_in_q(result, evmQueueId, txSender);
@@ -647,10 +641,6 @@ bool BlockAssembler::EvmTxPreapply(EvmTxPreApplyContext& ctx)
647641
return false;
648642
}
649643

650-
if (blockGasUsed + sortedGasUsed + txIter->GetEVMGasUsed() > blockGasLimit) {
651-
return false;
652-
}
653-
654644
return true;
655645
}
656646

@@ -699,16 +689,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
699689
std::map<uint256, CTxMemPool::FailedNonceIterator> failedNoncesLookup;
700690

701691
// Block gas limit
702-
CrossBoundaryResult result;
703-
auto blockGasLimitInt = evm_try_get_block_limit(result);
704-
if (!result.ok) {
705-
blockGasLimitInt = DEFAULT_EVM_BLOCK_GAS_LIMIT;
706-
}
707-
arith_uint256 blockGasLimit{blockGasLimitInt};
708-
709-
// Gas used in the block
710-
arith_uint256 blockGasUsed{};
711-
712692
while (mi != mempool.mapTx.get<T>().end() || !mapModifiedTxSet.empty() || !failedNonces.empty()) {
713693
// First try to find a new transaction in mapTx to evaluate.
714694
if (mi != mempool.mapTx.get<T>().end() &&
@@ -819,9 +799,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
819799
// Track failed custom TX. Used for removing EVM TXs from the queue.
820800
uint256 failedCustomTx;
821801

822-
// Gas used for the sorted entries
823-
arith_uint256 sortedGasUsed{};
824-
825802
// Apply and check custom TXs in order
826803
for (const auto& entry : sortedEntries) {
827804
const CTransaction& tx = entry->GetTx();
@@ -855,9 +832,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
855832
failedNonces,
856833
failedNoncesLookup,
857834
failedTxSet,
858-
sortedGasUsed,
859-
blockGasUsed,
860-
blockGasLimit,
861835
};
862836
auto res = EvmTxPreapply(evmTxCtx);
863837
if (res) {
@@ -880,15 +854,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
880854
break;
881855
}
882856

883-
if (evmType) {
884-
const auto totalGas = evm_try_unsafe_get_total_gas_used(result, evmQueueId);
885-
if (!result.ok) {
886-
LogPrintf("Failed to get total gas used in queue %d\n", evmQueueId);
887-
} else {
888-
sortedGasUsed = UintToArith256(uint256S({totalGas.begin(), totalGas.end()}));
889-
}
890-
}
891-
892857
// Track checked TXs to avoid double applying
893858
checkedDfTxHashSet.insert(tx.GetHash());
894859
}
@@ -919,6 +884,7 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
919884
// If the first TX in a failed set is not the failed TX
920885
// then remove from queue, otherwise it has not been added.
921886
if (entryHash != failedCustomTx) {
887+
CrossBoundaryResult result;
922888
evm_try_unsafe_remove_txs_above_hash_in_q(result, evmQueueId, entryHash.ToString());
923889
if (!result.ok) {
924890
LogPrintf("%s: Unable to remove %s from queue. Will result in a block hash mismatch.\n", __func__, entryHash.ToString());
@@ -938,9 +904,6 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
938904
cache.Flush();
939905
coinsCache.Flush();
940906

941-
// Set block gas used to sorted gas used
942-
blockGasUsed = sortedGasUsed;
943-
944907
for (const auto& entry : sortedEntries) {
945908
auto& hash = entry->GetTx().GetHash();
946909
if (failedNoncesLookup.count(hash)) {

src/txmempool.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class CTxMemPoolEntry
108108

109109
// EVM related data
110110
uint64_t evmMaxPromisedTipFee{};
111-
arith_uint256 evmGasUsed{};
112111
EvmAddressWithNonce evmAddressAndNonce;
113112
CustomTxType customTxType{CustomTxType::None};
114113

@@ -135,8 +134,6 @@ class CTxMemPoolEntry
135134
[[nodiscard]] CustomTxType GetCustomTxType() const { return customTxType; }
136135
void SetEVMPomisedTipFee(const uint64_t maxPromisedTipFee) { evmMaxPromisedTipFee = maxPromisedTipFee; }
137136
[[nodiscard]] uint64_t GetEVMPromisedTipFee() const { return evmMaxPromisedTipFee; }
138-
void SetEVMGasUsed(const arith_uint256 gasUsed) { evmGasUsed = gasUsed; }
139-
[[nodiscard]] arith_uint256 GetEVMGasUsed() const { return evmGasUsed; }
140137
void SetEVMAddrAndNonce(const EvmAddressWithNonce addrAndNonce) { evmAddressAndNonce = addrAndNonce; }
141138
[[nodiscard]] const EvmAddressWithNonce& GetEVMAddrAndNonce() const { return evmAddressAndNonce; }
142139

src/validation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,12 +946,10 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
946946
EvmAddressWithNonce evmAddrAndNonce{txResult.nonce, txResult.address.c_str()};
947947

948948
const auto tipFee = isEVMTx ? txResult.tip_fee : std::numeric_limits<uint64_t>::max();
949-
const auto usedGas = isEVMTx ? txResult.used_gas : std::numeric_limits<uint64_t>::min();
950949
const auto txResultSender = std::string(txResult.address.data(), txResult.address.length());
951950

952951
entry.SetEVMAddrAndNonce(evmAddrAndNonce);
953952
entry.SetEVMPomisedTipFee(tipFee);
954-
entry.SetEVMGasUsed(usedGas);
955953

956954
auto senderLimitFlag{false};
957955
if (!pool.checkAddressNonceAndFee(entry, txResultSender, senderLimitFlag)) {

0 commit comments

Comments
 (0)