Skip to content

Commit c5e3d9a

Browse files
authored
Remove some unused methods. (#4063)
## Motivation Some client functions are unused or unnecessarily public. Also, some code in the query functions is duplicated, and the user- and system-specific ones lack the functionality to download blobs. ## Proposal Remove unused code, make functions private, and use `query_application`. ## Test Plan CI ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent b6b1e48 commit c5e3d9a

File tree

2 files changed

+17
-48
lines changed

2 files changed

+17
-48
lines changed

linera-core/src/client/mod.rs

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ impl<Env: Environment> Client<Env> {
424424
Ok(self.make_nodes(&committee)?)
425425
}
426426

427+
/// Creates a [`RemoteNode`] for each validator in the committee.
427428
fn make_nodes(
428429
&self,
429430
committee: &Committee,
@@ -472,7 +473,7 @@ impl<Env: Environment> Client<Env> {
472473

473474
/// Handles the certificate in the local node and the resulting notifications.
474475
#[instrument(level = "trace", skip_all)]
475-
pub async fn process_certificate<T: ProcessableCertificate>(
476+
async fn process_certificate<T: ProcessableCertificate>(
476477
&self,
477478
certificate: Box<GenericCertificate<T>>,
478479
) -> Result<(), LocalNodeError> {
@@ -1079,7 +1080,7 @@ impl<Env: Environment> Client<Env> {
10791080

10801081
/// Downloads and processes confirmed block certificates that use the given blobs.
10811082
/// If this succeeds, the blobs will be in our storage.
1082-
pub async fn receive_certificates_for_blobs(
1083+
async fn receive_certificates_for_blobs(
10831084
&self,
10841085
blob_ids: Vec<BlobId>,
10851086
) -> Result<(), ChainClientError> {
@@ -1696,7 +1697,7 @@ impl<Env: Environment> ChainClient<Env> {
16961697
}
16971698

16981699
#[instrument(level = "trace")]
1699-
pub async fn chain_info_with_committees(&self) -> Result<Box<ChainInfo>, LocalNodeError> {
1700+
async fn chain_info_with_committees(&self) -> Result<Box<ChainInfo>, LocalNodeError> {
17001701
self.client.chain_info_with_committees(self.chain_id).await
17011702
}
17021703

@@ -1705,10 +1706,7 @@ impl<Env: Environment> ChainClient<Env> {
17051706
async fn epoch_and_committees(
17061707
&self,
17071708
) -> Result<(Epoch, BTreeMap<Epoch, Committee>), LocalNodeError> {
1708-
let info = self
1709-
.client
1710-
.chain_info_with_committees(self.chain_id)
1711-
.await?;
1709+
let info = self.chain_info_with_committees().await?;
17121710
let epoch = info.epoch;
17131711
let committees = info.into_committees()?;
17141712
Ok((epoch, committees))
@@ -1728,12 +1726,6 @@ impl<Env: Environment> ChainClient<Env> {
17281726
self.client.admin_committee().await
17291727
}
17301728

1731-
/// Obtains the current epoch of the local chain.
1732-
#[instrument(level = "trace")]
1733-
async fn epoch(&self) -> Result<Epoch, LocalNodeError> {
1734-
Ok(self.chain_info().await?.epoch)
1735-
}
1736-
17371729
/// Obtains the identity of the current owner of the chain.
17381730
///
17391731
/// Returns an error if we don't have the private key for the identity.
@@ -2277,7 +2269,7 @@ impl<Env: Environment> ChainClient<Env> {
22772269
let info = self.chain_info().await?;
22782270
let timestamp = self.next_timestamp(&incoming_bundles, info.timestamp);
22792271
let proposed_block = ProposedBlock {
2280-
epoch: self.epoch().await?,
2272+
epoch: info.epoch,
22812273
chain_id: self.chain_id,
22822274
incoming_bundles,
22832275
operations,
@@ -2357,11 +2349,7 @@ impl<Env: Environment> ChainClient<Env> {
23572349
let QueryOutcome {
23582350
response,
23592351
operations,
2360-
} = self
2361-
.client
2362-
.local_node
2363-
.query_application(self.chain_id, Query::System(query))
2364-
.await?;
2352+
} = self.query_application(Query::System(query)).await?;
23652353
match response {
23662354
QueryResponse::System(response) => Ok(QueryOutcome {
23672355
response,
@@ -2384,11 +2372,7 @@ impl<Env: Environment> ChainClient<Env> {
23842372
let QueryOutcome {
23852373
response,
23862374
operations,
2387-
} = self
2388-
.client
2389-
.local_node
2390-
.query_application(self.chain_id, query)
2391-
.await?;
2375+
} = self.query_application(query).await?;
23922376
match response {
23932377
QueryResponse::User(response_bytes) => {
23942378
let response = serde_json::from_slice(&response_bytes)?;
@@ -2459,7 +2443,7 @@ impl<Env: Environment> ChainClient<Env> {
24592443
let info = self.chain_info().await?;
24602444
let timestamp = self.next_timestamp(&incoming_bundles, info.timestamp);
24612445
let block = ProposedBlock {
2462-
epoch: self.epoch().await?,
2446+
epoch: info.epoch,
24632447
chain_id: self.chain_id,
24642448
incoming_bundles,
24652449
operations: Vec::new(),
@@ -2852,21 +2836,6 @@ impl<Env: Environment> ChainClient<Env> {
28522836
.await
28532837
}
28542838

2855-
/// Processes confirmed operation for which this chain is a recipient.
2856-
#[instrument(
2857-
level = "trace",
2858-
skip(certificate),
2859-
fields(certificate_hash = ?certificate.hash()),
2860-
)]
2861-
pub async fn receive_certificate(
2862-
&self,
2863-
certificate: ConfirmedBlockCertificate,
2864-
) -> Result<(), ChainClientError> {
2865-
self.client
2866-
.receive_certificate(certificate, ReceiveCertificateMode::NeedsCheck, None)
2867-
.await
2868-
}
2869-
28702839
/// Rotates the key of the chain.
28712840
///
28722841
/// Replaces current owners of the chain with the new key pair.
@@ -3175,7 +3144,7 @@ impl<Env: Environment> ChainClient<Env> {
31753144
ClientOutcome::Committed(_) => {}
31763145
outcome @ ClientOutcome::WaitForTimeout(_) => return Ok(outcome),
31773146
}
3178-
let epoch = self.epoch().await?.try_add_one()?;
3147+
let epoch = self.chain_info().await?.epoch.try_add_one()?;
31793148
self.execute_operation(SystemOperation::Admin(AdminOperation::CreateCommittee {
31803149
epoch,
31813150
blob_hash,

linera-core/src/unit_tests/client_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ where
11461146
// This must happen before the old committee is removed.
11471147
user.synchronize_from_validators().await.unwrap();
11481148
user.process_inbox().await.unwrap();
1149-
assert_eq!(user.epoch().await.unwrap(), Epoch::from(1));
1149+
assert_eq!(user.chain_info().await?.epoch, Epoch::from(1));
11501150
admin.finalize_committee().await.unwrap();
11511151

11521152
// Create a new committee.
@@ -1158,7 +1158,7 @@ where
11581158
);
11591159
assert!(admin.pending_proposal().is_none());
11601160
assert!(admin.identity().await.is_ok());
1161-
assert_eq!(admin.epoch().await.unwrap(), Epoch::from(2));
1161+
assert_eq!(admin.chain_info().await?.epoch, Epoch::from(2));
11621162

11631163
// Sending money from the admin chain is supported.
11641164
let cert = admin
@@ -1186,11 +1186,11 @@ where
11861186
user.receive_certificate_and_update_validators(cert).await,
11871187
Err(ChainClientError::CommitteeSynchronizationError)
11881188
);
1189-
assert_eq!(user.epoch().await.unwrap(), Epoch::from(1));
1189+
assert_eq!(user.chain_info().await?.epoch, Epoch::from(1));
11901190
user.synchronize_from_validators().await.unwrap();
11911191

11921192
user.process_inbox().await.unwrap();
1193-
assert_eq!(user.epoch().await.unwrap(), Epoch::from(2));
1193+
assert_eq!(user.chain_info().await?.epoch, Epoch::from(2));
11941194

11951195
// Have the admin chain deprecate the previous epoch.
11961196
admin.finalize_committee().await.unwrap();
@@ -1209,7 +1209,7 @@ where
12091209
.receive_certificate_and_update_validators(cert)
12101210
.await
12111211
.unwrap();
1212-
assert_eq!(user.epoch().await.unwrap(), Epoch::from(2));
1212+
assert_eq!(user.chain_info().await?.epoch, Epoch::from(2));
12131213

12141214
// Try again to make a transfer back to the admin chain.
12151215
let cert = user
@@ -1236,13 +1236,13 @@ where
12361236

12371237
let committee = Committee::new(validators, ResourceControlPolicy::default());
12381238
admin.stage_new_committee(committee).await.unwrap();
1239-
assert_eq!(admin.epoch().await.unwrap(), Epoch::from(3));
1239+
assert_eq!(admin.chain_info().await?.epoch, Epoch::from(3));
12401240

12411241
// Despite the restrictive application permissions, some system operations are still allowed,
12421242
// and the user chain can migrate to the new epoch.
12431243
user.synchronize_from_validators().await?;
12441244
user.process_inbox().await?;
1245-
assert_eq!(user.epoch().await.unwrap(), Epoch::from(3));
1245+
assert_eq!(user.chain_info().await?.epoch, Epoch::from(3));
12461246

12471247
Ok(())
12481248
}

0 commit comments

Comments
 (0)