Skip to content

Commit 60d95f8

Browse files
committed
Change the API to return true of the state is trivial.
1 parent 86951ed commit 60d95f8

File tree

8 files changed

+25
-30
lines changed

8 files changed

+25
-30
lines changed

linera-execution/src/execution_state_actor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ where
669669
callback.respond(validation_round);
670670
}
671671

672-
HasNonTrivialStorage {
672+
TotalStorageSize {
673673
application,
674674
callback,
675675
} => {
@@ -681,6 +681,7 @@ where
681681
}
682682
None => (0, 0),
683683
};
684+
tracing::info!("TotalStorageSize, result={result:?}");
684685
callback.respond(result);
685686
}
686687
}
@@ -1231,7 +1232,7 @@ pub enum ExecutionRequest {
12311232
callback: Sender<Option<u32>>,
12321233
},
12331234

1234-
HasNonTrivialStorage {
1235+
TotalStorageSize {
12351236
application: ApplicationId,
12361237
#[debug(skip)]
12371238
callback: Sender<(u32, u32)>,

linera-execution/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,8 @@ pub trait BaseRuntime {
735735
/// Asserts the existence of a data blob with the given hash.
736736
fn assert_data_blob_exists(&mut self, hash: DataBlobHash) -> Result<(), ExecutionError>;
737737

738-
/// Returns true if the corresponding contract uses a non-zero amount of storage.
739-
fn has_non_trivial_storage(
740-
&mut self,
741-
application: ApplicationId,
742-
) -> Result<bool, ExecutionError>;
738+
/// Returns true if the corresponding contract uses a zero amount of storage.
739+
fn has_trivial_storage(&mut self, application: ApplicationId) -> Result<bool, ExecutionError>;
743740
}
744741

745742
pub trait ServiceRuntime: BaseRuntime {

linera-execution/src/runtime.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,19 +898,16 @@ where
898898
.recv_response()
899899
}
900900

901-
fn has_non_trivial_storage(
902-
&mut self,
903-
application: ApplicationId,
904-
) -> Result<bool, ExecutionError> {
901+
fn has_trivial_storage(&mut self, application: ApplicationId) -> Result<bool, ExecutionError> {
905902
let this = self.inner();
906903
let (key_size, value_size) = this
907904
.execution_state_sender
908-
.send_request(move |callback| ExecutionRequest::HasNonTrivialStorage {
905+
.send_request(move |callback| ExecutionRequest::TotalStorageSize {
909906
application,
910907
callback,
911908
})?
912909
.recv_response()?;
913-
Ok(key_size > 0 || value_size > 0)
910+
Ok(key_size + value_size == 0)
914911
}
915912
}
916913

linera-execution/src/wasm/runtime_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ where
232232
}
233233

234234
/// Returns true if the corresponding contract uses a non-zero amount of storage.
235-
fn has_non_trivial_storage(
235+
fn has_trivial_storage(
236236
caller: &mut Caller,
237237
application: ApplicationId,
238238
) -> Result<bool, RuntimeError> {
239239
caller
240240
.user_data_mut()
241241
.runtime
242-
.has_non_trivial_storage(application)
242+
.has_trivial_storage(application)
243243
.map_err(|error| RuntimeError::Custom(error.into()))
244244
}
245245

linera-sdk/src/contract/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ where
166166
}
167167

168168
/// Returns true if the corresponding contract uses a non-zero amount of storage.
169-
pub fn has_non_trivial_storage(&mut self, application: ApplicationId) -> bool {
170-
base_wit::has_non_trivial_storage(application.into())
169+
pub fn has_trivial_storage(&mut self, application: ApplicationId) -> bool {
170+
base_wit::has_trivial_storage(application.into())
171171
}
172172
}
173173

linera-sdk/src/contract/test_runtime.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ where
7878
expected_http_requests: VecDeque<(http::Request, http::Response)>,
7979
expected_read_data_blob_requests: VecDeque<(DataBlobHash, Vec<u8>)>,
8080
expected_assert_data_blob_exists_requests: VecDeque<(DataBlobHash, Option<()>)>,
81-
expected_has_non_trivial_storage_requests: VecDeque<(ApplicationId, bool)>,
81+
expected_has_trivial_storage_requests: VecDeque<(ApplicationId, bool)>,
8282
expected_open_chain_calls: VecDeque<(ChainOwnership, ApplicationPermissions, Amount, ChainId)>,
8383
expected_publish_module_calls: VecDeque<ExpectedPublishModuleCall>,
8484
expected_create_application_calls: VecDeque<ExpectedCreateApplicationCall>,
@@ -128,7 +128,7 @@ where
128128
expected_http_requests: VecDeque::new(),
129129
expected_read_data_blob_requests: VecDeque::new(),
130130
expected_assert_data_blob_exists_requests: VecDeque::new(),
131-
expected_has_non_trivial_storage_requests: VecDeque::new(),
131+
expected_has_trivial_storage_requests: VecDeque::new(),
132132
expected_open_chain_calls: VecDeque::new(),
133133
expected_publish_module_calls: VecDeque::new(),
134134
expected_create_application_calls: VecDeque::new(),
@@ -938,13 +938,13 @@ where
938938
.push_back((hash, response));
939939
}
940940

941-
/// Adds an expected `has_non_trivial_storage` call, and the response it should return in the test.
942-
pub fn add_expected_has_non_trivial_storage_requests(
941+
/// Adds an expected `has_trivial_storage` call, and the response it should return in the test.
942+
pub fn add_expected_has_trivial_storage_requests(
943943
&mut self,
944944
application: ApplicationId,
945945
response: bool,
946946
) {
947-
self.expected_has_non_trivial_storage_requests
947+
self.expected_has_trivial_storage_requests
948948
.push_back((application, response));
949949
}
950950

@@ -1009,11 +1009,11 @@ where
10091009
response.expect("Blob does not exist!");
10101010
}
10111011

1012-
/// Returns true if the corresponding contract uses a non-zero amount of storage.
1013-
pub fn has_non_trivial_storage(&mut self, application: ApplicationId) -> bool {
1014-
let maybe_request = self.expected_has_non_trivial_storage_requests.pop_front();
1012+
/// Returns true if the corresponding contract uses a zero amount of storage.
1013+
pub fn has_trivial_storage(&mut self, application: ApplicationId) -> bool {
1014+
let maybe_request = self.expected_has_trivial_storage_requests.pop_front();
10151015
let (expected_application_id, response) =
1016-
maybe_request.expect("Unexpected has_non_trivial_storage request");
1016+
maybe_request.expect("Unexpected has_trivial_storage request");
10171017
assert_eq!(application, expected_application_id);
10181018
response
10191019
}

linera-sdk/src/service/runtime.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ where
160160
base_wit::assert_data_blob_exists(hash.into())
161161
}
162162

163-
/// Returns true if the corresponding contract uses a non-zero amount of storage.
164-
pub fn has_non_trivial_storage(&self, application: ApplicationId) -> bool {
165-
base_wit::has_non_trivial_storage(application.into())
163+
/// Returns true if the corresponding contract uses a zero amount of storage.
164+
pub fn has_trivial_storage(&self, application: ApplicationId) -> bool {
165+
base_wit::has_trivial_storage(application.into())
166166
}
167167
}
168168

linera-sdk/wit/base-runtime-api.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface base-runtime-api {
1616
assert-before: func(timestamp: timestamp);
1717
read-data-blob: func(hash: data-blob-hash) -> list<u8>;
1818
assert-data-blob-exists: func(hash: data-blob-hash);
19-
has-non-trivial-storage: func(application: application-id) -> bool;
19+
has-trivial-storage: func(application: application-id) -> bool;
2020
log: func(message: string, level: log-level);
2121
contains-key-new: func(key: list<u8>) -> u32;
2222
contains-key-wait: func(promise-id: u32) -> bool;

0 commit comments

Comments
 (0)