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

Commit

Permalink
KEP-973 review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paularchard committed Feb 27, 2019
1 parent c8c2c0c commit c20c87a
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 94 deletions.
41 changes: 16 additions & 25 deletions pbft/pbft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ pbft::initiate_viewchange()
this->view_is_valid = false;
pbft_msg view_change{pbft::make_viewchange(this->view.value() + 1, this->latest_stable_checkpoint().first
, this->stable_checkpoint_proof, this->operation_manager->prepared_operations_since(this->latest_stable_checkpoint().first))};
LOG(debug) << "Sending VIEWCHANGE for view " << this->view + 1;
LOG(debug) << "Sending VIEWCHANGE for view " << this->view.value() + 1;
this->broadcast(this->wrap_message(view_change));
}

Expand Down Expand Up @@ -1954,28 +1954,19 @@ pbft::generate_random_number(uint32_t min, uint32_t max)
void
pbft::initialize_persistent_state()
{
persistent<operation_key_t>::initialize<log_key_t>(this->storage, ACCEPTED_PREPREPARES_KEY, [this](auto value, auto key)
{
this->accepted_preprepares.emplace(key, value);
});

persistent<std::string>::initialize<uuid_t>(this->storage, STABLE_CHECKPOINT_PROOF_KEY, [this](auto value, auto key)
{
this->stable_checkpoint_proof.emplace(key, value);
});

persistent<checkpoint_t>::initialize<checkpoint_t>(this->storage, LOCAL_UNSTABLE_CHECKPOINTS_KEY, [this](auto value, auto /*key*/)
{
this->local_unstable_checkpoints.emplace(value);
});

persistent<std::string>::initialize<uuid_t, checkpoint_t>(this->storage, UNSTABLE_CHECKPOINT_PROOFS_KEY, [this](auto value, auto key1, auto key2)
{
this->unstable_checkpoint_proofs[key2].emplace(key1, value);
});

persistent<bzn_envelope>::initialize<uuid_t, uint64_t>(this->storage, VALID_VIEWCHANGE_MESSAGES_FOR_VIEW_KEY, [this](auto value, auto key1, auto key2)
{
this->valid_viewchange_messages_for_view[key2].emplace(key1, value);
});
persistent<operation_key_t>::init_kv_container<log_key_t>(this->storage, ACCEPTED_PREPREPARES_KEY,
this->accepted_preprepares);
persistent<std::string>::init_kv_container<uuid_t>(this->storage, STABLE_CHECKPOINT_PROOF_KEY,
this->stable_checkpoint_proof);
persistent<std::string>::init_kv_container2<uuid_t, checkpoint_t>(this->storage, UNSTABLE_CHECKPOINT_PROOFS_KEY,
this->unstable_checkpoint_proofs);
persistent<bzn_envelope>::init_kv_container2<uuid_t, uint64_t>(this->storage,
VALID_VIEWCHANGE_MESSAGES_FOR_VIEW_KEY, this->valid_viewchange_messages_for_view);

// sets need a custom initialize callback
persistent<checkpoint_t>::initialize<checkpoint_t>(this->storage, LOCAL_UNSTABLE_CHECKPOINTS_KEY
, [&](auto value, auto /*key*/)
{
this->local_unstable_checkpoints.emplace(value);
});
}
22 changes: 11 additions & 11 deletions pbft/pbft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ namespace
const uint64_t MAX_REQUEST_AGE_MS = 300000; // 5 minutes
const std::string NOOP_REQUEST_HASH = "<no op request hash>";

