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

Commit

Permalink
KEP-823 Adding Isabel's final fixes to clean up maybe_record_request …
Browse files Browse the repository at this point in the history
…and remove some duplication
  • Loading branch information
rnistuk authored and rnistuk committed Jun 20, 2019
1 parent e6540b1 commit b433d11
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions pbft/pbft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,27 +353,10 @@ pbft::forward_request_to_primary(const bzn_envelope& request_env)
}



//void
//pbft::maybe_record_internal_request(const bzn_envelope &request_env, const std::shared_ptr<pbft_operation> &op)
//{
// pbft_msg msg;
// msg.ParseFromString(request_env.pbft());
//
// if (this->crypto->hash(request_env) != msg.request_hash())
// {
// LOG(info) << "Not recording request because hashes do not match";
// return;
// }
// op->record_request(request_env);
//
//}


void
pbft::maybe_record_request(const bzn_envelope &request_env, const std::shared_ptr<pbft_operation> &op)
{
if (request_env.payload_case() != bzn_envelope::PayloadCase::PAYLOAD_NOT_SET && this->crypto->hash(request_env) != op->get_request_hash())
if (request_env.payload_case() == bzn_envelope::PayloadCase::PAYLOAD_NOT_SET || this->crypto->hash(request_env) != op->get_request_hash())
{
LOG(info) << "Not recording request because hashes do not match";
return;
Expand Down Expand Up @@ -762,7 +745,7 @@ pbft::do_prepared(const std::shared_ptr<pbft_operation>& op)
void
pbft::do_committed(const std::shared_ptr<pbft_operation>& op)
{
LOG(debug) << "Operation " << op->get_sequence() << " is committed-local";
LOG(debug) << "Operation " << op->get_sequence() << " " << bzn::bytes_to_debug_string(op->get_request_hash()) << " is committed-local";
op->advance_operation_stage(pbft_operation_stage::execute);

// If we have a pending session for this request, attach to the operation just before we pass off to the service.
Expand All @@ -775,6 +758,7 @@ pbft::do_committed(const std::shared_ptr<pbft_operation>& op)
const auto session = this->sessions_waiting_on_forwarded_requests.find(op->get_request_hash());
if (session != this->sessions_waiting_on_forwarded_requests.end() && !op->has_session())
{
LOG(debug) << "Found pending session for this operation";
op->set_session(session->second);
}

Expand Down Expand Up @@ -1958,6 +1942,7 @@ void pbft::add_session_to_sessions_waiting(const std::string& msg_hash, std::sha
{
if (session)
{
LOG(debug) << "Holding session for request " << bzn::bytes_to_debug_string(msg_hash);
this->sessions_waiting_on_forwarded_requests[msg_hash] = session;
session->add_shutdown_handler([msg_hash, this, session]()
{
Expand Down

0 comments on commit b433d11

Please sign in to comment.