Skip to content

Commit 9b3d7e3

Browse files
authored
refactor: remove service_name (sigp#8606)
Which issue # does this PR address? sigp#8586 Please list or describe the changes introduced by this PR. Remove `service_name` from `TaskExecutor` Co-Authored-By: Abhivansh <31abhivanshj@gmail.com>
1 parent 6dab3c9 commit 9b3d7e3

File tree

12 files changed

+26
-134
lines changed

12 files changed

+26
-134
lines changed

beacon_node/client/src/builder.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ where
168168
let store = store.ok_or("beacon_chain_start_method requires a store")?;
169169
let runtime_context =
170170
runtime_context.ok_or("beacon_chain_start_method requires a runtime context")?;
171-
let context = runtime_context.service_context("beacon".into());
171+
let context = runtime_context.clone();
172172
let spec = chain_spec.ok_or("beacon_chain_start_method requires a chain spec")?;
173173
let event_handler = if self.http_api_config.enabled {
174174
Some(ServerSentEventHandler::new(
@@ -179,7 +179,7 @@ where
179179
};
180180

181181
let execution_layer = if let Some(config) = config.execution_layer.clone() {
182-
let context = runtime_context.service_context("exec".into());
182+
let context = runtime_context.clone();
183183
let execution_layer = ExecutionLayer::from_config(config, context.executor.clone())
184184
.map_err(|e| format!("unable to start execution layer endpoints: {:?}", e))?;
185185
Some(execution_layer)
@@ -517,7 +517,7 @@ where
517517
.runtime_context
518518
.as_ref()
519519
.ok_or("node timer requires a runtime_context")?
520-
.service_context("node_timer".into());
520+
.clone();
521521
let beacon_chain = self
522522
.beacon_chain
523523
.clone()
@@ -557,7 +557,7 @@ where
557557
.runtime_context
558558
.as_ref()
559559
.ok_or("slasher requires a runtime_context")?
560-
.service_context("slasher_service_ctxt".into());
560+
.clone();
561561
SlasherService::new(beacon_chain, network_senders.network_send()).run(&context.executor)
562562
}
563563

@@ -568,7 +568,7 @@ where
568568
.runtime_context
569569
.as_ref()
570570
.ok_or("monitoring_client requires a runtime_context")?
571-
.service_context("monitoring_client".into());
571+
.clone();
572572
let monitoring_client = MonitoringHttpClient::new(config)?;
573573
monitoring_client.auto_update(
574574
context.executor,
@@ -583,7 +583,7 @@ where
583583
.runtime_context
584584
.as_ref()
585585
.ok_or("slot_notifier requires a runtime_context")?
586-
.service_context("slot_notifier".into());
586+
.clone();
587587
let beacon_chain = self
588588
.beacon_chain
589589
.clone()
@@ -692,7 +692,7 @@ where
692692

693693
if let Some(beacon_chain) = self.beacon_chain.as_ref() {
694694
if let Some(network_globals) = &self.network_globals {
695-
let beacon_processor_context = runtime_context.service_context("bproc".into());
695+
let beacon_processor_context = runtime_context.clone();
696696
BeaconProcessor {
697697
network_globals: network_globals.clone(),
698698
executor: beacon_processor_context.executor.clone(),
@@ -715,7 +715,7 @@ where
715715
)?;
716716
}
717717

718-
let state_advance_context = runtime_context.service_context("state_advance".into());
718+
let state_advance_context = runtime_context.clone();
719719
spawn_state_advance_timer(state_advance_context.executor, beacon_chain.clone());
720720

721721
if let Some(execution_layer) = beacon_chain.execution_layer.as_ref() {
@@ -767,8 +767,7 @@ where
767767
// Spawn service to publish light_client updates at some interval into the slot.
768768
if let Some(light_client_server_rv) = self.light_client_server_rv {
769769
let inner_chain = beacon_chain.clone();
770-
let light_client_update_context =
771-
runtime_context.service_context("lc_update".to_string());
770+
let light_client_update_context = runtime_context.clone();
772771
light_client_update_context.executor.spawn(
773772
async move {
774773
compute_light_client_updates(

beacon_node/lighthouse_network/tests/common.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ pub async fn build_libp2p_instance(
118118
boot_nodes: Vec<Enr>,
119119
fork_name: ForkName,
120120
chain_spec: Arc<ChainSpec>,
121-
service_name: String,
122121
disable_peer_scoring: bool,
123122
inbound_rate_limiter: Option<InboundRateLimiterConfig>,
124123
) -> Libp2pInstance {
@@ -127,7 +126,7 @@ pub async fn build_libp2p_instance(
127126

128127
let (signal, exit) = async_channel::bounded(1);
129128
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
130-
let executor = task_executor::TaskExecutor::new(rt, exit, shutdown_tx, service_name);
129+
let executor = task_executor::TaskExecutor::new(rt, exit, shutdown_tx);
131130
let custody_group_count = chain_spec.custody_requirement;
132131
let libp2p_context = lighthouse_network::Context {
133132
config,
@@ -177,7 +176,6 @@ pub async fn build_node_pair(
177176
vec![],
178177
fork_name,
179178
spec.clone(),
180-
"sender".to_string(),
181179
disable_peer_scoring,
182180
inbound_rate_limiter.clone(),
183181
)
@@ -187,7 +185,6 @@ pub async fn build_node_pair(
187185
vec![],
188186
fork_name,
189187
spec.clone(),
190-
"receiver".to_string(),
191188
disable_peer_scoring,
192189
inbound_rate_limiter,
193190
)
@@ -266,16 +263,7 @@ pub async fn build_linear(
266263
let mut nodes = Vec::with_capacity(n);
267264
for _ in 0..n {
268265
nodes.push(
269-
build_libp2p_instance(
270-
rt.clone(),
271-
vec![],
272-
fork_name,
273-
spec.clone(),
274-
"linear".to_string(),
275-
false,
276-
None,
277-
)
278-
.await,
266+
build_libp2p_instance(rt.clone(), vec![], fork_name, spec.clone(), false, None).await,
279267
);
280268
}
281269

beacon_node/network/src/service/tests.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ fn test_dht_persistence() {
3939

4040
let (signal, exit) = async_channel::bounded(1);
4141
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
42-
let executor = task_executor::TaskExecutor::new(
43-
Arc::downgrade(&runtime),
44-
exit,
45-
shutdown_tx,
46-
"test-dht-persistence".to_string(),
47-
);
42+
let executor = task_executor::TaskExecutor::new(Arc::downgrade(&runtime), exit, shutdown_tx);
4843

4944
let mut config = NetworkConfig::default();
5045
config.set_ipv4_listening_address(std::net::Ipv4Addr::UNSPECIFIED, 21212, 21212, 21213);
@@ -115,12 +110,8 @@ fn test_removing_topic_weight_on_old_topics() {
115110
let (mut network_service, network_globals, _network_senders) = runtime.block_on(async {
116111
let (_, exit) = async_channel::bounded(1);
117112
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
118-
let executor = task_executor::TaskExecutor::new(
119-
Arc::downgrade(&runtime),
120-
exit,
121-
shutdown_tx,
122-
"test-removing-topic-weight-on-old-topics".to_string(),
123-
);
113+
let executor =
114+
task_executor::TaskExecutor::new(Arc::downgrade(&runtime), exit, shutdown_tx);
124115

125116
let mut config = NetworkConfig::default();
126117
config.set_ipv4_listening_address(std::net::Ipv4Addr::UNSPECIFIED, 21214, 21214, 21215);

common/task_executor/src/lib.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ pub struct TaskExecutor {
8383
/// The task must provide a reason for shutting down.
8484
signal_tx: Sender<ShutdownReason>,
8585

86-
/// The name of the service for inclusion in the logger output.
87-
// FIXME(sproul): delete?
88-
#[allow(dead_code)]
89-
service_name: String,
90-
9186
rayon_pool_provider: Arc<RayonPoolProvider>,
9287
}
9388

@@ -103,28 +98,15 @@ impl TaskExecutor {
10398
handle: T,
10499
exit: async_channel::Receiver<()>,
105100
signal_tx: Sender<ShutdownReason>,
106-
service_name: String,
107101
) -> Self {
108102
Self {
109103
handle_provider: handle.into(),
110104
exit,
111105
signal_tx,
112-
service_name,
113106
rayon_pool_provider: Arc::new(RayonPoolProvider::default()),
114107
}
115108
}
116109

117-
/// Clones the task executor adding a service name.
118-
pub fn clone_with_name(&self, service_name: String) -> Self {
119-
TaskExecutor {
120-
handle_provider: self.handle_provider.clone(),
121-
exit: self.exit.clone(),
122-
signal_tx: self.signal_tx.clone(),
123-
service_name,
124-
rayon_pool_provider: self.rayon_pool_provider.clone(),
125-
}
126-
}
127-
128110
/// A convenience wrapper for `Self::spawn` which ignores a `Result` as long as both `Ok`/`Err`
129111
/// are of type `()`.
130112
///

common/task_executor/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Default for TestRuntime {
3737
(Some(runtime), handle)
3838
};
3939

40-
let task_executor = TaskExecutor::new(handle, exit, shutdown_tx, "test".to_string());
40+
let task_executor = TaskExecutor::new(handle, exit, shutdown_tx);
4141

4242
Self {
4343
runtime,

lighthouse/environment/src/lib.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,6 @@ pub struct RuntimeContext<E: EthSpec> {
109109
}
110110

111111
impl<E: EthSpec> RuntimeContext<E> {
112-
/// Returns a sub-context of this context.
113-
///
114-
/// The generated service will have the `service_name` in all it's logs.
115-
pub fn service_context(&self, service_name: String) -> Self {
116-
Self {
117-
executor: self.executor.clone_with_name(service_name),
118-
eth_spec_instance: self.eth_spec_instance.clone(),
119-
eth2_config: self.eth2_config.clone(),
120-
eth2_network_config: self.eth2_network_config.clone(),
121-
sse_logging_components: self.sse_logging_components.clone(),
122-
}
123-
}
124-
125112
/// Returns the `eth2_config` for this service.
126113
pub fn eth2_config(&self) -> &Eth2Config {
127114
&self.eth2_config
@@ -349,23 +336,6 @@ impl<E: EthSpec> Environment<E> {
349336
Arc::downgrade(self.runtime()),
350337
self.exit.clone(),
351338
self.signal_tx.clone(),
352-
"core".to_string(),
353-
),
354-
eth_spec_instance: self.eth_spec_instance.clone(),
355-
eth2_config: self.eth2_config.clone(),
356-
eth2_network_config: self.eth2_network_config.clone(),
357-
sse_logging_components: self.sse_logging_components.clone(),
358-
}
359-
}
360-
361-
/// Returns a `Context` where the `service_name` is added to the logger output.
362-
pub fn service_context(&self, service_name: String) -> RuntimeContext<E> {
363-
RuntimeContext {
364-
executor: TaskExecutor::new(
365-
Arc::downgrade(self.runtime()),
366-
self.exit.clone(),
367-
self.signal_tx.clone(),
368-
service_name,
369339
),
370340
eth_spec_instance: self.eth_spec_instance.clone(),
371341
eth2_config: self.eth2_config.clone(),

testing/execution_engine_integration/src/test_rig.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,7 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
120120
);
121121
let (runtime_shutdown, exit) = async_channel::bounded(1);
122122
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
123-
let executor = TaskExecutor::new(
124-
Arc::downgrade(&runtime),
125-
exit,
126-
shutdown_tx,
127-
"test".to_string(),
128-
);
123+
let executor = TaskExecutor::new(Arc::downgrade(&runtime), exit, shutdown_tx);
129124
let mut spec = TEST_FORK.make_genesis_spec(MainnetEthSpec::default_spec());
130125
spec.terminal_total_difficulty = Uint256::ZERO;
131126

testing/simulator/src/basic_sim.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ pub fn run_basic_sim(matches: &ArgMatches) -> Result<(), String> {
253253
network_1
254254
.add_validator_client_with_fallbacks(
255255
validator_config,
256-
i,
257256
beacon_nodes,
258257
files,
259258
)

testing/simulator/src/fallback_sim.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,7 @@ pub fn run_fallback_sim(matches: &ArgMatches) -> Result<(), String> {
249249
Some(SUGGESTED_FEE_RECIPIENT.into());
250250
println!("Adding validator client {}", i);
251251
network_1
252-
.add_validator_client_with_fallbacks(
253-
validator_config,
254-
i,
255-
beacon_nodes,
256-
files,
257-
)
252+
.add_validator_client_with_fallbacks(validator_config, beacon_nodes, files)
258253
.await
259254
.expect("should add validator");
260255
},

testing/simulator/src/local_network.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ impl<E: EthSpec> LocalNetwork<E> {
206206
beacon_config.network.enr_tcp4_port = Some(BOOTNODE_PORT.try_into().expect("non zero"));
207207
beacon_config.network.discv5_config.table_filter = |_| true;
208208

209-
let execution_node = LocalExecutionNode::new(
210-
self.context.service_context("boot_node_el".into()),
211-
mock_execution_config,
212-
);
209+
let execution_node = LocalExecutionNode::new(self.context.clone(), mock_execution_config);
213210

214211
beacon_config.execution_layer = Some(execution_layer::Config {
215212
execution_endpoint: Some(SensitiveUrl::parse(&execution_node.server.url()).unwrap()),
@@ -218,11 +215,7 @@ impl<E: EthSpec> LocalNetwork<E> {
218215
..Default::default()
219216
});
220217

221-
let beacon_node = LocalBeaconNode::production(
222-
self.context.service_context("boot_node".into()),
223-
beacon_config,
224-
)
225-
.await?;
218+
let beacon_node = LocalBeaconNode::production(self.context.clone(), beacon_config).await?;
226219

227220
Ok((beacon_node, execution_node))
228221
}
@@ -252,10 +245,7 @@ impl<E: EthSpec> LocalNetwork<E> {
252245
mock_execution_config.server_config.listen_port = EXECUTION_PORT + count;
253246

254247
// Construct execution node.
255-
let execution_node = LocalExecutionNode::new(
256-
self.context.service_context(format!("node_{}_el", count)),
257-
mock_execution_config,
258-
);
248+
let execution_node = LocalExecutionNode::new(self.context.clone(), mock_execution_config);
259249

260250
// Pair the beacon node and execution node.
261251
beacon_config.execution_layer = Some(execution_layer::Config {
@@ -266,11 +256,7 @@ impl<E: EthSpec> LocalNetwork<E> {
266256
});
267257

268258
// Construct beacon node using the config,
269-
let beacon_node = LocalBeaconNode::production(
270-
self.context.service_context(format!("node_{}", count)),
271-
beacon_config,
272-
)
273-
.await?;
259+
let beacon_node = LocalBeaconNode::production(self.context.clone(), beacon_config).await?;
274260

275261
Ok((beacon_node, execution_node))
276262
}
@@ -343,9 +329,7 @@ impl<E: EthSpec> LocalNetwork<E> {
343329
beacon_node: usize,
344330
validator_files: ValidatorFiles,
345331
) -> Result<(), String> {
346-
let context = self
347-
.context
348-
.service_context(format!("validator_{}", beacon_node));
332+
let context = self.context.clone();
349333
let self_1 = self.clone();
350334
let socket_addr = {
351335
let read_lock = self.beacon_nodes.read();
@@ -401,13 +385,10 @@ impl<E: EthSpec> LocalNetwork<E> {
401385
pub async fn add_validator_client_with_fallbacks(
402386
&self,
403387
mut validator_config: ValidatorConfig,
404-
validator_index: usize,
405388
beacon_nodes: Vec<usize>,
406389
validator_files: ValidatorFiles,
407390
) -> Result<(), String> {
408-
let context = self
409-
.context
410-
.service_context(format!("validator_{}", validator_index));
391+
let context = self.context.clone();
411392
let self_1 = self.clone();
412393
let mut beacon_node_urls = vec![];
413394
for beacon_node in beacon_nodes {

0 commit comments

Comments
 (0)