Skip to content

Commit eef99fc

Browse files
authored
Pin several large futures. (#4883)
Port of #4882. ## Motivation On `testnet_conway`, ``` export LINERA_FAUCET_URL=https://faucet.testnet-conway.linera.net cargo test test_wasm_end_to_end_fungible::remote_net_grpc --features remote-net ``` fails with a stack overflow. ## Proposal `Box::pin` a lot of futures larger than 3 kB (using Claude, also to resolve merge conflicts). ## Test Plan CI This change fixed it for me locally. ## Release Plan - Noting to do. ## Links - `testnet_conway` version: #4882 - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent a53b568 commit eef99fc

File tree

5 files changed

+42
-48
lines changed

5 files changed

+42
-48
lines changed

linera-core/src/chain_worker/state.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,8 @@ where
13501350
let (_, committee) = self.chain.current_committee()?;
13511351
block.check_proposal_size(committee.policy().maximum_block_proposal_size)?;
13521352

1353-
let executed_block = self
1354-
.execute_block(&block, local_time, round, published_blobs)
1355-
.await?;
1353+
let executed_block =
1354+
Box::pin(self.execute_block(&block, local_time, round, published_blobs)).await?;
13561355

13571356
// No need to sign: only used internally.
13581357
let mut response = ChainInfoResponse::new(&self.chain, None);
@@ -1478,7 +1477,7 @@ where
14781477
let block = if let Some(outcome) = outcome {
14791478
outcome.clone().with(proposal.content.block.clone())
14801479
} else {
1481-
self.execute_block(block, local_time, round.multi_leader(), &published_blobs)
1480+
Box::pin(self.execute_block(block, local_time, round.multi_leader(), &published_blobs))
14821481
.await?
14831482
};
14841483

@@ -1613,10 +1612,12 @@ where
16131612
let block_hash = CryptoHash::new(&block);
16141613
self.execution_state_cache.insert_owned(
16151614
&block_hash,
1616-
self.chain
1617-
.execution_state
1618-
.with_context(|ctx| InactiveContext(ctx.base_key().clone()))
1619-
.await,
1615+
Box::pin(
1616+
self.chain
1617+
.execution_state
1618+
.with_context(|ctx| InactiveContext(ctx.base_key().clone())),
1619+
)
1620+
.await,
16201621
);
16211622
Ok(block)
16221623
}

linera-core/src/local_node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ where
8989
proposal: BlockProposal,
9090
) -> Result<ChainInfoResponse, LocalNodeError> {
9191
// In local nodes, we can trust fully_handle_certificate to carry all actions eventually.
92-
let (response, _actions) = self.node.state.handle_block_proposal(proposal).await?;
92+
let (response, _actions) =
93+
Box::pin(self.node.state.handle_block_proposal(proposal)).await?;
9394
Ok(response)
9495
}
9596

linera-core/src/worker.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ impl ProcessableCertificate for ConfirmedBlock {
563563
worker: &WorkerState<S>,
564564
certificate: ConfirmedBlockCertificate,
565565
) -> Result<(ChainInfoResponse, NetworkActions), WorkerError> {
566-
worker.handle_confirmed_certificate(certificate, None).await
566+
Box::pin(worker.handle_confirmed_certificate(certificate, None)).await
567567
}
568568
}
569569

@@ -572,7 +572,7 @@ impl ProcessableCertificate for ValidatedBlock {
572572
worker: &WorkerState<S>,
573573
certificate: ValidatedBlockCertificate,
574574
) -> Result<(ChainInfoResponse, NetworkActions), WorkerError> {
575-
worker.handle_validated_certificate(certificate).await
575+
Box::pin(worker.handle_validated_certificate(certificate)).await
576576
}
577577
}
578578

