lighthouse/validator_client/src
Maksim Shcherbo 788a4b718f Optimise update_validators by decrypting key cache only when necessary (#4126)
## Title

Optimise `update_validators` by decrypting key cache only when necessary

## Issue Addressed

Resolves [#3968: Slow performance of validator client PATCH API with hundreds of keys](https://github.com/sigp/lighthouse/issues/3968)

## Proposed Changes

1. Add a check to determine if there is at least one local definition before decrypting the key cache.
2. Assign an empty `KeyCache` when all definitions are of the `Web3Signer` type.
3. Perform cache-related operations (e.g., saving the modified key cache) only if there are local definitions.

## Additional Info

This PR addresses the excessive CPU usage and slow performance experienced when using the `PATCH lighthouse/validators/{pubkey}` request with a large number of keys. The issue was caused by the key cache using cryptography to decipher and cipher the cache entities every time the request was made. This operation called `scrypt`, which was very slow and required a lot of memory when there were many concurrent requests.

These changes have no impact on the overall functionality but can lead to significant performance improvements when working with remote signers. Importantly, the key cache is never used when there are only `Web3Signer` definitions, avoiding the expensive operation of decrypting the key cache in such cases.

Co-authored-by: Maksim Shcherbo <max.shcherbo@consensys.net>
2023-03-29 02:56:39 +00:00
..
duties_service Validator registration request failures do not cause us to mark BNs offline (#3488) 2022-08-29 11:35:59 +00:00
http_api merge upstream/unstable 2022-12-28 14:43:25 -06:00
http_metrics Add VC metric for primary BN latency (#4051) 2023-03-06 04:08:49 +00:00
signing_method Clean capella (#4019) 2023-03-01 03:19:02 +00:00
attestation_service.rs Validator registration request failures do not cause us to mark BNs offline (#3488) 2022-08-29 11:35:59 +00:00
beacon_node_fallback.rs Log a WARN in the VC for a mismatched Capella fork epoch (#4050) 2023-03-06 04:08:48 +00:00
block_service.rs Optimise attestation selection proof signing (#4033) 2023-03-05 23:43:31 +00:00
check_synced.rs Remove duplicate log in BN fallback (#2116) 2021-01-06 03:01:48 +00:00
cli.rs Add latency measurement service to VC (#4024) 2023-03-05 23:43:29 +00:00
config.rs Add latency measurement service to VC (#4024) 2023-03-05 23:43:29 +00:00
doppelganger_service.rs Clippy lints for rust 1.66 (#3810) 2022-12-16 04:04:00 +00:00
duties_service.rs Optimise attestation selection proof signing (#4033) 2023-03-05 23:43:31 +00:00
graffiti_file.rs Rust 1.54.0 lints (#2483) 2021-07-30 01:11:47 +00:00
initialized_validators.rs Optimise update_validators by decrypting key cache only when necessary (#4126) 2023-03-29 02:56:39 +00:00
key_cache.rs Clippy lints for rust 1.66 (#3810) 2022-12-16 04:04:00 +00:00
latency.rs Add VC metric for primary BN latency (#4051) 2023-03-06 04:08:49 +00:00
lib.rs Add latency measurement service to VC (#4024) 2023-03-05 23:43:29 +00:00
notifier.rs Add new VC metrics for beacon node availability (#3193) 2022-05-26 02:05:16 +00:00
preparation_service.rs Publish subscriptions to all beacon nodes (#3529) 2022-09-28 19:53:35 +00:00
signing_method.rs cleanup 2022-12-30 11:00:14 -05:00
sync_committee_service.rs Sync committee sign bn fallback (#3624) 2022-11-13 22:40:43 +00:00
validator_store.rs Fixed Compiler Warnings & Failing Tests (#3771) 2022-12-03 10:42:12 +11:00