Skip to content

Commit

Permalink
add replay command to the CLI which point to existing replay commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lanvidr committed Oct 24, 2023
1 parent 5bd9ef0 commit 11debf0
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sui-replay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub async fn execute_replay_command(

sandbox_state.check_effects()?;

info!("Execution finished successfully. Local and on-chain effects match.");
println!("Execution finished successfully. Local and on-chain effects match.");
Some((1u64, 1u64))
}

Expand Down
1 change: 1 addition & 0 deletions crates/sui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sui-move = { workspace = true, features = ["all"] }
sui-move-build.workspace = true
sui-protocol-config.workspace = true
shared-crypto.workspace = true
sui-replay.workspace = true

fastcrypto.workspace = true
fastcrypto-zkp.workspace = true
Expand Down
107 changes: 106 additions & 1 deletion crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use fastcrypto::{
encoding::{Base64, Encoding},
traits::ToFromBytes,
};

use json_to_table::json_to_table;
use move_core_types::language_storage::TypeTag;
use move_package::BuildConfig as MoveBuildConfig;
Expand All @@ -40,6 +41,7 @@ use sui_move_build::{
build_from_resolution_graph, check_invalid_dependencies, check_unpublished_dependencies,
gather_published_ids, BuildConfig, CompiledPackage, PackageDependencies, PublishedAtError,
};
use sui_replay::ReplayToolCommand;
use sui_sdk::sui_client_config::{SuiClientConfig, SuiEnv};
use sui_sdk::wallet_context::WalletContext;
use sui_sdk::SuiClient;
Expand Down Expand Up @@ -607,6 +609,54 @@ pub enum SuiClientCommands {
#[clap(long)]
address_override: Option<ObjectID>,
},

/// Replay a given transaction to view transaction effects. Set environment variable MOVE_VM_STEP=1 to debug.
#[clap(name = "replay-transaction")]
ReplayTransaction {
/// The rpc url for a non-pruning fullnode to use for fetching the transaction dependencies
#[arg(long = "rpc")]
rpc_url: String,

/// The digest of the transaction to replay
#[arg(long, short)]
tx_digest: String,
},

/// Replay transactions listed in a file.
#[clap(name = "replay-batch")]
ReplayBatch {
/// The rpc url for a non-pruning fullnode to use for fetching the transaction dependencies
#[arg(long = "rpc")]
rpc_url: String,

/// The path to the file of transaction digests to replay, with one digest per line
#[arg(long, short)]
path: PathBuf,

/// If an error is encountered during a transaction, this specifies whether to terminate or continue
#[arg(long, short)]
terminate_early: bool,
},

/// Replay all transactions in a range of checkpoints.
#[command(name = "replay-checkpoint")]
ReplayCheckpoints {
/// The rpc url for a non-pruning fullnode to use for fetching the transaction dependencies
#[arg(long = "rpc")]
rpc_url: String,

/// The start value of the range of checkpoints to replay
#[arg(long, short)]
start: u64,

/// The end value of the range of checkpoints to replay
#[arg(long, short)]
end: u64,

/// If an error is encountered during a transaction, this specifies whether to terminate or continue
#[arg(long, short)]
terminate_early: bool,
},
}

