Skip to content

Commit

Permalink
Introduce --with-faucet for net up using the default chain (#3324)
Browse files Browse the repository at this point in the history
## Motivation

Right now we have a `--with-faucet-chain` option that both enables starting a faucet and also specifies what chain the faucet will be running on.
`linera faucet` however has a slightly different behavior, in which if you don't specify the chain, it just uses the default chain.

## Proposal

Introduce a `--with-faucet` option that controls whether a faucet will be started, which will by default start a faucet on the default chain, unless the `--faucet-chain` argument is provided.

## Test Plan

Run it locally, see the faucet being started using the default chain as expected, and previous behavior also works

## Release Plan

- Nothing to do / These changes follow the usual release cycle.
  • Loading branch information
ndr-ds authored Feb 17, 2025
1 parent f2b0942 commit 870552d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
5 changes: 4 additions & 1 deletion CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,10 @@ Start a Local Linera Network
* `--external-protocol <EXTERNAL_PROTOCOL>` — External protocol used, either `grpc` or `grpcs`

Default value: `grpc`
* `--with-faucet-chain <WITH_FAUCET_CHAIN>` — If present, a faucet is started using the given chain root number (0 for the admin chain, 1 for the first non-admin initial chain, etc)
* `--with-faucet` — If present, a faucet is started using the chain provided by --faucet-chain, or `ChainId::root(1)` if not provided, as root 0 is usually the admin chain

Default value: `false`
* `--faucet-chain <FAUCET_CHAIN>` — When using --with-faucet, this specifies the chain on which the faucet will be started. The chain is specified by its root number (0 for the admin chain, 1 for the first non-admin initial chain, etc)
* `--faucet-port <FAUCET_PORT>` — The port on which to run the faucet server

Default value: `8080`
Expand Down
12 changes: 9 additions & 3 deletions linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,16 @@ pub enum NetCommand {
#[arg(long, default_value = "grpc")]
external_protocol: String,

/// If present, a faucet is started using the given chain root number (0 for the
/// admin chain, 1 for the first non-admin initial chain, etc).
/// If present, a faucet is started using the chain provided by --faucet-chain, or
/// `ChainId::root(1)` if not provided, as root 0 is usually the admin chain.
#[arg(long, default_value = "false")]
with_faucet: bool,

/// When using --with-faucet, this specifies the chain on which the faucet will be started.
/// The chain is specified by its root number (0 for the admin chain, 1 for the first
/// non-admin initial chain, etc).
#[arg(long)]
with_faucet_chain: Option<u32>,
faucet_chain: Option<u32>,

/// The port on which to run the faucet server
#[arg(long, default_value = "8080")]
Expand Down
12 changes: 8 additions & 4 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,8 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
path: _,
storage: _,
external_protocol: _,
with_faucet_chain,
with_faucet,
faucet_chain,
faucet_port,
faucet_amount,
} => {
Expand All @@ -1628,7 +1629,8 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
*no_build,
docker_image_name.clone(),
policy_config.into_policy(),
*with_faucet_chain,
*with_faucet,
*faucet_chain,
*faucet_port,
*faucet_amount,
)
Expand All @@ -1648,7 +1650,8 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
path,
storage,
external_protocol,
with_faucet_chain,
with_faucet,
faucet_chain,
faucet_port,
faucet_amount,
..
Expand All @@ -1664,7 +1667,8 @@ async fn run(options: &ClientOptions) -> Result<i32, anyhow::Error> {
path,
storage,
external_protocol.clone(),
*with_faucet_chain,
*with_faucet,
*faucet_chain,
*faucet_port,
*faucet_amount,
)
Expand Down
42 changes: 31 additions & 11 deletions linera-service/src/linera/net_up_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ pub async fn handle_net_up_kubernetes(
no_build: bool,
docker_image_name: String,
policy: ResourceControlPolicy,
with_faucet_chain: Option<u32>,
with_faucet: bool,
faucet_chain: Option<u32>,
faucet_port: NonZeroU16,
faucet_amount: Amount,
) -> anyhow::Result<()> {
Expand All @@ -122,6 +123,12 @@ pub async fn handle_net_up_kubernetes(
if num_shards < 1 {
panic!("The local test network must have at least one shard per validator.");
}
if faucet_chain.is_some() {
assert!(
with_faucet,
"--faucet-chain must be provided only with --with-faucet"
);
}

let shutdown_notifier = CancellationToken::new();
tokio::spawn(listen_for_shutdown_signals(shutdown_notifier.clone()));
Expand All @@ -143,9 +150,11 @@ pub async fn handle_net_up_kubernetes(
extra_wallets,
&mut net,
client,
with_faucet_chain,
with_faucet,
faucet_chain,
faucet_port,
faucet_amount,
num_other_initial_chains,
)
.await?;
wait_for_shutdown(shutdown_notifier, &mut net, faucet_service).await
Expand All @@ -163,7 +172,8 @@ pub async fn handle_net_up_service(
path: &Option<String>,
storage: &Option<String>,
external_protocol: String,
with_faucet_chain: Option<u32>,
with_faucet: bool,
faucet_chain: Option<u32>,
faucet_port: NonZeroU16,
faucet_amount: Amount,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -208,9 +218,11 @@ pub async fn handle_net_up_service(
extra_wallets,
&mut net,
client,
with_faucet_chain,
with_faucet,
faucet_chain,
faucet_port,
faucet_amount,
num_other_initial_chains,
)
.await?;
wait_for_shutdown(shutdown_notifier, &mut net, faucet_service).await
Expand All @@ -234,13 +246,16 @@ async fn wait_for_shutdown(
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn create_wallets_and_faucets(
extra_wallets: Option<usize>,
net: &mut impl LineraNet,
client: ClientWrapper,
with_faucet_chain: Option<u32>,
with_faucet: bool,
faucet_chain: Option<u32>,
faucet_port: NonZeroU16,
faucet_amount: Amount,
num_other_initial_chains: u32,
) -> Result<Option<FaucetService>, anyhow::Error> {
let default_chain = client
.default_chain()
Expand Down Expand Up @@ -317,13 +332,18 @@ async fn create_wallets_and_faucets(
}

// Run the faucet,
let faucet_service = if let Some(faucet_chain) = with_faucet_chain {
let faucet_service = if with_faucet {
let faucet_chain = if let Some(faucet_chain) = faucet_chain {
ChainId::root(faucet_chain)
} else {
assert!(
num_other_initial_chains > 1,
"num_other_initial_chains must be greater than 1 if with_faucet is true"
);
ChainId::root(1)
};
let service = client
.run_faucet(
Some(faucet_port.into()),
ChainId::root(faucet_chain),
faucet_amount,
)
.run_faucet(Some(faucet_port.into()), faucet_chain, faucet_amount)
.await?;
Some(service)
} else {
Expand Down
3 changes: 2 additions & 1 deletion linera-service/tests/local_net_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ async fn test_storage_service_linera_net_up_simple() -> Result<()> {
command.args([
"net",
"up",
"--with-faucet-chain",
"--with-faucet",
"--faucet-chain",
"1",
"--faucet-port",
&port.to_string(),
Expand Down

1 comment on commit 870552d

@Anshul969

This comment was marked as spam.

Please sign in to comment.