mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 05:18:30 +00:00
Updated validator client to do better logging, including of JSON serialised signatures and such, for debugging purposes.
This commit is contained in:
@@ -6,7 +6,8 @@ pub use self::beacon_node_block::{BeaconNodeError, PublishOutcome};
|
||||
pub use self::grpc::BeaconBlockGrpcClient;
|
||||
use crate::signer::Signer;
|
||||
use core::marker::PhantomData;
|
||||
use slog::{error, info, warn};
|
||||
use serde_json;
|
||||
use slog::{error, info, trace, warn};
|
||||
use std::sync::Arc;
|
||||
use tree_hash::{SignedRoot, TreeHash};
|
||||
use types::{BeaconBlock, ChainSpec, Domain, EthSpec, Fork, Slot};
|
||||
@@ -53,27 +54,29 @@ pub struct BlockProducer<'a, B: BeaconNodeBlock, S: Signer, E: EthSpec> {
|
||||
pub slots_per_epoch: u64,
|
||||
/// Mere vessel for E.
|
||||
pub _phantom: PhantomData<E>,
|
||||
/// The logger, for logging
|
||||
pub log: slog::Logger,
|
||||
}
|
||||
|
||||
impl<'a, B: BeaconNodeBlock, S: Signer, E: EthSpec> BlockProducer<'a, B, S, E> {
|
||||
/// Handle outputs and results from block production.
|
||||
pub fn handle_produce_block(&mut self, log: slog::Logger) {
|
||||
pub fn handle_produce_block(&mut self) {
|
||||
match self.produce_block() {
|
||||
Ok(ValidatorEvent::BlockProduced(_slot)) => {
|
||||
info!(log, "Block produced"; "Validator" => format!("{}", self.signer))
|
||||
info!(self.log, "Block produced"; "Validator" => format!("{}", self.signer))
|
||||
}
|
||||
Err(e) => error!(log, "Block production error"; "Error" => format!("{:?}", e)),
|
||||
Err(e) => error!(self.log, "Block production error"; "Error" => format!("{:?}", e)),
|
||||
Ok(ValidatorEvent::SignerRejection(_slot)) => {
|
||||
error!(log, "Block production error"; "Error" => "Signer Could not sign the block".to_string())
|
||||
error!(self.log, "Block production error"; "Error" => "Signer Could not sign the block".to_string())
|
||||
}
|
||||
Ok(ValidatorEvent::SlashableBlockNotProduced(_slot)) => {
|
||||
error!(log, "Block production error"; "Error" => "Rejected the block as it could have been slashed".to_string())
|
||||
error!(self.log, "Block production error"; "Error" => "Rejected the block as it could have been slashed".to_string())
|
||||
}
|
||||
Ok(ValidatorEvent::BeaconNodeUnableToProduceBlock(_slot)) => {
|
||||
error!(log, "Block production error"; "Error" => "Beacon node was unable to produce a block".to_string())
|
||||
error!(self.log, "Block production error"; "Error" => "Beacon node was unable to produce a block".to_string())
|
||||
}
|
||||
Ok(v) => {
|
||||
warn!(log, "Unknown result for block production"; "Error" => format!("{:?}",v))
|
||||
warn!(self.log, "Unknown result for block production"; "Error" => format!("{:?}",v))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,14 +93,21 @@ impl<'a, B: BeaconNodeBlock, S: Signer, E: EthSpec> BlockProducer<'a, B, S, E> {
|
||||
/// slashing.
|
||||
pub fn produce_block(&mut self) -> Result<ValidatorEvent, Error> {
|
||||
let epoch = self.slot.epoch(self.slots_per_epoch);
|
||||
trace!(self.log, "Producing block"; "epoch" => epoch);
|
||||
|
||||
let message = epoch.tree_hash_root();
|
||||
let randao_reveal = match self.signer.sign_message(
|
||||
&message,
|
||||
self.spec.get_domain(epoch, Domain::Randao, &self.fork),
|
||||
) {
|
||||
None => return Ok(ValidatorEvent::SignerRejection(self.slot)),
|
||||
Some(signature) => signature,
|
||||
None => {
|
||||
warn!(self.log, "Signing rejected"; "message" => format!("{:?}", message));
|
||||
return Ok(ValidatorEvent::SignerRejection(self.slot));
|
||||
}
|
||||
Some(signature) => {
|
||||
info!(self.log, "Signed tree_hash_root for randao_reveal"; "message" => format!("{:?}", message), "signature" => serde_json::to_string(&signature).expect("We should always be able to serialize a signature as JSON."));
|
||||
signature
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(block) = self
|
||||
|
||||
Reference in New Issue
Block a user