Set graffiti per validator (#2044)

## Issue Addressed

Resolves #1944 

## Proposed Changes

Adds a "graffiti" key to the `validator_definitions.yml`. Setting the key will override anything passed through the validator `--graffiti` flag. 
Returns an error if the value for the graffiti key is > 32 bytes instead of silently truncating.
This commit is contained in:
Pawan Dhananjay
2021-03-02 22:35:46 +00:00
parent 1c507c588e
commit da8791abd7
18 changed files with 428 additions and 14 deletions

View File

@@ -20,7 +20,7 @@ use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io;
use std::path::PathBuf;
use types::{Keypair, PublicKey};
use types::{Graffiti, Keypair, PublicKey};
use crate::key_cache;
use crate::key_cache::KeyCache;
@@ -86,6 +86,7 @@ pub enum SigningMethod {
/// A validator that is ready to sign messages.
pub struct InitializedValidator {
signing_method: SigningMethod,
graffiti: Option<Graffiti>,
}
impl InitializedValidator {
@@ -213,6 +214,7 @@ impl InitializedValidator {
voting_keystore: voting_keystore.clone(),
voting_keypair,
},
graffiti: def.graffiti.map(Into::into),
})
}
}
@@ -363,6 +365,11 @@ impl InitializedValidators {
.map(|def| def.enabled)
}
/// Returns the `graffiti` for a given public key specified in the `ValidatorDefinitions`.
pub fn graffiti(&self, public_key: &PublicKey) -> Option<Graffiti> {
self.validators.get(public_key).and_then(|v| v.graffiti)
}
/// Sets the `InitializedValidator` and `ValidatorDefinition` `enabled` values.
///
/// ## Notes
@@ -533,7 +540,7 @@ impl InitializedValidators {
info!(
self.log,
"Enabled validator";
"voting_pubkey" => format!("{:?}", def.voting_public_key)
"voting_pubkey" => format!("{:?}", def.voting_public_key),
);
if let Some(lockfile_path) = existing_lockfile_path {