Skip to content

Commit 0187ca1

Browse files
authored
Fix typos, remove unreachable!. (#3886)
## Motivation Browsing through #3696 I found a few typos and an unnecessary `unreachable!`. ## Proposal Fix them. ## 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 df5132b commit 0187ca1

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

linera-base/src/crypto/signer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait Signer: Send + Sync {
2929
owner: &AccountOwner,
3030
) -> Result<AccountPublicKey, Box<dyn std::error::Error>>;
3131

32-
/// Returnes whether the given `owner` is a known signer.
32+
/// Returns whether the given `owner` is a known signer.
3333
async fn contains_key(&self, owner: &AccountOwner) -> Result<bool, Box<dyn std::error::Error>>;
3434
}
3535

@@ -55,7 +55,7 @@ impl Signer for Box<dyn Signer> {
5555
}
5656
}
5757

58-
/// In-memory implementatio of the [`Signer`] trait.
58+
/// In-memory implementation of the [`Signer`] trait.
5959
mod in_mem {
6060
use std::{
6161
collections::BTreeMap,
@@ -77,14 +77,14 @@ mod in_mem {
7777
pub struct InMemorySigner(Arc<RwLock<InMemSignerInner>>);
7878

7979
impl InMemorySigner {
80-
/// Creates a new `InMemSigner` seeded with `prng_seed`.
80+
/// Creates a new [`InMemorySigner`] seeded with `prng_seed`.
8181
/// If `prng_seed` is `None`, an `OsRng` will be used.
8282
#[cfg(with_getrandom)]
8383
pub fn new(prng_seed: Option<u64>) -> Self {
8484
InMemorySigner(Arc::new(RwLock::new(InMemSignerInner::new(prng_seed))))
8585
}
8686

87-
/// Creates a new `InMemSigner`.
87+
/// Creates a new [`InMemorySigner`].
8888
#[cfg(not(with_getrandom))]
8989
pub fn new() -> Self {
9090
InMemorySigner(Arc::new(RwLock::new(InMemSignerInner::new())))
@@ -202,7 +202,7 @@ mod in_mem {
202202
}
203203
}
204204

205-
/// Returnes whether the given `owner` is a known signer.
205+
/// Returns whether the given `owner` is a known signer.
206206
async fn contains_key(
207207
&self,
208208
owner: &AccountOwner,

linera-client/src/client_context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,10 @@ where
497497
) -> Result<(), Error> {
498498
let chain_id = chain_id.unwrap_or_else(|| self.default_chain());
499499
let chain_client = self.make_chain_client(chain_id).await?;
500-
info!(?ownership_config, %chain_id, preferred_owner=?chain_client.preferred_owner(), "Changing ownership of a chain");
500+
info!(
501+
?ownership_config, %chain_id, preferred_owner=?chain_client.preferred_owner(),
502+
"Changing ownership of a chain"
503+
);
501504
let time_start = Instant::now();
502505
let ownership = ChainOwnership::try_from(ownership_config)?;
503506

linera-core/src/client/mod.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub struct Client<Env: Environment> {
163163
tracked_chains: Arc<RwLock<HashSet<ChainId>>>,
164164
/// References to clients waiting for chain notifications.
165165
notifier: Arc<ChannelNotifier<Notification>>,
166-
/// A reference to the Signer used to sign messages.
166+
/// A reference to the [`Signer`] used to sign block proposals.
167167
signer: Box<dyn Signer>,
168168
/// Chain state for the managed chains.
169169
chains: DashMap<ChainId, ChainClientState>,
@@ -232,7 +232,7 @@ impl<Env: Environment> Client<Env> {
232232
&self.local_node
233233
}
234234

235-
/// Returns a reference to the `Signer`] of the client.
235+
/// Returns a reference to the [`Signer`] of the client.
236236
#[instrument(level = "trace", skip(self))]
237237
pub fn signer(&self) -> &impl Signer {
238238
&self.signer
@@ -1120,38 +1120,32 @@ impl<Env: Environment> ChainClient<Env> {
11201120
.chain(&manager.leader)
11211121
.any(|owner| *owner == preferred_owner);
11221122

1123+
if !is_owner {
1124+
let accepted_owners = manager
1125+
.ownership
1126+
.all_owners()
1127+
.chain(&manager.leader)
1128+
.collect::<Vec<_>>();
1129+
warn!(%self.chain_id, ?accepted_owners, ?preferred_owner,
1130+
"Chain has multiple owners configured but none is preferred owner",
1131+
);
1132+
return Err(ChainClientError::NotAnOwner(self.chain_id));
1133+
}
1134+
11231135
let has_signer = self
11241136
.signer()
11251137
.contains_key(&preferred_owner)
11261138
.await
11271139
.map_err(ChainClientError::signer_failure)?;
11281140

1129-
if is_owner && has_signer {
1130-
Ok(preferred_owner)
1131-
} else {
1132-
if !is_owner {
1133-
let accepted_owners = manager
1134-
.ownership
1135-
.all_owners()
1136-
.chain(&manager.leader)
1137-
.collect::<Vec<_>>();
1138-
warn!(%self.chain_id, ?accepted_owners, ?preferred_owner,
1139-
"Chain has multiple owners configured but none is preferred owner",
1140-
);
1141-
return Err(ChainClientError::NotAnOwner(self.chain_id));
1142-
}
1143-
1144-
if !has_signer {
1145-
warn!(%self.chain_id, ?preferred_owner,
1146-
"Chain is one of the owners but its Signer instance doesn't contain the key",
1147-
);
1148-
return Err(ChainClientError::CannotFindKeyForChain(self.chain_id));
1149-
}
1150-
unreachable!(
1151-
"Either is_owner and has_signer are both true,
1152-
or one of them if false - all three cases are covered."
1141+
if !has_signer {
1142+
warn!(%self.chain_id, ?preferred_owner,
1143+
"Chain is one of the owners but its Signer instance doesn't contain the key",
11531144
);
1145+
return Err(ChainClientError::CannotFindKeyForChain(self.chain_id));
11541146
}
1147+
1148+
Ok(preferred_owner)
11551149
}
11561150

11571151
/// Obtains the public key associated to the current identity.

0 commit comments

Comments
 (0)