Skip to content

Commit

Permalink
Update libraries/hotstuff/include/eosio/hotstuff/state.hpp
Browse files Browse the repository at this point in the history
Co-authored-by: Gregory Popovitch <greg7mdp@gmail.com>
  • Loading branch information
fcecin and greg7mdp authored Nov 18, 2023
1 parent c171034 commit d6d7ba3
Showing 1 changed file with 37 additions and 50 deletions.
87 changes: 37 additions & 50 deletions libraries/hotstuff/include/eosio/hotstuff/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,43 @@ namespace eosio::hotstuff {

using namespace eosio::chain;

struct safety_state {

void set_v_height(const fc::crypto::blslib::bls_public_key& finalizer_key, const eosio::chain::view_number v_height) {
_states[finalizer_key].first = v_height;
}

void set_b_lock(const fc::crypto::blslib::bls_public_key& finalizer_key, const fc::sha256& b_lock) {
_states[finalizer_key].second = b_lock;
}

std::pair<eosio::chain::view_number, fc::sha256> get_safety_state(const fc::crypto::blslib::bls_public_key& finalizer_key) const {
auto s = _states.find(finalizer_key);
if (s != _states.end()) return s->second;
else return {};
}

eosio::chain::view_number get_v_height(const fc::crypto::blslib::bls_public_key& finalizer_key) const {
auto s = _states.find(finalizer_key);
if (s != _states.end()) return s->second.first;
else return {};
};

fc::sha256 get_b_lock(const fc::crypto::blslib::bls_public_key& finalizer_key) const {
auto s_itr = _states.find(finalizer_key);
if (s_itr != _states.end()) return s_itr->second.second;
else return {};
};

//todo : implement safety state default / sorting

std::pair<eosio::chain::view_number, fc::sha256> get_safety_state() const {
auto s = _states.begin();
if (s != _states.end()) return s->second;
else return {};
}

eosio::chain::view_number get_v_height() const {
auto s = _states.begin();
if (s != _states.end()) return s->second.first;
else return {};
};

fc::sha256 get_b_lock() const {
auto s_itr = _states.begin();
if (s_itr != _states.end()) return s_itr->second.second;
else return {};
};

std::map<fc::crypto::blslib::bls_public_key, std::pair<eosio::chain::view_number, fc::sha256>> _states;
struct safety_states {
using safety_state = std::pair<eosio::chain::view_number, fc::sha256>;
using public_key = fc::crypto::blslib::bls_public_key;

void set_v_height(const public_key& finalizer_key, const eosio::chain::view_number v_height) {
_states[finalizer_key].first = v_height;
}

void set_b_lock(const public_key& finalizer_key, const fc::sha256& b_lock) {
_states[finalizer_key].second = b_lock;
}

std::optional<safety_state> get_safety_state(const public_key& finalizer_key) const {
auto s = _states.find(finalizer_key);
if (s != _states.end())
return s->second;
return {};
}

std::optional<eosio::chain::view_number> get_v_height(const public_key& finalizer_key) const {
auto s = get_safety_state(finalizer_key);
if (s)
return s->first;
return {};
};

std::optional<fc::sha256> get_b_lock(const public_key& finalizer_key) const {
auto s = get_safety_state(finalizer_key);
if (s)
return s->second;
return {};
};

//todo : implement safety state default / sorting

std::map<public_key, safety_state> _states;
};
}

FC_REFLECT(eosio::hotstuff::safety_state, (_states))
FC_REFLECT(eosio::hotstuff::safety_states, (_states))

0 comments on commit d6d7ba3

Please sign in to comment.