Skip to content

Commit

Permalink
Parallelize supply_fungible_tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-ds committed Feb 6, 2025
1 parent 9cd7bc7 commit 90c2c62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
27 changes: 20 additions & 7 deletions linera-client/src/client_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,7 @@ where
.expect("should execute block with OpenChain operations"))
}

/// Creates chains if necessary, and returns a map of exactly `num_chains` chain IDs
/// with key pairs.
/// Supplies fungible tokens to the chains.
pub async fn supply_fungible_tokens(
&mut self,
key_pairs: &HashMap<ChainId, KeyPair>,
Expand Down Expand Up @@ -788,11 +787,11 @@ where
.collect();
let chain_client = self.make_chain_client(default_chain_id)?;
// Put at most 1000 fungible token operations in each block.
for operations in operations.chunks(1000) {
for operation_chunk in operations.chunks(1000) {
chain_client
.execute_operations(operations.to_vec(), vec![])
.execute_operations(operation_chunk.to_vec(), vec![])
.await?
.expect("should execute block with OpenChain operations");
.expect("should execute block with Transfer operations");
}
self.update_wallet_from_client(&chain_client).await?;
// Make sure all chains have registered the application now.
Expand All @@ -802,8 +801,10 @@ where
.make_chain_client(chain_id)
.expect("chain should have been created");
join_set.spawn(async move {
for i in 0..5 {
linera_base::time::timer::sleep(Duration::from_secs(i)).await;
let mut delay_ms = 0;
let mut total_delay_ms = 0;
loop {
linera_base::time::timer::sleep(Duration::from_millis(delay_ms)).await;
chain_client.process_inbox().await?;
let chain_state = chain_client.chain_state_view().await?;
if chain_state
Expand All @@ -816,6 +817,18 @@ where
{
return Ok::<_, Error>(chain_client);
}

total_delay_ms += delay_ms;
// If we've been waiting already for more than 10 seconds, give up.
if total_delay_ms > 10_000 {
break;
}

if delay_ms == 0 {
delay_ms = 100;
} else {
delay_ms *= 2;
}
}
panic!("Could not instantiate application on chain {chain_id:?}");
});
Expand Down
5 changes: 5 additions & 0 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,12 @@ impl Runnable for Job {
);

if let Some(id) = fungible_application_id {
let start = Instant::now();
context.supply_fungible_tokens(&key_pairs, id).await?;
info!(
"Supplied fungible tokens in {} ms",
start.elapsed().as_millis()
);
}

// For this command, we create proposals and gather certificates without using
Expand Down

0 comments on commit 90c2c62

Please sign in to comment.