Skip to content

Commit acc42da

Browse files
committed
Add rpc configuration to MockConsensusNode
1 parent 855ac5a commit acc42da

File tree

3 files changed

+263
-76
lines changed

3 files changed

+263
-76
lines changed

domains/test/service/src/domain.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable, NumberFor};
4141
use sp_session::SessionKeys;
4242
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
4343
use std::future::Future;
44+
use std::net::SocketAddr;
4445
use std::sync::Arc;
4546
use std::time::Duration;
4647
use subspace_runtime_primitives::opaque::Block as CBlock;
@@ -146,6 +147,8 @@ where
146147
maybe_operator_id: Option<OperatorId>,
147148
role: Role,
148149
mock_consensus_node: &mut MockConsensusNode,
150+
rpc_addr: Option<SocketAddr>,
151+
rpc_port: Option<u16>,
149152
) -> Self {
150153
let mut domain_config = node_config(
151154
domain_id,
@@ -156,6 +159,8 @@ where
156159
role,
157160
base_path.clone(),
158161
Box::new(create_domain_spec()) as Box<_>,
162+
rpc_addr,
163+
rpc_port,
159164
)
160165
.expect("could not generate domain node Configuration");
161166

@@ -573,6 +578,8 @@ pub struct DomainNodeBuilder {
573578
skip_empty_bundle_production: bool,
574579
base_path: BasePath,
575580
maybe_operator_id: Option<OperatorId>,
581+
rpc_addr: Option<SocketAddr>,
582+
rpc_port: Option<u16>,
576583
}
577584

578585
impl DomainNodeBuilder {
@@ -588,6 +595,8 @@ impl DomainNodeBuilder {
588595
skip_empty_bundle_production: false,
589596
base_path,
590597
maybe_operator_id: None,
598+
rpc_addr: None,
599+
rpc_port: None,
591600
}
592601
}
593602

@@ -620,6 +629,18 @@ impl DomainNodeBuilder {
620629
self
621630
}
622631

632+
/// Set RPC address for the domain node
633+
pub fn rpc_addr(mut self, addr: SocketAddr) -> Self {
634+
self.rpc_addr = Some(addr);
635+
self
636+
}
637+
638+
/// Set RPC port for the domain node
639+
pub fn rpc_port(mut self, port: u16) -> Self {
640+
self.rpc_port = Some(port);
641+
self
642+
}
643+
623644
/// Build an EVM domain node
624645
pub async fn build_evm_node(
625646
self,
@@ -642,6 +663,8 @@ impl DomainNodeBuilder {
642663
self.maybe_operator_id,
643664
role,
644665
mock_consensus_node,
666+
self.rpc_addr,
667+
self.rpc_port,
645668
)
646669
.await
647670
}
@@ -668,6 +691,8 @@ impl DomainNodeBuilder {
668691
self.maybe_operator_id,
669692
role,
670693
mock_consensus_node,
694+
self.rpc_addr,
695+
self.rpc_port,
671696
)
672697
.await
673698
}
@@ -691,6 +716,8 @@ impl DomainNodeBuilder {
691716
self.maybe_operator_id,
692717
role,
693718
mock_consensus_node,
719+
self.rpc_addr,
720+
self.rpc_port,
694721
)
695722
.await
696723
}

domains/test/service/src/lib.rs

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use sc_network::multiaddr;
3131
use sc_service::config::{
3232
DatabaseSource, ExecutorConfiguration, KeystoreConfig, MultiaddrWithPeerId,
3333
NetworkConfiguration, OffchainWorkerConfig, PruningMode, RpcBatchRequestConfig,
34-
RpcConfiguration, WasmExecutionMethod, WasmtimeInstantiationStrategy,
34+
RpcConfiguration, RpcEndpoint, WasmExecutionMethod, WasmtimeInstantiationStrategy,
3535
};
3636
use sc_service::{
3737
BasePath, BlocksPruning, ChainSpec, Configuration as ServiceConfiguration,
@@ -48,6 +48,7 @@ use sp_runtime::generic;
4848
use sp_runtime::generic::SignedPayload;
4949
use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable};
5050
use std::fmt::{Debug, Display};
51+
use std::net::SocketAddr;
5152
use std::str::FromStr;
5253

