Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ValidatorPublicKey instead of ValidatorName #3372

Merged
merged 8 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ Show the version and genesis config hash of a new validator, and print a warning

###### **Options:**

* `--name <NAME>` — The public key of the validator. If given, the signature of the chain query info will be checked
* `--public-key <PUBLIC_KEY>` — The public key of the validator. If given, the signature of the chain query info will be checked



Expand Down Expand Up @@ -404,11 +404,11 @@ Synchronizes a validator with the local state of chains

Add or modify a validator (admin only)

**Usage:** `linera set-validator [OPTIONS] --name <NAME> --address <ADDRESS>`
**Usage:** `linera set-validator [OPTIONS] --public-key <PUBLIC_KEY> --address <ADDRESS>`

###### **Options:**

* `--name <NAME>` — The public key of the validator
* `--public-key <PUBLIC_KEY>` — The public key of the validator
* `--address <ADDRESS>` — Network address
* `--votes <VOTES>` — Voting power

Expand All @@ -421,11 +421,11 @@ Add or modify a validator (admin only)

Remove a validator (admin only)

**Usage:** `linera remove-validator --name <NAME>`
**Usage:** `linera remove-validator --public-key <PUBLIC_KEY>`

###### **Options:**

* `--name <NAME>` — The public key of the validator
* `--public-key <PUBLIC_KEY>` — The public key of the validator



Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions linera-base/src/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};

use super::{
le_bytes_to_u64_array, u64_array_to_le_bytes, BcsHashable, BcsSignable, CryptoError,
CryptoHash, HasTypeName, Hashable,
CryptoHash, HasTypeName, Hashable, ValidatorPublicKey, ValidatorSignature,
};
use crate::{doc_scalar, identifiers::Owner};

