Skip to content

Commit 28887a6

Browse files
bilboquetdamip
andauthored
decouple block production from blocking on pool slowness (#4942)
* decouple block production from blocking on pool slowness * remove time dependencies * fix var names * improve buffer swapping intervals * review fixes * fix endorsements * fix test comment ci task check_gas_cost_definitions untill we add back the required code add a timeout to APIs targeting pools Signed-off-by: Jean-François <[email protected]> --------- Signed-off-by: Jean-François <[email protected]> Co-authored-by: Damir Vodenicarevic <[email protected]>
1 parent 04b9619 commit 28887a6

File tree

37 files changed

+1179
-524
lines changed

37 files changed

+1179
-524
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,23 @@ jobs:
116116
submodules: "recursive"
117117
- uses: crate-ci/typos@master
118118

119-
misc:
120-
if: github.ref != 'refs/heads/staging'
121-
needs: sanity
122-
runs-on: ubuntu-latest
123-
continue-on-error: true
124-
steps:
125-
- uses: actions/checkout@v4
126-
with:
127-
submodules: "recursive"
128-
- uses: dtolnay/rust-toolchain@master
129-
with:
130-
toolchain: 1.81.0
131-
- uses: Swatinem/rust-cache@v2
132-
with:
133-
shared-key: "clippy"
134-
save-if: ${{ github.ref_name == 'main' }}
135-
- run: cargo xtask check_gas_cost_definitions
119+
# misc:
120+
# if: github.ref != 'refs/heads/staging'
121+
# needs: sanity
122+
# runs-on: ubuntu-latest
123+
# continue-on-error: true
124+
# steps:
125+
# - uses: actions/checkout@v4
126+
# with:
127+
# submodules: "recursive"
128+
# - uses: dtolnay/rust-toolchain@master
129+
# with:
130+
# toolchain: 1.81.0
131+
# - uses: Swatinem/rust-cache@v2
132+
# with:
133+
# shared-key: "clippy"
134+
# save-if: ${{ github.ref_name == 'main' }}
135+
# - run: cargo xtask check_gas_cost_definitions
136136

137137
# Full cross-platform tests required to merge on main branch
138138
full:

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

massa-api-exports/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ massa_hash = {workspace = true}
2323
massa_wallet = {workspace = true}
2424
massa_versioning = {workspace = true}
2525
massa_deferred_calls = { workspace = true }
26+
massa_pool_exports = { workspace = true }
2627

2728
[dev-dependencies]
2829
serial_test = {workspace = true}

massa-api-exports/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,6 @@ pub struct APIConfig {
9393
pub max_datastore_keys_queries: Option<u32>,
9494
/// Limit the number of addresses in a single datastore keys request
9595
pub max_addresses_datastore_keys_query: Option<u32>,
96+
/// timeout for API calls to pools (in milliseconds)
97+
pub pool_api_timeout: MassaTime,
9698
}

massa-api-exports/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use jsonrpsee::types::{ErrorObject, ErrorObjectOwned};
55

66
use massa_hash::MassaHashError;
77
use massa_models::error::ModelsError;
8+
use massa_pool_exports::PoolError;
89
use massa_time::TimeError;
910
use massa_versioning::versioning_factory::FactoryError;
1011
use massa_wallet::WalletError;
@@ -47,6 +48,8 @@ pub enum ApiError {
4748
InternalServerError(String),
4849
/// Versioning Factory error: {0}
4950
FactoryError(#[from] FactoryError),
51+
/// Pool error: {0}
52+
PoolError(#[from] PoolError),
5053
}
5154

5255
impl From<ApiError> for ErrorObjectOwned {
@@ -70,6 +73,7 @@ impl From<ApiError> for ErrorObjectOwned {
7073
ApiError::MissingConfig(_) => -32018,
7174
ApiError::WrongAPI => -32019,
7275
ApiError::FactoryError(_) => -32020,
76+
ApiError::PoolError(_) => -32021,
7377
};
7478

7579
ErrorObject::owned(code, err.to_string(), None::<()>)

massa-api/src/public.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,22 @@ impl MassaRpcServer for API<Public> {
521521
};
522522

523523
let pool_stats = (
524-
self.0.pool_command_sender.get_operation_count(),
525-
self.0.pool_command_sender.get_endorsement_count(),
524+
match self
525+
.0
526+
.pool_command_sender
527+
.get_operation_count(Some(self.0.api_settings.pool_api_timeout))
528+
{
529+
Ok(count) => count,
530+
Err(e) => return Err(ApiError::PoolError(e).into()),
531+
},
532+
match self
533+
.0
534+
.pool_command_sender
535+
.get_endorsement_count(Some(self.0.api_settings.pool_api_timeout))
536+
{
537+
Ok(count) => count,
538+
Err(e) => return Err(ApiError::PoolError(e).into()),
539+
},
526540
);
527541

528542
let next_slot_result = last_slot
@@ -683,7 +697,11 @@ impl MassaRpcServer for API<Public> {
683697
}
684698

685699
// ask pool whether it carries the operations
686-
let in_pool = self.0.pool_command_sender.contains_operations(&ops);
700+
let in_pool = self
701+
.0
702+
.pool_command_sender
703+
.contains_operations(&ops, Some(api_cfg.pool_api_timeout))
704+
.map_err(|e| ApiError::InternalServerError(format!("Pool error: {}", e)))?;
687705

688706
let op_exec_statuses = self.0.execution_controller.get_ops_exec_status(&ops);
689707

@@ -797,7 +815,8 @@ impl MassaRpcServer for API<Public> {
797815
let in_pool = self
798816
.0
799817
.pool_command_sender
800-
.contains_endorsements(&endorsement_ids);
818+
.contains_endorsements(&endorsement_ids, Some(self.0.api_settings.pool_api_timeout))
819+
.map_err(|e| ApiError::InternalServerError(format!("Pool error: {}", e)))?;
801820

802821
// check finality by cross-referencing Consensus and looking for final blocks that contain the endorsement
803822
let is_final: Vec<bool> = {

massa-api/src/tests/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub(crate) fn get_apiv2_server(addr: &SocketAddr) -> (API<ApiV2>, APIConfig) {
7474
max_datastore_keys_queries: Some(1000),
7575
max_datastore_key_length: 255,
7676
max_addresses_datastore_keys_query: Some(50),
77+
pool_api_timeout: MassaTime::from_millis(1000),
7778
};
7879

7980
// let shared_storage: massa_storage::Storage = massa_storage::Storage::create_root();
@@ -154,6 +155,7 @@ pub(crate) fn start_public_api(addr: SocketAddr) -> (API<Public>, APIConfig) {
154155
max_datastore_keys_queries: Some(1000),
155156
max_datastore_key_length: 255,
156157
max_addresses_datastore_keys_query: Some(50),
158+
pool_api_timeout: MassaTime::from_millis(1000),
157159
};
158160

159161
let shared_storage: massa_storage::Storage = massa_storage::Storage::create_root();

massa-api/src/tests/public.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ async fn get_status() {
102102
});
103103

104104
let mut pool_ctrl = MockPoolController::new();
105-
pool_ctrl.expect_get_operation_count().returning(|| 1024);
106-
pool_ctrl.expect_get_endorsement_count().returning(|| 2048);
105+
pool_ctrl
106+
.expect_get_operation_count()
107+
.returning(|_| Ok(1024));
108+
pool_ctrl
109+
.expect_get_endorsement_count()
110+
.returning(|_| Ok(2048));
107111

108112
api_public.0.pool_command_sender = Box::new(pool_ctrl);
109113
api_public.0.protocol_controller = Box::new(protocol_ctrl);
@@ -178,7 +182,7 @@ async fn get_operations() {
178182
let mut pool_ctrl = MockPoolController::new();
179183
pool_ctrl
180184
.expect_contains_operations()
181-
.returning(|ids| ids.iter().map(|_id| true).collect());
185+
.returning(|ids, _| Ok(ids.iter().map(|_id| true).collect()));
182186

183187
let mut exec_ctrl = MockExecutionController::new();
184188
exec_ctrl
@@ -221,7 +225,7 @@ async fn get_endorsements() {
221225
let mut pool_ctrl = MockPoolController::new();
222226
pool_ctrl
223227
.expect_contains_endorsements()
224-
.returning(|ids| ids.iter().map(|_| true).collect::<Vec<bool>>());
228+
.returning(|ids, _| Ok(ids.iter().map(|_| true).collect::<Vec<bool>>()));
225229

226230
let mut consensus_ctrl = MockConsensusController::new();
227231
consensus_ctrl

massa-execution-worker/src/tests/scenarios_mandatories.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ fn send_and_receive_async_message() {
931931
Address::from_str("AS12DSPbsNvvdP1ScCivmKpbQfcJJ3tCQFkNb8ewkRuNjsgoL2AeQ").unwrap()
932932
}
933933
77658377 => {
934-
Address::from_str("AS127QtY6Hzm6BnJc9wqCBfPNvEH9fKer3LiMNNQmcX3MzLwCL6G6").unwrap()
934+
Address::from_str("AS1Ua3PVmURnETZMLeFXDFGkbgqGjz8NfEHTyGRRGe15sk1kCM9a").unwrap()
935935
}
936936
_ => panic!("CHAINID not supported"),
937937
};
@@ -4294,7 +4294,7 @@ fn send_and_receive_async_message_with_reset() {
42944294
Address::from_str("AS12DSPbsNvvdP1ScCivmKpbQfcJJ3tCQFkNb8ewkRuNjsgoL2AeQ").unwrap()
42954295
}
42964296
77658377 => {
4297-
Address::from_str("AS12KJXFU1tBJRVm7ADek2RzXgKPCR9vmpy7vK7Ywe1UaqNMtTZeA").unwrap()
4297+
Address::from_str("AS1g6jtsCD2ptEKJ4f6Bj5xJnCxu1Uimdkgwx7vEXfgCLMQNoxRv").unwrap()
42984298
}
42994299
_ => panic!("CHAINID not supported"),
43004300
};
@@ -4652,7 +4652,7 @@ fn execution_trace_nested() {
46524652

46534653
let from_addr = match *CHAINID {
46544654
77 => "AS1aEhosr1ebJJZ7cEMpSVKbY6xp1p4DdXabGb8fdkKKJ6WphGnR".to_string(),
4655-
77658377 => "AS1Bc3kZ6LhPLJvXV4vcVJLFRExRFbkPWD7rCg9aAdQ1NGzRwgnu".to_string(),
4655+
77658377 => "AS128FLq3PrWe7RQKD1UoNzk4fKeGwm4PjEYHiTXi2QHyQx5UE71L".to_string(),
46564656
_ => {
46574657
panic!("Invalid chain id for this test");
46584658
}

massa-execution-worker/src/tests/universe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ impl ExecutionTestUniverse {
272272
let op = OperationType::ExecuteSC {
273273
data: data.to_vec(),
274274
// MAX_GAS MUST BE AT LEAST 314_000_000 (SP COMPIL)
275-
// here we use 1.5B as most of the tests perform a SC creation:
276-
// 314_000_000 (SP COMPIL) + 745_000_000 (CL COMPIL) + margin
277-
max_gas: 1_500_000_000,
275+
276+
// 314_000_000 (SP COMPIL) + 745_000_000 (CL COMPIL) + BIG margin
277+
max_gas: 3_500_000_000,
278278
max_coins: Amount::from_str("5000000").unwrap(),
279279
datastore,
280280
};

0 commit comments

Comments
 (0)