Skip to content

Commit f6b3103

Browse files
committed
Revert "Automatically rotate the faucet chain once it has a maximum length. (linera-io#3848) (linera-io#3852)"
This reverts commit 026f601.
1 parent d7d69d9 commit f6b3103

9 files changed

Lines changed: 36 additions & 114 deletions

File tree

CLI.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,6 @@ Run a GraphQL service that exposes a faucet where users can claim tokens. This g
603603
Default value: `8080`
604604
* `--amount <AMOUNT>` — The number of tokens to send to each new chain
605605
* `--limit-rate-until <LIMIT_RATE_UNTIL>` — The end timestamp: The faucet will rate-limit the token supply so it runs out of money no earlier than this
606-
* `--max-chain-length <MAX_CHAIN_LENGTH>` — The maximum number of blocks in the faucet chain, before a new one is created
607-
608-
Default value: `100`
609606
* `--listener-skip-process-inbox` — Do not create blocks automatically to receive incoming messages. Instead, wait for an explicit mutation `processInbox`
610607
* `--listener-delay-before-ms <DELAY_BEFORE_MS>` — Wait before processing any notification (useful for testing)
611608

linera-faucet/server/src/lib.rs

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use axum::{Extension, Router};
1111
use futures::lock::Mutex;
1212
use linera_base::{
1313
crypto::{CryptoHash, ValidatorPublicKey},
14-
data_types::{Amount, ApplicationPermissions, BlockHeight, Timestamp},
14+
data_types::{Amount, ApplicationPermissions, Timestamp},
1515
identifiers::{AccountOwner, ChainId, MessageId},
1616
ownership::ChainOwnership,
1717
};
@@ -42,15 +42,14 @@ mod tests;
4242
pub struct QueryRoot<C> {
4343
context: Arc<Mutex<C>>,
4444
genesis_config: Arc<GenesisConfig>,
45-
chain_id: Arc<Mutex<ChainId>>,
45+
chain_id: ChainId,
4646
}
4747

