Skip to content

Commit

Permalink
Add option --policy-config to linera net up (linera-io#2182)
Browse files Browse the repository at this point in the history
* add option --policy to `linera net up`

* update CLI.md

* fix clippy after rebase
  • Loading branch information
ma2bd authored Jun 25, 2024
1 parent 4f7d994 commit 034a07e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,12 @@ Start a Local Linera Network
* `--shards <SHARDS>` — The number of shards per validator in the local test network. Default is 1

Default value: `1`
* `--policy-config <POLICY_CONFIG>` — Configure the resource control policy (notably fees) according to pre-defined settings

Default value: `default`

Possible values: `default`, `only-fuel`, `fuel-and-block`, `all-categories`, `devnet`

* `--testing-prng-seed <TESTING_PRNG_SEED>` — Force this wallet to generate keys using a PRNG and a given seed. USE FOR TESTING ONLY
* `--table-name <TABLE_NAME>` — The name for the database table to store the chain data in

Expand Down
1 change: 0 additions & 1 deletion linera-execution/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ impl ResourceControlPolicy {
}
}

#[cfg(with_testing)]
impl ResourceControlPolicy {
/// Creates a policy with no cost for anything except fuel.
///
Expand Down
45 changes: 43 additions & 2 deletions linera-service/src/linera/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use linera_base::{
};
use linera_core::client::MessagePolicy;
use linera_execution::{
committee::ValidatorName, system::SystemChannel, UserApplicationId, WasmRuntime,
WithWasmDefault as _,
committee::ValidatorName, system::SystemChannel, ResourceControlPolicy, UserApplicationId,
WasmRuntime, WithWasmDefault as _,
};
use linera_service::{
chain_listener::ChainListenerConfig,
Expand Down Expand Up @@ -786,6 +786,11 @@ pub enum NetCommand {
#[arg(long, default_value = "1")]
shards: usize,

/// Configure the resource control policy (notably fees) according to pre-defined
/// settings.
#[arg(long, default_value = "default")]
policy_config: ResourceControlPolicyConfig,

/// Force this wallet to generate keys using a PRNG and a given seed. USE FOR
/// TESTING ONLY.
#[arg(long)]
Expand Down Expand Up @@ -813,6 +818,42 @@ pub enum NetCommand {
Helper,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum ResourceControlPolicyConfig {
Default,
OnlyFuel,
FuelAndBlock,
AllCategories,
Devnet,
}

impl ResourceControlPolicyConfig {
pub fn into_policy(self) -> ResourceControlPolicy {
use ResourceControlPolicyConfig::*;
match self {
Default => ResourceControlPolicy::default(),
OnlyFuel => ResourceControlPolicy::only_fuel(),
FuelAndBlock => ResourceControlPolicy::fuel_and_block(),
AllCategories => ResourceControlPolicy::all_categories(),
Devnet => ResourceControlPolicy::devnet(),
}
}
}

impl std::str::FromStr for ResourceControlPolicyConfig {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
clap::ValueEnum::from_str(s, true)
}
}

impl std::fmt::Display for ResourceControlPolicyConfig {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

#[derive(Clone, clap::Subcommand)]
pub enum WalletCommand {
/// Show the contents of the wallet.
Expand Down
6 changes: 6 additions & 0 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ async fn run(options: ClientOptions) -> anyhow::Result<()> {
shards,
testing_prng_seed,
table_name: _,
policy_config,
kubernetes: true,
binaries,
} => {
Expand All @@ -1361,7 +1362,9 @@ async fn run(options: ClientOptions) -> anyhow::Result<()> {
*shards,
*testing_prng_seed,
binaries,
policy_config.into_policy(),
)
.boxed()
.await
}

Expand All @@ -1373,6 +1376,7 @@ async fn run(options: ClientOptions) -> anyhow::Result<()> {
shards,
testing_prng_seed,
table_name,
policy_config,
..
} => {
net_up_utils::handle_net_up_service(
Expand All @@ -1383,7 +1387,9 @@ async fn run(options: ClientOptions) -> anyhow::Result<()> {
*shards,
*testing_prng_seed,
table_name,
policy_config.into_policy(),
)
.boxed()
.await
}

Expand Down
8 changes: 6 additions & 2 deletions linera-service/src/linera/net_up_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use {
std::path::PathBuf,
};

#[allow(clippy::too_many_arguments)]
#[cfg(feature = "kubernetes")]
pub async fn handle_net_up_kubernetes(
extra_wallets: Option<usize>,
Expand All @@ -35,6 +36,7 @@ pub async fn handle_net_up_kubernetes(
num_shards: usize,
testing_prng_seed: Option<u64>,
binaries: &Option<Option<PathBuf>>,
policy: ResourceControlPolicy,
) -> anyhow::Result<()> {
if num_initial_validators < 1 {
panic!("The local test network must have at least one validator.");
Expand All @@ -54,13 +56,14 @@ pub async fn handle_net_up_kubernetes(
num_initial_validators,
num_shards,
binaries: binaries.clone().into(),
policy: ResourceControlPolicy::default(),
policy,
};
let (mut net, client1) = config.instantiate().await?;
net_up(extra_wallets, &mut net, client1).await?;
wait_for_shutdown(shutdown_notifier, &mut net).await
}

#[allow(clippy::too_many_arguments)]
pub async fn handle_net_up_service(
extra_wallets: Option<usize>,
num_other_initial_chains: u32,
Expand All @@ -69,6 +72,7 @@ pub async fn handle_net_up_service(
num_shards: usize,
testing_prng_seed: Option<u64>,
table_name: &str,
policy: ResourceControlPolicy,
) -> anyhow::Result<()> {
if num_initial_validators < 1 {
panic!("The local test network must have at least one validator.");
Expand Down Expand Up @@ -102,7 +106,7 @@ pub async fn handle_net_up_service(
initial_amount: Amount::from_tokens(initial_amount),
num_initial_validators,
num_shards,
policy: ResourceControlPolicy::default(),
policy,
storage_config_builder,
path_provider,
};
Expand Down

0 comments on commit 034a07e

Please sign in to comment.