Skip to content

Commit

Permalink
Iterate on the notion of resources for messages in the linera-sdk (#1534
Browse files Browse the repository at this point in the history
)

* add missing fields to Resources

* update fixtures
  • Loading branch information
ma2bd authored Jan 22, 2024
1 parent 4ac2bee commit 79d3541
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
13 changes: 11 additions & 2 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,30 @@ impl fmt::Display for Timestamp {
}
}

/// Resources that are spent during an execution.
/// Resources that an application may spend during the execution of transaction or an
/// application call.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Resources {
/// An amount of execution fuel.
pub fuel: u64,
/// A number of read operations to be executed.
pub read_operations: u32,
/// A number of write operations to be executed.
// TODO(#1530): This is not used at the moment.
pub write_operations: u32,
/// A number of bytes to read.
pub bytes_to_read: u32,
/// A number of bytes to write.
pub bytes_to_write: u32,
/// An amount of storage space to use.
/// A number of messages to be sent.
pub messages: u32,
/// The size of the messages to be sent.
// TODO(#1531): Account for the type of message to be sent.
pub message_size: u32,
/// An increase in the amount of storage space.
pub storage_size_delta: u32,
// TODO(#1532): Account for the system calls that we plan on calling.
// TODO(#1533): Allow declaring calls to other applications instead of having to count them here.
}

/// An error type for arithmetic errors.
Expand Down
Binary file modified linera-execution/tests/fixtures/counter_contract.wasm
Binary file not shown.
Binary file modified linera-execution/tests/fixtures/counter_service.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions linera-execution/tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use test_case::test_case;
/// called correctly and consume the expected amount of fuel.
///
/// To update the bytecode files, run `linera-execution/update_wasm_fixtures.sh`.
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::Wasmer, 37_048, ExecutionRuntimeConfig::Synchronous; "wasmer"))]
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::WasmerWithSanitizer, 37_471, ExecutionRuntimeConfig::Synchronous; "wasmer_with_sanitizer"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::Wasmtime, 37_471, ExecutionRuntimeConfig::Synchronous; "wasmtime"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::WasmtimeWithSanitizer, 37_471, ExecutionRuntimeConfig::Synchronous; "wasmtime_with_sanitizer"))]
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::Wasmer, 36_458, ExecutionRuntimeConfig::Synchronous; "wasmer"))]
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::WasmerWithSanitizer, 36_876, ExecutionRuntimeConfig::Synchronous; "wasmer_with_sanitizer"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::Wasmtime, 36_876, ExecutionRuntimeConfig::Synchronous; "wasmtime"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::WasmtimeWithSanitizer, 36_876, ExecutionRuntimeConfig::Synchronous; "wasmtime_with_sanitizer"))]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_fuel_for_counter_wasm_application(
wasm_runtime: WasmRuntime,
Expand Down
2 changes: 2 additions & 0 deletions linera-sdk/contract.wit
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ record resources {
write-operations: u32,
bytes-to-read: u32,
bytes-to-write: u32,
messages: u32,
message-size: u32,
storage-size-delta: u32,
}

Expand Down
2 changes: 2 additions & 0 deletions linera-sdk/src/contract/conversions_to_wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ impl From<Resources> for wit_types::Resources {
write_operations: resources.write_operations,
bytes_to_read: resources.bytes_to_read,
bytes_to_write: resources.bytes_to_write,
messages: resources.messages,
message_size: resources.message_size,
storage_size_delta: resources.storage_size_delta,
}
}
Expand Down

0 comments on commit 79d3541

Please sign in to comment.