-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1/x][dev-inspect] Adds execution mode for a more expressive dry-run
- Introduces dev-inspect transaction type that can call any Move function - Allows return values from that Move function - Also provides much more detailed error message information
- Loading branch information
Showing
10 changed files
with
404 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use move_vm_runtime::session::SerializedReturnValues; | ||
use sui_types::error::ExecutionError; | ||
|
||
pub type TransactionIndex = usize; | ||
|
||
pub trait ExecutionMode { | ||
type ExecutionResult; | ||
type ExecutionResults; | ||
|
||
fn allow_arbitrary_function_calls() -> bool; | ||
|
||
fn make_result( | ||
return_values: &SerializedReturnValues, | ||
) -> Result<Self::ExecutionResult, ExecutionError>; | ||
|
||
fn empty_results() -> Self::ExecutionResults; | ||
|
||
fn add_result( | ||
results: &mut Self::ExecutionResults, | ||
idx: TransactionIndex, | ||
result: Self::ExecutionResult, | ||
); | ||
} | ||
|
||
pub struct Normal; | ||
|
||
impl ExecutionMode for Normal { | ||
type ExecutionResult = (); | ||
type ExecutionResults = (); | ||
|
||
fn allow_arbitrary_function_calls() -> bool { | ||
false | ||
} | ||
|
||
fn make_result(srv: &SerializedReturnValues) -> Result<Self::ExecutionResult, ExecutionError> { | ||
assert_invariant!(srv.return_values.is_empty(), "Return values must be empty"); | ||
Ok(()) | ||
} | ||
|
||
fn empty_results() -> Self::ExecutionResults { | ||
() | ||
} | ||
|
||
fn add_result(_: &mut Self::ExecutionResults, _: TransactionIndex, _: Self::ExecutionResult) { | ||
() | ||
} | ||
} | ||
|
||
pub struct DevInspect; | ||
|
||
impl ExecutionMode for DevInspect { | ||
type ExecutionResult = SerializedReturnValues; | ||
type ExecutionResults = Vec<(TransactionIndex, SerializedReturnValues)>; | ||
|
||
fn allow_arbitrary_function_calls() -> bool { | ||
true | ||
} | ||
|
||
fn make_result(srv: &SerializedReturnValues) -> Result<Self::ExecutionResult, ExecutionError> { | ||
let SerializedReturnValues { | ||
mutable_reference_outputs, | ||
return_values, | ||
} = srv; | ||
Ok(SerializedReturnValues { | ||
mutable_reference_outputs: mutable_reference_outputs.clone(), | ||
return_values: return_values.clone(), | ||
}) | ||
} | ||
|
||
fn empty_results() -> Self::ExecutionResults { | ||
todo!() | ||
} | ||
|
||
fn add_result( | ||
results: &mut Self::ExecutionResults, | ||
idx: TransactionIndex, | ||
result: Self::ExecutionResult, | ||
) { | ||
results.push((idx, result)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
macro_rules! assert_invariant { | ||
($cond:expr, $msg:expr) => { | ||
if !$cond { | ||
return Err(sui_types::error::ExecutionError::new_with_source( | ||
sui_types::error::ExecutionErrorKind::InvariantViolation, | ||
$msg, | ||
)); | ||
} | ||
}; | ||
} | ||
|
||
pub mod adapter; | ||
pub mod execution_mode; | ||
pub mod genesis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.