4848
/// The root GraphQL mutation type.
4949
pub struct MutationRoot<C> {
50-
chain_id: Arc<Mutex<ChainId>>,
50+
chain_id: ChainId,
5151
context: Arc<Mutex<C>>,
5252
amount: Amount,
53-
end_block_height: BlockHeight,
5453
end_timestamp: Timestamp,
5554
start_timestamp: Timestamp,
5655
start_balance: Amount,
@@ -90,8 +89,7 @@ where
9089

9190
/// Returns the current committee's validators.
9291
async fn current_validators(&self) -> Result<Vec<Validator>, Error> {
93-
let chain_id = *self.chain_id.lock().await;
94-
let client = self.context.lock().await.make_chain_client(chain_id)?;
92+
let client = self.context.lock().await.make_chain_client(self.chain_id)?;
9593
let committee = client.local_committee().await?;
9694
Ok(committee
9795
.validators()
@@ -120,8 +118,7 @@ where
120118
C: ClientContext,
121119
{
122120
async fn do_claim(&self, owner: AccountOwner) -> Result<ClaimOutcome, Error> {
123-
let chain_id = *self.chain_id.lock().await;
124-
let client = self.context.lock().await.make_chain_client(chain_id)?;
121+
let client = self.context.lock().await.make_chain_client(self.chain_id)?;
125122

126123
if self.start_timestamp < self.end_timestamp {
127124
let local_time = client.storage_client().clock().current_time();
@@ -152,32 +149,16 @@ where
152149
.open_chain(ownership, ApplicationPermissions::default(), self.amount)
153150
.await;
154151
self.context.lock().await.update_wallet(&client).await?;
155-
let (message_id, certificate) = result?.try_unwrap()?;
156-
157-
if client.next_block_height() >= self.end_block_height {
158-
let key_pair = client.key_pair().await?;
159-
let balance = client.local_balance().await?.try_sub(Amount::ONE)?;
160-
let ownership = client.chain_state_view().await?.ownership().clone();
161-
let (message_id, certificate) = client
162-
.open_chain(ownership, ApplicationPermissions::default(), balance)
163-
.await?
164-
.try_unwrap()?;
165-
// TODO(#1795): Move the remaining tokens to the new chain.
166-
client.close_chain().await?.try_unwrap()?;
167-
let chain_id = ChainId::child(message_id);
168-
info!("Switching to a new faucet chain {chain_id:8}; remaining balance: {balance}");
169-
self.context
170-
.lock()
171-
.await
172-
.update_wallet_for_new_chain(
173-
chain_id,
174-
Some(key_pair),
175-
certificate.block().header.timestamp,
176-
)
177-
.await?;
178-
*self.chain_id.lock().await = chain_id;
179-
}
180-
152+
let (message_id, certificate) = match result? {
153+
ClientOutcome::Committed(result) => result,
154+
ClientOutcome::WaitForTimeout(timeout) => {
155+
return Err(Error::new(format!(
156+
"This faucet is using a multi-owner chain and is not the leader right now. \
157+
Try again at {}",
158+
timeout.timestamp,
159+
)));
160+
}
161+
};
181162
let chain_id = ChainId::child(message_id);
182163
Ok(ClaimOutcome {
183164
message_id,
@@ -204,15 +185,14 @@ pub struct FaucetService<C>
204185
where
205186
C: ClientContext,
206187
{
207-
chain_id: Arc<Mutex<ChainId>>,
188+
chain_id: ChainId,
208189
context: Arc<Mutex<C>>,
209190
genesis_config: Arc<GenesisConfig>,
210191
config: ChainListenerConfig,
211192
storage: C::Storage,
212193
port: NonZeroU16,
213194
amount: Amount,
214195
end_timestamp: Timestamp,
215-
end_block_height: BlockHeight,
216196
start_timestamp: Timestamp,
217197
start_balance: Amount,
218198
}
@@ -223,14 +203,13 @@ where
223203
{
224204
fn clone(&self) -> Self {
225205
Self {
226-
chain_id: self.chain_id.clone(),
206+
chain_id: self.chain_id,
227207
context: Arc::clone(&self.context),
228208
genesis_config: Arc::clone(&self.genesis_config),
229209
config: self.config.clone(),
230210
storage: self.storage.clone(),
231211
port: self.port,
232212
amount: self.amount,
233-
end_block_height: self.end_block_height,
234213
end_timestamp: self.end_timestamp,
235214
start_timestamp: self.start_timestamp,
236215
start_balance: self.start_balance,
@@ -249,7 +228,6 @@ where
249228
chain_id: ChainId,
250229
context: C,
251230
amount: Amount,
252-
end_block_height: BlockHeight,
253231
end_timestamp: Timestamp,
254232
genesis_config: Arc<GenesisConfig>,
255233
config: ChainListenerConfig,
@@ -261,14 +239,13 @@ where
261239
client.process_inbox().await?;
262240
let start_balance = client.local_balance().await?;
263241
Ok(Self {
264-
chain_id: Arc::new(Mutex::new(chain_id)),
242+
chain_id,
265243
context,
266244
genesis_config,
267245
config,
268246
storage,
269247
port,
270248
amount,
271-
end_block_height,
272249
end_timestamp,
273250
start_timestamp,
274251
start_balance,
@@ -277,18 +254,17 @@ where
277254

278255
pub fn schema(&self) -> Schema<QueryRoot<C>, MutationRoot<C>, EmptySubscription> {
279256
let mutation_root = MutationRoot {
280-
chain_id: self.chain_id.clone(),
257+
chain_id: self.chain_id,
281258
context: Arc::clone(&self.context),
282259
amount: self.amount,
283-
end_block_height: self.end_block_height,
284260
end_timestamp: self.end_timestamp,
285261
start_timestamp: self.start_timestamp,
286262
start_balance: self.start_balance,
287263
};
288264
let query_root = QueryRoot {
289265
genesis_config: Arc::clone(&self.genesis_config),
290266
context: Arc::clone(&self.context),
291-
chain_id: self.chain_id.clone(),
267+
chain_id: self.chain_id,
292268
};
293269
Schema::build(query_root, mutation_root, EmptySubscription).finish()
294270
}
@@ -327,27 +303,3 @@ where
327303
schema.execute(request.into_inner()).await.into()
328304
}
329305
}
330-
331-
trait ClientOutcomeExt {
332-
type Output;
333-
334-
/// Returns the committed result or an error if we are not the leader.
335-
///
336-
/// It is recommended to use single-owner chains for the faucet to avoid this error.
337-
fn try_unwrap(self) -> Result<Self::Output, Error>;
338-
}
339-
340-
impl<T> ClientOutcomeExt for ClientOutcome<T> {
341-
type Output = T;
342-
343-
fn try_unwrap(self) -> Result<Self::Output, Error> {
344-
match self {
345-
ClientOutcome::Committed(result) => Ok(result),
346-
ClientOutcome::WaitForTimeout(timeout) => Err(Error::new(format!(
347-
"This faucet is using a multi-owner chain and is not the leader right now. \
348-
Try again at {}",
349-
timeout.timestamp,
350-
))),
351-
}
352-
}
353-
}

linera-faucet/server/src/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use async_trait::async_trait;
99
use futures::lock::Mutex;
1010
use linera_base::{
1111
crypto::{AccountPublicKey, AccountSecretKey},
12-
data_types::{Amount, BlockHeight, Timestamp},
12+
data_types::{Amount, Timestamp},
1313
identifiers::ChainId,
1414
};
1515
use linera_client::{chain_listener, wallet::Wallet};
@@ -83,10 +83,9 @@ async fn test_faucet_rate_limiting() {
8383
};
8484
let context = Arc::new(Mutex::new(context));
8585
let root = MutationRoot {
86-
chain_id: Arc::new(Mutex::new(chain_id)),
86+
chain_id,
8787
context: context.clone(),
8888
amount: Amount::from_tokens(1),
89-
end_block_height: BlockHeight::from(10),
9089
end_timestamp: Timestamp::from(6000),
9190
start_timestamp: Timestamp::from(0),
9291
start_balance: Amount::from_tokens(6),

linera-service/src/cli_wrappers/wallet.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -517,22 +517,15 @@ impl ClientWrapper {
517517
port: impl Into<Option<u16>>,
518518
chain_id: ChainId,
519519
amount: Amount,
520-
max_chain_length: Option<u64>,
521520
) -> Result<FaucetService> {
522521
let port = port.into().unwrap_or(8080);
523522
let mut command = self.command().await?;
524-
command
523+
let child = command
525524
.arg("faucet")
526525
.arg(chain_id.to_string())
527526
.args(["--port".to_string(), port.to_string()])
528-
.args(["--amount".to_string(), amount.to_string()]);
529-
if let Some(max_chain_length) = max_chain_length {
530-
command.args([
531-
"--max-chain-length".to_string(),
532-
max_chain_length.to_string(),
533-
]);
534-
}
535-
let child = command.spawn_into()?;
527+
.args(["--amount".to_string(), amount.to_string()])
528+
.spawn_into()?;
536529
let client = reqwest_client();
537530
for i in 0..10 {
538531
linera_base::time::timer::sleep(Duration::from_secs(i)).await;

linera-service/src/linera/command.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,6 @@ pub enum ClientCommand {
614614
#[arg(long)]
615615
limit_rate_until: Option<DateTime<Utc>>,
616616

617-
/// The maximum number of blocks in the faucet chain, before a new one is created.
618-
#[arg(long, default_value = "100")]
619-
max_chain_length: u64,
620-
621617
/// Configuration for the faucet chain listener.
622618
#[command(flatten)]
623619
config: ChainListenerConfig,

linera-service/src/linera/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use command::{ClientCommand, DatabaseToolCommand, NetCommand, ProjectCommand, Wa
2222
use futures::{lock::Mutex, FutureExt as _, StreamExt};
2323
use linera_base::{
2424
crypto::{AccountSecretKey, CryptoHash, CryptoRng, Ed25519SecretKey},
25-
data_types::{ApplicationPermissions, BlockHeight, Timestamp},
25+
data_types::{ApplicationPermissions, Timestamp},
2626
identifiers::{AccountOwner, ChainDescription, ChainId},
2727
ownership::ChainOwnership,
2828
};
@@ -849,7 +849,6 @@ impl Runnable for Job {
849849
port,
850850
amount,
851851
limit_rate_until,
852-
max_chain_length,
853852
config,
854853
} => {
855854
let chain_id = chain_id.unwrap_or_else(|| context.default_chain());
@@ -867,7 +866,6 @@ impl Runnable for Job {
867866
chain_id,
868867
context,
869868
amount,
870-
BlockHeight(max_chain_length),
871869
end_timestamp,
872870
genesis_config,
873871
config,

linera-service/src/linera/net_up_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ async fn print_messages_and_create_faucet(
290290
ChainId::root(1)
291291
};
292292
let service = client
293-
.run_faucet(Some(faucet_port.into()), faucet_chain, faucet_amount, None)
293+
.run_faucet(Some(faucet_port.into()), faucet_chain, faucet_amount)
294294
.await?;
295295
Some(service)
296296
} else {

linera-service/tests/linera_net_tests.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,7 @@ async fn test_end_to_end_faucet(config: impl LineraNetConfig) -> Result<()> {
28622862
let owner2 = client2.keygen().await?;
28632863

28642864
let mut faucet_service = client1
2865-
.run_faucet(None, chain1, Amount::from_tokens(2), None)
2865+
.run_faucet(None, chain1, Amount::from_tokens(2))
28662866
.await?;
28672867
let faucet = faucet_service.instance();
28682868
let outcome = faucet.claim(&owner2).await?;
@@ -2955,29 +2955,16 @@ async fn test_end_to_end_faucet_with_long_chains(config: impl LineraNetConfig) -
29552955
}
29562956

29572957
let amount = Amount::ONE;
2958-
let mut faucet_service = faucet_client
2959-
.run_faucet(None, faucet_chain, amount, Some(chain_count as u64))
2960-
.await?;
2958+
let mut faucet_service = faucet_client.run_faucet(None, faucet_chain, amount).await?;
29612959
let faucet = faucet_service.instance();
29622960

2963-
// Create a new wallet using the faucet
2964-
let other_client = net.make_client().await;
2965-
let (other_outcome, _) = other_client
2966-
.wallet_init(&[], FaucetOption::NewChain(&faucet))
2967-
.await?
2968-
.unwrap();
2969-
29702961
// Create a new wallet using the faucet
29712962
let client = net.make_client().await;
29722963
let (outcome, _) = client
29732964
.wallet_init(&[], FaucetOption::NewChain(&faucet))
29742965
.await?
29752966
.unwrap();
29762967

2977-
// Since the faucet chain exceeds the configured maximum length, the faucet should have
2978-
// switched after the first new chain.
2979-
assert!(other_outcome.message_id.chain_id != outcome.message_id.chain_id);
2980-
29812968
let chain = outcome.chain_id;
29822969
assert_eq!(chain, client.load_wallet()?.default_chain().unwrap());
29832970

@@ -3020,7 +3007,7 @@ async fn test_end_to_end_fungible_client_benchmark(config: impl LineraNetConfig)
30203007

30213008
let chain1 = client1.load_wallet()?.default_chain().unwrap();
30223009

3023-
let mut faucet_service = client1.run_faucet(None, chain1, Amount::ONE, None).await?;
3010+
let mut faucet_service = client1.run_faucet(None, chain1, Amount::ONE).await?;
30243011
let faucet = faucet_service.instance();
30253012

30263013
let path =

0 commit comments

Comments
 (0)