@@ -939,8 +939,13 @@ where
939939
) -> Result<(ChainInfoResponse, NetworkActions), WorkerError> {
940940
match self.full_certificate(certificate).await? {
941941
Either::Left(confirmed) => {
942-
self.handle_confirmed_certificate(confirmed, notify_when_messages_are_delivered)
943-
.await
942+
Box::pin(
943+
self.handle_confirmed_certificate(
944+
confirmed,
945+
notify_when_messages_are_delivered,
946+
),
947+
)
948+
.await
944949
}
945950
Either::Right(validated) => {
946951
if let Some(notifier) = notify_when_messages_are_delivered {
@@ -949,7 +954,7 @@ where
949954
warn!("Failed to notify message delivery to caller");
950955
}
951956
}
952-
self.handle_validated_certificate(validated).await
957+
Box::pin(self.handle_validated_certificate(validated)).await
953958
}
954959
}
955960
}
@@ -979,9 +984,9 @@ where
979984
.collect::<Vec<_>>(),
980985
);
981986

982-
let (info, actions, _outcome) = self
983-
.process_confirmed_block(certificate, notify_when_messages_are_delivered)
984-
.await?;
987+
let (info, actions, _outcome) =
988+
Box::pin(self.process_confirmed_block(certificate, notify_when_messages_are_delivered))
989+
.await?;
985990

