Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime api #3402

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

runtime api #3402

wants to merge 2 commits into from

Conversation

usagi32
Copy link
Contributor

@usagi32 usagi32 commented Feb 24, 2025

addresses #1977

@usagi32
Copy link
Contributor Author

usagi32 commented Feb 24, 2025

I’m not yet allowed to request for reviews, but since you opened the issue, @jvff, a review would be appreciated.

@ma2bd ma2bd requested a review from jvff February 24, 2025 23:00
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Could you try to minimize the changes in the PR to make the review easier?

@usagi32 usagi32 requested a review from jvff February 25, 2025 14:30
Comment on lines +27 to +30
#[cfg_attr(with_wasmer, test_case(WasmRuntime::Wasmer, 92357; "wasmer"))]
#[cfg_attr(with_wasmer, test_case(WasmRuntime::WasmerWithSanitizer, 92917; "wasmer_with_sanitizer"))]
#[cfg_attr(with_wasmtime, test_case(WasmRuntime::Wasmtime, 92749; "wasmtime"))]
#[cfg_attr(with_wasmtime, test_case(WasmRuntime::WasmtimeWithSanitizer, 92749; "wasmtime_with_sanitizer"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: adding an underscore to make it easier to read.

Suggested change
#[cfg_attr(with_wasmer, test_case(WasmRuntime::Wasmer, 92357; "wasmer"))]
#[cfg_attr(with_wasmer, test_case(WasmRuntime::WasmerWithSanitizer, 92917; "wasmer_with_sanitizer"))]
#[cfg_attr(with_wasmtime, test_case(WasmRuntime::Wasmtime, 92749; "wasmtime"))]
#[cfg_attr(with_wasmtime, test_case(WasmRuntime::WasmtimeWithSanitizer, 92749; "wasmtime_with_sanitizer"))]
#[cfg_attr(with_wasmer, test_case(WasmRuntime::Wasmer, 92_357; "wasmer"))]
#[cfg_attr(with_wasmer, test_case(WasmRuntime::WasmerWithSanitizer, 92_917; "wasmer_with_sanitizer"))]
#[cfg_attr(with_wasmtime, test_case(WasmRuntime::Wasmtime, 92_749; "wasmtime"))]
#[cfg_attr(with_wasmtime, test_case(WasmRuntime::WasmtimeWithSanitizer, 92_749; "wasmtime_with_sanitizer"))]

@@ -44,13 +45,15 @@ pub mod views;

use std::fmt::Debug;

extern crate linera_base as linera_base_crate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this. We can keep using linera_base for now.

Comment on lines +6 to +9
mod conversions_from_contract_wit;
mod conversions_from_service_wit;
mod conversions_to_contract_wit;
mod conversions_to_service_wit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be possible to join the contract/service module pairs so that we only have conversions_from_wit and conversions_to_wit. We could get the common code and place it in a macro, and then use wit_base_api identifier as the macro's parameter. Then it could be called like:

conversions_to_wit(crate::contract::wit::base_runtime_api);
conversions_to_wit(crate::service::wit::base_runtime_api);

@jvff jvff added the refactor label Feb 25, 2025
@jvff jvff added this to the Mainnet milestone Feb 25, 2025
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! Just a few tweaks would be nice before merging 😄

@@ -31,6 +31,27 @@ where
balance_owners: Mutex<Option<Vec<AccountOwner>>>,
}

impl<Application> ServiceRuntime<Application>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to move this to the end of the file. The public methods that users can call are more important than this helper method, so they should come first in the file.

identifiers::{
Account, AccountOwner, ApplicationId, BytecodeId, ChainId, ChannelName, Destination,
MessageId, Owner, StreamName,
},
ownership::{ChainOwnership, TimeoutConfig},
};
use linera_base_crate::data_types::BlockHeight;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be in the import above.

pub fn new(runtime: Runtime) -> Self {
SystemApiData {
Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I usually use Self in the method signatures to keep them short, and the expanded name when constructing to avoid using Self too much and making it harder to find what it Self when glancing at the code.

Suggested change
Self {
RuntimeApiData {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually avoid using the non syntactic sugared full name because when refactoring, changing the type's name would require many consequent changes. But I guess this could be done for the constructor.


#[wit_export(package = "linera:app")]
impl<Caller, Runtime> ContractSystemApi<Caller>
#[linera_witty::wit_export(package = "linera:app")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The full path shouldn't be needed here.

Suggested change
#[linera_witty::wit_export(package = "linera:app")]
#[wit_export(package = "linera:app")]

impl WriteBatch for ContractSyncRuntimeHandle {
fn write_batch(&mut self, batch: Batch) -> Result<(), ExecutionError> {
ContractRuntime::write_batch(self, batch)
#[linera_witty::wit_export(package = "linera:app")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Same here regarding the path prefix.

Suggested change
#[linera_witty::wit_export(package = "linera:app")]
#[wit_export(package = "linera:app")]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants