|
|
@@ -248,7 +248,7 @@ impl ValidatorState {
|
|
|
/// Find slot leader, using a simple hash method.
|
|
|
/// Leader calculation is based on how many nodes are participating
|
|
|
/// in the network.
|
|
|
- pub fn slot_leader(&mut self) -> Address {
|
|
|
+ pub fn slot_leader(&mut self) -> Participant {
|
|
|
let slot = self.current_slot();
|
|
|
// DefaultHasher is used to hash the slot number
|
|
|
// because it produces a number string which then can be modulated by the len.
|
|
|
@@ -258,13 +258,13 @@ impl ValidatorState {
|
|
|
let pos = hasher.finish() % (self.consensus.participants.len() as u64);
|
|
|
// Since BTreeMap orders by key in asceding order, each node will have
|
|
|
// the same key in calculated position.
|
|
|
- self.consensus.participants.iter().nth(pos as usize).unwrap().1.address
|
|
|
+ self.consensus.participants.iter().nth(pos as usize).unwrap().1.clone()
|
|
|
}
|
|
|
|
|
|
/// Check if we're the current slot leader
|
|
|
pub fn is_slot_leader(&mut self) -> bool {
|
|
|
let address = self.address;
|
|
|
- address == self.slot_leader()
|
|
|
+ address == self.slot_leader().address
|
|
|
}
|
|
|
|
|
|
/// Generate a block proposal for the current slot, containing all
|
|
|
@@ -294,7 +294,6 @@ impl ValidatorState {
|
|
|
let signed_proposal = self.secret.sign(&header.headerhash().as_bytes()[..]);
|
|
|
|
|
|
Ok(Some(BlockProposal::new(
|
|
|
- self.public,
|
|
|
signed_proposal,
|
|
|
self.address,
|
|
|
header,
|
|
|
@@ -371,16 +370,16 @@ impl ValidatorState {
|
|
|
self.refresh_participants()?;
|
|
|
|
|
|
let leader = self.slot_leader();
|
|
|
- if leader != proposal.address {
|
|
|
+ if leader.address != proposal.address {
|
|
|
warn!(
|
|
|
"Received proposal not from slot leader ({}), but from ({})",
|
|
|
- leader,
|
|
|
+ leader.address.to_string(),
|
|
|
proposal.address.to_string()
|
|
|
);
|
|
|
return Ok(None)
|
|
|
}
|
|
|
|
|
|
- if !proposal
|
|
|
+ if !leader
|
|
|
.public_key
|
|
|
.verify(proposal.block.header.headerhash().as_bytes(), &proposal.signature)
|
|
|
{
|
|
|
@@ -819,7 +818,7 @@ impl ValidatorState {
|
|
|
None => {
|
|
|
// Slot leader is always quarantined, to cover the case they become inactive the slot before
|
|
|
// becoming the leader. This can be used for slashing in the future.
|
|
|
- if participant.address == leader {
|
|
|
+ if participant.address == leader.address {
|
|
|
debug!(
|
|
|
"refresh_participants(): Quaranteening leader: {:?} (joined {:?}, voted {:?})",
|
|
|
participant.address.to_string(),
|