Skip to content

Commit

Permalink
Merge pull request #199 from casper-ecosystem/new-execution-engine
Browse files Browse the repository at this point in the history
New execution engine support
  • Loading branch information
mpapierski authored Nov 19, 2024
2 parents e48014c + 3da0df8 commit 94e3a69
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ uint = "0.9.5"
tempfile = "3.8.1"

[patch.crates-io]
casper-types = { version = "5.0.0", git = "https://github.com/casper-network/casper-node", branch = "feat-2.0" }
casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }

[package.metadata.deb]
features = ["vendored-openssl"]
Expand Down
9 changes: 9 additions & 0 deletions lib/cli/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{num::ParseIntError, str::ParseBoolError};

use base16::DecodeError;
use humantime::{DurationError, TimestampError};
use thiserror::Error;

Expand Down Expand Up @@ -187,6 +188,14 @@ pub enum CliError {
/// Failed to parse a validator public key.
#[error("Failed to parse a validator public key")]
FailedToParseValidatorPublicKey,

/// Failed to parse base16 bytes.
#[error("Failed to parse base16 bytes: {0}")]
FailedToParseBase16(#[from] DecodeError),

/// Unexpected transaction args variant.
#[error("Unexpected transaction args variant")]
UnexpectedTransactionArgsVariant,
}

impl From<CLValueError> for CliError {
Expand Down
49 changes: 38 additions & 11 deletions lib/cli/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use casper_types::SecretKey;
use casper_types::{
account::AccountHash, bytesrepr::Bytes, crypto, AsymmetricType, BlockHash, DeployHash, Digest,
EntityAddr, ExecutableDeployItem, HashAddr, Key, NamedArg, PricingMode, PublicKey, RuntimeArgs,
TimeDiff, Timestamp, TransactionHash, TransactionV1Hash, TransferTarget, UIntParseError, URef,
U512,
TimeDiff, Timestamp, TransactionArgs, TransactionHash, TransactionV1Hash, TransferTarget,
UIntParseError, URef, U512,
};

use super::{simple_args, CliError, PaymentStrParams, SessionStrParams};
Expand Down Expand Up @@ -238,18 +238,25 @@ fn check_no_conflicting_arg_types(
/// let simple_args = RuntimeArgs::new(); // Simple arguments
/// let json_args = RuntimeArgs::new(); // JSON arguments
///
/// let _result_args = args_from_simple_or_json(Some(simple_args), None);
/// let _result_args = args_from_simple_or_json(None, Some(json_args));
/// let _result_args = args_from_simple_or_json(Some(simple_args), None, None);
/// let _result_args = args_from_simple_or_json(None, Some(json_args), None);
/// ```
pub fn args_from_simple_or_json(
simple: Option<RuntimeArgs>,
json: Option<RuntimeArgs>,
) -> RuntimeArgs {
chunked: Option<Vec<u8>>,
) -> TransactionArgs {
// We can have exactly zero or one of the two as `Some`.
match (simple, json) {
(Some(args), None) | (None, Some(args)) => args,
(None, None) => RuntimeArgs::new(),
_ => unreachable!("should not have more than one of simple, json args"),
match chunked {
Some(chunked) => TransactionArgs::Bytesrepr(chunked.into()),
None => {
let named_args = match (simple, json) {
(Some(args), None) | (None, Some(args)) => args,
(None, None) => RuntimeArgs::new(),
_ => unreachable!("should not have more than one of simple, json args"),
};
TransactionArgs::Named(named_args)
}
}
}

Expand Down Expand Up @@ -361,6 +368,7 @@ pub(super) fn session_executable_deploy_item(
session_version,
session_entry_point,
is_session_transfer: session_transfer,
session_chunked_args,
} = params;
// This is to make sure that we're using &str consistently in the macro call below.
let is_session_transfer = if session_transfer { "true" } else { "" };
Expand Down Expand Up @@ -390,9 +398,11 @@ pub(super) fn session_executable_deploy_item(
let session_args = args_from_simple_or_json(
arg_simple::session::parse(session_args_simple)?,
args_json::session::parse(session_args_json)?,
session_chunked_args.map(ToOwned::to_owned),
);

if session_transfer {
let session_args = session_args.as_named().unwrap().clone();
if session_args.is_empty() {
return Err(CliError::InvalidArgument {
context: "is_session_transfer",
Expand All @@ -406,6 +416,8 @@ pub(super) fn session_executable_deploy_item(
error: session_entry_point.to_string(),
};
if let Some(session_name) = name(session_name) {
let session_args = session_args.as_named().unwrap().clone();

return Ok(ExecutableDeployItem::StoredContractByName {
name: session_name,
entry_point: entry_point(session_entry_point).ok_or_else(invalid_entry_point)?,
Expand All @@ -414,6 +426,7 @@ pub(super) fn session_executable_deploy_item(
}

if let Some(session_hash) = contract_hash(session_hash)? {
let session_args = session_args.as_named().unwrap().clone();
return Ok(ExecutableDeployItem::StoredContractByHash {
hash: session_hash.into(),
entry_point: entry_point(session_entry_point).ok_or_else(invalid_entry_point)?,
Expand All @@ -423,6 +436,7 @@ pub(super) fn session_executable_deploy_item(

let version = version(session_version)?;
if let Some(package_name) = name(session_package_name) {
let session_args = session_args.as_named().unwrap().clone();
return Ok(ExecutableDeployItem::StoredVersionedContractByName {
name: package_name,
version, // defaults to highest enabled version
Expand All @@ -432,6 +446,7 @@ pub(super) fn session_executable_deploy_item(
}

if let Some(package_hash) = contract_hash(session_package_hash)? {
let session_args = session_args.as_named().unwrap().clone();
return Ok(ExecutableDeployItem::StoredVersionedContractByHash {
hash: package_hash.into(),
version, // defaults to highest enabled version
Expand All @@ -454,9 +469,13 @@ pub(super) fn session_executable_deploy_item(
});
};

let args = session_args
.as_named()
.ok_or(CliError::UnexpectedTransactionArgsVariant)?;

Ok(ExecutableDeployItem::ModuleBytes {
module_bytes,
args: session_args,
args: args.clone(),
})
}

Expand Down Expand Up @@ -540,6 +559,7 @@ pub(super) fn payment_executable_deploy_item(
let payment_args = args_from_simple_or_json(
arg_simple::payment::parse(payment_args_simple)?,
args_json::payment::parse(payment_args_json)?,
None,
);

if let Ok(payment_args) = standard_payment(payment_amount) {
Expand All @@ -554,6 +574,11 @@ pub(super) fn payment_executable_deploy_item(
error: payment_entry_point.to_string(),
};

let payment_args = payment_args
.as_named()
.cloned()
.ok_or(CliError::UnexpectedTransactionArgsVariant)?;

if let Some(payment_name) = name(payment_name) {
return Ok(ExecutableDeployItem::StoredContractByName {
name: payment_name,
Expand Down Expand Up @@ -1036,6 +1061,7 @@ mod tests {
session_version: "",
session_entry_point: "entrypoint",
is_session_transfer: false,
session_chunked_args: None,
})
.unwrap_err();

Expand Down Expand Up @@ -1085,7 +1111,8 @@ mod tests {
session_args_json: "",
session_version: "",
session_entry_point: "",
is_session_transfer: false
is_session_transfer: false,
session_chunked_args: None,
}),
Err(CliError::ConflictingArguments { context, .. }) if context == test_context
));
Expand Down
1 change: 1 addition & 0 deletions lib/cli/session_str_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct SessionStrParams<'a> {
pub(super) session_version: &'a str,
pub(super) session_entry_point: &'a str,
pub(super) is_session_transfer: bool,
pub(super) session_chunked_args: Option<&'a [u8]>,
}

impl<'a> SessionStrParams<'a> {
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/simple_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub mod help;

use std::{fmt::Debug, mem, str::FromStr};
use std::{fmt::Debug, mem::size_of, str::FromStr};

use num_traits::Num;

Expand Down Expand Up @@ -87,7 +87,7 @@ fn parse_int<T: CLTyped + ToBytes + Debug + Num>(
value: &str,
) -> Result<CLValue, CliError> {
let parse = || {
let bit_width = mem::size_of::<T>() * 8;
let bit_width = size_of::<T>() * 8;
if value.is_empty() {
return Err(CliError::InvalidCLValue(format!(
"can't parse '' as u{}",
Expand Down
Loading

0 comments on commit 94e3a69

Please sign in to comment.