5354
/// The domain id of the evm domain
@@ -72,6 +73,8 @@ pub fn node_config(
7273
role: Role,
7374
base_path: BasePath,
7475
chain_spec: Box<dyn ChainSpec>,
76+
rpc_addr: Option<SocketAddr>,
77+
rpc_port: Option<u16>,
7578
) -> Result<ServiceConfiguration, ServiceError> {
7679
let root = base_path.path().to_path_buf();
7780

@@ -104,6 +107,59 @@ pub fn node_config(
104107

105108
network_config.transport = TransportConfig::MemoryOnly;
106109

110+
let rpc_configuration = match rpc_addr {
111+
Some(listen_addr) => {
112+
let port = rpc_port.unwrap_or(9945);
113+
RpcConfiguration {
114+
addr: Some(vec![RpcEndpoint {
115+
batch_config: RpcBatchRequestConfig::Disabled,
116+
max_connections: 10,
117+
listen_addr,
118+
rpc_methods: Default::default(),
119+
rate_limit: None,
120+
rate_limit_trust_proxy_headers: false,
121+
rate_limit_whitelisted_ips: vec![],
122+
max_payload_in_mb: 15,
123+
max_payload_out_mb: 15,
124+
max_subscriptions_per_connection: 10,
125+
max_buffer_capacity_per_connection: 10,
126+
cors: None,
127+
retry_random_port: true,
128+
is_optional: false,
129+
}]),
130+
max_request_size: 15,
131+
max_response_size: 15,
132+
id_provider: None,
133+
max_subs_per_conn: 1024,
134+
port,
135+
message_buffer_capacity: 1024,
136+
batch_config: RpcBatchRequestConfig::Disabled,
137+
max_connections: 1000,
138+
cors: None,
139+
methods: Default::default(),
140+
rate_limit: None,
141+
rate_limit_whitelisted_ips: vec![],
142+
rate_limit_trust_proxy_headers: false,
143+
}
144+
}
145+
None => RpcConfiguration {
146+
addr: None,
147+
max_request_size: 0,
148+
max_response_size: 0,
149+
id_provider: None,
150+
max_subs_per_conn: 0,
151+
port: 0,
152+
message_buffer_capacity: 0,
153+
batch_config: RpcBatchRequestConfig::Disabled,
154+
max_connections: 0,
155+
cors: None,
156+
methods: Default::default(),
157+
rate_limit: None,
158+
rate_limit_whitelisted_ips: vec![],
159+
rate_limit_trust_proxy_headers: false,
160+
},
161+
};
162+
107163
Ok(ServiceConfiguration {
108164
impl_name: "domain-test-node".to_string(),
109165
impl_version: "0.1".to_string(),
@@ -127,22 +183,7 @@ pub fn node_config(
127183
default_heap_pages: None,
128184
runtime_cache_size: 2,
129185
},
130-
rpc: RpcConfiguration {
131-
addr: None,
132-
max_request_size: 0,
133-
max_response_size: 0,
134-
id_provider: None,
135-
max_subs_per_conn: 0,
136-
port: 0,
137-
message_buffer_capacity: 0,
138-
batch_config: RpcBatchRequestConfig::Disabled,
139-
max_connections: 0,
140-
cors: None,
141-
methods: Default::default(),
142-
rate_limit: None,
143-
rate_limit_whitelisted_ips: vec![],
144-
rate_limit_trust_proxy_headers: false,
145-
},
186+
rpc: rpc_configuration,
146187
prometheus_config: None,
147188
telemetry_endpoints: None,
148189
offchain_worker: OffchainWorkerConfig {

0 commit comments

Comments
 (0)