Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::{
},
errors::{invalid_params_check, Result as CoreResult},
verification::{
compute_receipts_root, VerificationConfig, VerifyTxLocalMode,
compute_epoch_receipts_root, VerificationConfig, VerifyTxLocalMode,
VerifyTxMode,
},
SharedTransactionPool,
Expand Down Expand Up @@ -1108,7 +1108,7 @@ impl ConsensusExecutionHandler {
self.data_man.insert_epoch_execution_commitment(
pivot_block.hash(),
commit_result.state_root.clone(),
compute_receipts_root(&epoch_receipts),
compute_epoch_receipts_root(&epoch_receipts),
BlockHeaderBuilder::compute_block_logs_bloom_hash(&epoch_receipts),
);

Expand Down
17 changes: 10 additions & 7 deletions crates/cfxcore/core/src/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use primitives::{
};
use secret_store::SecretStore;

use crate::verification::{compute_receipts_root, compute_transaction_root};
use crate::verification::{
compute_epoch_receipts_root, compute_transaction_root,
};
use cfx_executor::{
executive::{
contract_address, ExecutionOutcome, ExecutiveContext, TransactOptions,
Expand Down Expand Up @@ -379,12 +381,13 @@ pub fn genesis_block(
/* debug_record = */ debug_record.as_mut(),
)
.unwrap();
let receipt_root = compute_receipts_root(&vec![Arc::new(BlockReceipts {
receipts: vec![],
block_number: 0,
secondary_reward: U256::zero(),
tx_execution_error_messages: vec![],
})]);
let receipt_root =
compute_epoch_receipts_root(&vec![Arc::new(BlockReceipts {
receipts: vec![],
block_number: 0,
secondary_reward: U256::zero(),
tx_execution_error_messages: vec![],
})]);

let mut genesis = Block::new(
BlockHeaderBuilder::new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
message::{msgid, GetReceipts, ReceiptsWithEpoch},
},
message::{Message, RequestId},
verification::compute_receipts_root,
verification::compute_epoch_receipts_root,
UniqueId,
};
use cfx_parameters::light::{
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Receipts {
.map(|rs| Arc::new(rs))
.collect();

let received = compute_receipts_root(&rs);
let received = compute_epoch_receipts_root(&rs);

// retrieve local receipts root
let expected = self.witnesses.root_hashes_of(epoch)?.receipts_root_hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
synchronization_state::PeerFilter,
SynchronizationProtocolHandler,
},
verification::compute_receipts_root,
verification::compute_epoch_receipts_root,
};
use cfx_internal_common::{StateRootAuxInfo, StateRootWithAuxInfo};
use cfx_parameters::{
Expand Down Expand Up @@ -569,7 +569,7 @@ impl SnapshotManifestManager {
return None;
}
}
let receipt_root = compute_receipts_root(&epoch_receipts);
let receipt_root = compute_epoch_receipts_root(&epoch_receipts);
let logs_bloom_hash =
BlockHeaderBuilder::compute_block_logs_bloom_hash(
&epoch_receipts,
Expand Down
41 changes: 26 additions & 15 deletions crates/cfxcore/core/src/transaction_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::{
block_data_manager::BlockDataManager,
consensus::BestInformation,
transaction_pool::{nonce_pool::TxWithReadyInfo, pool_metrics::*},
verification::{VerificationConfig, VerifyTxLocalMode, VerifyTxMode},
verification::{
PackingCheckResult, VerificationConfig, VerifyTxLocalMode, VerifyTxMode,
},
};
use cfx_executor::{
machine::Machine, spec::TransitionsEpochHeight, state::State,
Expand Down Expand Up @@ -718,6 +720,21 @@ impl TransactionPool {
}
}

fn check_validity(
&self, tx: &SignedTransaction, best_epoch_height: u64,
best_block_number: u64,
) -> PackingCheckResult {
let spec = self.machine.spec(best_block_number, best_epoch_height);
let transitions = &self.machine.params().transition_heights;

self.verification_config.fast_recheck(
tx,
best_epoch_height,
transitions,
&spec,
)
}

pub fn pack_transactions<'a>(
&self, num_txs: usize, block_gas_limit: U256, evm_gas_limit: U256,
block_size_limit: usize, mut best_epoch_height: u64,
Expand All @@ -727,15 +744,17 @@ impl TransactionPool {
best_epoch_height += 1;
// The best block number is not necessary an exact number.
best_block_number += 1;

let validity = |tx: &SignedTransaction| {
self.check_validity(tx, best_epoch_height, best_block_number)
};

inner.pack_transactions(
num_txs,
block_gas_limit,
evm_gas_limit,
block_size_limit,
best_epoch_height,
best_block_number,
&self.verification_config,
&self.machine,
validity,
)
}

Expand All @@ -749,16 +768,8 @@ impl TransactionPool {
// The best block number is not necessary an exact number.
best_block_number += 1;

let spec = self.machine.spec(best_block_number, best_epoch_height);
let transitions = &self.machine.params().transition_heights;

let validity = |tx: &SignedTransaction| {
self.verification_config.fast_recheck(
tx,
best_epoch_height,
transitions,
&spec,
)
self.check_validity(tx, best_epoch_height, best_block_number)
};

inner.pack_transactions_1559(
Expand Down Expand Up @@ -800,7 +811,7 @@ impl TransactionPool {
for tx in txs {
gas_used[tx.space()] += *tx.gas_limit();
min_gas_price[tx.space()] =
min_gas_price[tx.space()].min(*tx.gas_limit());
min_gas_price[tx.space()].min(*tx.gas_price());
}

let core_gas_limit =
Expand Down
32 changes: 12 additions & 20 deletions crates/cfxcore/core/src/transaction_pool/transaction_pool_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ use super::{
TransactionPoolError,
};

use crate::verification::{PackingCheckResult, VerificationConfig};
use crate::verification::PackingCheckResult;
use cfx_executor::machine::Machine;
use cfx_packing_pool::PackingPoolConfig;
use cfx_parameters::{
block::cspace_block_gas_limit_after_cip1559,
block::{
cspace_block_gas_limit_after_cip1559,
espace_block_gas_limit_of_enabled_block,
},
consensus_internal::ELASTICITY_MULTIPLIER,
staking::DRIPS_PER_STORAGE_COLLATERAL_UNIT,
};
Expand Down Expand Up @@ -643,35 +646,22 @@ impl TransactionPoolInner {
/// pack at most num_txs transactions randomly
pub fn pack_transactions<'a>(
&mut self, num_txs: usize, block_gas_limit: U256, evm_gas_limit: U256,
block_size_limit: usize, best_epoch_height: u64,
best_block_number: u64, verification_config: &VerificationConfig,
machine: &Machine,
block_size_limit: usize,
validity: impl Fn(&SignedTransaction) -> PackingCheckResult,
) -> Vec<Arc<SignedTransaction>> {
let mut packed_transactions: Vec<Arc<SignedTransaction>> = Vec::new();
if num_txs == 0 {
return packed_transactions;
}

let spec = machine.spec(best_block_number, best_epoch_height);
let transitions = &machine.params().transition_heights;

let validity = |tx: &SignedTransaction| {
verification_config.fast_recheck(
tx,
best_epoch_height,
transitions,
&spec,
)
};

let (sampled_tx, used_gas, used_size) =
self.deferred_pool.packing_sampler(
Space::Ethereum,
std::cmp::min(block_gas_limit, evm_gas_limit),
block_size_limit,
num_txs,
U256::zero(),
validity,
&validity,
);
packed_transactions.extend_from_slice(&sampled_tx);

Expand All @@ -681,7 +671,7 @@ impl TransactionPoolInner {
block_size_limit - used_size,
num_txs - sampled_tx.len(),
U256::zero(),
validity,
&validity,
);
packed_transactions.extend_from_slice(&sampled_tx);

Expand Down Expand Up @@ -722,7 +712,9 @@ impl TransactionPoolInner {
machine.params().can_pack_evm_transaction(best_epoch_height);

let (evm_packed_tx_num, evm_used_size) = if can_pack_evm {
let gas_target = block_gas_limit * 5 / 10 / ELASTICITY_MULTIPLIER;
let gas_target =
espace_block_gas_limit_of_enabled_block(block_gas_limit)
/ ELASTICITY_MULTIPLIER;
let parent_base_price = parent_base_price[Space::Ethereum];
let min_base_price =
machine.params().min_base_price()[Space::Ethereum];
Expand Down
6 changes: 3 additions & 3 deletions crates/cfxcore/core/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn compute_block_receipts_root(block_receipts: &Vec<Receipt>) -> MerkleHash {
}

/// Compute a proof for the `tx_index_in_block`-th receipt in a block.
pub fn compute_block_receipt_proof(
pub fn compute_block_receipts_proof(
block_receipts: &Vec<Receipt>, tx_index_in_block: usize,
) -> TrieProof {
simple_mpt_proof(
Expand All @@ -118,7 +118,7 @@ fn epoch_receipts_trie(epoch_receipts: &Vec<Arc<BlockReceipts>>) -> SimpleMpt {

/// Compute epoch receipts root.
/// This value is stored in the `deferred_receipts_root` header field.
pub fn compute_receipts_root(
pub fn compute_epoch_receipts_root(
epoch_receipts: &Vec<Arc<BlockReceipts>>,
) -> MerkleHash {
simple_mpt_merkle_root(&mut epoch_receipts_trie(epoch_receipts))
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn compute_epoch_receipt_proof(
epoch_receipts: &Vec<Arc<BlockReceipts>>, block_index_in_epoch: usize,
tx_index_in_block: usize,
) -> EpochReceiptProof {
let block_receipt_proof = compute_block_receipt_proof(
let block_receipt_proof = compute_block_receipts_proof(
&epoch_receipts[block_index_in_epoch].receipts,
tx_index_in_block,
);
Expand Down
4 changes: 2 additions & 2 deletions crates/cfxcore/packing-pool/src/key_mng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<TX: PackingPoolTransaction> KeyMngTrait<PackingPoolMap<TX>>
) {
match (value, old_value) {
(Some(v), _) => {
self.insert(*key, v.first_gas_price());
self.insert(*key, v.first_priority_gas_price());
}
(None, Some(_)) => {
self.remove(key);
Expand All @@ -57,6 +57,6 @@ impl<TX: PackingPoolTransaction> KeyMngTrait<PackingPoolMap<TX>>
fn make_sort_key(
&self, _key: &TX::Sender, value: &PackingBatch<TX>,
) -> U256 {
value.first_gas_price()
value.first_priority_gas_price()
}
}
11 changes: 8 additions & 3 deletions crates/cfxcore/packing-pool/src/mock_tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::transaction::PackingPoolTransaction;
use cfx_types::U256;

#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, Hash)]
/// A minimal implementation of the [`PackingPoolTransaction`] trait for testing
Expand Down Expand Up @@ -26,9 +27,13 @@ impl PackingPoolTransaction for MockTransaction {

fn sender(&self) -> Self::Sender { self.sender }

fn nonce(&self) -> cfx_types::U256 { self.nonce.into() }
fn nonce(&self) -> U256 { self.nonce.into() }

fn gas_price(&self) -> cfx_types::U256 { self.gas_price.into() }
fn gas_price(&self) -> U256 { self.gas_price.into() }

fn gas_limit(&self) -> cfx_types::U256 { self.gas_limit.into() }
// mock tx is a eip155 like transaction, so we use gas_price as
// max_priority_gas_price
fn max_priority_gas_price(&self) -> U256 { self.gas_price.into() }

fn gas_limit(&self) -> U256 { self.gas_limit.into() }
}
Loading
Loading