Skip to content

Commit 7ba8e2c

Browse files
Some corrections of the linera-execution code. (#4514)
## Motivation The `CreateApplication` return value has the possibility of an error, which can never happen. ## Proposal The `Result<_,_>` return type for `CreateApplication` is eliminated. Other changes are made: * Simplify the processing of errors when possible. * Remove the conversion `.into_iter().collect()` when the input and return type are the same. * Remove the dependency on the orders of the return values for the tests. ## Test Plan CI ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None.
1 parent 240e7a9 commit 7ba8e2c

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

linera-execution/src/execution_state_actor.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ where
175175
}
176176

177177
OwnerBalances { callback } => {
178-
let balances = self.state.system.balances.index_values().await?;
179-
callback.respond(balances.into_iter().collect());
178+
callback.respond(self.state.system.balances.index_values().await?);
180179
}
181180

182181
BalanceOwners { callback } => {
@@ -379,7 +378,7 @@ where
379378
self.txn_tracker,
380379
)
381380
.await?;
382-
callback.respond(Ok(create_application_result));
381+
callback.respond(create_application_result);
383382
}
384383

385384
PerformHttpRequest {
@@ -1113,7 +1112,7 @@ pub enum ExecutionRequest {
11131112
parameters: Vec<u8>,
11141113
required_application_ids: Vec<ApplicationId>,
11151114
#[debug(skip)]
1116-
callback: Sender<Result<CreateApplicationResult, ExecutionError>>,
1115+
callback: Sender<CreateApplicationResult>,
11171116
},
11181117

11191118
PerformHttpRequest {

linera-execution/src/runtime.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -860,16 +860,14 @@ where
860860

861861
this.resource_controller.track_http_request()?;
862862

863-
let response = this
864-
.execution_state_sender
863+
this.execution_state_sender
865864
.send_request(|callback| ExecutionRequest::PerformHttpRequest {
866865
request,
867866
http_responses_are_oracle_responses:
868867
Self::LIMIT_HTTP_RESPONSE_SIZE_TO_ORACLE_RESPONSE_SIZE,
869868
callback,
870869
})?
871-
.recv_response()?;
872-
Ok(response)
870+
.recv_response()
873871
}
874872

875873
fn assert_before(&mut self, timestamp: Timestamp) -> Result<(), ExecutionError> {
@@ -897,8 +895,7 @@ where
897895
let blob_id = hash.into();
898896
this.execution_state_sender
899897
.send_request(|callback| ExecutionRequest::AssertBlobExists { blob_id, callback })?
900-
.recv_response()?;
901-
Ok(())
898+
.recv_response()
902899
}
903900
}
904901

@@ -1467,7 +1464,7 @@ impl ContractRuntime for ContractSyncRuntimeHandle {
14671464
required_application_ids,
14681465
callback,
14691466
})?
1470-
.recv_response()??;
1467+
.recv_response()?;
14711468

14721469
let contract = self.inner().prepare_for_call(self.clone(), true, app_id)?;
14731470

linera-execution/tests/service_runtime_apis.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
#![allow(clippy::field_reassign_with_default)]
55

6-
use std::{collections::BTreeMap, vec};
6+
use std::{
7+
collections::{BTreeMap, BTreeSet},
8+
vec,
9+
};
710

811
use linera_base::{data_types::Amount, identifiers::AccountOwner};
912
use linera_execution::{
@@ -116,8 +119,12 @@ async fn test_read_owner_balances_system_api(
116119

117120
application.expect_call(ExpectedCall::handle_query(move |runtime, _query| {
118121
assert_eq!(
119-
runtime.read_owner_balances().unwrap(),
120-
accounts.into_iter().collect::<Vec<_>>(),
122+
runtime
123+
.read_owner_balances()
124+
.unwrap()
125+
.into_iter()
126+
.collect::<BTreeMap<_, _>>(),
127+
accounts,
121128
);
122129
Ok(vec![])
123130
}));
@@ -148,8 +155,12 @@ async fn test_read_balance_owners_system_api(
148155

149156
application.expect_call(ExpectedCall::handle_query(move |runtime, _query| {
150157
assert_eq!(
151-
runtime.read_balance_owners().unwrap(),
152-
accounts.keys().copied().collect::<Vec<_>>()
158+
runtime
159+
.read_balance_owners()
160+
.unwrap()
161+
.into_iter()
162+
.collect::<BTreeSet<_>>(),
163+
accounts.keys().copied().collect::<BTreeSet<_>>()
153164
);
154165
Ok(vec![])
155166
}));

0 commit comments

Comments
 (0)