impl SuiClientCommands {
Expand All @@ -615,6 +665,54 @@ impl SuiClientCommands {
context: &mut WalletContext,
) -> Result<SuiClientCommandResult, anyhow::Error> {
let ret = Ok(match self {
SuiClientCommands::ReplayTransaction { rpc_url, tx_digest } => {
let cmd = ReplayToolCommand::ReplayTransaction {
tx_digest,
show_effects: true,
diag: false,
executor_version_override: None,
protocol_version_override: None,
};
// todo: automatically get non pruning fullnode url
let _command_result =
sui_replay::execute_replay_command(Some(rpc_url), false, false, None, cmd)
.await;
SuiClientCommandResult::ReplayTransaction
}
SuiClientCommands::ReplayBatch {
rpc_url,
path,
terminate_early,
} => {
let cmd = ReplayToolCommand::ReplayBatch {
path,
terminate_early,
batch_size: 16,
};
// todo: automatically get non pruning fullnode url
let _command_result =
sui_replay::execute_replay_command(Some(rpc_url), false, false, None, cmd)
.await;
SuiClientCommandResult::ReplayBatch
}
SuiClientCommands::ReplayCheckpoints {
rpc_url,
start,
end,
terminate_early,
} => {
let cmd = ReplayToolCommand::ReplayCheckpoints {
start,
end,
terminate_early,
max_tasks: 16,
};
// todo: automatically get non pruning fullnode url
let _command_result =
sui_replay::execute_replay_command(Some(rpc_url), false, false, None, cmd)
.await;
SuiClientCommandResult::ReplayCheckpoints
}
SuiClientCommands::Addresses => {
let active_address = context.active_address()?;
let addresses = context.config.keystore.addresses();
Expand All @@ -623,7 +721,6 @@ impl SuiClientCommands {
active_address,
})
}

SuiClientCommands::DynamicFieldQuery { id, cursor, limit } => {
let client = context.get_client().await?;
let df_read = client
Expand Down Expand Up @@ -1637,6 +1734,11 @@ impl Display for SuiClientCommandResult {
table.with(tabled::settings::style::BorderSpanCorrection);
writeln!(f, "{}", table)?;
}
// todo: for all replay commands format results using tabular structure instead of
// todo: println statements in original command
SuiClientCommandResult::ReplayTransaction => {}
SuiClientCommandResult::ReplayBatch => {}
SuiClientCommandResult::ReplayCheckpoints => {}
}
write!(f, "{}", writer.trim_end_matches('\n'))
}
Expand Down Expand Up @@ -1949,6 +2051,9 @@ pub enum SuiClientCommandResult {
used_module_ticks: u128,
},
VerifySource,
ReplayTransaction,
ReplayBatch,
ReplayCheckpoints,
}

#[derive(Serialize, Clone, Debug)]
Expand Down
56 changes: 30 additions & 26 deletions doc/src/build/cli-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,36 @@ The Sui Client CLI installs when you install Sui. See the [Install Sui](install.

The Sui Client CLI supports the following commands:

| Command | Description |
| --- | --- |
| `active-address` | Default address used for commands when none specified. |
| `active-env` | Default environment used for commands when none specified. |
| `addresses` | Obtain the Addresses managed by the client. |
| `call` | Call Move function. |
| `dynamic-field` | Query a dynamic field by address. |
| `envs` | List all Sui environments. |
| `execute-signed-tx` | Execute a Signed Transaction. This is useful when the user prefers to sign elsewhere and use this command to execute. |
| `gas` | Obtain all gas objects owned by the address. |
| `help` | Print this message or the help of the given subcommand(s). |
| `merge-coin` | Merge two coin objects into one coin. |
| `new-address` | Generate new address and keypair with keypair scheme flag {ed25519 or secp256k1 or secp256r1} with optional derivation path, default to m/44'/784'/0'/0'/0' for ed25519 or m/54'/784'/0'/0/0 for secp256k1 or m/74'/784'/0'/0/0 for secp256r1 |
| `new-env` | Add new Sui environment. |
| `object` | Get object information. |
| `objects` | Obtain all objects owned by the address. |
| `pay` | Pay SUI to recipients following specified amounts, with input coins. Length of recipients must be the same as that of amounts. |
| `pay_all_sui` | Pay all residual SUI coins to the recipient with input coins, after deducting the gas cost. The input coins also include the coin for gas payment, so no extra gas coin is required. |
| `pay_sui` | Pay SUI coins to recipients following specified amounts, with input coins. Length of recipients must be the same as that of amounts. The input coins also include the coin for gas payment, so no extra gas coin is required. |
| `publish` | Publish Move modules. |
| `split-coin` | Split a coin object into multiple coins. |
| `switch` | Switch active address and network. |
| `transfer` | Transfer object. |
| `transfer-sui` | Transfer SUI, and pay gas with the same SUI coin object. If amount is specified, transfers only the amount. If not specified, transfers the object. |
| `upgrade` | Upgrade a Move module. |
| `verify-source` | Verify local Move packages against on-chain packages, and optionally their dependencies. |
| Command | Description |
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `active-address` | Default address used for commands when none specified. |
| `active-env` | Default environment used for commands when none specified. |
| `addresses` | Obtain the Addresses managed by the client. |
| `call` | Call Move function. |
| `dynamic-field` | Query a dynamic field by address. |
| `envs` | List all Sui environments. |
| `execute-signed-tx` | Execute a Signed Transaction. This is useful when the user prefers to sign elsewhere and use this command to execute. |
| `gas` | Obtain all gas objects owned by the address. |
| `help` | Print this message or the help of the given subcommand(s). |
| `merge-coin` | Merge two coin objects into one coin. |
| `new-address` | Generate new address and keypair with keypair scheme flag {ed25519 or secp256k1 or secp256r1} with optional derivation path, default to m/44'/784'/0'/0'/0' for ed25519 or m/54'/784'/0'/0/0 for secp256k1 or m/74'/784'/0'/0/0 for secp256r1 |
| `new-env` | Add new Sui environment. |
| `object` | Get object information. |
| `objects` | Obtain all objects owned by the address. |
| `pay` | Pay SUI to recipients following specified amounts, with input coins. Length of recipients must be the same as that of amounts. |
| `pay_all_sui` | Pay all residual SUI coins to the recipient with input coins, after deducting the gas cost. The input coins also include the coin for gas payment, so no extra gas coin is required. |
| `pay_sui` | Pay SUI coins to recipients following specified amounts, with input coins. Length of recipients must be the same as that of amounts. The input coins also include the coin for gas payment, so no extra gas coin is required. |
| `publish` | Publish Move modules. |
| `split-coin` | Split a coin object into multiple coins. |
| `switch` | Switch active address and network. |
| `transfer` | Transfer object. |
| `transfer-sui` | Transfer SUI, and pay gas with the same SUI coin object. If amount is specified, transfers only the amount. If not specified, transfers the object. |
| `upgrade` | Upgrade a Move module. |
| `verify-source` | Verify local Move packages against on-chain packages, and optionally their dependencies. |
| `replay-transaction` | Replay a given transaction to view transaction effects. Set environment variable MOVE_VM_STEP=1 to debug. |
| `replay-batch` | Replay transactions listed in a file. |
| `replay-checkpoint` | Replay all transactions in a range of checkpoints. |
\

**Note:** The `clear`, `echo`, `env`, and `exit` commands exist only in the interactive shell.

Expand Down

2 comments on commit 11debf0

@vercel
Copy link

@vercel vercel bot commented on 11debf0 Oct 24, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 11debf0 Oct 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

mysten-ui – ./apps/ui

mysten-ui.vercel.app
mysten-ui-mysten-labs.vercel.app
mysten-ui-git-main-mysten-labs.vercel.app

Please sign in to comment.