Skip to content

Commit

Permalink
Introduce the VmRuntime.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Feb 21, 2025
1 parent 4f3e9e8 commit 4ee42ae
Show file tree
Hide file tree
Showing 39 changed files with 429 additions and 394 deletions.
32 changes: 2 additions & 30 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use crate::{
crypto::{BcsHashable, CryptoHash},
doc_scalar, hex_debug, http,
identifiers::{
ApplicationId, BlobId, BlobType, BytecodeId, ChainId, Destination, EventId,
GenericApplicationId, MessageId, StreamId, UserApplicationId,
ApplicationId, BlobId, BlobType, ChainId, Destination, EventId, GenericApplicationId,
StreamId,
},
limited_writer::{LimitedWriter, LimitedWriterError},
time::{Duration, SystemTime},
Expand Down Expand Up @@ -782,30 +782,6 @@ pub enum OracleResponse {

impl<'de> BcsHashable<'de> for OracleResponse {}

/// Description of the necessary information to run a user application.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash, Serialize)]
pub struct UserApplicationDescription {
/// The unique ID of the bytecode to use for the application.
pub bytecode_id: BytecodeId,
/// The unique ID of the application's creation.
pub creation: MessageId,
/// The parameters of the application.
#[serde(with = "serde_bytes")]
#[debug(with = "hex_debug")]
pub parameters: Vec<u8>,
/// Required dependencies.
pub required_application_ids: Vec<UserApplicationId>,
}

impl From<&UserApplicationDescription> for UserApplicationId {
fn from(description: &UserApplicationDescription) -> Self {
UserApplicationId {
bytecode_id: description.bytecode_id,
creation: description.creation,
}
}
}

/// A WebAssembly module's bytecode.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Bytecode {
Expand Down Expand Up @@ -1156,10 +1132,6 @@ doc_scalar!(
Blob,
"A blob of binary data, with its content-addressed blob ID."
);
doc_scalar!(
UserApplicationDescription,
"Description of the necessary information to run a user application"
);

/// The time it takes to compress a bytecode.
#[cfg(with_metrics)]
Expand Down
6 changes: 2 additions & 4 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use async_graphql::SimpleObject;
use futures::stream::{self, StreamExt, TryStreamExt};
use linera_base::{
crypto::{CryptoHash, ValidatorPublicKey},
data_types::{
Amount, ArithmeticError, BlockHeight, OracleResponse, Timestamp, UserApplicationDescription,
},
data_types::{Amount, ArithmeticError, BlockHeight, OracleResponse, Timestamp},
ensure,
identifiers::{
ChainId, ChannelFullName, Destination, GenericApplicationId, MessageId, Owner,
Expand All @@ -28,7 +26,7 @@ use linera_execution::{
ExecutionOutcome, ExecutionRuntimeContext, ExecutionStateView, Message, MessageContext,
Operation, OperationContext, Query, QueryContext, QueryOutcome, RawExecutionOutcome,
RawOutgoingMessage, ResourceController, ResourceTracker, ServiceRuntimeEndpoint,
TransactionTracker,
TransactionTracker, UserApplicationDescription,
};
use linera_views::{
context::Context,
Expand Down
8 changes: 4 additions & 4 deletions linera-chain/src/unit_tests/chain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use std::{collections::BTreeMap, iter};
use assert_matches::assert_matches;
use linera_base::{
crypto::{AccountPublicKey, CryptoHash, ValidatorPublicKey},
data_types::{
Amount, ApplicationPermissions, Blob, BlockHeight, Bytecode, Timestamp,
UserApplicationDescription,
},
data_types::{Amount, ApplicationPermissions, Blob, BlockHeight, Bytecode, Timestamp},
hashed::Hashed,
identifiers::{ApplicationId, BytecodeId, ChainId, MessageId},
ownership::ChainOwnership,
Expand All @@ -22,6 +19,7 @@ use linera_execution::{
test_utils::{ExpectedCall, MockApplication},
ExecutionError, ExecutionRuntimeConfig, ExecutionRuntimeContext, Message, MessageKind,
Operation, ResourceControlPolicy, SystemMessage, SystemOperation, TestExecutionRuntimeContext,
UserApplicationDescription, VmRuntime,
};
use linera_views::{
context::{Context as _, MemoryContext},
Expand Down Expand Up @@ -66,11 +64,13 @@ fn make_app_description() -> (UserApplicationDescription, Blob, Blob) {
let service = Bytecode::new(b"service".into());
let contract_blob = Blob::new_contract_bytecode(contract.compress());
let service_blob = Blob::new_service_bytecode(service.compress());
let vm_runtime = VmRuntime::default();

let bytecode_id = BytecodeId::new(contract_blob.id().hash, service_blob.id().hash);
(
UserApplicationDescription {
bytecode_id,
vm_runtime,
creation: make_admin_message_id(BlockHeight(2)),
required_application_ids: vec![],
parameters: vec![],
Expand Down
19 changes: 13 additions & 6 deletions linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use linera_base::{
time::Duration,
};
use linera_core::{client::BlanketMessagePolicy, DEFAULT_GRACE_PERIOD};
use linera_execution::{ResourceControlPolicy, WasmRuntime, WithWasmDefault as _};
use linera_execution::{ResourceControlPolicy, VmRuntime};
use linera_views::store::CommonStoreConfig;

#[cfg(feature = "fs")]
Expand Down Expand Up @@ -96,10 +96,6 @@ pub struct ClientOptions {
#[arg(long, default_value = "10")]
pub max_pending_message_bundles: usize,

/// The WebAssembly runtime to use.
#[arg(long)]
pub wasm_runtime: Option<WasmRuntime>,

/// The maximal number of chains loaded in memory at a given time.
#[arg(long, default_value = "40")]
pub max_loaded_chains: NonZeroUsize,
Expand Down Expand Up @@ -202,7 +198,6 @@ impl ClientOptions {
.add_common_config(self.common_config())
.await?,
&genesis_config,
self.wasm_runtime.with_wasm_default(),
job,
))
.await?;
Expand Down Expand Up @@ -802,6 +797,10 @@ pub enum ClientCommand {
/// The bytecode ID of the application to create.
bytecode_id: BytecodeId,

/// The virtual machine runtime to use.
#[arg(long)]
vm_runtime: Option<VmRuntime>,

/// An optional chain ID to host the application. The default chain of the wallet
/// is used otherwise.
creator: Option<ChainId>,
Expand Down Expand Up @@ -835,6 +834,10 @@ pub enum ClientCommand {
/// Path to the Wasm file for the application "service" bytecode.
service: PathBuf,

/// The virtual machine runtime to use.
#[arg(long)]
vm_runtime: Option<VmRuntime>,

/// An optional chain ID to publish the bytecode. The default chain of the wallet
/// is used otherwise.
publisher: Option<ChainId>,
Expand Down Expand Up @@ -1241,6 +1244,10 @@ pub enum ProjectCommand {
/// is used otherwise.
publisher: Option<ChainId>,

/// The virtual machine runtime to use.
#[arg(long)]
vm_runtime: Option<VmRuntime>,

/// The shared parameters as JSON string.
#[arg(long)]
json_parameters: Option<String>,
Expand Down
61 changes: 14 additions & 47 deletions linera-client/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{fmt, str::FromStr};

use async_trait::async_trait;
use linera_base::identifiers::{BlobId, ChainId};
use linera_execution::WasmRuntime;
#[cfg(with_storage)]
use linera_storage::{list_all_blob_ids, list_all_chain_ids};
use linera_storage::{DbStorage, Storage};
Expand Down Expand Up @@ -637,7 +636,6 @@ pub trait Runnable {
pub async fn run_with_storage<Job>(
config: StoreConfig,
genesis_config: &GenesisConfig,
wasm_runtime: Option<WasmRuntime>,
job: Job,
) -> Result<Job::Output, Error>
where
Expand All @@ -647,37 +645,29 @@ where
StoreConfig::Memory(config, namespace) => {
let store_config = MemoryStoreConfig::new(config.common_config.max_stream_queries);
let mut storage =
DbStorage::<MemoryStore, _>::new(store_config, &namespace, ROOT_KEY, wasm_runtime)
.await?;
DbStorage::<MemoryStore, _>::new(store_config, &namespace, ROOT_KEY).await?;
genesis_config.initialize_storage(&mut storage).await?;
Ok(job.run(storage).await)
}
#[cfg(feature = "storage-service")]
StoreConfig::Service(config, namespace) => {
let storage =
DbStorage::<ServiceStoreClient, _>::new(config, &namespace, ROOT_KEY, wasm_runtime)
.await?;
DbStorage::<ServiceStoreClient, _>::new(config, &namespace, ROOT_KEY).await?;
Ok(job.run(storage).await)
}
#[cfg(feature = "rocksdb")]
StoreConfig::RocksDb(config, namespace) => {
let storage =
DbStorage::<RocksDbStore, _>::new(config, &namespace, ROOT_KEY, wasm_runtime)
.await?;
let storage = DbStorage::<RocksDbStore, _>::new(config, &namespace, ROOT_KEY).await?;
Ok(job.run(storage).await)
}
#[cfg(feature = "dynamodb")]
StoreConfig::DynamoDb(config, namespace) => {
let storage =
DbStorage::<DynamoDbStore, _>::new(config, &namespace, ROOT_KEY, wasm_runtime)
.await?;
let storage = DbStorage::<DynamoDbStore, _>::new(config, &namespace, ROOT_KEY).await?;
Ok(job.run(storage).await)
}
#[cfg(feature = "scylladb")]
StoreConfig::ScyllaDb(config, namespace) => {
let storage =
DbStorage::<ScyllaDbStore, _>::new(config, &namespace, ROOT_KEY, wasm_runtime)
.await?;
let storage = DbStorage::<ScyllaDbStore, _>::new(config, &namespace, ROOT_KEY).await?;
Ok(job.run(storage).await)
}
}
Expand All @@ -694,50 +684,27 @@ pub async fn full_initialize_storage(
)),
#[cfg(feature = "storage-service")]
StoreConfig::Service(config, namespace) => {
let wasm_runtime = None;
let mut storage = DbStorage::<ServiceStoreClient, _>::initialize(
config,
&namespace,
ROOT_KEY,
wasm_runtime,
)
.await?;
let mut storage =
DbStorage::<ServiceStoreClient, _>::initialize(config, &namespace, ROOT_KEY)
.await?;
Ok(genesis_config.initialize_storage(&mut storage).await?)
}
#[cfg(feature = "rocksdb")]
StoreConfig::RocksDb(config, namespace) => {
let wasm_runtime = None;
let mut storage = DbStorage::<RocksDbStore, _>::initialize(
config,
&namespace,
ROOT_KEY,
wasm_runtime,
)
.await?;
let mut storage =
DbStorage::<RocksDbStore, _>::initialize(config, &namespace, ROOT_KEY).await?;
Ok(genesis_config.initialize_storage(&mut storage).await?)
}
#[cfg(feature = "dynamodb")]
StoreConfig::DynamoDb(config, namespace) => {
let wasm_runtime = None;
let mut storage = DbStorage::<DynamoDbStore, _>::initialize(
config,
&namespace,
ROOT_KEY,
wasm_runtime,
)
.await?;
let mut storage =
DbStorage::<DynamoDbStore, _>::initialize(config, &namespace, ROOT_KEY).await?;
Ok(genesis_config.initialize_storage(&mut storage).await?)
}
#[cfg(feature = "scylladb")]
StoreConfig::ScyllaDb(config, namespace) => {
let wasm_runtime = None;
let mut storage = DbStorage::<ScyllaDbStore, _>::initialize(
config,
&namespace,
ROOT_KEY,
wasm_runtime,
)
.await?;
let mut storage =
DbStorage::<ScyllaDbStore, _>::initialize(config, &namespace, ROOT_KEY).await?;
Ok(genesis_config.initialize_storage(&mut storage).await?)
}
}
Expand Down
6 changes: 4 additions & 2 deletions linera-core/src/chain_worker/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use custom_debug_derive::Debug;
use linera_base::{
crypto::{CryptoHash, ValidatorPublicKey},
data_types::{Blob, BlockHeight, Timestamp, UserApplicationDescription},
data_types::{Blob, BlockHeight, Timestamp},
hashed::Hashed,
identifiers::{BlobId, ChainId, UserApplicationId},
};
Expand All @@ -22,7 +22,9 @@ use linera_chain::{
ChainStateView,
};
use linera_execution::{
committee::Epoch, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, ServiceSyncRuntime,
committee::{Epoch, ValidatorName},
Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, ServiceSyncRuntime,
UserApplicationDescription,
};
use linera_storage::Storage;
use tokio::sync::{mpsc, oneshot, OwnedRwLockReadGuard};
Expand Down
7 changes: 4 additions & 3 deletions linera-core/src/chain_worker/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{

use linera_base::{
crypto::{CryptoHash, ValidatorPublicKey},
data_types::{Blob, BlockHeight, UserApplicationDescription},
data_types::{Blob, BlockHeight},
ensure,
hashed::Hashed,
identifiers::{BlobId, ChainId, UserApplicationId},
Expand All @@ -27,8 +27,9 @@ use linera_chain::{
ChainError, ChainStateView,
};
use linera_execution::{
committee::Epoch, Message, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint,
SystemMessage,
committee::{Epoch, ValidatorName},
Message, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, SystemMessage,
UserApplicationDescription,
};
use linera_storage::{Clock as _, Storage};
use linera_views::views::{ClonableView, ViewError};
Expand Down
4 changes: 2 additions & 2 deletions linera-core/src/chain_worker/state/temporary_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
//! Operations that don't persist any changes to the chain state.
use linera_base::{
data_types::{ArithmeticError, Timestamp, UserApplicationDescription},
data_types::{ArithmeticError, Timestamp},
ensure,
identifiers::{AccountOwner, ChannelFullName, GenericApplicationId, UserApplicationId},
};
use linera_chain::data_types::{
BlockExecutionOutcome, ExecutedBlock, IncomingBundle, Medium, MessageAction, ProposalContent,
ProposedBlock,
};
use linera_execution::{ChannelSubscription, Query, QueryOutcome};
use linera_execution::{ChannelSubscription, Query, QueryOutcome, UserApplicationDescription};
use linera_storage::{Clock as _, Storage};
use linera_views::views::View;
#[cfg(with_testing)]
Expand Down
6 changes: 5 additions & 1 deletion linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use linera_execution::{
CREATE_APPLICATION_MESSAGE_INDEX, OPEN_CHAIN_MESSAGE_INDEX,
},
ExecutionError, Operation, Query, QueryOutcome, QueryResponse, SystemExecutionError,
SystemQuery, SystemResponse,
SystemQuery, SystemResponse, VmRuntime,
};
use linera_storage::{Clock as _, Storage};
use linera_views::views::ViewError;
Expand Down Expand Up @@ -2912,6 +2912,7 @@ where
>(
&self,
bytecode_id: BytecodeId<A, Parameters, InstantiationArgument>,
vm_runtime: VmRuntime,
parameters: &Parameters,
instantiation_argument: &InstantiationArgument,
required_application_ids: Vec<UserApplicationId>,
Expand All @@ -2922,6 +2923,7 @@ where
Ok(self
.create_application_untyped(
bytecode_id.forget_abi(),
vm_runtime,
parameters,
instantiation_argument,
required_application_ids,
Expand All @@ -2944,13 +2946,15 @@ where
pub async fn create_application_untyped(
&self,
bytecode_id: BytecodeId,
vm_runtime: VmRuntime,
parameters: Vec<u8>,
instantiation_argument: Vec<u8>,
required_application_ids: Vec<UserApplicationId>,
) -> Result<ClientOutcome<(UserApplicationId, ConfirmedBlockCertificate)>, ChainClientError>
{
self.execute_operation(Operation::System(SystemOperation::CreateApplication {
bytecode_id,
vm_runtime,
parameters,
instantiation_argument,
required_application_ids,
Expand Down
Loading

0 comments on commit 4ee42ae

Please sign in to comment.