Skip to content

Commit

Permalink
fix proc reconfigure msg in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rink1969 committed Mar 13, 2024
1 parent d5b1a66 commit f099d80
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Peer {
};

// Communicate with controller
let (controller_tx, mut controller_rx) = mpsc::channel::<ConsensusConfiguration>(1);
let (controller_tx, mut controller_rx) = mpsc::channel::<ConsensusConfiguration>(1000);
let raft_svc = RaftConsensusService(controller_tx);

// Network grpc client
Expand Down Expand Up @@ -241,8 +241,19 @@ impl Peer {
info!(logger, "waiting for `reconfigure` from controller..");
let (wants_campaign, trigger_config) = loop {
tokio::time::sleep(Duration::from_secs(3)).await;
match controller_rx.try_recv() {
Ok(mut trigger_config) => {
let mut opt_trigger_config = None;
// 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) = controller_rx.try_recv() {
opt_trigger_config = Some(config);
}
match opt_trigger_config {
Some(mut trigger_config) => {
info!(
logger,
"get reconfigure from controller, height is {}", trigger_config.height
);
// if recorded_height == trigger_height + 1, try to recommit entry
let recorded_height = storage.get_block_height();
let trigger_height = trigger_config.height;
Expand Down Expand Up @@ -309,7 +320,7 @@ impl Peer {
);
}
}
Err(_) => {
None => {
let pwp = ProposalWithProof {
proposal: Some(Proposal {
height: u64::MAX,
Expand Down Expand Up @@ -386,13 +397,15 @@ impl Peer {

send_time_out_to_transferee: false,

logger,
logger: logger.clone(),
};

this.maybe_pending_conf_change();

if wants_campaign {
info!(logger, "start campaign ...");
this.core.campaign().unwrap();
info!(logger, "campaign success");
}

this
Expand Down

0 comments on commit f099d80

Please sign in to comment.