Expand Down Expand Up @@ -330,7 +330,7 @@ impl Ed25519Signature {
pub fn verify_batch<'a, 'de, T, I>(value: &'a T, votes: I) -> Result<(), CryptoError>
where
T: BcsSignable<'de>,
I: IntoIterator<Item = (&'a Ed25519PublicKey, &'a Ed25519Signature)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside the ed25519 module I wouldn't use the alias.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, found that in the next PR. Will push here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm gonna do that in the follow-up PRs to avoid waiting for the CI again.

I: IntoIterator<Item = (&'a ValidatorPublicKey, &'a ValidatorSignature)>,
{
Ed25519Signature::verify_batch_internal(value, votes).map_err(|error| {
CryptoError::InvalidSignature {
Expand Down
6 changes: 3 additions & 3 deletions linera-chain/src/certificate/confirmed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// SPDX-License-Identifier: Apache-2.0

use linera_base::{
crypto::ValidatorSignature,
crypto::{ValidatorPublicKey, ValidatorSignature},
data_types::Round,
hashed::Hashed,
identifiers::{BlobId, ChainId, MessageId},
};
use linera_execution::committee::{Epoch, ValidatorName};
use linera_execution::committee::Epoch;
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize};

use super::{generic::GenericCertificate, Certificate};
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<'de> Deserialize<'de> for GenericCertificate<ConfirmedBlock> {
struct Helper {
value: Hashed<ConfirmedBlock>,
round: Round,
signatures: Vec<(ValidatorName, ValidatorSignature)>,
signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>,
}

let helper = Helper::deserialize(deserializer)?;
Expand Down
26 changes: 16 additions & 10 deletions linera-chain/src/certificate/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use custom_debug_derive::Debug;
use linera_base::{
crypto::{CryptoHash, ValidatorSignature},
crypto::{CryptoHash, ValidatorPublicKey, ValidatorSignature},
data_types::Round,
hashed::Hashed,
};
use linera_execution::committee::{Committee, ValidatorName};
use linera_execution::committee::Committee;

use super::CertificateValue;
use crate::{data_types::LiteValue, ChainError};
Expand All @@ -18,14 +18,14 @@ use crate::{data_types::LiteValue, ChainError};
pub struct GenericCertificate<T> {
value: Hashed<T>,
pub round: Round,
signatures: Vec<(ValidatorName, ValidatorSignature)>,
signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>,
}

impl<T> GenericCertificate<T> {
pub fn new(
value: Hashed<T>,
round: Round,
mut signatures: Vec<(ValidatorName, ValidatorSignature)>,
mut signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>,
) -> Self {
signatures.sort_by_key(|&(validator_name, _)| validator_name);

Expand Down Expand Up @@ -61,25 +61,31 @@ impl<T> GenericCertificate<T> {
self.value.hash()
}

pub fn destructure(self) -> (Hashed<T>, Round, Vec<(ValidatorName, ValidatorSignature)>) {
pub fn destructure(
self,
) -> (
Hashed<T>,
Round,
Vec<(ValidatorPublicKey, ValidatorSignature)>,
) {
(self.value, self.round, self.signatures)
}

pub fn signatures(&self) -> &Vec<(ValidatorName, ValidatorSignature)> {
pub fn signatures(&self) -> &Vec<(ValidatorPublicKey, ValidatorSignature)> {
&self.signatures
}

#[cfg(with_testing)]
pub fn signatures_mut(&mut self) -> &mut Vec<(ValidatorName, ValidatorSignature)> {
pub fn signatures_mut(&mut self) -> &mut Vec<(ValidatorPublicKey, ValidatorSignature)> {
&mut self.signatures
}

/// Adds a signature to the certificate's list of signatures
/// It's the responsibility of the caller to not insert duplicates
pub fn add_signature(
&mut self,
signature: (ValidatorName, ValidatorSignature),
) -> &Vec<(ValidatorName, ValidatorSignature)> {
signature: (ValidatorPublicKey, ValidatorSignature),
) -> &Vec<(ValidatorPublicKey, ValidatorSignature)> {
let index = self
.signatures
.binary_search_by(|(name, _)| name.cmp(&signature.0))
Expand All @@ -89,7 +95,7 @@ impl<T> GenericCertificate<T> {
}

/// Returns whether the validator is among the signatories of this certificate.
pub fn is_signed_by(&self, validator_name: &ValidatorName) -> bool {
pub fn is_signed_by(&self, validator_name: &ValidatorPublicKey) -> bool {
self.signatures
.binary_search_by(|(name, _)| name.cmp(validator_name))
.is_ok()
Expand Down
18 changes: 11 additions & 7 deletions linera-chain/src/certificate/lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

use std::borrow::Cow;

use linera_base::{crypto::ValidatorSignature, data_types::Round, hashed::Hashed};
use linera_execution::committee::{Committee, ValidatorName};
use linera_base::{
crypto::{ValidatorPublicKey, ValidatorSignature},
data_types::Round,
hashed::Hashed,
};
use linera_execution::committee::Committee;
use serde::{Deserialize, Serialize};

use super::{CertificateValue, GenericCertificate};
Expand All @@ -23,14 +27,14 @@ pub struct LiteCertificate<'a> {
/// The round in which the value was certified.
pub round: Round,
/// Signatures on the value.
pub signatures: Cow<'a, [(ValidatorName, ValidatorSignature)]>,
pub signatures: Cow<'a, [(ValidatorPublicKey, ValidatorSignature)]>,
}

impl<'a> LiteCertificate<'a> {
pub fn new(
value: LiteValue,
round: Round,
mut signatures: Vec<(ValidatorName, ValidatorSignature)>,
mut signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>,
) -> Self {
signatures.sort_by_key(|&(validator_name, _)| validator_name);

Expand All @@ -49,15 +53,15 @@ impl<'a> LiteCertificate<'a> {
let LiteVote {
value,
round,
validator,
public_key,
signature,
} = votes.next()?;
let mut signatures = vec![(validator, signature)];
let mut signatures = vec![(public_key, signature)];
for vote in votes {
if vote.value.value_hash != value.value_hash || vote.round != round {
return None;
}
signatures.push((vote.validator, vote.signature));
signatures.push((vote.public_key, vote.signature));
}
Some(LiteCertificate::new(value, round, signatures))
}
Expand Down
6 changes: 3 additions & 3 deletions linera-chain/src/certificate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use std::collections::BTreeSet;

pub use generic::GenericCertificate;
use linera_base::{
crypto::ValidatorSignature,
crypto::{ValidatorPublicKey, ValidatorSignature},
data_types::{BlockHeight, Round},
identifiers::{BlobId, ChainId},
};
use linera_execution::committee::{Epoch, ValidatorName};
use linera_execution::committee::Epoch;
pub use lite::LiteCertificate;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -76,7 +76,7 @@ impl Certificate {
}
}

pub fn signatures(&self) -> &Vec<(ValidatorName, ValidatorSignature)> {
pub fn signatures(&self) -> &Vec<(ValidatorPublicKey, ValidatorSignature)> {
match self {
Certificate::Validated(cert) => cert.signatures(),
Certificate::Confirmed(cert) => cert.signatures(),
Expand Down
9 changes: 6 additions & 3 deletions linera-chain/src/certificate/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use linera_base::{crypto::ValidatorSignature, data_types::Round, hashed::Hashed};
use linera_execution::committee::ValidatorName;
use linera_base::{
crypto::{ValidatorPublicKey, ValidatorSignature},
data_types::Round,
hashed::Hashed,
};
use serde::{
ser::{Serialize, SerializeStruct, Serializer},
Deserialize, Deserializer,
Expand Down Expand Up @@ -49,7 +52,7 @@ impl<'de> Deserialize<'de> for GenericCertificate<Timeout> {
struct Inner {
value: Hashed<Timeout>,
round: Round,
signatures: Vec<(ValidatorName, ValidatorSignature)>,
signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>,
}
let inner = Inner::deserialize(deserializer)?;
if !crate::data_types::is_strictly_ordered(&inner.signatures) {
Expand Down
8 changes: 5 additions & 3 deletions linera-chain/src/certificate/validated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// SPDX-License-Identifier: Apache-2.0

use linera_base::{
crypto::ValidatorSignature, data_types::Round, hashed::Hashed, identifiers::BlobId,
crypto::{ValidatorPublicKey, ValidatorSignature},
data_types::Round,
hashed::Hashed,
identifiers::BlobId,
};
use linera_execution::committee::ValidatorName;
use serde::{
ser::{Serialize, SerializeStruct, Serializer},
Deserialize, Deserializer,
Expand Down Expand Up @@ -67,7 +69,7 @@ impl<'de> Deserialize<'de> for GenericCertificate<ValidatedBlock> {
struct Inner {
value: Hashed<ValidatedBlock>,
round: Round,
signatures: Vec<(ValidatorName, ValidatorSignature)>,
signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>,
}
let inner = Inner::deserialize(deserializer)?;
if !crate::data_types::is_strictly_ordered(&inner.signatures) {
Expand Down
8 changes: 4 additions & 4 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use async_graphql::SimpleObject;
use futures::stream::{self, StreamExt, TryStreamExt};
use linera_base::{
crypto::CryptoHash,
crypto::{CryptoHash, ValidatorPublicKey},
data_types::{
Amount, ArithmeticError, BlockHeight, OracleResponse, Timestamp, UserApplicationDescription,
},
Expand All @@ -23,7 +23,7 @@ use linera_base::{
ownership::ChainOwnership,
};
use linera_execution::{
committee::{Committee, Epoch, ValidatorName},
committee::{Committee, Epoch},
system::OpenChainConfig,
ExecutionOutcome, ExecutionRuntimeContext, ExecutionStateView, Message, MessageContext,
Operation, OperationContext, Query, QueryContext, QueryOutcome, RawExecutionOutcome,
Expand Down Expand Up @@ -212,7 +212,7 @@ where
/// Sender chain and height of all certified blocks known as a receiver (local ordering).
pub received_log: LogView<C, ChainAndHeight>,
/// The number of `received_log` entries we have synchronized, for each validator.
pub received_certificate_trackers: RegisterView<C, HashMap<ValidatorName, u64>>,
pub received_certificate_trackers: RegisterView<C, HashMap<ValidatorPublicKey, u64>>,

/// Mailboxes used to receive messages indexed by their origin.
pub inboxes: ReentrantCollectionView<C, Origin, InboxStateView<C>>,
Expand Down Expand Up @@ -549,7 +549,7 @@ where
/// Updates the `received_log` trackers.
pub fn update_received_certificate_trackers(
&mut self,
new_trackers: BTreeMap<ValidatorName, u64>,
new_trackers: BTreeMap<ValidatorPublicKey, u64>,
) {
for (name, tracker) in new_trackers {
self.received_certificate_trackers
Expand Down
Loading