Skip to content

Commit c01fd11

Browse files
authored
Revert automatic faucet chain rotation. (#3890)
## Motivation The current approach to automatic faucet chain rotation doesn't work well. In particular, it closes the original chain, so restarts don't work with the same command line arguments. ## Proposal Revert #3848. ## Test Plan CI ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - Reverted PR: #3848 - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 6bcb950 commit c01fd11

File tree

9 files changed

+26
-113
lines changed

9 files changed

+26
-113
lines changed

CLI.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,6 @@ Run a GraphQL service that exposes a faucet where users can claim tokens. This g
619619
Default value: `8080`
620620
* `--amount <AMOUNT>` — The number of tokens to send to each new chain
621621
* `--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
622-
* `--max-chain-length <MAX_CHAIN_LENGTH>` — The maximum number of blocks in the faucet chain, before a new one is created
623-
624-
Default value: `100`
625622
* `--listener-skip-process-inbox` — Do not create blocks automatically to receive incoming messages. Instead, wait for an explicit mutation `processInbox`
626623
* `--listener-delay-before-ms <DELAY_BEFORE_MS>` — Wait before processing any notification (useful for testing)
627624

linera-faucet/server/src/lib.rs

Lines changed: 10 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use axum::{Extension, Router};
1111
use futures::{lock::Mutex, FutureExt as _};
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},
1616
ownership::ChainOwnership,
1717
};
@@ -43,15 +43,14 @@ mod tests;
4343
pub struct QueryRoot<C> {
4444
context: Arc<Mutex<C>>,
4545
genesis_config: Arc<GenesisConfig>,
46-
chain_id: Arc<Mutex<ChainId>>,
46+
chain_id: ChainId,
4747
}
4848

4949
/// The root GraphQL mutation type.
5050
pub struct MutationRoot<C> {
51-
chain_id: Arc<Mutex<ChainId>>,
51+
chain_id: ChainId,
5252
context: Arc<Mutex<C>>,
5353
amount: Amount,
54-
end_block_height: BlockHeight,
5554
end_timestamp: Timestamp,
5655
start_timestamp: Timestamp,
5756
start_balance: Amount,
@@ -89,12 +88,11 @@ where
8988

9089
/// Returns the current committee's validators.
9190
async fn current_validators(&self) -> Result<Vec<Validator>, Error> {
92-
let chain_id = *self.chain_id.lock().await;
9391
let client = self
9492
.context
9593
.lock()
9694
.await
97-
.make_chain_client(chain_id)
95+
.make_chain_client(self.chain_id)
9896
.await?;
9997
let committee = client.local_committee().await?;
10098
Ok(committee
@@ -124,12 +122,11 @@ where
124122
C: ClientContext,
125123
{
126124
async fn do_claim(&self, owner: AccountOwner) -> Result<ClaimOutcome, Error> {
127-
let chain_id = *self.chain_id.lock().await;
128125
let client = self
129126
.context
130127
.lock()
131128
.await
132-
.make_chain_client(chain_id)
129+
.make_chain_client(self.chain_id)
133130
.await?;
134131

135132
if self.start_timestamp < self.end_timestamp {
@@ -171,30 +168,6 @@ where
171168
)));
172169
}
173170
};
174-
175-
if client.next_block_height() >= self.end_block_height {
176-
let preferred_owner = client.preferred_owner();
177-
let balance = client.local_balance().await?.try_sub(Amount::ONE)?;
178-
let ownership = client.chain_state_view().await?.ownership().clone();
179-
let (chain_id, certificate) = client
180-
.open_chain(ownership, ApplicationPermissions::default(), balance)
181-
.await?
182-
.try_unwrap()?;
183-
// TODO(#1795): Move the remaining tokens to the new chain.
184-
client.close_chain().await?.try_unwrap()?;
185-
info!("Switching to a new faucet chain {chain_id:8}; remaining balance: {balance}");
186-
self.context
187-
.lock()
188-
.await
189-
.update_wallet_for_new_chain(
190-
chain_id,
191-
preferred_owner,
192-
certificate.block().header.timestamp,
193-
)
194-
.await?;
195-
*self.chain_id.lock().await = chain_id;
196-
}
197-
198171
Ok(ClaimOutcome {
199172
chain_id,
200173
certificate_hash: certificate.hash(),
@@ -219,15 +192,14 @@ pub struct FaucetService<C>
219192
where
220193
C: ClientContext,
221194
{
222-
chain_id: Arc<Mutex<ChainId>>,
195+
chain_id: ChainId,
223196
context: Arc<Mutex<C>>,
224197
genesis_config: Arc<GenesisConfig>,
225198
config: ChainListenerConfig,
226199
storage: <C::Environment as linera_core::Environment>::Storage,
227200
port: NonZeroU16,
228201
amount: Amount,
229202
end_timestamp: Timestamp,
230-
end_block_height: BlockHeight,
231203
start_timestamp: Timestamp,
232204
start_balance: Amount,
233205
}
@@ -238,14 +210,13 @@ where
238210
{
239211
fn clone(&self) -> Self {
240212
Self {
241-
chain_id: self.chain_id.clone(),
213+
chain_id: self.chain_id,
242214
context: Arc::clone(&self.context),
243215
genesis_config: Arc::clone(&self.genesis_config),
244216
config: self.config.clone(),
245217
storage: self.storage.clone(),
246218
port: self.port,
247219
amount: self.amount,
248-
end_block_height: self.end_block_height,
249220
end_timestamp: self.end_timestamp,
250221
start_timestamp: self.start_timestamp,
251222
start_balance: self.start_balance,
@@ -264,7 +235,6 @@ where
264235
chain_id: ChainId,
265236
context: C,
266237
amount: Amount,
267-
end_block_height: BlockHeight,
268238
end_timestamp: Timestamp,
269239
genesis_config: Arc<GenesisConfig>,
270240
config: ChainListenerConfig,
@@ -276,14 +246,13 @@ where
276246
client.process_inbox().await?;
277247
let start_balance = client.local_balance().await?;
278248
Ok(Self {
279-
chain_id: Arc::new(Mutex::new(chain_id)),
249+
chain_id,
280250
context,
281251
genesis_config,
282252
config,
283253
storage,
284254
port,
285255
amount,
286-
end_block_height,
287256
end_timestamp,
288257
start_timestamp,
289258
start_balance,
@@ -292,18 +261,17 @@ where
292261

293262
pub fn schema(&self) -> Schema<QueryRoot<C>, MutationRoot<C>, EmptySubscription> {
294263
let mutation_root = MutationRoot {
295-
chain_id: self.chain_id.clone(),
264+
chain_id: self.chain_id,
296265
context: Arc::clone(&self.context),
297266
amount: self.amount,
298-
end_block_height: self.end_block_height,
299267
end_timestamp: self.end_timestamp,
300268
start_timestamp: self.start_timestamp,
301269
start_balance: self.start_balance,
302270
};
303271
let query_root = QueryRoot {
304272
genesis_config: Arc::clone(&self.genesis_config),
305273
context: Arc::clone(&self.context),
306-
chain_id: self.chain_id.clone(),
274+
chain_id: self.chain_id,
307275
};
308276
Schema::build(query_root, mutation_root, EmptySubscription).finish()
309277
}
@@ -342,27 +310,3 @@ where
342310
schema.execute(request.into_inner()).await.into()
343311
}
344312
}
345-
346-
trait ClientOutcomeExt {
347-
type Output;
348-
349-
/// Returns the committed result or an error if we are not the leader.
350-
///
351-
/// It is recommended to use single-owner chains for the faucet to avoid this error.
352-
fn try_unwrap(self) -> Result<Self::Output, Error>;
353-
}
354-
355-
impl<T> ClientOutcomeExt for ClientOutcome<T> {
356-
type Output = T;
357-
358-
fn try_unwrap(self) -> Result<Self::Output, Error> {
359-
match self {
360-
ClientOutcome::Committed(result) => Ok(result),
361-
ClientOutcome::WaitForTimeout(timeout) => Err(Error::new(format!(
362-
"This faucet is using a multi-owner chain and is not the leader right now. \
363-
Try again at {}",
364-
timeout.timestamp,
365-
))),
366-
}
367-
}
368-
}

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, InMemorySigner},
12-
data_types::{Amount, BlockHeight, Timestamp},
12+
data_types::{Amount, Timestamp},
1313
identifiers::{AccountOwner, ChainId},
1414
};
1515
use linera_client::{chain_listener, wallet::Wallet};
@@ -89,10 +89,9 @@ async fn test_faucet_rate_limiting() {
8989
};
9090
let context = Arc::new(Mutex::new(context));
9191
let root = MutationRoot {
92-
chain_id: Arc::new(Mutex::new(chain_id)),
92+
chain_id,
9393
context: context.clone(),
9494
amount: Amount::from_tokens(1),
95-
end_block_height: BlockHeight::from(10),
9695
end_timestamp: Timestamp::from(6000),
9796
start_timestamp: Timestamp::from(0),
9897
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
@@ -520,22 +520,15 @@ impl ClientWrapper {
520520
port: impl Into<Option<u16>>,
521521
chain_id: ChainId,
522522
amount: Amount,
523-
max_chain_length: Option<u64>,
524523
) -> Result<FaucetService> {
525524
let port = port.into().unwrap_or(8080);
526525
let mut command = self.command().await?;
527-
command
526+
let child = command
528527
.arg("faucet")
529528
.arg(chain_id.to_string())
530529
.args(["--port".to_string(), port.to_string()])
531-
.args(["--amount".to_string(), amount.to_string()]);
532-
if let Some(max_chain_length) = max_chain_length {
533-
command.args([
534-
"--max-chain-length".to_string(),
535-
max_chain_length.to_string(),
536-
]);
537-
}
538-
let child = command.spawn_into()?;
530+
.args(["--amount".to_string(), amount.to_string()])
531+
.spawn_into()?;
539532
let client = reqwest_client();
540533
for i in 0..10 {
541534
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
@@ -631,10 +631,6 @@ pub enum ClientCommand {
631631
#[arg(long)]
632632
limit_rate_until: Option<DateTime<Utc>>,
633633

634-
/// The maximum number of blocks in the faucet chain, before a new one is created.
635-
#[arg(long, default_value = "100")]
636-
max_chain_length: u64,
637-
638634
/// Configuration for the faucet chain listener.
639635
#[command(flatten)]
640636
config: ChainListenerConfig,

linera-service/src/linera/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use linera_base::{
2525
bcs,
2626
crypto::{CryptoHash, InMemorySigner, Signer},
2727
data_types::{
28-
ApplicationPermissions, BlockHeight, ChainDescription, ChainOrigin, Epoch,
29-
InitialChainConfig, Timestamp,
28+
ApplicationPermissions, ChainDescription, ChainOrigin, Epoch, InitialChainConfig, Timestamp,
3029
},
3130
identifiers::{AccountOwner, ChainId},
3231
listen_for_shutdown_signals,
@@ -974,7 +973,6 @@ impl Runnable for Job {
974973
port,
975974
amount,
976975
limit_rate_until,
977-
max_chain_length,
978976
config,
979977
} => {
980978
let context = ClientContext::new(
@@ -999,7 +997,6 @@ impl Runnable for Job {
999997
chain_id,
1000998
context,
1001999
amount,
1002-
BlockHeight(max_chain_length),
10031000
end_timestamp,
10041001
genesis_config,
10051002
config,

linera-service/src/linera/net_up_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async fn print_messages_and_create_faucet(
306306
.nth(faucet_chain_idx as usize)
307307
.unwrap(); // we checked that there are enough chains above, so this should be safe
308308
let service = client
309-
.run_faucet(Some(faucet_port.into()), faucet_chain, faucet_amount, None)
309+
.run_faucet(Some(faucet_port.into()), faucet_chain, faucet_amount)
310310
.await?;
311311
Some(service)
312312
} else {

linera-service/tests/linera_net_tests.rs

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

31683168
let mut faucet_service = client1
3169-
.run_faucet(None, chain1, Amount::from_tokens(2), None)
3169+
.run_faucet(None, chain1, Amount::from_tokens(2))
31703170
.await?;
31713171
let faucet = faucet_service.instance();
31723172
let outcome = faucet.claim(&owner2).await?;
@@ -3258,29 +3258,16 @@ async fn test_end_to_end_faucet_with_long_chains(config: impl LineraNetConfig) -
32583258
}
32593259

32603260
let amount = Amount::ONE;
3261-
let mut faucet_service = faucet_client
3262-
.run_faucet(None, faucet_chain, amount, Some(chain_count as u64))
3263-
.await?;
3261+
let mut faucet_service = faucet_client.run_faucet(None, faucet_chain, amount).await?;
32643262
let faucet = faucet_service.instance();
32653263

3266-
// Create a new wallet using the faucet
3267-
let other_client = net.make_client().await;
3268-
let (other_outcome, _) = other_client
3269-
.wallet_init(&[], FaucetOption::NewChain(&faucet))
3270-
.await?
3271-
.unwrap();
3272-
32733264
// Create a new wallet using the faucet
32743265
let client = net.make_client().await;
32753266
let (outcome, _) = client
32763267
.wallet_init(&[], FaucetOption::NewChain(&faucet))
32773268
.await?
32783269
.unwrap();
32793270

3280-
// Since the faucet chain exceeds the configured maximum length, the faucet should have
3281-
// switched after the first new chain.
3282-
assert!(other_outcome.chain_id != outcome.chain_id);
3283-
32843271
let chain = outcome.chain_id;
32853272
assert_eq!(chain, client.load_wallet()?.default_chain().unwrap());
32863273

@@ -3323,7 +3310,7 @@ async fn test_end_to_end_fungible_client_benchmark(config: impl LineraNetConfig)
33233310

33243311
let chain1 = client1.load_wallet()?.default_chain().unwrap();
33253312

3326-
let mut faucet_service = client1.run_faucet(None, chain1, Amount::ONE, None).await?;
3313+
let mut faucet_service = client1.run_faucet(None, chain1, Amount::ONE).await?;
33273314
let faucet = faucet_service.instance();
33283315

33293316
let path =

linera-service/tests/local_net_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async fn test_end_to_end_reconfiguration(config: LocalNetConfig) -> Result<()> {
6969
.await?;
7070

7171
let mut faucet_service = faucet_client
72-
.run_faucet(None, faucet_chain, Amount::from_tokens(2), None)
72+
.run_faucet(None, faucet_chain, Amount::from_tokens(2))
7373
.await?;
7474

7575
faucet_service.ensure_is_running()?;
@@ -249,7 +249,7 @@ async fn test_end_to_end_receipt_of_old_create_committee_messages(
249249

250250
if matches!(network, Network::Grpc) {
251251
let mut faucet_service = faucet_client
252-
.run_faucet(None, faucet_chain, Amount::from_tokens(2), None)
252+
.run_faucet(None, faucet_chain, Amount::from_tokens(2))
253253
.await?;
254254

255255
faucet_service.ensure_is_running()?;
@@ -283,7 +283,7 @@ async fn test_end_to_end_receipt_of_old_create_committee_messages(
283283
faucet_client.process_inbox(faucet_chain).await?;
284284

285285
let mut faucet_service = faucet_client
286-
.run_faucet(None, faucet_chain, Amount::from_tokens(2), None)
286+
.run_faucet(None, faucet_chain, Amount::from_tokens(2))
287287
.await?;
288288

289289
faucet_service.ensure_is_running()?;
@@ -337,7 +337,7 @@ async fn test_end_to_end_receipt_of_old_remove_committee_messages(
337337

338338
if matches!(network, Network::Grpc) {
339339
let mut faucet_service = faucet_client
340-
.run_faucet(None, faucet_chain, Amount::from_tokens(2), None)
340+
.run_faucet(None, faucet_chain, Amount::from_tokens(2))
341341
.await?;
342342

343343
faucet_service.ensure_is_running()?;
@@ -373,7 +373,7 @@ async fn test_end_to_end_receipt_of_old_remove_committee_messages(
373373

374374
if matches!(network, Network::Grpc) {
375375
let mut faucet_service = faucet_client
376-
.run_faucet(None, faucet_chain, Amount::from_tokens(2), None)
376+
.run_faucet(None, faucet_chain, Amount::from_tokens(2))
377377
.await?;
378378

379379
faucet_service.ensure_is_running()?;
@@ -409,7 +409,7 @@ async fn test_end_to_end_receipt_of_old_remove_committee_messages(
409409
faucet_client.process_inbox(faucet_chain).await?;
410410

411411
let mut faucet_service = faucet_client
412-
.run_faucet(None, faucet_chain, Amount::from_tokens(2), None)
412+
.run_faucet(None, faucet_chain, Amount::from_tokens(2))
413413
.await?;
414414

415415
faucet_service.ensure_is_running()?;

0 commit comments

Comments
 (0)