mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
Use spawn_async in ByRoot handling workers (#5557)
* Use spawn_async in ByRoot handling workers * box large variants
This commit is contained in:
@@ -571,7 +571,7 @@ pub enum BlockingOrAsync {
|
||||
/// queuing specifics.
|
||||
pub enum Work<E: EthSpec> {
|
||||
GossipAttestation {
|
||||
attestation: GossipAttestationPackage<E>,
|
||||
attestation: Box<GossipAttestationPackage<E>>,
|
||||
process_individual: Box<dyn FnOnce(GossipAttestationPackage<E>) + Send + Sync>,
|
||||
process_batch: Box<dyn FnOnce(Vec<GossipAttestationPackage<E>>) + Send + Sync>,
|
||||
},
|
||||
@@ -583,7 +583,7 @@ pub enum Work<E: EthSpec> {
|
||||
process_batch: Box<dyn FnOnce(Vec<GossipAttestationPackage<E>>) + Send + Sync>,
|
||||
},
|
||||
GossipAggregate {
|
||||
aggregate: GossipAggregatePackage<E>,
|
||||
aggregate: Box<GossipAggregatePackage<E>>,
|
||||
process_individual: Box<dyn FnOnce(GossipAggregatePackage<E>) + Send + Sync>,
|
||||
process_batch: Box<dyn FnOnce(Vec<GossipAggregatePackage<E>>) + Send + Sync>,
|
||||
},
|
||||
@@ -624,8 +624,8 @@ pub enum Work<E: EthSpec> {
|
||||
ChainSegment(AsyncFn),
|
||||
ChainSegmentBackfill(AsyncFn),
|
||||
Status(BlockingFn),
|
||||
BlocksByRangeRequest(BlockingFnWithManualSendOnIdle),
|
||||
BlocksByRootsRequest(BlockingFnWithManualSendOnIdle),
|
||||
BlocksByRangeRequest(AsyncFn),
|
||||
BlocksByRootsRequest(AsyncFn),
|
||||
BlobsByRangeRequest(BlockingFn),
|
||||
BlobsByRootsRequest(BlockingFn),
|
||||
GossipBlsToExecutionChange(BlockingFn),
|
||||
@@ -1015,7 +1015,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
|
||||
process_individual: _,
|
||||
process_batch,
|
||||
} => {
|
||||
aggregates.push(aggregate);
|
||||
aggregates.push(*aggregate);
|
||||
if process_batch_opt.is_none() {
|
||||
process_batch_opt = Some(process_batch);
|
||||
}
|
||||
@@ -1075,7 +1075,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
|
||||
process_individual: _,
|
||||
process_batch,
|
||||
} => {
|
||||
attestations.push(attestation);
|
||||
attestations.push(*attestation);
|
||||
if process_batch_opt.is_none() {
|
||||
process_batch_opt = Some(process_batch);
|
||||
}
|
||||
@@ -1445,7 +1445,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
|
||||
process_individual,
|
||||
process_batch: _,
|
||||
} => task_spawner.spawn_blocking(move || {
|
||||
process_individual(attestation);
|
||||
process_individual(*attestation);
|
||||
}),
|
||||
Work::GossipAttestationBatch {
|
||||
attestations,
|
||||
@@ -1458,7 +1458,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
|
||||
process_individual,
|
||||
process_batch: _,
|
||||
} => task_spawner.spawn_blocking(move || {
|
||||
process_individual(aggregate);
|
||||
process_individual(*aggregate);
|
||||
}),
|
||||
Work::GossipAggregateBatch {
|
||||
aggregates,
|
||||
@@ -1493,7 +1493,7 @@ impl<E: EthSpec> BeaconProcessor<E> {
|
||||
task_spawner.spawn_blocking(process_fn)
|
||||
}
|
||||
Work::BlocksByRangeRequest(work) | Work::BlocksByRootsRequest(work) => {
|
||||
task_spawner.spawn_blocking_with_manual_send_idle(work)
|
||||
task_spawner.spawn_async(work)
|
||||
}
|
||||
Work::ChainSegmentBackfill(process_fn) => task_spawner.spawn_async(process_fn),
|
||||
Work::ApiRequestP0(process_fn) | Work::ApiRequestP1(process_fn) => match process_fn {
|
||||
@@ -1555,23 +1555,6 @@ impl TaskSpawner {
|
||||
WORKER_TASK_NAME,
|
||||
)
|
||||
}
|
||||
|
||||
/// Spawn a blocking task, passing the `SendOnDrop` into the task.
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
/// Users must ensure the `SendOnDrop` is dropped at the appropriate time!
|
||||
pub fn spawn_blocking_with_manual_send_idle<F>(self, task: F)
|
||||
where
|
||||
F: FnOnce(SendOnDrop) + Send + 'static,
|
||||
{
|
||||
self.executor.spawn_blocking(
|
||||
|| {
|
||||
task(self.send_idle_on_drop);
|
||||
},
|
||||
WORKER_TASK_NAME,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// This struct will send a message on `self.tx` when it is dropped. An error will be logged on
|
||||
|
||||
Reference in New Issue
Block a user