std::string VIEW_KEY{"view"};
std::string NEXT_ISSUED_SEQUENCE_NUMBER_KEY{"next_issued_sequence_number"};
std::string ACCEPTED_PREPREPARES_KEY{"accepted_preprepares"};
std::string STABLE_CHECKPOINT_KEY{"stable_checkpoint"};
std::string LOCAL_UNSTABLE_CHECKPOINTS_KEY{"local_unstable_checkpoints"};
std::string UNSTABLE_CHECKPOINT_PROOFS_KEY{"unstable_checkpoint_proofs"};
std::string STABLE_CHECKPOINT_PROOF_KEY{"stable_checkpoint_proof"};
std::string VIEW_IS_VALID_KEY{"view_is_valid"};
std::string LAST_VIEW_SENT_KEY{"last_view_sent"};
std::string VALID_VIEWCHANGE_MESSAGES_FOR_VIEW_KEY{"valid_viewchange_messages_for_view"};
std::string SAVED_NEWVIEW_KEY{"saved_newview"};
const std::string VIEW_KEY{"view"};
const std::string NEXT_ISSUED_SEQUENCE_NUMBER_KEY{"next_issued_sequence_number"};
const std::string ACCEPTED_PREPREPARES_KEY{"accepted_preprepares"};
const std::string STABLE_CHECKPOINT_KEY{"stable_checkpoint"};
const std::string LOCAL_UNSTABLE_CHECKPOINTS_KEY{"local_unstable_checkpoints"};
const std::string UNSTABLE_CHECKPOINT_PROOFS_KEY{"unstable_checkpoint_proofs"};
const std::string STABLE_CHECKPOINT_PROOF_KEY{"stable_checkpoint_proof"};
const std::string VIEW_IS_VALID_KEY{"view_is_valid"};
const std::string LAST_VIEW_SENT_KEY{"last_view_sent"};
const std::string VALID_VIEWCHANGE_MESSAGES_FOR_VIEW_KEY{"valid_viewchange_messages_for_view"};
const std::string SAVED_NEWVIEW_KEY{"saved_newview"};
}


Expand Down
11 changes: 2 additions & 9 deletions pbft/pbft_config_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ using namespace bzn;
pbft_config_store::pbft_config_store(std::shared_ptr<bzn::storage_base> storage)
: storage(storage)
{
persistent<config_info>::initialize<hash_t>(this->storage, CONFIG_STORE_CONFIGS_KEY, [this](const persistent<config_info>& value, auto key)
{
this->configs.emplace(key, value);
});

persistent<hash_t>::initialize<uint64_t>(this->storage, CONFIG_STORE_VIEW_CONFIGS_KEY, [this](auto value, auto key)
{
this->view_configs.emplace(key, value);
});
persistent<config_info>::init_kv_container<hash_t>(this->storage, CONFIG_STORE_CONFIGS_KEY, this->configs);
persistent<hash_t>::init_kv_container<uint64_t>(this->storage, CONFIG_STORE_VIEW_CONFIGS_KEY, this->view_configs);
}

void
Expand Down
12 changes: 6 additions & 6 deletions pbft/pbft_persistent_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

using namespace bzn;

std::set<std::string> persist_base::initialized_containers;

std::string
persist_base::escape(const std::string& input)
{
std::string output;

for (auto ch : input)
{
output += (ch == SEPARATOR) ? std::string{SEPARATOR} + ch : std::string{ch};
output += (ch == ESCAPE_1) ? std::string{ESCAPE_1} + ESCAPE_2 : std::string{ch};
}

return output;
Expand All @@ -40,16 +42,16 @@ persist_base::unescape(const std::string& input)
auto it = input.begin();
while (it != input.end())
{
if (*it == SEPARATOR)
if (*it == ESCAPE_1)
{
if (it + 1 != input.end() && *(it + 1) == SEPARATOR)
if (it + 1 != input.end() && *(it + 1) == ESCAPE_2)
{
output += *it;
it += 2;
}
else
{
// a bare SEPARATOR character was found, which should never happen.
// a bare ESCAPE_1 character was found, which should never happen.
// if you hit this you've likely specified a key incorrectly
LOG(error) << "illegal character unescaping key for persistent value";
throw std::runtime_error("illegal character unescaping key for persistent value");
Expand Down Expand Up @@ -109,7 +111,6 @@ persistent<bzn::log_key_t>::from_string(const std::string &value)

LOG(error) << "bad log key from persistent state";
throw std::runtime_error("bad log key from persistent state");
// return log_key_t{0, 0};
}

template<>
Expand Down Expand Up @@ -148,7 +149,6 @@ persistent<bzn::operation_key_t>::from_string(const std::string &value)

LOG(error) << "bad log key from persistent state";
throw std::runtime_error("bad log key from persistent state");
//return operation_key_t{0, 0, "<bad hash>"};
}

template<>
Expand Down

0 comments on commit c20c87a

Please sign in to comment.