Add short ID to logging for BLS public keys

This commit is contained in:
Paul Hauner 2019-01-22 09:05:34 +11:00
parent 87ffeaa833
commit 992f2101c2
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
6 changed files with 39 additions and 24 deletions

View File

@ -5,6 +5,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
bls = { path = "../beacon_chain/utils/bls" }
grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] } grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] }
protobuf = "2.0.2" protobuf = "2.0.2"
protos = { path = "../protos" } protos = { path = "../protos" }
@ -15,4 +16,5 @@ futures = "0.1.23"
slog = "^2.2.3" slog = "^2.2.3"
slog-term = "^2.4.0" slog-term = "^2.4.0"
slog-async = "^2.3.0" slog-async = "^2.3.0"
ssz = { path = "../beacon_chain/utils/ssz" }
tokio = "0.1" tokio = "0.1"

View File

@ -1,10 +1,12 @@
use bls::PublicKey;
use futures::Future; use futures::Future;
use grpcio::{RpcContext, UnarySink}; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
use protos::services::{ use protos::services::{
IndexResponse, ProposeBlockSlotRequest, ProposeBlockSlotResponse, PublicKey as PublicKeyRequest, IndexResponse, ProposeBlockSlotRequest, ProposeBlockSlotResponse, PublicKey as PublicKeyRequest,
}; };
use protos::services_grpc::ValidatorService; use protos::services_grpc::ValidatorService;
use slog::{debug, Logger}; use slog::{debug, Logger};
use ssz::Decodable;
#[derive(Clone)] #[derive(Clone)]
pub struct ValidatorServiceInstance { pub struct ValidatorServiceInstance {
@ -18,17 +20,27 @@ impl ValidatorService for ValidatorServiceInstance {
req: PublicKeyRequest, req: PublicKeyRequest,
sink: UnarySink<IndexResponse>, sink: UnarySink<IndexResponse>,
) { ) {
debug!(self.log, "RPC got ValidatorIndex"; "public_key" => format!("{:x?}", req.get_public_key())); if let Ok((public_key, _)) = PublicKey::ssz_decode(req.get_public_key(), 0) {
debug!(self.log, "RPC request"; "endpoint" => "ValidatorIndex", "public_key" => public_key.concatenated_hex_id());
let mut resp = IndexResponse::new(); let mut resp = IndexResponse::new();
// TODO: return a legit value. // TODO: return a legit value.
resp.set_index(1); resp.set_index(1);
let f = sink let f = sink
.success(resp) .success(resp)
.map_err(move |e| println!("failed to reply {:?}: {:?}", req, e)); .map_err(move |e| println!("failed to reply {:?}: {:?}", req, e));
ctx.spawn(f) ctx.spawn(f)
} else {
let f = sink
.fail(RpcStatus::new(
RpcStatusCode::InvalidArgument,
Some("Invalid public_key".to_string()),
))
.map_err(move |e| println!("failed to reply {:?}: {:?}", req, e));
ctx.spawn(f)
}
} }
fn propose_block_slot( fn propose_block_slot(
@ -37,7 +49,7 @@ impl ValidatorService for ValidatorServiceInstance {
req: ProposeBlockSlotRequest, req: ProposeBlockSlotRequest,
sink: UnarySink<ProposeBlockSlotResponse>, sink: UnarySink<ProposeBlockSlotResponse>,
) { ) {
debug!(self.log, "RPC got ProposeBlockSlot"; "epoch" => req.get_epoch(), "validator_index" => req.get_validator_index()); debug!(self.log, "RPC request"; "endpoint" => "ProposeBlockSlot", "epoch" => req.get_epoch(), "validator_index" => req.get_validator_index());
let mut resp = ProposeBlockSlotResponse::new(); let mut resp = ProposeBlockSlotResponse::new();

View File

@ -1,8 +1,6 @@
use super::traits::{BeaconNode, BeaconNodeError}; use super::traits::{BeaconNode, BeaconNodeError};
use super::EpochDuties; use super::EpochDuties;
use protos::services::{ use protos::services::{ProposeBlockSlotRequest, PublicKey as IndexRequest};
IndexResponse, ProposeBlockSlotRequest, ProposeBlockSlotResponse, PublicKey as IndexRequest,
};
use protos::services_grpc::ValidatorServiceClient; use protos::services_grpc::ValidatorServiceClient;
use ssz::ssz_encode; use ssz::ssz_encode;
use types::PublicKey; use types::PublicKey;

View File

@ -33,7 +33,7 @@ pub type EpochDutiesMap = HashMap<u64, EpochDuties>;
#[derive(Debug, PartialEq, Clone, Copy)] #[derive(Debug, PartialEq, Clone, Copy)]
pub enum PollOutcome { pub enum PollOutcome {
NoChange(u64, EpochDuties), NoChange(u64),
NewDuties(u64, EpochDuties), NewDuties(u64, EpochDuties),
DutiesChanged(u64, EpochDuties), DutiesChanged(u64, EpochDuties),
UnknownValidatorOrEpoch(u64), UnknownValidatorOrEpoch(u64),
@ -80,7 +80,7 @@ impl<T: SlotClock, U: BeaconNode> DutiesManager<T, U> {
// If these duties were known, check to see if they're updates or identical. // If these duties were known, check to see if they're updates or identical.
let result = if let Some(known_duties) = map.get(&epoch) { let result = if let Some(known_duties) = map.get(&epoch) {
if *known_duties == duties { if *known_duties == duties {
Ok(PollOutcome::NoChange(epoch, duties)) Ok(PollOutcome::NoChange(epoch))
} else { } else {
Ok(PollOutcome::DutiesChanged(epoch, duties)) Ok(PollOutcome::DutiesChanged(epoch, duties))
} }
@ -129,25 +129,27 @@ mod tests {
}; };
// Configure response from the BeaconNode. // Configure response from the BeaconNode.
beacon_node.set_next_shuffling_result(Ok(Some(EpochDuties { let duties = EpochDuties {
validator_index: 0, validator_index: 0,
block_production_slot: Some(10), block_production_slot: Some(10),
}))); };
beacon_node.set_next_shuffling_result(Ok(Some(duties)));
// Get the duties for the first time... // Get the duties for the first time...
assert_eq!(manager.poll(), Ok(PollOutcome::NewDuties)); assert_eq!(manager.poll(), Ok(PollOutcome::NewDuties(0, duties)));
// Get the same duties again... // Get the same duties again...
assert_eq!(manager.poll(), Ok(PollOutcome::NoChange)); assert_eq!(manager.poll(), Ok(PollOutcome::NoChange(0)));
// Return new duties. // Return new duties.
beacon_node.set_next_shuffling_result(Ok(Some(EpochDuties { let duties = EpochDuties {
validator_index: 0, validator_index: 0,
block_production_slot: Some(11), block_production_slot: Some(11),
}))); };
assert_eq!(manager.poll(), Ok(PollOutcome::DutiesChanged)); beacon_node.set_next_shuffling_result(Ok(Some(duties)));
assert_eq!(manager.poll(), Ok(PollOutcome::DutiesChanged(0, duties)));
// Return no duties. // Return no duties.
beacon_node.set_next_shuffling_result(Ok(None)); beacon_node.set_next_shuffling_result(Ok(None));
assert_eq!(manager.poll(), Ok(PollOutcome::UnknownValidatorOrEpoch)); assert_eq!(manager.poll(), Ok(PollOutcome::UnknownValidatorOrEpoch(0)));
} }
} }

View File

@ -17,7 +17,7 @@ impl<T: SlotClock, U: BeaconNode> DutiesManagerService<T, U> {
Err(error) => { Err(error) => {
error!(self.log, "Epoch duties poll error"; "error" => format!("{:?}", error)) error!(self.log, "Epoch duties poll error"; "error" => format!("{:?}", error))
} }
Ok(PollOutcome::NoChange(epoch, _)) => { Ok(PollOutcome::NoChange(epoch)) => {
debug!(self.log, "No change in duties"; "epoch" => epoch) debug!(self.log, "No change in duties"; "epoch" => epoch)
} }
Ok(PollOutcome::DutiesChanged(epoch, duties)) => { Ok(PollOutcome::DutiesChanged(epoch, duties)) => {

View File

@ -103,6 +103,7 @@ fn main() {
let mut threads = vec![]; let mut threads = vec![];
for keypair in keypairs { for keypair in keypairs {
info!(log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
let duties_map = Arc::new(RwLock::new(EpochDutiesMap::new())); let duties_map = Arc::new(RwLock::new(EpochDutiesMap::new()));
let duties_manager_thread = { let duties_manager_thread = {