Skip to content

Commit

Permalink
fix at first is validator then is not validator
Browse files Browse the repository at this point in the history
  • Loading branch information
rink1969 committed Mar 13, 2024
1 parent f099d80 commit b7accf0
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ pub struct Peer {

// slog logger
logger: Logger,

node_addr: Vec<u8>,
}

impl Peer {
Expand Down Expand Up @@ -398,6 +400,8 @@ impl Peer {
send_time_out_to_transferee: false,

logger: logger.clone(),

node_addr: node_addr.clone(),
};

this.maybe_pending_conf_change();
Expand Down Expand Up @@ -444,14 +448,18 @@ impl Peer {
// used for transferring leader when we can't get a valid proposal from controller
let mut last_time_start_fetching: Option<Instant> = None;

let mut is_validator = true;

loop {
tokio::select! {
// timing
_ = &mut tick_timeout => {
self.core.tick();
tick_timeout
.as_mut()
.reset(time::Instant::now() + tick_interval);
if is_validator {
self.core.tick();
tick_timeout
.as_mut()
.reset(time::Instant::now() + tick_interval);
}
}
_ = &mut fetching_timeout, if self.is_leader() && fetching_proposal.is_none() && self.pending_proposal.is_none() => {
// fetching new proposal
Expand Down Expand Up @@ -485,7 +493,21 @@ impl Peer {
}

// reconfigure
Some(_) = self.controller_rx.recv() => {}
Some(config) = self.controller_rx.recv() => {
let mut trigger_config = config;
// read all reconfigure messages in channel
// when start a new node, sync blocks quickly, there will be many reconfigure messages in channel
// we only need proc latest one
while let Ok(config) = self.controller_rx.try_recv() {
trigger_config = config;
}

is_validator = trigger_config.validators.contains(&self.node_addr);
info!(
self.logger,
"get reconfigure from controller, height is {}, now is_validator = {}", trigger_config.height, is_validator
);
}

// raft msg from remote peers
Some(raft_msg) = self.peer_rx.recv() => {
Expand Down

0 comments on commit b7accf0

Please sign in to comment.