Implement Display and clean validator output
This commit is contained in:
parent
405ea619e2
commit
68b33620c2
@ -120,7 +120,7 @@ impl TestingBeaconStateBuilder {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let genesis_time = 1553753928; // arbitrary
|
||||
let genesis_time = 1553776331; // arbitrary
|
||||
|
||||
let mut state = BeaconState::genesis(
|
||||
genesis_time,
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use types::{AttestationDuty, Epoch, PublicKey, Slot};
|
||||
|
||||
@ -55,11 +56,25 @@ impl EpochDuty {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for EpochDuty {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut display_block = String::from("None");
|
||||
if let Some(block_slot) = self.block_production_slot {
|
||||
display_block = block_slot.to_string();
|
||||
}
|
||||
write!(
|
||||
f,
|
||||
"produce block slot: {}, attestation slot: {}, attestation shard: {}",
|
||||
display_block, self.attestation_slot, self.attestation_shard
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps a list of public keys (many validators) to an EpochDuty.
|
||||
pub type EpochDuties = HashMap<PublicKey, Option<EpochDuty>>;
|
||||
|
||||
pub enum EpochDutiesMapError {
|
||||
Poisoned,
|
||||
UnknownEpoch,
|
||||
UnknownValidator,
|
||||
}
|
||||
|
@ -82,7 +82,8 @@ impl<U: BeaconNode> DutiesManager<U> {
|
||||
info!(log, "Duties changed (potential re-org)"; "epoch" => epoch, "duties" => format!("{:?}", duties))
|
||||
}
|
||||
Ok(UpdateOutcome::NewDuties(epoch, duties)) => {
|
||||
info!(log, "New duties obtained"; "epoch" => epoch, "duties" => format!("{:?}", duties))
|
||||
info!(log, "New duties obtained"; "epoch" => epoch);
|
||||
print_duties(&log, duties);
|
||||
}
|
||||
};
|
||||
Ok(Async::Ready(()))
|
||||
@ -126,13 +127,22 @@ impl<T> From<std::sync::PoisonError<T>> for Error {
|
||||
impl From<EpochDutiesMapError> for Error {
|
||||
fn from(e: EpochDutiesMapError) -> Error {
|
||||
match e {
|
||||
EpochDutiesMapError::Poisoned => Error::EpochMapPoisoned,
|
||||
EpochDutiesMapError::UnknownEpoch => Error::UnknownEpoch,
|
||||
EpochDutiesMapError::UnknownValidator => Error::UnknownValidator,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_duties(log: &slog::Logger, duties: EpochDuties) {
|
||||
for (pk, duty) in duties.iter() {
|
||||
if let Some(display_duty) = duty {
|
||||
info!(log, "Validator: {}",pk; "Duty" => format!("{}",display_duty));
|
||||
} else {
|
||||
info!(log, "Validator: {}",pk; "Duty" => "None");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Modify tests for new Duties Manager form
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
Loading…
Reference in New Issue
Block a user