mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 13:56:58 +03:00
display simplified cost breakdown for deployments or executions by default
This commit is contained in:
parent
f5f186790b
commit
9b79386014
@ -116,11 +116,7 @@ fn handle_deploy<A: Aleo<Network = N, BaseField = N::Field>, N: Network>(
|
||||
// Fetch the package from the directory.
|
||||
let package = SnarkVMPackage::<N>::open(path)?;
|
||||
|
||||
if !command.fee_options.estimate_fee {
|
||||
println!("📦 Creating deployment transaction for '{}'...\n", &name.bold());
|
||||
} else {
|
||||
println!("📦 Estimating deployment cost for '{}'...\n", &name.bold());
|
||||
}
|
||||
println!("📦 Creating deployment transaction for '{}'...\n", &name.bold());
|
||||
|
||||
// Generate the deployment
|
||||
let deployment = package.deploy::<A>(None)?;
|
||||
@ -134,17 +130,14 @@ fn handle_deploy<A: Aleo<Network = N, BaseField = N::Field>, N: Network>(
|
||||
// Compute the minimum deployment cost.
|
||||
let (total_cost, (storage_cost, synthesis_cost, namespace_cost)) = deployment_cost(&deployment)?;
|
||||
|
||||
if command.fee_options.estimate_fee {
|
||||
// Use `credit` denomination instead of `microcredit`.
|
||||
deploy_cost_breakdown(
|
||||
name,
|
||||
total_cost as f64 / 1_000_000.0,
|
||||
storage_cost as f64 / 1_000_000.0,
|
||||
synthesis_cost as f64 / 1_000_000.0,
|
||||
namespace_cost as f64 / 1_000_000.0,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Display the deployment cost breakdown using `credit` denomination.
|
||||
deploy_cost_breakdown(
|
||||
name,
|
||||
total_cost as f64 / 1_000_000.0,
|
||||
storage_cost as f64 / 1_000_000.0,
|
||||
synthesis_cost as f64 / 1_000_000.0,
|
||||
namespace_cost as f64 / 1_000_000.0,
|
||||
);
|
||||
|
||||
// Initialize an RNG.
|
||||
let rng = &mut rand::thread_rng();
|
||||
@ -183,14 +176,16 @@ fn handle_deploy<A: Aleo<Network = N, BaseField = N::Field>, N: Network>(
|
||||
println!("✅ Created deployment transaction for '{}'", name.bold());
|
||||
|
||||
// Determine if the transaction should be broadcast, stored, or displayed to the user.
|
||||
handle_broadcast(
|
||||
&format!("{}/{}/transaction/broadcast", command.options.endpoint, command.options.network),
|
||||
transaction,
|
||||
name,
|
||||
)?;
|
||||
|
||||
if index < all_paths.len() - 1 {
|
||||
std::thread::sleep(std::time::Duration::from_secs(command.wait));
|
||||
if !command.fee_options.dry_run {
|
||||
handle_broadcast(
|
||||
&format!("{}/{}/transaction/broadcast", command.options.endpoint, command.options.network),
|
||||
transaction,
|
||||
name,
|
||||
)?;
|
||||
// Wait between successive deployments to prevent out of order deployments.
|
||||
if index < all_paths.len() - 1 {
|
||||
std::thread::sleep(std::time::Duration::from_secs(command.wait));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,22 +194,20 @@ fn handle_deploy<A: Aleo<Network = N, BaseField = N::Field>, N: Network>(
|
||||
|
||||
// A helper function to display a cost breakdown of the deployment.
|
||||
fn deploy_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, synthesis_cost: f64, namespace_cost: f64) {
|
||||
println!("✅ Estimated deployment cost for '{}' is {} credits.", name.bold(), total_cost);
|
||||
println!("Base deployment cost for '{}' is {} credits.", name.bold(), total_cost);
|
||||
// Display the cost breakdown in a table.
|
||||
let data = [
|
||||
[name, "Cost (credits)", "Cost reduction tips"],
|
||||
["Storage", &format!("{:.6}", storage_cost), "Use less instructions"],
|
||||
[name, "Cost (credits)"],
|
||||
["Transaction Storage", &format!("{:.6}", storage_cost)],
|
||||
[
|
||||
"Synthesis",
|
||||
"Program Synthesis",
|
||||
&format!("{:.6}", synthesis_cost),
|
||||
"Remove expensive operations (Ex: SHA3), or unnecessary imports",
|
||||
],
|
||||
[
|
||||
"Namespace",
|
||||
&format!("{:.6}", namespace_cost),
|
||||
"Lengthen the program name (each additional character makes it 10x cheaper)",
|
||||
],
|
||||
["Total", &format!("{:.6}", total_cost), ""],
|
||||
["Total", &format!("{:.6}", total_cost)],
|
||||
];
|
||||
let mut out = Vec::new();
|
||||
text_tables::render(&mut out, data).unwrap();
|
||||
|
@ -216,26 +216,26 @@ fn handle_execute<N: Network>(command: Execute, context: Context) -> Result<<Exe
|
||||
}
|
||||
|
||||
// Print the cost breakdown.
|
||||
if command.fee_options.estimate_fee {
|
||||
execution_cost_breakdown(
|
||||
&program_name,
|
||||
total_cost as f64 / 1_000_000.0,
|
||||
storage_cost as f64 / 1_000_000.0,
|
||||
finalize_cost as f64 / 1_000_000.0,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
execution_cost_breakdown(
|
||||
&program_name,
|
||||
total_cost as f64 / 1_000_000.0,
|
||||
storage_cost as f64 / 1_000_000.0,
|
||||
finalize_cost as f64 / 1_000_000.0,
|
||||
);
|
||||
|
||||
println!("✅ Created execution transaction for '{}'", program_id.to_string().bold());
|
||||
|
||||
handle_broadcast(
|
||||
&format!(
|
||||
"{}/{}/transaction/broadcast",
|
||||
command.compiler_options.endpoint, command.compiler_options.network
|
||||
),
|
||||
transaction,
|
||||
&program_name,
|
||||
)?;
|
||||
// Broadcast the execution transaction.
|
||||
if !command.fee_options.dry_run {
|
||||
handle_broadcast(
|
||||
&format!(
|
||||
"{}/{}/transaction/broadcast",
|
||||
command.compiler_options.endpoint, command.compiler_options.network
|
||||
),
|
||||
transaction,
|
||||
&program_name,
|
||||
)?;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@ -317,21 +317,19 @@ fn load_program_from_network<N: Network>(
|
||||
|
||||
// A helper function to display a cost breakdown of the execution.
|
||||
fn execution_cost_breakdown(name: &String, total_cost: f64, storage_cost: f64, finalize_cost: f64) {
|
||||
println!("✅ Estimated execution cost for '{}' is {} credits.", name.bold(), total_cost);
|
||||
println!("Base execution cost for '{}' is {} credits.", name.bold(), total_cost);
|
||||
// Display the cost breakdown in a table.
|
||||
let data = [
|
||||
[name, "Cost (credits)", "Cost reduction tips"],
|
||||
[name, "Cost (credits)"],
|
||||
[
|
||||
"Storage",
|
||||
"Transaction Storage",
|
||||
&format!("{:.6}", storage_cost),
|
||||
"Use fewer nested transition functions and smaller input and output datatypes",
|
||||
],
|
||||
[
|
||||
"On-chain",
|
||||
"On-chain Execution",
|
||||
&format!("{:.6}", finalize_cost),
|
||||
"Remove operations that are expensive computationally (Ex: hash functions) or storage-wise (Ex: Mapping insertions)",
|
||||
],
|
||||
["Total", &format!("{:.6}", total_cost), ""],
|
||||
["Total", &format!("{:.6}", total_cost)],
|
||||
];
|
||||
let mut out = Vec::new();
|
||||
text_tables::render(&mut out, data).unwrap();
|
||||
|
@ -209,12 +209,8 @@ impl Default for BuildOptions {
|
||||
/// Used by Execute and Deploy commands.
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
pub struct FeeOptions {
|
||||
#[clap(
|
||||
long,
|
||||
help = "Estimate the deploy or execution fee without broadcasting to the network.",
|
||||
default_value = "false"
|
||||
)]
|
||||
pub(crate) estimate_fee: bool,
|
||||
#[clap(short, long, help = "Performs a dry-run of transaction generation")]
|
||||
pub(crate) dry_run: bool,
|
||||
#[clap(long, help = "Priority fee in microcredits. Defaults to 0.", default_value = "0")]
|
||||
pub(crate) priority_fee: u64,
|
||||
#[clap(long, help = "Private key to authorize fee expenditure.")]
|
||||
|
Loading…
Reference in New Issue
Block a user