Merge branch 'unstable' into validator-manager

This commit is contained in:
Paul Hauner
2023-05-15 15:54:31 +10:00
400 changed files with 13266 additions and 12760 deletions

View File

@@ -1015,7 +1015,23 @@ impl InitializedValidators {
let cache =
KeyCache::open_or_create(&self.validators_dir).map_err(Error::UnableToOpenKeyCache)?;
let mut key_cache = self.decrypt_key_cache(cache, &mut key_stores).await?;
// Check if there is at least one local definition.
let has_local_definitions = self.definitions.as_slice().iter().any(|def| {
matches!(
def.signing_definition,
SigningDefinition::LocalKeystore { .. }
)
});
// Only decrypt cache when there is at least one local definition.
// Decrypting cache is a very expensive operation which is never used for web3signer.
let mut key_cache = if has_local_definitions {
self.decrypt_key_cache(cache, &mut key_stores).await?
} else {
// Assign an empty KeyCache if all definitions are of the Web3Signer type.
KeyCache::new()
};
let mut disabled_uuids = HashSet::new();
for def in self.definitions.as_slice() {
@@ -1141,13 +1157,16 @@ impl InitializedValidators {
);
}
}
for uuid in disabled_uuids {
key_cache.remove(&uuid);
if has_local_definitions {
for uuid in disabled_uuids {
key_cache.remove(&uuid);
}
}
let validators_dir = self.validators_dir.clone();
let log = self.log.clone();
if key_cache.is_modified() {
if has_local_definitions && key_cache.is_modified() {
tokio::task::spawn_blocking(move || {
match key_cache.save(validators_dir) {
Err(e) => warn!(