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

Fix max op not taken in account #3587

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion massa-models/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub const ENDORSEMENT_COUNT: u32 = 16;
/// Threshold for fitness.
pub const DELTA_F0: u64 = 64 * (ENDORSEMENT_COUNT as u64 + 1);
/// Maximum number of operations per block
pub const MAX_OPERATIONS_PER_BLOCK: u32 = 5000;
pub const MAX_OPERATIONS_PER_BLOCK: u32 = 10000;
/// Maximum block size in bytes
pub const MAX_BLOCK_SIZE: u32 = 1_000_000;
/// Maximum capacity of the asynchronous messages pool
Expand Down
1 change: 1 addition & 0 deletions massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ async fn launch(
roll_price: ROLL_PRICE,
max_block_endorsement_count: ENDORSEMENT_COUNT,
operation_validity_periods: OPERATION_VALIDITY_PERIODS,
max_operations_per_block: MAX_OPERATIONS_PER_BLOCK,
max_operation_pool_size_per_thread: SETTINGS.pool.max_pool_size_per_thread,
max_endorsements_pool_size_per_thread: SETTINGS.pool.max_pool_size_per_thread,
channels_size: POOL_CONTROLLER_CHANNEL_SIZE,
Expand Down
2 changes: 2 additions & 0 deletions massa-pool-exports/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct PoolConfig {
pub roll_price: Amount,
/// operation validity periods
pub operation_validity_periods: u64,
/// max operations per block
pub max_operations_per_block: u32,
/// max operation pool size per thread (in number of operations)
pub max_operation_pool_size_per_thread: usize,
/// max endorsement pool size per thread (in number of endorsements)
Expand Down
5 changes: 3 additions & 2 deletions massa-pool-exports/src/test_exports/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2022 MASSA LABS <info@massa.net>

use massa_models::config::{
ENDORSEMENT_COUNT, MAX_BLOCK_SIZE, MAX_GAS_PER_BLOCK, OPERATION_VALIDITY_PERIODS, ROLL_PRICE,
THREAD_COUNT,
ENDORSEMENT_COUNT, MAX_BLOCK_SIZE, MAX_GAS_PER_BLOCK, MAX_OPERATIONS_PER_BLOCK,
OPERATION_VALIDITY_PERIODS, ROLL_PRICE, THREAD_COUNT,
};

use crate::PoolConfig;
Expand All @@ -17,6 +17,7 @@ impl Default for PoolConfig {
max_block_size: MAX_BLOCK_SIZE,
max_operation_pool_size_per_thread: 1000,
max_endorsements_pool_size_per_thread: 1000,
max_operations_per_block: MAX_OPERATIONS_PER_BLOCK,
max_block_endorsement_count: ENDORSEMENT_COUNT,
channels_size: 1024,
broadcast_enabled: false,
Expand Down
9 changes: 9 additions & 0 deletions massa-pool-worker/src/operation_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,17 @@ impl OperationPool {
let mut remaining_space = self.config.max_block_size as usize;
// init remaining gas
let mut remaining_gas = self.config.max_block_gas;
// init remaining number of operations
let mut remaining_ops = self.config.max_operations_per_block;
// cache of balances
let mut balance_cache: PreHashMap<Address, Amount> = Default::default();

// iterate over pool operations in the right thread, from best to worst
for cursor in self.sorted_ops_per_thread[slot.thread as usize].iter() {
// if we have reached the maximum number of operations, stop
if remaining_ops == 0 {
break;
}
let op_info = self
.operations
.get(&cursor.get_id())
Expand Down Expand Up @@ -262,6 +268,9 @@ impl OperationPool {
// update remaining block gas
remaining_gas -= op_info.max_gas;

// update remaining number of operations
remaining_ops -= 1;

// update balance cache
*creator_balance = creator_balance.saturating_sub(op_info.max_spending);
}
Expand Down