986991
#[cfg(with_metrics)]
987992
{
@@ -1030,7 +1035,7 @@ where
10301035
#[cfg(with_metrics)]
10311036
let cert_str = certificate.inner().to_log_str();
10321037

1033-
let (info, actions, _outcome) = self.process_validated_block(certificate).await?;
1038+
let (info, actions, _outcome) = Box::pin(self.process_validated_block(certificate)).await?;
10341039
#[cfg(with_metrics)]
10351040
{
10361041
if matches!(_outcome, BlockOutcome::Processed) {

linera-execution/src/execution.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ where
129129
&[],
130130
);
131131
txn_tracker.add_created_blob(blob);
132-
ExecutionStateActor::new(self, &mut txn_tracker, &mut resource_controller)
133-
.run_user_action(application_id, action, context.refund_grant_to(), None)
134-
.await?;
132+
Box::pin(
133+
ExecutionStateActor::new(self, &mut txn_tracker, &mut resource_controller)
134+
.run_user_action(application_id, action, context.refund_grant_to(), None),
135+
)
136+
.await?;
135137

136138
Ok(())
137139
}

linera-views/src/backends/scylla_db.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,7 @@ impl ScyllaDbClient {
350350
let statement = self.get_multi_key_values_statement(map.len()).await?;
351351
let mut inputs = vec![root_key.to_vec()];
352352
inputs.extend(map.keys().cloned());
353-
let mut rows = self
354-
.session
355-
.execute_iter(statement, &inputs)
353+
let mut rows = Box::pin(self.session.execute_iter(statement, &inputs))
356354
.await?
357355
.rows_stream::<(Vec<u8>, Vec<u8>)>()?;
358356

@@ -378,9 +376,7 @@ impl ScyllaDbClient {
378376
let statement = self.get_multi_keys_statement(map.len()).await?;
379377
let mut inputs = vec![root_key.to_vec()];
380378
inputs.extend(map.keys().cloned());
381-
let mut rows = self
382-
.session
383-
.execute_iter(statement, &inputs)
379+
let mut rows = Box::pin(self.session.execute_iter(statement, &inputs))
384380
.await?
385381
.rows_stream::<(Vec<u8>,)>()?;
386382

@@ -471,13 +467,11 @@ impl ScyllaDbClient {
471467
let rows = match get_upper_bound_option(&key_prefix) {
472468
None => {
473469
let values = (root_key.to_vec(), key_prefix.clone());
474-
session
475-
.execute_iter(query_unbounded.clone(), values)
476-
.await?
470+
Box::pin(session.execute_iter(query_unbounded.clone(), values)).await?
477471
}
478472
Some(upper_bound) => {
479473
let values = (root_key.to_vec(), key_prefix.clone(), upper_bound);
480-
session.execute_iter(query_bounded.clone(), values).await?
474+
Box::pin(session.execute_iter(query_bounded.clone(), values)).await?
481475
}
482476
};
483477
let mut rows = rows.rows_stream::<(Vec<u8>,)>()?;
@@ -504,13 +498,11 @@ impl ScyllaDbClient {
504498
let rows = match get_upper_bound_option(&key_prefix) {
505499
None => {
506500
let values = (root_key.to_vec(), key_prefix.clone());
507-
session
508-
.execute_iter(query_unbounded.clone(), values)
509-
.await?
501+
Box::pin(session.execute_iter(query_unbounded.clone(), values)).await?
510502
}
511503
Some(upper_bound) => {
512504
let values = (root_key.to_vec(), key_prefix.clone(), upper_bound);
513-
session.execute_iter(query_bounded.clone(), values).await?
505+
Box::pin(session.execute_iter(query_bounded.clone(), values)).await?
514506
}
515507
};
516508
let mut rows = rows.rows_stream::<(Vec<u8>, Vec<u8>)>()?;
@@ -630,17 +622,13 @@ impl ReadableKeyValueStore for ScyllaDbStoreInternal {
630622
) -> Result<Option<Vec<u8>>, ScyllaDbStoreInternalError> {
631623
let store = self.store.deref();
632624
let _guard = self.acquire().await;
633-
store
634-
.read_value_internal(&self.root_key, key.to_vec())
635-
.await
625+
Box::pin(store.read_value_internal(&self.root_key, key.to_vec())).await
636626
}
637627

638628
async fn contains_key(&self, key: &[u8]) -> Result<bool, ScyllaDbStoreInternalError> {
639629
let store = self.store.deref();
640630
let _guard = self.acquire().await;
641-
store
642-
.contains_key_internal(&self.root_key, key.to_vec())
643-
.await
631+
Box::pin(store.contains_key_internal(&self.root_key, key.to_vec())).await
644632
}
645633

646634
async fn contains_keys(
@@ -687,9 +675,7 @@ impl ReadableKeyValueStore for ScyllaDbStoreInternal {
687675
) -> Result<Vec<Vec<u8>>, ScyllaDbStoreInternalError> {
688676
let store = self.store.deref();
689677
let _guard = self.acquire().await;
690-
store
691-
.find_keys_by_prefix_internal(&self.root_key, key_prefix.to_vec())
692-
.await
678+
Box::pin(store.find_keys_by_prefix_internal(&self.root_key, key_prefix.to_vec())).await
693679
}
694680

695681
async fn find_key_values_by_prefix(
@@ -698,8 +684,7 @@ impl ReadableKeyValueStore for ScyllaDbStoreInternal {
698684
) -> Result<Vec<(Vec<u8>, Vec<u8>)>, ScyllaDbStoreInternalError> {
699685
let store = self.store.deref();
700686
let _guard = self.acquire().await;
701-
store
702-
.find_key_values_by_prefix_internal(&self.root_key, key_prefix.to_vec())
687+
Box::pin(store.find_key_values_by_prefix_internal(&self.root_key, key_prefix.to_vec()))
703688
.await
704689
}
705690
}
@@ -792,7 +777,7 @@ impl KeyValueDatabase for ScyllaDbDatabaseInternal {
792777
let statement = session
793778
.prepare(format!("DESCRIBE KEYSPACE {}", KEYSPACE))
794779
.await?;
795-
let result = session.execute_iter(statement, &[]).await;
780+
let result = Box::pin(session.execute_iter(statement, &[])).await;
796781
let miss_msg = format!("'{}' not found in keyspaces", KEYSPACE);
797782
let result = match result {
798783
Ok(result) => result,
@@ -832,7 +817,7 @@ impl KeyValueDatabase for ScyllaDbDatabaseInternal {
832817
.await?;
833818

834819
// Execute the query
835-
let rows = self.store.session.execute_iter(statement, &[]).await?;
820+
let rows = Box::pin(self.store.session.execute_iter(statement, &[])).await?;
836821
let mut rows = rows.rows_stream::<(Vec<u8>,)>()?;
837822
let mut root_keys = BTreeSet::new();
838823
while let Some(row) = rows.next().await {

0 commit comments

Comments
 (0)