Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
fixed swarm joining logic (my removing it). we will just act like we'…
Browse files Browse the repository at this point in the history
…re in the swarm always.
  • Loading branch information
isabelsavannah committed Sep 13, 2019
1 parent 9ec8185 commit 3169e19
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 104 deletions.
89 changes: 0 additions & 89 deletions pbft/pbft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ pbft::start()
}
}
);

this->join_swarm();
});
}

Expand Down Expand Up @@ -713,23 +711,6 @@ pbft::do_committed(const std::shared_ptr<pbft_operation>& op)
}
}

void
pbft::handle_new_config_timeout(const boost::system::error_code& ec)
{
if (ec == boost::asio::error::operation_aborted)
{
return;
}

if (ec)
{
LOG(error) << "handle_new_config_timeout error: " << ec.message();
return;
}

this->initiate_viewchange();
}

bool
pbft::is_primary() const
{
Expand Down Expand Up @@ -1468,7 +1449,6 @@ pbft::handle_newview(const pbft_msg& msg, const bzn_envelope& original_msg)

this->view = msg.view();
this->view_is_valid = true;
this->new_config_in_flight = false;

// after moving to the new view processes the preprepares
for (size_t i{0}; i < static_cast<size_t>(msg.pre_prepare_messages_size()); ++i)
Expand Down Expand Up @@ -1655,75 +1635,6 @@ pbft::honest_majority_size(size_t swarm_size)
return pbft::faulty_nodes_bound(swarm_size) * 2 + 1;
}

void
pbft::join_swarm()
{
// TODO
/*
// are we already in the peers list?
if (this->is_peer(this->uuid))
{
this->in_swarm = swarm_status::joined;
return;
}
pbft_membership_msg join_msg;
join_msg.set_type(PBFT_MMSG_JOIN);
join_msg.mutable_peer_info()->set_host(this->options->get_listener().address().to_string());
join_msg.mutable_peer_info()->set_port(this->options->get_listener().port());
join_msg.mutable_peer_info()->set_uuid(this->uuid);
// is_peer checks against uuid only, we need to bail if the list contains a node with the same IP and port,
// So, check the peers list for node with same ip and port and post error and bail if found.
const auto bad_peer = std::find_if(
std::begin(*this->peers_beacon->current())
, std::end(*this->peers_beacon->current())
, [&](const bzn::peer_address_t& address)
{
return address.port == join_msg.peer_info().port() && address.host == join_msg.peer_info().host();
});
if (bad_peer != std::end(*this->peers_beacon->current()))
{
LOG (error) << "Bootstrap configuration file validation failure - peer with UUID: " << bad_peer->uuid << " hides local peer";
throw std::runtime_error("Bad peer found in Bootstrap Configuration file");
}
uint32_t selected = this->generate_random_number(0, this->peers_beacon->current()->size() - 1);
auto ptr = this->peers_beacon->ordered();
LOG(info) << "Sending request to join swarm to node " << ptr->at(selected).uuid;
auto msg_ptr = std::make_shared<bzn_envelope>(this->wrap_message(join_msg));
this->node->send_signed_message(make_endpoint(ptr->at(selected)), msg_ptr);
this->in_swarm = swarm_status::joining;
this->join_retry_timer->expires_from_now(JOIN_RETRY_INTERVAL);
this->join_retry_timer->async_wait(
std::bind(&pbft::handle_join_retry_timeout, shared_from_this(), std::placeholders::_1));
*/
}

void
pbft::handle_join_retry_timeout(const boost::system::error_code& /*ec*/)
{
// TODO
/*
if (ec == boost::asio::error::operation_aborted)
{
return;
}
if (ec)
{
LOG(error) << "handle_new_join_retry_timeout error: " << ec.message();
return;
}
this->join_swarm();
*/
}

uint32_t
pbft::generate_random_number(uint32_t min, uint32_t max)
{
Expand Down
15 changes: 0 additions & 15 deletions pbft/pbft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
namespace
{
const std::chrono::milliseconds HEARTBEAT_INTERVAL{std::chrono::milliseconds(5000)};
const std::chrono::seconds NEW_CONFIG_INTERVAL{std::chrono::seconds(30)};
const std::chrono::seconds JOIN_RETRY_INTERVAL{std::chrono::seconds(30)};
const uint64_t CHECKPOINT_INTERVAL = 100; //TODO: KEP-574
const double HIGH_WATER_INTERVAL_IN_CHECKPOINTS = 2.0; //TODO: KEP-574
const uint64_t MAX_REQUEST_AGE_MS = 300000; // 5 minutes
Expand Down Expand Up @@ -157,8 +155,6 @@ namespace bzn
void handle_prepare(const pbft_msg& msg, const bzn_envelope& original_msg);
void handle_commit(const pbft_msg& msg, const bzn_envelope& original_msg);
void handle_checkpoint(const pbft_msg& msg, const bzn_envelope& original_msg);
void handle_join_or_leave(const bzn_envelope& env, const pbft_membership_msg& msg, std::shared_ptr<bzn::session_base> session, const std::string& msg_hash);
void handle_join_response(const pbft_membership_msg& msg);
void handle_get_state(const pbft_membership_msg& msg, std::shared_ptr<bzn::session_base> session) const;
void handle_set_state(const pbft_membership_msg& msg);
void handle_config_message(const pbft_msg& msg, const std::shared_ptr<pbft_operation>& op);
Expand Down Expand Up @@ -196,8 +192,6 @@ namespace bzn


void handle_audit_heartbeat_timeout(const boost::system::error_code& ec);
void handle_new_config_timeout(const boost::system::error_code& ec);
void handle_join_retry_timeout(const boost::system::error_code& ec);

void notify_audit_failure_detected();

Expand All @@ -208,16 +202,13 @@ namespace bzn
size_t max_faulty_nodes() const;

void initialize_persistent_state();
bool initialize_configuration(const bzn::peers_list_t& peers);

void maybe_record_request(const bzn_envelope &env, const std::shared_ptr<pbft_operation> &op);

timestamp_t now() const;
bool already_seen_request(const bzn_envelope& msg, const request_hash_t& hash) const;
void saw_request(const bzn_envelope& msg, const request_hash_t& hash);

void join_swarm();

// VIEWCHANGE/NEWVIEW Helper methods
void initiate_viewchange();
std::shared_ptr<bzn_envelope> make_viewchange(uint64_t new_view, uint64_t n, const std::unordered_map<bzn::uuid_t, std::string>& stable_checkpoint_proof, const std::map<uint64_t, std::shared_ptr<bzn::pbft_operation>>& prepared_operations);
Expand Down Expand Up @@ -263,11 +254,6 @@ namespace bzn

bool audit_enabled = true;

enum class swarm_status {not_joined, joining, waiting, joined};
swarm_status in_swarm = swarm_status::not_joined;

bool new_config_in_flight = false;

std::multimap<timestamp_t, std::pair<bzn::uuid_t, request_hash_t>> recent_requests;

std::shared_ptr<crypto_base> crypto;
Expand Down Expand Up @@ -312,7 +298,6 @@ namespace bzn
FRIEND_TEST(bzn::test::pbft_test, ensure_save_all_requests_records_requests);

friend class pbft_proto_test;
friend class pbft_join_leave_test;
friend class pbft_viewchange_test;

std::map<bzn::hash_t, std::shared_ptr<bzn::session_base>> sessions_waiting_on_forwarded_requests;
Expand Down

0 comments on commit 3169e19

Please sign in to comment.