Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added global and per sender limits to txns pool #2300

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ consensus.eth_block_gas_limit = 84000000
consensus.gas_price = "4_761_904_800_000"

consensus.genesis_fork = { at_height = 0, call_mode_1_sets_caller_to_parent_caller = false, failed_scilla_call_from_gas_exempt_caller_causes_revert = false, scilla_messages_can_call_evm_contracts = false, scilla_contract_creation_increments_account_balance = false, scilla_json_preserve_order = false }

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 20
txn_pool.total_slots_for_all_senders = 50000

5 changes: 5 additions & 0 deletions config-single-node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ consensus.gas_price = "4_761_904_800_000"
consensus.local_address = "host.docker.internal"

consensus.genesis_fork = { at_height = 0, call_mode_1_sets_caller_to_parent_caller = false, failed_scilla_call_from_gas_exempt_caller_causes_revert = false, scilla_messages_can_call_evm_contracts = false, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true }

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 20
txn_pool.total_slots_for_all_senders = 50000

4 changes: 4 additions & 0 deletions z2/resources/chain-specs/zq2-devnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ consensus.scilla_call_gas_exempt_addrs = []
consensus.contract_upgrade_block_heights = { deposit_v3 = 3600, deposit_v4 = 428400 }

api_servers = [{ port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
4 changes: 4 additions & 0 deletions z2/resources/chain-specs/zq2-infratest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ consensus.scilla_call_gas_exempt_addrs = []
consensus.contract_upgrade_block_heights = { deposit_v4 = 0 }

api_servers = [{ port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
4 changes: 4 additions & 0 deletions z2/resources/chain-specs/zq2-perftest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ consensus.scilla_call_gas_exempt_addrs = []
consensus.contract_upgrade_block_heights = { deposit_v4 = 0 }

api_servers = [{ port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
6 changes: 5 additions & 1 deletion z2/resources/chain-specs/zq2-protomainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ consensus.genesis_fork = { at_height = 0, call_mode_1_sets_caller_to_parent_call
consensus.forks = [
{ at_height = 5342400, failed_scilla_call_from_gas_exempt_caller_causes_revert = true, call_mode_1_sets_caller_to_parent_caller = true },
{ at_height = 7966800, scilla_messages_can_call_evm_contracts = true, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true },
]
]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
6 changes: 5 additions & 1 deletion z2/resources/chain-specs/zq2-prototestnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ consensus.forks = [
{ at_height = 8404000, failed_scilla_call_from_gas_exempt_caller_causes_revert = true, call_mode_1_sets_caller_to_parent_caller = true },
{ at_height = 10200000, scilla_messages_can_call_evm_contracts = true },
{ at_height = 11152000, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true },
]
]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
4 changes: 4 additions & 0 deletions z2/resources/chain-specs/zq2-richard.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ consensus.scilla_call_gas_exempt_addrs = []
consensus.contract_upgrade_block_heights = { deposit_v4 = 0 }

api_servers = [{ port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
4 changes: 4 additions & 0 deletions z2/resources/chain-specs/zq2-uccbtest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ consensus.scilla_call_gas_exempt_addrs = []
consensus.contract_upgrade_block_heights = { deposit_v4 = 0 }

api_servers = [{ port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]

txn_pool.maximum_global_size = 100000
txn_pool.maximum_txn_count_per_sender = 200
txn_pool.total_slots_for_all_senders = 50000
3 changes: 2 additions & 1 deletion z2/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use zilliqa::{
eth_chain_id_default, failed_request_sleep_duration_default, local_address_default,
max_blocks_in_flight_default, scilla_address_default, scilla_ext_libs_path_default,
scilla_stdlib_dir_default, state_rpc_limit_default, total_native_token_supply_default,
Amount, ConsensusConfig, ContractUpgradesBlockHeights, GenesisDeposit,
Amount, ConsensusConfig, ContractUpgradesBlockHeights, GenesisDeposit, TxnPoolConfig,
},
transaction::EvmGas,
};
Expand Down Expand Up @@ -544,6 +544,7 @@ impl Setup {
forks: vec![],
genesis_fork: genesis_fork_default(),
},
txn_pool: TxnPoolConfig::default(),
block_request_limit: block_request_limit_default(),
max_blocks_in_flight: max_blocks_in_flight_default(),
block_request_batch_size: block_request_batch_size_default(),
Expand Down
6 changes: 6 additions & 0 deletions zilliqa/benches/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ fn process_empty(c: &mut Criterion) {
"0x0000000000000000000000000000000000000001",
],
]
txn_pool.maximum_global_size = 10000000000
txn_pool.maximum_txn_count_per_sender = 200000000
txn_pool.total_slots_for_all_senders = 50000000
"#,
secret_key.node_public_key()
))
Expand Down Expand Up @@ -200,6 +203,9 @@ fn consensus(
consensus.genesis_fork.scilla_messages_can_call_evm_contracts = true
consensus.genesis_fork.scilla_contract_creation_increments_account_balance = true
consensus.genesis_fork.scilla_json_preserve_order = true
txn_pool.maximum_global_size = 10000000000
txn_pool.maximum_txn_count_per_sender = 200000000
txn_pool.total_slots_for_all_senders = 50000000
"#,
)
.unwrap();
Expand Down
5 changes: 4 additions & 1 deletion zilliqa/src/api/zilliqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ fn create_transaction(
| ValidationOutcome::InsufficientGasEvm(_, _)
| ValidationOutcome::NonceTooLow(_, _)
| ValidationOutcome::InsufficientFunds(_, _)
| ValidationOutcome::BlockGasLimitExceeded(_, _) => {
| ValidationOutcome::BlockGasLimitExceeded(_, _)
| ValidationOutcome::TotalNumberOfSlotsExceeded
| ValidationOutcome::GlobalTransactionCountExceeded
| ValidationOutcome::TransactionCountExceededForSender => {
RPCErrorCode::RpcInvalidParameter
}
_ => RPCErrorCode::RpcVerifyRejected,
Expand Down
36 changes: 36 additions & 0 deletions zilliqa/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub struct NodeConfig {
pub eth_chain_id: u64,
/// Consensus-specific data.
pub consensus: ConsensusConfig,
/// Transaction pool config
pub txn_pool: TxnPoolConfig,
/// The maximum duration between a recieved block's timestamp and the current time. Defaults to 10 seconds.
#[serde(default = "allowed_timestamp_skew_default")]
pub allowed_timestamp_skew: Duration,
Expand Down Expand Up @@ -167,6 +169,7 @@ impl Default for NodeConfig {
api_servers: vec![],
eth_chain_id: eth_chain_id_default(),
consensus: ConsensusConfig::default(),
txn_pool: TxnPoolConfig::default(),
allowed_timestamp_skew: allowed_timestamp_skew_default(),
data_dir: None,
state_cache_size: state_cache_size_default(),
Expand Down Expand Up @@ -472,6 +475,39 @@ impl Default for ConsensusConfig {
}
}

#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct TxnPoolConfig {
/// Maximum number of transactions transaction pool can hold
pub maximum_global_size: u64,
/// Maximum number of transactions per single sender
pub maximum_txn_count_per_sender: u64,
/// total slots for all senders
pub total_slots_for_all_senders: u64,
}

pub fn maximum_txn_pool_global_size() -> u64 {
10000
}

pub fn maximum_txn_pool_txn_count_per_user() -> u64 {
500
}

pub fn total_slots_for_all_senders() -> u64 {
1_000_000
}

impl Default for TxnPoolConfig {
fn default() -> Self {
Self {
maximum_global_size: maximum_txn_pool_global_size(),
maximum_txn_count_per_sender: maximum_txn_pool_txn_count_per_user(),
total_slots_for_all_senders: total_slots_for_all_senders(),
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Forks(Vec<Fork>);

Expand Down
3 changes: 2 additions & 1 deletion zilliqa/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ impl Consensus {
peers.clone(),
)?;

let txn_pool_config = config.txn_pool.clone();
let mut consensus = Consensus {
secret_key,
config,
Expand All @@ -334,7 +335,7 @@ impl Consensus {
db,
receipts_cache: HashMap::new(),
receipts_cache_hash: Hash::ZERO,
transaction_pool: Default::default(),
transaction_pool: TransactionPool::new(txn_pool_config),
early_proposal: None,
create_next_block_on_timeout: false,
view_updated_at: SystemTime::now(),
Expand Down
Loading