Skip to content

Commit 713eae6

Browse files
committed
Use blocking task for DB op
1 parent bba7a11 commit 713eae6

File tree

2 files changed

+15
-4
lines changed
  • validator_client
    • lighthouse_validator_store/src
    • validator_store/src

2 files changed

+15
-4
lines changed

validator_client/lighthouse_validator_store/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore for LighthouseValidatorS
883883
}
884884

885885
async fn sign_attestations(
886-
&self,
886+
self: &Arc<Self>,
887887
mut attestations: Vec<(PublicKeyBytes, usize, Attestation<Self::E>)>,
888888
) -> Result<Vec<Attestation<E>>, Error> {
889889
// Sign all attestations concurrently.
@@ -934,8 +934,18 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore for LighthouseValidatorS
934934
return Ok(vec![]);
935935
}
936936

937-
// Check slashing protection and insert into database.
938-
let safe_attestations = self.slashing_protect_attestations(signed_attestations)?;
937+
// Check slashing protection and insert into database. Use a dedicated blocking thread
938+
// to avoid clogging the async executor with blocking database I/O.
939+
let validator_store = self.clone();
940+
let safe_attestations = self
941+
.task_executor
942+
.spawn_blocking_handle(
943+
move || validator_store.slashing_protect_attestations(signed_attestations),
944+
"slashing_protect_attestations",
945+
)
946+
.ok_or(Error::ExecutorError)?
947+
.await
948+
.map_err(|_| Error::ExecutorError)??;
939949
Ok(safe_attestations)
940950
}
941951

validator_client/validator_store/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub enum Error<T> {
2222
GreaterThanCurrentEpoch { epoch: Epoch, current_epoch: Epoch },
2323
UnableToSignAttestation(AttestationError),
2424
SpecificError(T),
25+
ExecutorError,
2526
Middleware(String),
2627
}
2728

@@ -108,7 +109,7 @@ pub trait ValidatorStore: Send + Sync {
108109
/// Only successfully signed attestations that pass slashing protection are returned.
109110
#[allow(clippy::type_complexity)]
110111
fn sign_attestations(
111-
&self,
112+
self: &Arc<Self>,
112113
attestations: Vec<(PublicKeyBytes, usize, Attestation<Self::E>)>,
113114
) -> impl Future<Output = Result<Vec<Attestation<Self::E>>, Error<Self::Error>>> + Send;
114115

0 commit comments

Comments
 (0)