diff --git a/Cargo.lock b/Cargo.lock index ab76e42a57e7..1b30dfe45877 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4641,7 +4641,6 @@ dependencies = [ "anyhow", "linera-base", "linera-client", - "linera-execution", "linera-faucet", "linera-version", "reqwest 0.11.27", @@ -4661,7 +4660,6 @@ dependencies = [ "linera-base", "linera-client", "linera-core", - "linera-execution", "linera-storage", "linera-version", "linera-views", diff --git a/linera-base/src/crypto/ed25519.rs b/linera-base/src/crypto/ed25519.rs index de2573cae843..303a89b731f0 100644 --- a/linera-base/src/crypto/ed25519.rs +++ b/linera-base/src/crypto/ed25519.rs @@ -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}; @@ -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, + I: IntoIterator, { Ed25519Signature::verify_batch_internal(value, votes).map_err(|error| { CryptoError::InvalidSignature { diff --git a/linera-chain/src/certificate/confirmed.rs b/linera-chain/src/certificate/confirmed.rs index 682c0b09e7da..a38c91a0fb5d 100644 --- a/linera-chain/src/certificate/confirmed.rs +++ b/linera-chain/src/certificate/confirmed.rs @@ -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}; @@ -92,7 +92,7 @@ impl<'de> Deserialize<'de> for GenericCertificate { struct Helper { value: Hashed, round: Round, - signatures: Vec<(ValidatorName, ValidatorSignature)>, + signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>, } let helper = Helper::deserialize(deserializer)?; diff --git a/linera-chain/src/certificate/generic.rs b/linera-chain/src/certificate/generic.rs index 5c16354a13e8..9ccb99c18b8d 100644 --- a/linera-chain/src/certificate/generic.rs +++ b/linera-chain/src/certificate/generic.rs @@ -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}; @@ -18,14 +18,14 @@ use crate::{data_types::LiteValue, ChainError}; pub struct GenericCertificate { value: Hashed, pub round: Round, - signatures: Vec<(ValidatorName, ValidatorSignature)>, + signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>, } impl GenericCertificate { pub fn new( value: Hashed, round: Round, - mut signatures: Vec<(ValidatorName, ValidatorSignature)>, + mut signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>, ) -> Self { signatures.sort_by_key(|&(validator_name, _)| validator_name); @@ -61,16 +61,22 @@ impl GenericCertificate { self.value.hash() } - pub fn destructure(self) -> (Hashed, Round, Vec<(ValidatorName, ValidatorSignature)>) { + pub fn destructure( + self, + ) -> ( + Hashed, + 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 } @@ -78,8 +84,8 @@ impl GenericCertificate { /// 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)) @@ -89,7 +95,7 @@ impl GenericCertificate { } /// 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() diff --git a/linera-chain/src/certificate/lite.rs b/linera-chain/src/certificate/lite.rs index 4db7d388c3e9..0a4737ea305d 100644 --- a/linera-chain/src/certificate/lite.rs +++ b/linera-chain/src/certificate/lite.rs @@ -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}; @@ -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); diff --git a/linera-chain/src/certificate/mod.rs b/linera-chain/src/certificate/mod.rs index 73e4ff71b9d0..3d57c7ef3e6b 100644 --- a/linera-chain/src/certificate/mod.rs +++ b/linera-chain/src/certificate/mod.rs @@ -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}; @@ -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(), diff --git a/linera-chain/src/certificate/timeout.rs b/linera-chain/src/certificate/timeout.rs index 0df04880e5cf..b3aca6b02aea 100644 --- a/linera-chain/src/certificate/timeout.rs +++ b/linera-chain/src/certificate/timeout.rs @@ -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, @@ -49,7 +52,7 @@ impl<'de> Deserialize<'de> for GenericCertificate { struct Inner { value: Hashed, round: Round, - signatures: Vec<(ValidatorName, ValidatorSignature)>, + signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>, } let inner = Inner::deserialize(deserializer)?; if !crate::data_types::is_strictly_ordered(&inner.signatures) { diff --git a/linera-chain/src/certificate/validated.rs b/linera-chain/src/certificate/validated.rs index 9e10d60bc421..f0b7c44582b0 100644 --- a/linera-chain/src/certificate/validated.rs +++ b/linera-chain/src/certificate/validated.rs @@ -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, @@ -67,7 +69,7 @@ impl<'de> Deserialize<'de> for GenericCertificate { struct Inner { value: Hashed, round: Round, - signatures: Vec<(ValidatorName, ValidatorSignature)>, + signatures: Vec<(ValidatorPublicKey, ValidatorSignature)>, } let inner = Inner::deserialize(deserializer)?; if !crate::data_types::is_strictly_ordered(&inner.signatures) { diff --git a/linera-chain/src/chain.rs b/linera-chain/src/chain.rs index 840d3c59d04d..05a3a608d998 100644 --- a/linera-chain/src/chain.rs +++ b/linera-chain/src/chain.rs @@ -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, }, @@ -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, @@ -212,7 +212,7 @@ where /// Sender chain and height of all certified blocks known as a receiver (local ordering). pub received_log: LogView, /// The number of `received_log` entries we have synchronized, for each validator. - pub received_certificate_trackers: RegisterView>, + pub received_certificate_trackers: RegisterView>, /// Mailboxes used to receive messages indexed by their origin. pub inboxes: ReentrantCollectionView>, @@ -549,7 +549,7 @@ where /// Updates the `received_log` trackers. pub fn update_received_certificate_trackers( &mut self, - new_trackers: BTreeMap, + new_trackers: BTreeMap, ) { for (name, tracker) in new_trackers { self.received_certificate_trackers diff --git a/linera-chain/src/data_types.rs b/linera-chain/src/data_types.rs index 19a2aa3b1adf..79572238cb72 100644 --- a/linera-chain/src/data_types.rs +++ b/linera-chain/src/data_types.rs @@ -13,7 +13,7 @@ use linera_base::{ bcs, crypto::{ AccountPublicKey, AccountSecretKey, AccountSignature, BcsHashable, BcsSignable, - CryptoError, CryptoHash, ValidatorSecretKey, ValidatorSignature, + CryptoError, CryptoHash, ValidatorPublicKey, ValidatorSecretKey, ValidatorSignature, }, data_types::{Amount, BlockHeight, Event, OracleResponse, Round, Timestamp}, doc_scalar, ensure, @@ -23,7 +23,7 @@ use linera_base::{ }, }; use linera_execution::{ - committee::{Committee, Epoch, ValidatorName}, + committee::{Committee, Epoch}, system::OpenChainConfig, Message, MessageKind, Operation, SystemMessage, SystemOperation, }; @@ -424,7 +424,7 @@ struct VoteValue(CryptoHash, Round, CertificateKind); pub struct Vote { pub value: Hashed, pub round: Round, - pub validator: ValidatorName, + pub validator: ValidatorPublicKey, pub signature: ValidatorSignature, } @@ -439,7 +439,7 @@ impl Vote { Self { value, round, - validator: ValidatorName(key_pair.public()), + validator: key_pair.public(), signature, } } @@ -469,7 +469,7 @@ impl Vote { pub struct LiteVote { pub value: LiteValue, pub round: Round, - pub validator: ValidatorName, + pub validator: ValidatorPublicKey, pub signature: ValidatorSignature, } @@ -816,7 +816,7 @@ impl LiteVote { Self { value, round, - validator: ValidatorName(key_pair.public()), + validator: key_pair.public(), signature, } } @@ -824,14 +824,14 @@ impl LiteVote { /// Verifies the signature in the vote. pub fn check(&self) -> Result<(), ChainError> { let hash_and_round = VoteValue(self.value.value_hash, self.round, self.value.kind); - Ok(self.signature.check(&hash_and_round, self.validator.0)?) + Ok(self.signature.check(&hash_and_round, self.validator)?) } } pub struct SignatureAggregator<'a, T> { committee: &'a Committee, weight: u64, - used_validators: HashSet, + used_validators: HashSet, partial: GenericCertificate, } @@ -851,14 +851,14 @@ impl<'a, T> SignatureAggregator<'a, T> { /// of `check` below. Returns an error if the signed value cannot be aggregated. pub fn append( &mut self, - validator: ValidatorName, + validator: ValidatorPublicKey, signature: ValidatorSignature, ) -> Result>, ChainError> where T: CertificateValue, { let hash_and_round = VoteValue(self.partial.hash(), self.partial.round, T::KIND); - signature.check(&hash_and_round, validator.0)?; + signature.check(&hash_and_round, validator)?; // Check that each validator only appears once. ensure!( !self.used_validators.contains(&validator), @@ -883,7 +883,7 @@ impl<'a, T> SignatureAggregator<'a, T> { // Checks if the array slice is strictly ordered. That means that if the array // has duplicates, this will return False, even if the array is sorted -pub(crate) fn is_strictly_ordered(values: &[(ValidatorName, ValidatorSignature)]) -> bool { +pub(crate) fn is_strictly_ordered(values: &[(ValidatorPublicKey, ValidatorSignature)]) -> bool { values.windows(2).all(|pair| pair[0].0 < pair[1].0) } @@ -892,7 +892,7 @@ pub(crate) fn check_signatures( value_hash: CryptoHash, certificate_kind: CertificateKind, round: Round, - signatures: &[(ValidatorName, ValidatorSignature)], + signatures: &[(ValidatorPublicKey, ValidatorSignature)], committee: &Committee, ) -> Result<(), ChainError> { // Check the quorum. @@ -916,7 +916,7 @@ pub(crate) fn check_signatures( ); // All that is left is checking signatures! let hash_and_round = VoteValue(value_hash, round, certificate_kind); - ValidatorSignature::verify_batch(&hash_and_round, signatures.iter().map(|(v, s)| (&v.0, s)))?; + ValidatorSignature::verify_batch(&hash_and_round, signatures.iter().map(|(v, s)| (v, s)))?; Ok(()) } diff --git a/linera-chain/src/unit_tests/chain_tests.rs b/linera-chain/src/unit_tests/chain_tests.rs index cb350f4d3874..2a9b68c075cb 100644 --- a/linera-chain/src/unit_tests/chain_tests.rs +++ b/linera-chain/src/unit_tests/chain_tests.rs @@ -17,7 +17,7 @@ use linera_base::{ ownership::ChainOwnership, }; use linera_execution::{ - committee::{Committee, Epoch, ValidatorName, ValidatorState}, + committee::{Committee, Epoch, ValidatorState}, system::{OpenChainConfig, Recipient}, test_utils::{ExpectedCall, MockApplication}, ExecutionError, ExecutionRuntimeConfig, ExecutionRuntimeContext, Message, MessageKind, @@ -93,7 +93,7 @@ fn make_admin_message_id(height: BlockHeight) -> MessageId { } fn make_open_chain_config() -> OpenChainConfig { - let committee = Committee::make_simple(vec![ValidatorPublicKey::test_key(1).into()]); + let committee = Committee::make_simple(vec![ValidatorPublicKey::test_key(1)]); OpenChainConfig { ownership: ChainOwnership::single(AccountPublicKey::test_key(0).into()), admin_id: admin_id(), @@ -120,7 +120,7 @@ async fn test_block_size_limit() { Epoch(0), Committee::new( BTreeMap::from([( - ValidatorName(ValidatorPublicKey::test_key(1)), + ValidatorPublicKey::test_key(1), ValidatorState { network_address: ValidatorPublicKey::test_key(1).to_string(), votes: 1, diff --git a/linera-chain/src/unit_tests/data_types_tests.rs b/linera-chain/src/unit_tests/data_types_tests.rs index ad0433d41f0b..cd2cae51ba0e 100644 --- a/linera-chain/src/unit_tests/data_types_tests.rs +++ b/linera-chain/src/unit_tests/data_types_tests.rs @@ -14,7 +14,7 @@ use crate::{ fn test_signed_values() { let key1 = ValidatorSecretKey::generate(); let key2 = ValidatorSecretKey::generate(); - let name1 = ValidatorName(key1.public()); + let validator_1 = key1.public(); let block = make_first_block(ChainId::root(1)).with_simple_transfer(ChainId::root(2), Amount::ONE); @@ -38,7 +38,7 @@ fn test_signed_values() { ); let mut v = LiteVote::new(LiteValue::new(&confirmed_value), Round::Fast, &key2); - v.validator = name1; + v.validator = validator_1; assert!(v.check().is_err()); assert!(validated_vote.check().is_ok()); @@ -84,10 +84,10 @@ fn test_certificates() { let key1 = ValidatorSecretKey::generate(); let key2 = ValidatorSecretKey::generate(); let key3 = ValidatorSecretKey::generate(); - let name1 = ValidatorName(key1.public()); - let name2 = ValidatorName(key2.public()); + let validator1_pk = key1.public(); + let validator2_pk = key2.public(); - let committee = Committee::make_simple(vec![name1, name2]); + let committee = Committee::make_simple(vec![validator1_pk, validator2_pk]); let block = make_first_block(ChainId::root(1)).with_simple_transfer(ChainId::root(1), Amount::ONE); diff --git a/linera-client/src/client_options.rs b/linera-client/src/client_options.rs index 4ad4980bb42f..ceff929297da 100644 --- a/linera-client/src/client_options.rs +++ b/linera-client/src/client_options.rs @@ -10,7 +10,7 @@ use std::{ use chrono::{DateTime, Utc}; use linera_base::{ - crypto::CryptoHash, + crypto::{CryptoHash, ValidatorPublicKey}, data_types::{Amount, ApplicationPermissions, TimeDelta}, identifiers::{ Account, ApplicationId, BytecodeId, ChainId, MessageId, Owner, UserApplicationId, @@ -19,9 +19,7 @@ use linera_base::{ time::Duration, }; use linera_core::{client::BlanketMessagePolicy, DEFAULT_GRACE_PERIOD}; -use linera_execution::{ - committee::ValidatorName, ResourceControlPolicy, WasmRuntime, WithWasmDefault as _, -}; +use linera_execution::{ResourceControlPolicy, WasmRuntime, WithWasmDefault as _}; use linera_views::store::CommonStoreConfig; #[cfg(feature = "fs")] @@ -453,7 +451,7 @@ pub enum ClientCommand { /// The public key of the validator. If given, the signature of the chain query /// info will be checked. #[arg(long)] - name: Option, + name: Option, }, /// Show the current set of validators for a chain. Also print some information about @@ -477,7 +475,7 @@ pub enum ClientCommand { SetValidator { /// The public key of the validator. #[arg(long)] - name: ValidatorName, + name: ValidatorPublicKey, /// Network address #[arg(long)] @@ -496,7 +494,7 @@ pub enum ClientCommand { RemoveValidator { /// The public key of the validator. #[arg(long)] - name: ValidatorName, + name: ValidatorPublicKey, }, /// Deprecates all committees except the last one. diff --git a/linera-client/src/config.rs b/linera-client/src/config.rs index 843cdd32d5e7..197f17ac94bd 100644 --- a/linera-client/src/config.rs +++ b/linera-client/src/config.rs @@ -9,13 +9,14 @@ use std::{ use linera_base::{ crypto::{ - AccountPublicKey, AccountSecretKey, BcsSignable, CryptoHash, CryptoRng, ValidatorSecretKey, + AccountPublicKey, AccountSecretKey, BcsSignable, CryptoHash, CryptoRng, ValidatorPublicKey, + ValidatorSecretKey, }, data_types::{Amount, Timestamp}, identifiers::{ChainDescription, ChainId}, }; use linera_execution::{ - committee::{Committee, ValidatorName, ValidatorState}, + committee::{Committee, ValidatorState}, ResourceControlPolicy, }; use linera_rpc::config::{ValidatorInternalNetworkConfig, ValidatorPublicNetworkConfig}; @@ -47,7 +48,7 @@ util::impl_from_dynamic!(Error:Persistence, persistent::file::Error); #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ValidatorConfig { /// The public key of the validator. - pub name: ValidatorName, + pub name: ValidatorPublicKey, /// The network configuration for the validator. pub network: ValidatorPublicNetworkConfig, } diff --git a/linera-core/src/chain_worker/actor.rs b/linera-core/src/chain_worker/actor.rs index 6fdd68119a57..eda7933d0a18 100644 --- a/linera-core/src/chain_worker/actor.rs +++ b/linera-core/src/chain_worker/actor.rs @@ -11,7 +11,7 @@ use std::{ use custom_debug_derive::Debug; use linera_base::{ - crypto::CryptoHash, + crypto::{CryptoHash, ValidatorPublicKey}, data_types::{Blob, BlockHeight, Timestamp, UserApplicationDescription}, hashed::Hashed, identifiers::{BlobId, ChainId, UserApplicationId}, @@ -22,8 +22,7 @@ use linera_chain::{ ChainStateView, }; use linera_execution::{ - committee::{Epoch, ValidatorName}, - Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, ServiceSyncRuntime, + committee::Epoch, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, ServiceSyncRuntime, }; use linera_storage::Storage; use tokio::sync::{mpsc, oneshot, OwnedRwLockReadGuard}; @@ -158,7 +157,7 @@ where /// Update the received certificate trackers to at least the given values. UpdateReceivedCertificateTrackers { - new_trackers: BTreeMap, + new_trackers: BTreeMap, callback: oneshot::Sender>, }, } diff --git a/linera-core/src/chain_worker/state/attempted_changes.rs b/linera-core/src/chain_worker/state/attempted_changes.rs index 02d4ece359c5..4a5e4b3e8e37 100644 --- a/linera-core/src/chain_worker/state/attempted_changes.rs +++ b/linera-core/src/chain_worker/state/attempted_changes.rs @@ -7,6 +7,7 @@ use std::{borrow::Cow, collections::BTreeMap}; use futures::future::Either; use linera_base::{ + crypto::ValidatorPublicKey, data_types::{Blob, BlockHeight, Timestamp}, ensure, identifiers::{ChainId, Owner}, @@ -20,7 +21,7 @@ use linera_chain::{ types::{ConfirmedBlockCertificate, TimeoutCertificate, ValidatedBlockCertificate}, ChainExecutionContext, ChainStateView, ExecutionResultExt as _, }; -use linera_execution::committee::{Committee, Epoch, ValidatorName}; +use linera_execution::committee::{Committee, Epoch}; use linera_storage::{Clock as _, Storage}; use linera_views::{ context::Context, @@ -540,7 +541,7 @@ where pub async fn update_received_certificate_trackers( &mut self, - new_trackers: BTreeMap, + new_trackers: BTreeMap, ) -> Result<(), WorkerError> { self.state .chain diff --git a/linera-core/src/chain_worker/state/mod.rs b/linera-core/src/chain_worker/state/mod.rs index d1b94a5d4879..e3c0716a044a 100644 --- a/linera-core/src/chain_worker/state/mod.rs +++ b/linera-core/src/chain_worker/state/mod.rs @@ -13,7 +13,7 @@ use std::{ }; use linera_base::{ - crypto::CryptoHash, + crypto::{CryptoHash, ValidatorPublicKey}, data_types::{Blob, BlockHeight, UserApplicationDescription}, ensure, hashed::Hashed, @@ -27,8 +27,8 @@ use linera_chain::{ ChainError, ChainStateView, }; use linera_execution::{ - committee::{Epoch, ValidatorName}, - Message, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, SystemMessage, + committee::Epoch, Message, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, + SystemMessage, }; use linera_storage::{Clock as _, Storage}; use linera_views::views::{ClonableView, ViewError}; @@ -553,7 +553,7 @@ where /// Updates the received certificate trackers to at least the given values. pub async fn update_received_certificate_trackers( &mut self, - new_trackers: BTreeMap, + new_trackers: BTreeMap, ) -> Result<(), WorkerError> { ChainWorkerStateWithAttemptedChanges::new(self) .await diff --git a/linera-core/src/client/mod.rs b/linera-core/src/client/mod.rs index c0bcbfc83d1c..08566f43cbe2 100644 --- a/linera-core/src/client/mod.rs +++ b/linera-core/src/client/mod.rs @@ -53,7 +53,7 @@ use linera_chain::{ ChainError, ChainExecutionContext, ChainStateView, ExecutionResultExt as _, }; use linera_execution::{ - committee::{Committee, Epoch, ValidatorName}, + committee::{Committee, Epoch}, system::{ AdminOperation, OpenChainConfig, Recipient, SystemChannel, SystemOperation, CREATE_APPLICATION_MESSAGE_INDEX, OPEN_CHAIN_MESSAGE_INDEX, @@ -3330,7 +3330,7 @@ where #[instrument(level = "trace", skip(senders))] async fn update_streams( &self, - senders: &mut HashMap, + senders: &mut HashMap, ) -> Result, ChainClientError> { let (chain_id, nodes, local_node) = { let committee = self.local_committee().await?; @@ -3342,8 +3342,8 @@ where (self.chain_id, nodes, self.client.local_node.clone()) }; // Drop removed validators. - senders.retain(|name, abort| { - if !nodes.contains_key(name) { + senders.retain(|validator, abort| { + if !nodes.contains_key(validator) { abort.abort(); } !abort.is_aborted() @@ -3502,7 +3502,7 @@ impl Drop for AbortOnDrop { /// The result of `synchronize_received_certificates_from_validator`. struct ReceivedCertificatesFromValidator { /// The name of the validator we downloaded from. - name: ValidatorName, + name: ValidatorPublicKey, /// The new tracker value for that validator. tracker: u64, /// The downloaded certificates. The signatures were already checked and they are ready diff --git a/linera-core/src/data_types.rs b/linera-core/src/data_types.rs index f0dff792efba..c95641fcc87a 100644 --- a/linera-core/src/data_types.rs +++ b/linera-core/src/data_types.rs @@ -6,7 +6,10 @@ use std::{collections::BTreeMap, ops::Not}; use custom_debug_derive::Debug; use linera_base::{ - crypto::{BcsSignable, CryptoError, CryptoHash, ValidatorSecretKey, ValidatorSignature}, + crypto::{ + BcsSignable, CryptoError, CryptoHash, ValidatorPublicKey, ValidatorSecretKey, + ValidatorSignature, + }, data_types::{Amount, BlockHeight, Round, Timestamp}, identifiers::{AccountOwner, ChainDescription, ChainId}, }; @@ -16,7 +19,7 @@ use linera_chain::{ ChainStateView, }; use linera_execution::{ - committee::{Committee, Epoch, ValidatorName}, + committee::{Committee, Epoch}, ExecutionRuntimeContext, }; use linera_storage::ChainRuntimeContext; @@ -304,8 +307,8 @@ impl ChainInfoResponse { self.signature = Some(ValidatorSignature::new(&*self.info, key_pair)); } - pub fn check(&self, name: &ValidatorName) -> Result<(), CryptoError> { - ValidatorSignature::check_optional_signature(self.signature.as_ref(), &*self.info, &name.0) + pub fn check(&self, name: &ValidatorPublicKey) -> Result<(), CryptoError> { + ValidatorSignature::check_optional_signature(self.signature.as_ref(), &*self.info, &name) } /// Returns the committee in the latest epoch. diff --git a/linera-core/src/local_node.rs b/linera-core/src/local_node.rs index 136d56b5174a..2c4ebb29e888 100644 --- a/linera-core/src/local_node.rs +++ b/linera-core/src/local_node.rs @@ -9,6 +9,7 @@ use std::{ use futures::{future::Either, stream, StreamExt as _, TryStreamExt as _}; use linera_base::{ + crypto::ValidatorPublicKey, data_types::{ArithmeticError, Blob, BlockHeight, UserApplicationDescription}, identifiers::{BlobId, ChainId, MessageId, UserApplicationId}, }; @@ -17,7 +18,7 @@ use linera_chain::{ types::{ConfirmedBlockCertificate, GenericCertificate, LiteCertificate}, ChainStateView, }; -use linera_execution::{committee::ValidatorName, Query, QueryOutcome}; +use linera_execution::{Query, QueryOutcome}; use linera_storage::Storage; use linera_views::views::ViewError; use thiserror::Error; @@ -354,7 +355,7 @@ where pub async fn update_received_certificate_trackers( &self, chain_id: ChainId, - new_trackers: BTreeMap, + new_trackers: BTreeMap, ) -> Result<(), LocalNodeError> { self.node .state diff --git a/linera-core/src/node.rs b/linera-core/src/node.rs index aad0b2811c01..13053d47547e 100644 --- a/linera-core/src/node.rs +++ b/linera-core/src/node.rs @@ -8,7 +8,7 @@ use futures::stream::BoxStream; use futures::stream::LocalBoxStream as BoxStream; use futures::stream::Stream; use linera_base::{ - crypto::{CryptoError, CryptoHash}, + crypto::{CryptoError, CryptoHash, ValidatorPublicKey}, data_types::{ArithmeticError, BlobContent, BlockHeight}, identifiers::{BlobId, ChainId}, }; @@ -20,10 +20,7 @@ use linera_chain::{ }, ChainError, }; -use linera_execution::{ - committee::{Committee, ValidatorName}, - ExecutionError, -}; +use linera_execution::{committee::Committee, ExecutionError}; use linera_version::VersionInfo; use linera_views::views::ViewError; use serde::{Deserialize, Serialize}; @@ -153,7 +150,7 @@ pub trait ValidatorNodeProvider: 'static { fn make_nodes( &self, committee: &Committee, - ) -> Result + '_, NodeError> { + ) -> Result + '_, NodeError> { let validator_addresses: Vec<_> = committee .validator_addresses() .map(|(node, name)| (node, name.to_owned())) @@ -163,8 +160,8 @@ pub trait ValidatorNodeProvider: 'static { fn make_nodes_from_list( &self, - validators: impl IntoIterator, - ) -> Result, NodeError> + validators: impl IntoIterator, + ) -> Result, NodeError> where A: AsRef, { diff --git a/linera-core/src/remote_node.rs b/linera-core/src/remote_node.rs index dddb7fb732cd..4065464b5489 100644 --- a/linera-core/src/remote_node.rs +++ b/linera-core/src/remote_node.rs @@ -6,7 +6,7 @@ use std::{collections::HashSet, time::Duration}; use custom_debug_derive::Debug; use futures::{future::try_join_all, stream::FuturesUnordered, StreamExt}; use linera_base::{ - crypto::CryptoHash, + crypto::{CryptoHash, ValidatorPublicKey}, data_types::{Blob, BlockHeight}, ensure, identifiers::{BlobId, ChainId}, @@ -18,7 +18,6 @@ use linera_chain::{ TimeoutCertificate, ValidatedBlockCertificate, }, }; -use linera_execution::committee::ValidatorName; use rand::seq::SliceRandom as _; use tracing::{instrument, warn}; @@ -30,7 +29,7 @@ use crate::{ /// A validator node together with the validator's name. #[derive(Clone, Debug)] pub struct RemoteNode { - pub name: ValidatorName, + pub name: ValidatorPublicKey, #[debug(skip)] pub node: N, } diff --git a/linera-core/src/unit_tests/test_utils.rs b/linera-core/src/unit_tests/test_utils.rs index 466ef5946c3c..e0f1f33da260 100644 --- a/linera-core/src/unit_tests/test_utils.rs +++ b/linera-core/src/unit_tests/test_utils.rs @@ -16,7 +16,9 @@ use futures::{ Future, }; use linera_base::{ - crypto::{AccountPublicKey, AccountSecretKey, CryptoHash, ValidatorSecretKey}, + crypto::{ + AccountPublicKey, AccountSecretKey, CryptoHash, ValidatorPublicKey, ValidatorSecretKey, + }, data_types::*, identifiers::{BlobId, ChainDescription, ChainId}, }; @@ -27,10 +29,7 @@ use linera_chain::{ LiteCertificate, Timeout, ValidatedBlock, }, }; -use linera_execution::{ - committee::{Committee, ValidatorName}, - ResourceControlPolicy, WasmRuntime, -}; +use linera_execution::{committee::Committee, ResourceControlPolicy, WasmRuntime}; use linera_storage::{DbStorage, Storage, TestClock}; #[cfg(all(not(target_arch = "wasm32"), feature = "storage-service"))] use linera_storage_service::client::ServiceStoreClient; @@ -93,7 +92,7 @@ pub struct LocalValidatorClient where S: Storage, { - name: ValidatorName, + validator_pk: ValidatorPublicKey, client: Arc>>, } @@ -251,20 +250,20 @@ impl LocalValidatorClient where S: Storage + Clone + Send + Sync + 'static, { - fn new(name: ValidatorName, state: WorkerState) -> Self { + fn new(name: ValidatorPublicKey, state: WorkerState) -> Self { let client = LocalValidator { fault_type: FaultType::Honest, state, notifier: Arc::new(ChannelNotifier::default()), }; Self { - name, + validator_pk: name, client: Arc::new(Mutex::new(client)), } } - pub fn name(&self) -> ValidatorName { - self.name + pub fn name(&self) -> ValidatorPublicKey { + self.validator_pk } async fn set_fault_type(&self, fault_type: FaultType) { @@ -600,7 +599,7 @@ where } #[derive(Clone)] -pub struct NodeProvider(BTreeMap>>>) +pub struct NodeProvider(BTreeMap>>>) where S: Storage; @@ -616,21 +615,29 @@ where fn make_nodes_from_list( &self, - validators: impl IntoIterator, - ) -> Result, NodeError> + validators: impl IntoIterator, + ) -> Result, NodeError> where A: AsRef, { Ok(validators .into_iter() - .map(|(name, address)| { + .map(|(public_key, address)| { self.0 - .get(&name) + .get(&public_key) .ok_or_else(|| NodeError::CannotResolveValidatorAddress { address: address.as_ref().to_string(), }) .cloned() - .map(|client| (name, LocalValidatorClient { name, client })) + .map(|client| { + ( + public_key, + LocalValidatorClient { + validator_pk: public_key, + client, + }, + ) + }) }) .collect::, _>>()? .into_iter()) @@ -645,7 +652,8 @@ where where T: IntoIterator>, { - let destructure = |validator: LocalValidatorClient| (validator.name, validator.client); + let destructure = + |validator: LocalValidatorClient| (validator.validator_pk, validator.client); Self(iter.into_iter().map(destructure).collect()) } } @@ -662,7 +670,7 @@ pub struct TestBuilder { admin_id: ChainId, genesis_storage_builder: GenesisStorageBuilder, validator_clients: Vec>, - validator_storages: HashMap, + validator_storages: HashMap, chain_client_storages: Vec, } @@ -734,7 +742,7 @@ where let mut validators = Vec::new(); for _ in 0..count { let key_pair = ValidatorSecretKey::generate(); - let name = ValidatorName(key_pair.public()); + let name = key_pair.public(); validators.push(name); key_pairs.push(key_pair); } @@ -743,7 +751,7 @@ where let mut validator_storages = HashMap::new(); let mut faulty_validators = HashSet::new(); for (i, key_pair) in key_pairs.into_iter().enumerate() { - let name = ValidatorName(key_pair.public()); + let name = key_pair.public(); let storage = storage_builder.build().await?; let state = WorkerState::new( format!("Node {}", i), @@ -787,7 +795,7 @@ where for index in indexes.as_ref() { let validator = &mut self.validator_clients[*index]; validator.set_fault_type(fault_type).await; - faulty_validators.push(validator.name); + faulty_validators.push(validator.validator_pk); } tracing::info!( "Making the following validators {:?}: {:?}", @@ -809,7 +817,10 @@ where self.genesis_storage_builder .add(description, public_key, balance); for validator in &self.validator_clients { - let storage = self.validator_storages.get_mut(&validator.name).unwrap(); + let storage = self + .validator_storages + .get_mut(&validator.validator_pk) + .unwrap(); if validator.fault_type().await == FaultType::Malicious { storage .create_chain( @@ -939,7 +950,7 @@ where let mut certificate = None; for validator in self.validator_clients.clone() { if let Ok(response) = validator.handle_chain_info_query(query.clone()).await { - if response.check(&validator.name).is_ok() { + if response.check(&validator.validator_pk).is_ok() { let ChainInfo { mut requested_sent_certificate_hashes, .. @@ -978,7 +989,7 @@ where if let Ok(response) = validator.handle_chain_info_query(query.clone()).await { if response.info.manager.current_round == round && response.info.next_block_height == block_height - && response.check(&validator.name).is_ok() + && response.check(&validator.validator_pk).is_ok() { count += 1; } diff --git a/linera-core/src/unit_tests/worker_tests.rs b/linera-core/src/unit_tests/worker_tests.rs index 0addda75b8e7..3df42105ce4d 100644 --- a/linera-core/src/unit_tests/worker_tests.rs +++ b/linera-core/src/unit_tests/worker_tests.rs @@ -41,7 +41,7 @@ use linera_chain::{ ChainError, ChainExecutionContext, }; use linera_execution::{ - committee::{Committee, Epoch, ValidatorName}, + committee::{Committee, Epoch}, system::{ AdminOperation, OpenChainConfig, Recipient, SystemChannel, SystemMessage, SystemOperation, }, @@ -90,7 +90,7 @@ where S: Storage + Clone + Send + Sync + 'static, { let key_pair = ValidatorSecretKey::generate(); - let committee = Committee::make_simple(vec![ValidatorName(key_pair.public())]); + let committee = Committee::make_simple(vec![key_pair.public()]); let worker = WorkerState::new( "Single validator node".to_string(), Some(key_pair), @@ -1186,7 +1186,7 @@ where .into_first_proposal(&sender_key_pair); let (chain_info_response, _actions) = worker.handle_block_proposal(block_proposal).await?; - chain_info_response.check(&ValidatorName(worker.public_key()))?; + chain_info_response.check(&worker.public_key())?; let chain = worker.chain_state_view(ChainId::root(1)).await?; assert!(chain.is_active()); assert!(chain.manager.confirmed_vote().is_none()); // It was a multi-leader @@ -1201,7 +1201,7 @@ where let (chain_info_response, _actions) = worker .handle_validated_certificate(validated_certificate) .await?; - chain_info_response.check(&ValidatorName(worker.public_key()))?; + chain_info_response.check(&worker.public_key())?; let chain = worker.chain_state_view(ChainId::root(1)).await?; assert!(chain.is_active()); assert!(chain.manager.validated_vote().is_none()); // Should be confirmed by now. @@ -1245,7 +1245,7 @@ where .into_first_proposal(&sender_key_pair); let (response, _actions) = worker.handle_block_proposal(block_proposal.clone()).await?; - response.check(&ValidatorName(worker.public_key()))?; + response.check(&worker.public_key())?; let (replay_response, _actions) = worker.handle_block_proposal(block_proposal).await?; // Workaround lack of equality. assert_eq!( diff --git a/linera-core/src/worker.rs b/linera-core/src/worker.rs index 994ec137d753..501e13a84758 100644 --- a/linera-core/src/worker.rs +++ b/linera-core/src/worker.rs @@ -10,10 +10,8 @@ use std::{ }; use futures::future::Either; -#[cfg(with_testing)] -use linera_base::crypto::ValidatorPublicKey; use linera_base::{ - crypto::{CryptoError, CryptoHash, ValidatorSecretKey}, + crypto::{CryptoError, CryptoHash, ValidatorPublicKey, ValidatorSecretKey}, data_types::{ ArithmeticError, Blob, BlockHeight, DecompressionError, Round, UserApplicationDescription, }, @@ -33,10 +31,7 @@ use linera_chain::{ }, ChainError, ChainStateView, }; -use linera_execution::{ - committee::{Epoch, ValidatorName}, - ExecutionError, Query, QueryOutcome, -}; +use linera_execution::{committee::Epoch, ExecutionError, Query, QueryOutcome}; use linera_storage::Storage; use linera_views::views::ViewError; use lru::LruCache; @@ -1038,7 +1033,7 @@ where pub async fn update_received_certificate_trackers( &self, chain_id: ChainId, - new_trackers: BTreeMap, + new_trackers: BTreeMap, ) -> Result<(), WorkerError> { self.query_chain_worker(chain_id, move |callback| { ChainWorkerRequest::UpdateReceivedCertificateTrackers { diff --git a/linera-execution/src/committee.rs b/linera-execution/src/committee.rs index 897e63fa724f..cd891ffb66fe 100644 --- a/linera-execution/src/committee.rs +++ b/linera-execution/src/committee.rs @@ -103,7 +103,7 @@ pub struct ValidatorState { #[derive(Eq, PartialEq, Hash, Clone, Debug, Default, InputObject)] pub struct Committee { /// The validators in the committee. - validators: BTreeMap, + validators: BTreeMap, /// The sum of all voting rights. total_votes: u64, /// The threshold to form a quorum. @@ -145,7 +145,7 @@ impl<'de> Deserialize<'de> for Committee { #[derive(Serialize, Deserialize)] #[serde(rename = "Committee")] struct CommitteeFull<'a> { - validators: Cow<'a, BTreeMap>, + validators: Cow<'a, BTreeMap>, total_votes: u64, quorum_threshold: u64, validity_threshold: u64, @@ -155,7 +155,7 @@ struct CommitteeFull<'a> { #[derive(Serialize, Deserialize)] #[serde(rename = "Committee")] struct CommitteeMinimal<'a> { - validators: Cow<'a, BTreeMap>, + validators: Cow<'a, BTreeMap>, policy: Cow<'a, ResourceControlPolicy>, } @@ -290,7 +290,7 @@ impl Epoch { impl Committee { pub fn new( - validators: BTreeMap, + validators: BTreeMap, policy: ResourceControlPolicy, ) -> Self { let total_votes = validators.values().fold(0, |sum, state| sum + state.votes); @@ -311,7 +311,7 @@ impl Committee { } #[cfg(with_testing)] - pub fn make_simple(keys: Vec) -> Self { + pub fn make_simple(keys: Vec) -> Self { let map = keys .into_iter() .map(|k| { @@ -327,7 +327,7 @@ impl Committee { Committee::new(map, ResourceControlPolicy::default()) } - pub fn weight(&self, author: &ValidatorName) -> u64 { + pub fn weight(&self, author: &ValidatorPublicKey) -> u64 { match self.validators.get(author) { Some(state) => state.votes, None => 0, @@ -337,10 +337,10 @@ impl Committee { pub fn keys_and_weights(&self) -> impl Iterator + '_ { self.validators .iter() - .map(|(name, validator)| (name.0, validator.votes)) + .map(|(name, validator)| (*name, validator.votes)) } - pub fn network_address(&self, author: &ValidatorName) -> Option<&str> { + pub fn network_address(&self, author: &ValidatorPublicKey) -> Option<&str> { self.validators .get(author) .map(|state| state.network_address.as_ref()) @@ -354,11 +354,11 @@ impl Committee { self.validity_threshold } - pub fn validators(&self) -> &BTreeMap { + pub fn validators(&self) -> &BTreeMap { &self.validators } - pub fn validator_addresses(&self) -> impl Iterator { + pub fn validator_addresses(&self) -> impl Iterator { self.validators .iter() .map(|(name, validator)| (*name, &*validator.network_address)) diff --git a/linera-execution/src/graphql.rs b/linera-execution/src/graphql.rs index 555c3177269b..f4a142dd6bc2 100644 --- a/linera-execution/src/graphql.rs +++ b/linera-execution/src/graphql.rs @@ -4,6 +4,7 @@ use std::collections::BTreeMap; use linera_base::{ + crypto::ValidatorPublicKey, data_types::{Amount, Timestamp}, doc_scalar, identifiers::{AccountOwner, ChainDescription, ChainId}, @@ -12,7 +13,7 @@ use linera_base::{ use linera_views::{context::Context, map_view::MapView}; use crate::{ - committee::{Committee, Epoch, ValidatorName, ValidatorState}, + committee::{Committee, Epoch, ValidatorState}, system::{Recipient, UserData}, ChannelSubscription, ExecutionStateView, SystemExecutionStateView, }; @@ -23,12 +24,12 @@ doc_scalar!( ); doc_scalar!(Recipient, "The recipient of a transfer"); doc_scalar!(UserData, "Optional user message attached to a transfer"); -doc_scalar!(ValidatorName, "The identity of a validator"); +// doc_scalar!(ValidatorPublicKey, "The identity of a validator"); #[async_graphql::Object(cache_control(no_cache))] impl Committee { #[graphql(derived(name = "validators"))] - async fn _validators(&self) -> &BTreeMap { + async fn _validators(&self) -> &BTreeMap { self.validators() } diff --git a/linera-execution/tests/test_execution.rs b/linera-execution/tests/test_execution.rs index bed5292e7e13..320cab872575 100644 --- a/linera-execution/tests/test_execution.rs +++ b/linera-execution/tests/test_execution.rs @@ -1412,7 +1412,7 @@ async fn test_multiple_messages_from_different_applications() -> anyhow::Result< /// Tests the system API calls `open_chain` and `chain_ownership`. #[tokio::test] async fn test_open_chain() -> anyhow::Result<()> { - let committee = Committee::make_simple(vec![ValidatorPublicKey::test_key(0).into()]); + let committee = Committee::make_simple(vec![ValidatorPublicKey::test_key(0)]); let committees = BTreeMap::from([(Epoch::ZERO, committee)]); let chain_key = AccountPublicKey::test_key(1); let ownership = ChainOwnership::single(chain_key.into()); @@ -1517,7 +1517,7 @@ async fn test_open_chain() -> anyhow::Result<()> { /// Tests the system API call `close_chain``. #[tokio::test] async fn test_close_chain() -> anyhow::Result<()> { - let committee = Committee::make_simple(vec![ValidatorPublicKey::test_key(0).into()]); + let committee = Committee::make_simple(vec![ValidatorPublicKey::test_key(0)]); let committees = BTreeMap::from([(Epoch::ZERO, committee)]); let ownership = ChainOwnership::single(AccountPublicKey::test_key(1).into()); let state = SystemExecutionState { diff --git a/linera-faucet/client/Cargo.toml b/linera-faucet/client/Cargo.toml index d10ec694888b..dc4963b3a8e8 100644 --- a/linera-faucet/client/Cargo.toml +++ b/linera-faucet/client/Cargo.toml @@ -11,7 +11,6 @@ edition.workspace = true anyhow.workspace = true linera-base.workspace = true linera-client.workspace = true -linera-execution.workspace = true linera-faucet = { version = "0.14.0", path = ".." } linera-version.workspace = true reqwest.workspace = true diff --git a/linera-faucet/client/src/lib.rs b/linera-faucet/client/src/lib.rs index 3f455de15f6a..77d584fdb0c2 100644 --- a/linera-faucet/client/src/lib.rs +++ b/linera-faucet/client/src/lib.rs @@ -4,9 +4,8 @@ //! The client component of the Linera faucet. use anyhow::{bail, Context, Result}; -use linera_base::identifiers::Owner; +use linera_base::{crypto::ValidatorPublicKey, identifiers::Owner}; use linera_client::config::GenesisConfig; -use linera_execution::committee::ValidatorName; use linera_faucet::ClaimOutcome; use linera_version::VersionInfo; use serde_json::{json, Value}; @@ -170,7 +169,7 @@ impl Faucet { Ok(outcome) } - pub async fn current_validators(&self) -> Result> { + pub async fn current_validators(&self) -> Result> { let query = "query { currentValidators { name networkAddress } }"; let client = reqwest_client(); let response = client @@ -199,7 +198,7 @@ impl Faucet { validators .into_iter() .map(|mut validator| { - let name = serde_json::from_value::(validator["name"].take()) + let name = serde_json::from_value::(validator["name"].take()) .context("could not parse current validators: invalid name")?; let addr = validator["networkAddress"] .as_str() diff --git a/linera-faucet/server/Cargo.toml b/linera-faucet/server/Cargo.toml index 411ad3eb99b0..23980266772f 100644 --- a/linera-faucet/server/Cargo.toml +++ b/linera-faucet/server/Cargo.toml @@ -16,7 +16,6 @@ futures.workspace = true linera-base.workspace = true linera-client.workspace = true linera-core.workspace = true -linera-execution.workspace = true linera-storage.workspace = true linera-version.workspace = true serde.workspace = true diff --git a/linera-faucet/server/src/lib.rs b/linera-faucet/server/src/lib.rs index cc3eca32351c..a4bbe40f1d0b 100644 --- a/linera-faucet/server/src/lib.rs +++ b/linera-faucet/server/src/lib.rs @@ -10,7 +10,7 @@ use async_graphql_axum::{GraphQLRequest, GraphQLResponse, GraphQLSubscription}; use axum::{Extension, Router}; use futures::lock::Mutex; use linera_base::{ - crypto::CryptoHash, + crypto::{CryptoHash, ValidatorPublicKey}, data_types::{Amount, ApplicationPermissions, Timestamp}, identifiers::{ChainId, MessageId, Owner}, ownership::ChainOwnership, @@ -20,7 +20,6 @@ use linera_client::{ config::GenesisConfig, }; use linera_core::data_types::ClientOutcome; -use linera_execution::committee::ValidatorName; use linera_storage::{Clock as _, Storage}; use serde::Deserialize; use tower_http::cors::CorsLayer; @@ -69,7 +68,7 @@ pub struct ClaimOutcome { #[derive(Debug, Deserialize, SimpleObject)] pub struct Validator { - pub name: ValidatorName, + pub name: ValidatorPublicKey, pub network_address: String, } diff --git a/linera-rpc/src/config.rs b/linera-rpc/src/config.rs index 95fafa6c99cc..13e189abac46 100644 --- a/linera-rpc/src/config.rs +++ b/linera-rpc/src/config.rs @@ -1,8 +1,7 @@ // Copyright (c) Zefchain Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use linera_base::identifiers::ChainId; -use linera_execution::committee::ValidatorName; +use linera_base::{crypto::ValidatorPublicKey, identifiers::ChainId}; use serde::{Deserialize, Serialize}; #[cfg(with_simple_network)] @@ -103,8 +102,8 @@ pub type ValidatorPublicNetworkConfig = ValidatorPublicNetworkPreConfig { - /// The name of the validator. - pub name: ValidatorName, + /// The public key of the validator. + pub name: ValidatorPublicKey, /// The network protocol to use for all shards. pub protocol: P, /// The available shards. Each chain UID is mapped to a unique shard in the vector in diff --git a/linera-rpc/src/grpc/conversions.rs b/linera-rpc/src/grpc/conversions.rs index bb9bf5704f2c..6280f5e2fcb5 100644 --- a/linera-rpc/src/grpc/conversions.rs +++ b/linera-rpc/src/grpc/conversions.rs @@ -20,7 +20,6 @@ use linera_core::{ node::NodeError, worker::Notification, }; -use linera_execution::committee::ValidatorName; use thiserror::Error; use tonic::{Code, Status}; @@ -631,22 +630,6 @@ impl TryFrom for ValidatorPublicKey { } } -impl From for api::PublicKey { - fn from(validator_name: ValidatorName) -> Self { - Self { - bytes: validator_name.0 .0.to_vec(), - } - } -} - -impl TryFrom for ValidatorName { - type Error = GrpcProtoConversionError; - - fn try_from(public_key: api::PublicKey) -> Result { - Ok(ValidatorName(public_key.try_into()?)) - } -} - impl From for api::Signature { fn from(signature: AccountSignature) -> Self { Self { @@ -1031,11 +1014,11 @@ pub mod tests { } #[test] - pub fn validator_name() { - let validator_name = ValidatorName::from(ValidatorSecretKey::generate().public()); + pub fn validator_public_key() { + let validator_key = ValidatorPublicKey::from(ValidatorSecretKey::generate().public()); // This is a correct comparison - `ValidatorNameRpc` does not exist in our // proto definitions. - round_trip_check::<_, api::PublicKey>(validator_name); + round_trip_check::<_, api::PublicKey>(validator_key); } #[test] @@ -1140,7 +1123,7 @@ pub mod tests { }, round: Round::MultiLeader(2), signatures: Cow::Owned(vec![( - ValidatorName::from(key_pair.public()), + key_pair.public(), ValidatorSignature::new(&Foo("test".into()), &key_pair), )]), }; @@ -1165,7 +1148,7 @@ pub mod tests { )), Round::MultiLeader(3), vec![( - ValidatorName::from(key_pair.public()), + key_pair.public(), ValidatorSignature::new(&Foo("test".into()), &key_pair), )], ); @@ -1208,7 +1191,7 @@ pub mod tests { Hashed::new(ValidatedBlock::new(outcome.clone().with(get_block()))), Round::SingleLeader(2), vec![( - ValidatorName::from(key_pair.public()), + key_pair.public(), ValidatorSignature::new(&Foo("signed".into()), &key_pair), )], ) diff --git a/linera-rpc/tests/snapshots/format__format.yaml.snap b/linera-rpc/tests/snapshots/format__format.yaml.snap index fb3603315978..f9c1c8ac1953 100644 --- a/linera-rpc/tests/snapshots/format__format.yaml.snap +++ b/linera-rpc/tests/snapshots/format__format.yaml.snap @@ -340,7 +340,7 @@ Committee: - validators: MAP: KEY: - TYPENAME: ValidatorName + TYPENAME: Ed25519PublicKey VALUE: TYPENAME: ValidatorState - policy: @@ -354,7 +354,7 @@ ConfirmedBlockCertificate: - signatures: SEQ: TUPLE: - - TYPENAME: ValidatorName + - TYPENAME: Ed25519PublicKey - TYPENAME: Ed25519Signature CrateVersion: STRUCT: @@ -466,7 +466,7 @@ LiteCertificate: - signatures: SEQ: TUPLE: - - TYPENAME: ValidatorName + - TYPENAME: Ed25519PublicKey - TYPENAME: Ed25519Signature LiteValue: STRUCT: @@ -483,7 +483,7 @@ LiteVote: - round: TYPENAME: Round - validator: - TYPENAME: ValidatorName + TYPENAME: Ed25519PublicKey - signature: TYPENAME: Ed25519Signature LockingBlock: @@ -1133,7 +1133,7 @@ TimeoutCertificate: - signatures: SEQ: TUPLE: - - TYPENAME: ValidatorName + - TYPENAME: Ed25519PublicKey - TYPENAME: Ed25519Signature TimeoutConfig: STRUCT: @@ -1167,11 +1167,8 @@ ValidatedBlockCertificate: - signatures: SEQ: TUPLE: - - TYPENAME: ValidatorName + - TYPENAME: Ed25519PublicKey - TYPENAME: Ed25519Signature -ValidatorName: - NEWTYPESTRUCT: - TYPENAME: Ed25519PublicKey ValidatorState: STRUCT: - network_address: STR diff --git a/linera-sdk/src/test/validator.rs b/linera-sdk/src/test/validator.rs index d4fd4ee13ed4..c1c4440e9548 100644 --- a/linera-sdk/src/test/validator.rs +++ b/linera-sdk/src/test/validator.rs @@ -18,7 +18,7 @@ use linera_base::{ }; use linera_core::worker::WorkerState; use linera_execution::{ - committee::{Committee, Epoch, ValidatorName}, + committee::{Committee, Epoch}, system::{OpenChainConfig, SystemOperation, OPEN_CHAIN_MESSAGE_INDEX}, WasmRuntime, }; @@ -68,7 +68,7 @@ impl TestValidator { /// Creates a new [`TestValidator`]. pub async fn new() -> Self { let key_pair = ValidatorSecretKey::generate(); - let committee = Committee::make_simple(vec![ValidatorName(key_pair.public())]); + let committee = Committee::make_simple(vec![key_pair.public()]); let wasm_runtime = Some(WasmRuntime::default()); let storage = DbStorage::::make_test_storage(wasm_runtime) .now_or_never() diff --git a/linera-service/src/linera/main.rs b/linera-service/src/linera/main.rs index 76c84bc8e41a..37bcda45044f 100644 --- a/linera-service/src/linera/main.rs +++ b/linera-service/src/linera/main.rs @@ -40,10 +40,11 @@ use linera_core::{ JoinSetExt as _, }; use linera_execution::{ - committee::{Committee, ValidatorName, ValidatorState}, + committee::{Committee, ValidatorState}, Message, ResourceControlPolicy, SystemMessage, }; use linera_faucet_server::FaucetService; +use linera_sdk::base::ValidatorPublicKey; use linera_service::{ cli_wrappers, node_service::NodeService, @@ -1208,7 +1209,7 @@ impl Job { chain_id: ChainId, message_id: MessageId, owner: Owner, - validators: Option>, + validators: Option>, context: &mut ClientContext>, ) -> anyhow::Result<()> where diff --git a/linera-service/src/proxy/grpc.rs b/linera-service/src/proxy/grpc.rs index e9f3f86c4653..2b0e36e01760 100644 --- a/linera-service/src/proxy/grpc.rs +++ b/linera-service/src/proxy/grpc.rs @@ -698,14 +698,13 @@ mod proto_message_cap { data_types::{BlockExecutionOutcome, ExecutedBlock}, types::{Certificate, ConfirmedBlock, ConfirmedBlockCertificate}, }; - use linera_execution::committee::ValidatorName; use linera_sdk::base::{ChainId, TestString, ValidatorSecretKey, ValidatorSignature}; use super::{CertificatesBatchResponse, GrpcMessageLimiter}; fn test_certificate() -> Certificate { let keypair = ValidatorSecretKey::generate(); - let validator = ValidatorName(keypair.public()); + let validator = keypair.public(); let signature = ValidatorSignature::new(&TestString::new("Test"), &keypair); let executed_block = ExecutedBlock { block: linera_chain::test::make_first_block(ChainId::root(0)), diff --git a/linera-service/src/schema_export.rs b/linera-service/src/schema_export.rs index e9047cb91c9f..6a7228782085 100644 --- a/linera-service/src/schema_export.rs +++ b/linera-service/src/schema_export.rs @@ -27,7 +27,8 @@ use linera_core::{ ValidatorNodeProvider, }, }; -use linera_execution::committee::{Committee, ValidatorName}; +use linera_execution::committee::Committee; +use linera_sdk::base::ValidatorPublicKey; use linera_service::node_service::NodeService; use linera_storage::{DbStorage, Storage}; use linera_version::VersionInfo; @@ -150,7 +151,7 @@ impl ValidatorNodeProvider for DummyValidatorNodeProvider { fn make_nodes( &self, _committee: &Committee, - ) -> Result + '_, NodeError> { + ) -> Result + '_, NodeError> { Err::, _>(NodeError::UnexpectedMessage) } } diff --git a/linera-service/src/server.rs b/linera-service/src/server.rs index 6f730304c6f7..af77866a9a97 100644 --- a/linera-service/src/server.rs +++ b/linera-service/src/server.rs @@ -24,7 +24,7 @@ use linera_client::{ storage::{full_initialize_storage, run_with_storage, Runnable, StorageConfigNamespace}, }; use linera_core::{worker::WorkerState, JoinSetExt as _}; -use linera_execution::{committee::ValidatorName, WasmRuntime, WithWasmDefault}; +use linera_execution::{WasmRuntime, WithWasmDefault}; use linera_rpc::{ config::{ CrossChainConfig, NetworkProtocol, NotificationConfig, ShardConfig, ShardId, TlsConfig, @@ -284,7 +284,7 @@ fn make_server_config( options: ValidatorOptions, ) -> anyhow::Result> { let key = ValidatorSecretKey::generate_from(rng); - let name = ValidatorName(key.public()); + let name = key.public(); let network = ValidatorPublicNetworkConfig { protocol: options.external_protocol, host: options.host,