Skip to content

Commit cb7a8c4

Browse files
authored
Remove LocalValidatorNode(Provider) and LocalNotificationStream (#2522)
* rename LocalNotificationStream into WebNotificationStream * remove LocalValidatorNode(Provider)
1 parent 0090fed commit cb7a8c4

File tree

15 files changed

+50
-67
lines changed

15 files changed

+50
-67
lines changed

linera-client/src/chain_listener.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use linera_base::{
1717
use linera_chain::data_types::OutgoingMessage;
1818
use linera_core::{
1919
client::{ChainClient, ChainClientError},
20-
node::{LocalValidatorNodeProvider, ValidatorNode, ValidatorNodeProvider},
20+
node::{ValidatorNode, ValidatorNodeProvider},
2121
worker::Reason,
2222
};
2323
use linera_execution::{Message, SystemMessage};
@@ -60,7 +60,7 @@ pub struct ChainListenerConfig {
6060
#[cfg_attr(not(web), async_trait)]
6161
#[cfg_attr(web, async_trait(?Send))]
6262
pub trait ClientContext {
63-
type ValidatorNodeProvider: LocalValidatorNodeProvider;
63+
type ValidatorNodeProvider: ValidatorNodeProvider;
6464
type Storage: Storage;
6565

6666
fn wallet(&self) -> &Wallet;

linera-client/src/wallet.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use linera_base::{
1313
identifiers::{BlobId, ChainDescription, ChainId},
1414
};
1515
use linera_chain::data_types::Block;
16-
use linera_core::{client::ChainClient, node::LocalValidatorNodeProvider};
16+
use linera_core::{client::ChainClient, node::ValidatorNodeProvider};
1717
use linera_storage::Storage;
1818
use rand::Rng as _;
1919
use serde::{Deserialize, Serialize};
@@ -164,7 +164,7 @@ impl Wallet {
164164

165165
pub async fn update_from_state<P, S>(&mut self, chain_client: &ChainClient<P, S>)
166166
where
167-
P: LocalValidatorNodeProvider + Sync + 'static,
167+
P: ValidatorNodeProvider + Sync + 'static,
168168
S: Storage + Clone + Send + Sync + 'static,
169169
{
170170
let key_pair = chain_client.key_pair().await.map(|k| k.copy()).ok();

linera-core/src/client.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ use crate::{
6868
},
6969
local_node::{LocalNodeClient, LocalNodeError, NamedNode},
7070
node::{
71-
CrossChainMessageDelivery, LocalValidatorNode, LocalValidatorNodeProvider, NodeError,
72-
NotificationStream,
71+
CrossChainMessageDelivery, NodeError, NotificationStream, ValidatorNode,
72+
ValidatorNodeProvider,
7373
},
7474
notifier::Notifier,
7575
updater::{communicate_with_quorum, CommunicateAction, CommunicationError, ValidatorUpdater},
@@ -288,7 +288,7 @@ impl<P, S: Storage + Clone> Client<P, S> {
288288

289289
impl<P, S> Client<P, S>
290290
where
291-
P: LocalValidatorNodeProvider + Sync + 'static,
291+
P: ValidatorNodeProvider + Sync + 'static,
292292
S: Storage + Sync + Send + Clone + 'static,
293293
{
294294
async fn download_certificates(
@@ -657,7 +657,7 @@ enum ReceiveCertificateMode {
657657

658658
impl<P, S> ChainClient<P, S>
659659
where
660-
P: LocalValidatorNodeProvider + Sync + 'static,
660+
P: ValidatorNodeProvider + Sync + 'static,
661661
S: Storage + Clone + Send + Sync + 'static,
662662
{
663663
#[tracing::instrument(level = "trace")]

linera-core/src/local_node.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use tracing::warn;
3131

3232
use crate::{
3333
data_types::{BlockHeightRange, ChainInfo, ChainInfoQuery, ChainInfoResponse},
34-
node::{CrossChainMessageDelivery, LocalValidatorNode, NodeError},
34+
node::{CrossChainMessageDelivery, NodeError, ValidatorNode},
3535
value_cache::ValueCache,
3636
worker::{Notification, WorkerError, WorkerState},
3737
};
@@ -256,7 +256,7 @@ where
256256
#[tracing::instrument(level = "trace", skip_all)]
257257
pub async fn try_process_certificates(
258258
&self,
259-
named_node: &NamedNode<impl LocalValidatorNode>,
259+
named_node: &NamedNode<impl ValidatorNode>,
260260
chain_id: ChainId,
261261
certificates: Vec<Certificate>,
262262
notifications: &mut impl Extend<Notification>,
@@ -364,7 +364,7 @@ where
364364
/// Downloads and processes all certificates up to (excluding) the specified height.
365365
pub async fn download_certificates(
366366
&self,
367-
validators: &[NamedNode<impl LocalValidatorNode>],
367+
validators: &[NamedNode<impl ValidatorNode>],
368368
chain_id: ChainId,
369369
target_next_block_height: BlockHeight,
370370
notifications: &mut impl Extend<Notification>,
@@ -424,7 +424,7 @@ where
424424
/// given validator.
425425
async fn try_download_certificates_from(
426426
&self,
427-
named_node: &NamedNode<impl LocalValidatorNode>,
427+
named_node: &NamedNode<impl ValidatorNode>,
428428
chain_id: ChainId,
429429
mut start: BlockHeight,
430430
stop: BlockHeight,
@@ -457,7 +457,7 @@ where
457457
#[tracing::instrument(level = "trace", skip_all)]
458458
async fn try_query_certificates_from(
459459
&self,
460-
named_node: &NamedNode<impl LocalValidatorNode>,
460+
named_node: &NamedNode<impl ValidatorNode>,
461461
chain_id: ChainId,
462462
start: BlockHeight,
463463
limit: u64,
@@ -483,7 +483,7 @@ where
483483

484484
#[tracing::instrument(level = "trace", skip(validators))]
485485
async fn download_blob(
486-
validators: &[NamedNode<impl LocalValidatorNode>],
486+
validators: &[NamedNode<impl ValidatorNode>],
487487
blob_id: BlobId,
488488
) -> Option<Blob> {
489489
// Sequentially try each validator in random order.
@@ -500,7 +500,7 @@ where
500500
#[tracing::instrument(level = "trace", skip(nodes))]
501501
pub async fn download_blobs(
502502
blob_ids: &[BlobId],
503-
nodes: &[NamedNode<impl LocalValidatorNode>],
503+
nodes: &[NamedNode<impl ValidatorNode>],
504504
) -> Vec<Blob> {
505505
future::join_all(
506506
blob_ids
@@ -549,7 +549,7 @@ impl<N> fmt::Debug for NamedNode<N> {
549549
}
550550

551551
#[allow(clippy::result_large_err)]
552-
impl<N: LocalValidatorNode> NamedNode<N> {
552+
impl<N: ValidatorNode> NamedNode<N> {
553553
pub async fn handle_chain_info_query(
554554
&self,
555555
query: ChainInfoQuery,

linera-core/src/node.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// Copyright (c) Zefchain Labs, Inc.
33
// SPDX-License-Identifier: Apache-2.0
44

5-
use futures::stream::{BoxStream, LocalBoxStream, Stream};
5+
#[cfg(not(web))]
6+
use futures::stream::BoxStream;
7+
#[cfg(web)]
8+
use futures::stream::LocalBoxStream as BoxStream;
9+
use futures::stream::Stream;
610
use linera_base::{
711
crypto::{CryptoError, CryptoHash},
812
data_types::{ArithmeticError, Blob, BlobContent, BlockHeight},
@@ -28,8 +32,6 @@ use crate::{
2832

2933
/// A pinned [`Stream`] of Notifications.
3034
pub type NotificationStream = BoxStream<'static, Notification>;
31-
/// A pinned [`Stream`] of Notifications, without the `Send` constraint.
32-
pub type LocalNotificationStream = LocalBoxStream<'static, Notification>;
3335

3436
/// Whether to wait for the delivery of outgoing cross-chain messages.
3537
#[derive(Debug, Default, Clone, Copy)]
@@ -40,8 +42,9 @@ pub enum CrossChainMessageDelivery {
4042
}
4143

4244
/// How to communicate with a validator node.
43-
#[trait_variant::make(ValidatorNode: Send)]
44-
pub trait LocalValidatorNode {
45+
#[allow(async_fn_in_trait)]
46+
#[cfg_attr(not(web), trait_variant::make(Send))]
47+
pub trait ValidatorNode {
4548
type NotificationStream: Stream<Item = Notification> + Unpin;
4649

4750
/// Proposes a new block.
@@ -94,9 +97,13 @@ pub trait LocalValidatorNode {
9497
}
9598

9699
/// Turn an address into a validator node.
100+
#[cfg_attr(not(web), trait_variant::make(Send))]
97101
#[expect(clippy::result_large_err)]
98-
pub trait LocalValidatorNodeProvider {
99-
type Node: LocalValidatorNode + Clone + 'static;
102+
pub trait ValidatorNodeProvider {
103+
#[cfg(not(web))]
104+
type Node: ValidatorNode + Send + Sync + Clone + 'static;
105+
#[cfg(web)]
106+
type Node: ValidatorNode + Clone + 'static;
100107

101108
fn make_node(&self, address: &str) -> Result<Self::Node, NodeError>;
102109

@@ -126,19 +133,6 @@ pub trait LocalValidatorNodeProvider {
126133
}
127134
}
128135

129-
pub trait ValidatorNodeProvider:
130-
LocalValidatorNodeProvider<Node = <Self as ValidatorNodeProvider>::Node>
131-
{
132-
type Node: ValidatorNode + Send + Sync + Clone + 'static;
133-
}
134-
135-
impl<T: LocalValidatorNodeProvider> ValidatorNodeProvider for T
136-
where
137-
T::Node: ValidatorNode + Send + Sync + Clone + 'static,
138-
{
139-
type Node = <T as LocalValidatorNodeProvider>::Node;
140-
}
141-
142136
/// Error type for node queries.
143137
///
144138
/// This error is meant to be serialized over the network and aggregated by clients (i.e.

linera-core/src/unit_tests/test_utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ use crate::{
5454
client::{ChainClient, Client},
5555
data_types::*,
5656
node::{
57-
CrossChainMessageDelivery, LocalValidatorNodeProvider, NodeError, NotificationStream,
58-
ValidatorNode,
57+
CrossChainMessageDelivery, NodeError, NotificationStream, ValidatorNode,
58+
ValidatorNodeProvider,
5959
},
6060
notifier::Notifier,
6161
worker::{NetworkActions, Notification, WorkerState},
@@ -492,7 +492,7 @@ pub struct NodeProvider<S>(BTreeMap<ValidatorName, Arc<Mutex<LocalValidator<S>>>
492492
where
493493
S: Storage;
494494

495-
impl<S> LocalValidatorNodeProvider for NodeProvider<S>
495+
impl<S> ValidatorNodeProvider for NodeProvider<S>
496496
where
497497
S: Storage + Clone + Send + Sync + 'static,
498498
{

linera-core/src/updater.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use tracing::{error, warn};
2626
use crate::{
2727
data_types::{ChainInfo, ChainInfoQuery},
2828
local_node::{LocalNodeClient, NamedNode},
29-
node::{CrossChainMessageDelivery, LocalValidatorNode, NodeError},
29+
node::{CrossChainMessageDelivery, NodeError, ValidatorNode},
3030
};
3131

3232
/// The amount of time we wait for additional validators to contribute to the result, as a fraction
@@ -101,7 +101,7 @@ pub async fn communicate_with_quorum<'a, A, V, K, F, R, G>(
101101
execute: F,
102102
) -> Result<(K, Vec<V>), CommunicationError<NodeError>>
103103
where
104-
A: LocalValidatorNode + Clone + 'static,
104+
A: ValidatorNode + Clone + 'static,
105105
F: Clone + Fn(NamedNode<A>) -> R,
106106
R: Future<Output = Result<V, NodeError>> + 'a,
107107
G: Fn(&V) -> K,
@@ -192,7 +192,7 @@ where
192192

193193
impl<A, S> ValidatorUpdater<A, S>
194194
where
195-
A: LocalValidatorNode + Clone + 'static,
195+
A: ValidatorNode + Clone + 'static,
196196
S: Storage + Clone + Send + Sync + 'static,
197197
{
198198
async fn send_optimized_certificate(

linera-rpc/src/client.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ use linera_base::{
99
use linera_chain::data_types::{
1010
BlockProposal, Certificate, HashedCertificateValue, LiteCertificate,
1111
};
12-
#[cfg(web)]
13-
use linera_core::node::{
14-
LocalNotificationStream as NotificationStream, LocalValidatorNode as ValidatorNode,
15-
};
16-
#[cfg(not(web))]
17-
use linera_core::node::{NotificationStream, ValidatorNode};
1812
use linera_core::{
1913
data_types::{ChainInfoQuery, ChainInfoResponse},
20-
node::{CrossChainMessageDelivery, NodeError},
14+
node::{CrossChainMessageDelivery, NodeError, NotificationStream, ValidatorNode},
2115
};
2216

2317
use crate::grpc::GrpcClient;

linera-rpc/src/grpc/client.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ use linera_base::{
1111
time::Duration,
1212
};
1313
use linera_chain::data_types::{self, Certificate, CertificateValue, HashedCertificateValue};
14-
#[cfg(web)]
15-
use linera_core::node::{
16-
LocalNotificationStream as NotificationStream, LocalValidatorNode as ValidatorNode,
17-
};
1814
use linera_core::{
19-
node::{CrossChainMessageDelivery, NodeError},
15+
node::{CrossChainMessageDelivery, NodeError, NotificationStream, ValidatorNode},
2016
worker::Notification,
2117
};
2218
use linera_version::VersionInfo;
@@ -26,7 +22,6 @@ use tracing::{debug, info, instrument, warn};
2622
use {
2723
super::GrpcProtoConversionError,
2824
crate::{mass_client, RpcMessage},
29-
linera_core::node::{NotificationStream, ValidatorNode},
3025
};
3126

3227
use super::{

linera-rpc/src/grpc/node_provider.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::str::FromStr as _;
55

6-
use linera_core::node::{LocalValidatorNodeProvider, NodeError};
6+
use linera_core::node::{NodeError, ValidatorNodeProvider};
77

88
use super::GrpcClient;
99
use crate::{config::ValidatorPublicNetworkConfig, node_provider::NodeOptions};
@@ -17,7 +17,7 @@ impl GrpcNodeProvider {
1717
}
1818
}
1919

20-
impl LocalValidatorNodeProvider for GrpcNodeProvider {
20+
impl ValidatorNodeProvider for GrpcNodeProvider {
2121
type Node = GrpcClient;
2222

2323
fn make_node(&self, address: &str) -> anyhow::Result<Self::Node, NodeError> {

linera-rpc/src/node_provider.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use linera_base::time::Duration;
5-
use linera_core::node::{LocalValidatorNodeProvider, NodeError};
5+
use linera_core::node::{NodeError, ValidatorNodeProvider};
66

77
#[cfg(with_simple_network)]
88
use crate::simple::SimpleNodeProvider;
@@ -27,7 +27,7 @@ impl NodeProvider {
2727
}
2828
}
2929

30-
impl LocalValidatorNodeProvider for NodeProvider {
30+
impl ValidatorNodeProvider for NodeProvider {
3131
type Node = Client;
3232

3333
fn make_node(&self, address: &str) -> anyhow::Result<Self::Node, NodeError> {

linera-rpc/src/simple/node_provider.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::str::FromStr as _;
55

6-
use linera_core::node::{LocalValidatorNodeProvider, NodeError};
6+
use linera_core::node::{NodeError, ValidatorNodeProvider};
77

88
use super::SimpleClient;
99
use crate::{config::ValidatorPublicNetworkPreConfig, node_provider::NodeOptions};
@@ -18,7 +18,7 @@ impl SimpleNodeProvider {
1818
}
1919
}
2020

21-
impl LocalValidatorNodeProvider for SimpleNodeProvider {
21+
impl ValidatorNodeProvider for SimpleNodeProvider {
2222
type Node = SimpleClient;
2323

2424
fn make_node(&self, address: &str) -> Result<Self::Node, NodeError> {

linera-rpc/tests/transport.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
1010
// this test currently must be run manually, as it requires a Linera proxy to be running on 127.0.0.1:9000.
1111
async fn client() {
1212
use linera_base::time::Duration;
13-
use linera_core::node::LocalValidatorNode as _;
13+
use linera_core::node::ValidatorNode as _;
1414
use linera_rpc::config::*;
1515

1616
let network_config = ValidatorPublicNetworkPreConfig {

linera-service/src/linera/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use linera_client::{
3434
use linera_core::{
3535
data_types::{ChainInfoQuery, ClientOutcome},
3636
local_node::{LocalNodeClient, NamedNode},
37-
node::LocalValidatorNodeProvider,
37+
node::ValidatorNodeProvider,
3838
worker::{Reason, WorkerState},
3939
JoinSetExt as _,
4040
};

linera-service/src/schema_export.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use linera_core::{
1919
client::ChainClient,
2020
data_types::{ChainInfoQuery, ChainInfoResponse},
2121
node::{
22-
CrossChainMessageDelivery, LocalValidatorNodeProvider, NodeError, NotificationStream,
23-
ValidatorNode,
22+
CrossChainMessageDelivery, NodeError, NotificationStream, ValidatorNode,
23+
ValidatorNodeProvider,
2424
},
2525
};
2626
use linera_execution::committee::{Committee, ValidatorName};
@@ -100,7 +100,7 @@ impl ValidatorNode for DummyValidatorNode {
100100

101101
struct DummyValidatorNodeProvider;
102102

103-
impl LocalValidatorNodeProvider for DummyValidatorNodeProvider {
103+
impl ValidatorNodeProvider for DummyValidatorNodeProvider {
104104
type Node = DummyValidatorNode;
105105

106106
fn make_node(&self, _address: &str) -> Result<Self::Node, NodeError> {
@@ -128,7 +128,7 @@ struct DummyContext<P, S> {
128128
}
129129

130130
#[async_trait]
131-
impl<P: LocalValidatorNodeProvider + Send, S: Storage + Send + Sync> ClientContext
131+
impl<P: ValidatorNodeProvider + Send, S: Storage + Send + Sync> ClientContext
132132
for DummyContext<P, S>
133133
{
134134
type ValidatorNodeProvider = P;

0 commit comments

Comments
 (0)