void ViewChangeManager::MayStart()

in platform/consensus/ordering/pbft/viewchange_manager.cpp [107:147]


void ViewChangeManager::MayStart() {
  if (started_) {
    return;
  }
  started_ = true;
  LOG(ERROR) << "MAYSTART";

  if (config_.GetPublicKeyCertificateInfo()
          .public_key()
          .public_key_info()
          .type() == CertificateKeyInfo::CLIENT) {
    LOG(ERROR) << "client type not process view change";
    return;
  }

  checkpoint_manager_->SetTimeoutHandler([&]() {
    // LOG(ERROR) << "checkpoint timeout";
    if (status_ == ViewChangeStatus::NONE) {
      view_change_counter_ = 1;
    } else if (status_ == ViewChangeStatus::READY_NEW_VIEW) {
      // If the new view msg expires after receiving enough view
      // messages, trigger a new primary.
      view_change_counter_++;
    }
    // std::lock_guard<std::mutex> lk(status_mutex_);
    if (ChangeStatue(ViewChangeStatus::READY_VIEW_CHANGE)) {
      SendViewChangeMsg();
      auto viewchange_timer = std::make_shared<ViewChangeTimeout>(
          ViewChangeTimerType::TYPE_VIEWCHANGE, system_info_->GetCurrentView(),
          config_.GetSelfInfo().id(), "null", GetCurrentTime(),
          timeout_length_);
      std::lock_guard<std::mutex> lk(vc_mutex_);
      if (viewchange_timeout_min_heap_[config_.GetSelfInfo().id()].size() <
          config_.GetMaxClientComplaintNum()) {
        viewchange_timeout_min_heap_[config_.GetSelfInfo().id()].push(
            viewchange_timer);
        sem_post(&viewchange_timer_signal_);
      }
    }
  });
}