Skip to content

Commit

Permalink
Allow creating a ChainClient if the chain is already in the map. (#2597)
Browse files Browse the repository at this point in the history
* Allow creating a ChainClient if the chain is already in the map.

* Add the storage-service feature to run the benchmark test in CI.

* Add TODO for #2600.

* Make the other benchmark test stable, too. Rename it.
  • Loading branch information
afck authored Oct 9, 2024
1 parent 0d82a0c commit afc59e1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
cargo test --locked -p linera-execution --features wasmtime
- name: Run the benchmark test
run: |
cargo build --locked -p linera-service --bin linera-benchmark --features benchmark
cargo test --locked -p linera-service --features benchmark benchmark
cargo build --locked -p linera-service --bin linera-benchmark --features benchmark,storage-service
cargo test --locked -p linera-service --features benchmark,storage-service benchmark
- name: Run Wasm application tests
run: |
cd examples
Expand Down
2 changes: 2 additions & 0 deletions linera-client/src/client_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ where
let chain_client = self.make_chain_client(chain_id);
self.process_inbox(&chain_client).await.unwrap();
chain_client.update_validators().await.unwrap();
self.update_wallet_from_client(&chain_client).await.unwrap();
}
}

Expand Down Expand Up @@ -576,6 +577,7 @@ where
.await?;
}
}
self.update_wallet_from_client(&chain_client).await?;
let updated_chain_client = self.make_chain_client(default_chain_id);
updated_chain_client
.retry_pending_outgoing_messages()
Expand Down
40 changes: 28 additions & 12 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

use std::{
collections::{hash_map, BTreeMap, HashMap, HashSet},
collections::{hash_map, BTreeMap, BTreeSet, HashMap, HashSet},
convert::Infallible,
iter,
num::NonZeroUsize,
Expand Down Expand Up @@ -255,18 +255,34 @@ impl<P, S: Storage + Clone> Client<P, S> {
pending_block: Option<Block>,
pending_blobs: BTreeMap<BlobId, Blob>,
) -> ChainClient<P, S> {
let dashmap::mapref::entry::Entry::Vacant(e) = self.chains.entry(chain_id) else {
panic!("Inserting already-existing chain {chain_id}");
match self.chains.entry(chain_id) {
dashmap::mapref::entry::Entry::Vacant(e) => {
e.insert(ChainState::new(
known_key_pairs,
admin_id,
block_hash,
timestamp,
next_block_height,
pending_block,
pending_blobs,
));
}
dashmap::mapref::entry::Entry::Occupied(e) => {
// TODO(#2600): Find a better way to handle this case.
let state = e.get();
let owners = known_key_pairs
.into_iter()
.map(|kp| Owner::from(kp.public()))
.collect::<BTreeSet<_>>();
assert!(state.known_key_pairs().keys().eq(&owners));
assert_eq!(state.admin_id(), admin_id);
assert_eq!(state.block_hash(), block_hash);
assert_eq!(state.timestamp(), timestamp);
assert_eq!(state.next_block_height(), next_block_height);
assert_eq!(state.pending_block(), &pending_block);
assert!(state.pending_blobs().keys().eq(pending_blobs.keys()));
}
};
e.insert(ChainState::new(
known_key_pairs,
admin_id,
block_hash,
timestamp,
next_block_height,
pending_block,
pending_blobs,
));

ChainClient {
client: self.clone(),
Expand Down
1 change: 1 addition & 0 deletions linera-service/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ async fn benchmark_with_fungible(
if expected_balance == Amount::ZERO {
return Ok(()); // No transfers: The app won't be registered on this chain.
}
node_service.process_inbox(&context.default_chain).await?;
let app = FungibleApp(
node_service
.make_application(
Expand Down
2 changes: 1 addition & 1 deletion linera-service/tests/linera_net_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,7 @@ async fn test_end_to_end_faucet_with_long_chains(config: impl LineraNetConfig) -
#[cfg_attr(feature = "kubernetes", test_case(SharedLocalKubernetesNetTestingConfig::new(Network::Grpc, BuildArg::Build) ; "kubernetes_grpc"))]
#[cfg_attr(feature = "remote-net", test_case(RemoteNetTestingConfig::new(None) ; "remote_net_grpc"))]
#[test_log::test(tokio::test)]
async fn test_end_to_end_fungible_benchmark(config: impl LineraNetConfig) -> Result<()> {
async fn test_end_to_end_fungible_client_benchmark(config: impl LineraNetConfig) -> Result<()> {
use linera_base::command::CommandExt;
use tokio::process::Command;

Expand Down

0 comments on commit afc59e1

Please sign in to comment.