Skip to content

Commit

Permalink
Merge pull request #30 from AntelopeIO/GH-12-cleanup
Browse files Browse the repository at this point in the history
IF: Remove hotstuff references
  • Loading branch information
heifner authored Apr 19, 2024
2 parents 395724e + 53673ea commit 64b77f4
Show file tree
Hide file tree
Showing 45 changed files with 115 additions and 280 deletions.
16 changes: 7 additions & 9 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/genesis_state_root_key.cpp.in ${CMAKE

file(GLOB HEADERS "include/eosio/chain/*.hpp"
"include/eosio/chain/webassembly/*.hpp"
"include/eosio/chain/hotstuff/*.hpp"
"include/eosio/chain/finality/*.hpp"
"${CMAKE_CURRENT_BINARY_DIR}/include/eosio/chain/core_symbol.hpp" )

if((APPLE AND UNIX) OR (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD"))
Expand Down Expand Up @@ -79,10 +79,11 @@ set(CHAIN_WEBASSEMBLY_SOURCES
webassembly/transaction.cpp
)

set(CHAIN_HOTSTUFF_SOURCES
hotstuff/finalizer.cpp
hotstuff/instant_finality_extension.cpp
hotstuff/hotstuff.cpp
set(CHAIN_FINALITY_SOURCES
finality/finalizer.cpp
finality/instant_finality_extension.cpp
finality/quorum_certificate.cpp
finality/finality_core.cpp
)

add_library(eosio_rapidjson INTERFACE)
Expand All @@ -98,7 +99,6 @@ add_library( eosio_chain
block_state.cpp
block_header_state_legacy.cpp
block_state_legacy.cpp
finality_core.cpp
fork_database.cpp
controller.cpp
authorization_manager.cpp
Expand Down Expand Up @@ -128,7 +128,7 @@ add_library( eosio_chain
${CHAIN_EOSVMOC_SOURCES}
${CHAIN_EOSVM_SOURCES}
${CHAIN_WEBASSEMBLY_SOURCES}
${CHAIN_HOTSTUFF_SOURCES}
${CHAIN_FINALITY_SOURCES}

authority.cpp
trace.cpp
Expand Down Expand Up @@ -181,8 +181,6 @@ if(EOSVMOC_ENABLE_DEVELOPER_OPTIONS)
target_compile_definitions(eosio_chain PUBLIC EOSIO_EOS_VM_OC_DEVELOPER)
endif()

add_subdirectory(hotstuff/test)

install( TARGETS eosio_chain
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT dev EXCLUDE_FROM_ALL
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT dev EXCLUDE_FROM_ALL
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/chain/asset.hpp>
#include <eosio/chain/exceptions.hpp>
#include <eosio/chain/hotstuff/instant_finality_extension.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <fc/io/raw.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <fc/io/varint.hpp>
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/block_header.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <eosio/chain/block.hpp>
#include <eosio/chain/hotstuff/finalizer_authority.hpp>
#include <eosio/chain/finality/finalizer_authority.hpp>
#include <eosio/chain/merkle.hpp>
#include <fc/io/raw.hpp>
#include <fc/bitutil.hpp>
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <eosio/chain/block_header_state.hpp>
#include <eosio/chain/block_header_state_utils.hpp>
#include <eosio/chain/hotstuff/instant_finality_extension.hpp>
#include <eosio/chain/hotstuff/proposer_policy.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/finality/proposer_policy.hpp>
#include <eosio/chain/exceptions.hpp>
#include <limits>

Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <eosio/chain/block_state.hpp>
#include <eosio/chain/block_header_state_utils.hpp>
#include <eosio/chain/block_state_legacy.hpp>
#include <eosio/chain/hotstuff/finalizer.hpp>
#include <eosio/chain/finality/finalizer.hpp>
#include <eosio/chain/snapshot_detail.hpp>
#include <eosio/chain/exceptions.hpp>

Expand Down Expand Up @@ -203,7 +203,7 @@ void block_state::verify_qc(const valid_quorum_certificate& qc) const {
auto num_finalizers = finalizers.size();

// utility to accumulate voted weights
auto weights = [&] ( const hs_bitset& votes_bitset ) -> uint64_t {
auto weights = [&] ( const vote_bitset& votes_bitset ) -> uint64_t {
uint64_t sum = 0;
auto n = std::min(num_finalizers, votes_bitset.size());
for (auto i = 0u; i < n; ++i) {
Expand Down
7 changes: 4 additions & 3 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#include <eosio/chain/platform_timer.hpp>
#include <eosio/chain/block_header_state_utils.hpp>
#include <eosio/chain/deep_mind.hpp>
#include <eosio/chain/hotstuff/finalizer.hpp>
#include <eosio/chain/hotstuff/finalizer_policy.hpp>
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/finality/finalizer.hpp>
#include <eosio/chain/finality/finalizer_policy.hpp>
#include <eosio/chain/finality/quorum_certificate.hpp>
#include <eosio/chain/finality/vote_message.hpp>
#include <eosio/chain/vote_processor.hpp>

#include <chainbase/chainbase.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <eosio/chain/finality_core.hpp>
#include <eosio/chain/finality/finality_core.hpp>
#include <eosio/chain/block_header.hpp>

namespace eosio::chain {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <eosio/chain/hotstuff/finalizer.hpp>
#include <eosio/chain/finality/finalizer.hpp>
#include <eosio/chain/exceptions.hpp>
#include <fc/log/logger_config.hpp>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <eosio/chain/hotstuff/instant_finality_extension.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/exceptions.hpp>

namespace eosio::chain {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/finality/quorum_certificate.hpp>
#include <eosio/chain/finality/vote_message.hpp>
#include <fc/crypto/bls_utils.hpp>

namespace eosio::chain {

inline std::string bitset_to_string(const hs_bitset& bs) {
inline std::string bitset_to_string(const vote_bitset& bs) {
std::string r;
boost::to_string(bs, r);
return r;
}

inline hs_bitset vector_to_bitset(const std::vector<uint32_t>& v) {
inline vote_bitset vector_to_bitset(const std::vector<uint32_t>& v) {
return {v.cbegin(), v.cend()};
}

inline std::vector<uint32_t> bitset_to_vector(const hs_bitset& bs) {
inline std::vector<uint32_t> bitset_to_vector(const vote_bitset& bs) {
std::vector<uint32_t> r;
r.resize(bs.num_blocks());
boost::to_block_range(bs, r.begin());
Expand Down Expand Up @@ -138,14 +139,14 @@ vote_status pending_quorum_certificate::add_weak_vote(size_t index, const bls_si

// thread safe
vote_status pending_quorum_certificate::add_vote(uint32_t connection_id, block_num_type block_num,
bool strong, std::span<const uint8_t> proposal_digest, size_t index,
bool strong, std::span<const uint8_t> finalizer_digest, size_t index,
const bls_public_key& pubkey, const bls_signature& sig, uint64_t weight) {
if (has_voted_no_lock(strong, index)) {
fc_dlog(vote_logger, "connection - ${c} block_num: ${bn}, duplicate", ("c", connection_id)("bn", block_num));
return vote_status::duplicate;
}

if (!fc::crypto::blslib::verify(pubkey, proposal_digest, sig)) {
if (!fc::crypto::blslib::verify(pubkey, finalizer_digest, sig)) {
fc_wlog(vote_logger, "connection - ${c} signature from finalizer ${k}.. cannot be verified", ("k", pubkey.to_string().substr(8,16)));
return vote_status::invalid_signature;
}
Expand Down
6 changes: 0 additions & 6 deletions libraries/chain/hotstuff/test/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/block.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <eosio/chain/block_header.hpp>
#include <eosio/chain/transaction.hpp>
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/finality/quorum_certificate.hpp>

namespace eosio { namespace chain {

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <eosio/chain/block_timestamp.hpp>
#include <eosio/chain/producer_schedule.hpp>
#include <eosio/chain/protocol_feature_activation.hpp>
#include <eosio/chain/hotstuff/instant_finality_extension.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>

#include <optional>
#include <type_traits>
Expand Down
8 changes: 4 additions & 4 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once
#include <eosio/chain/block_header.hpp>
#include <eosio/chain/finality_core.hpp>
#include <eosio/chain/finality/finality_core.hpp>
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/hotstuff/finalizer_policy.hpp>
#include <eosio/chain/hotstuff/instant_finality_extension.hpp>
#include <eosio/chain/finality/quorum_certificate.hpp>
#include <eosio/chain/finality/finalizer_policy.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/chain_snapshot.hpp>
#include <future>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace snapshot_detail {
namespace detail {
struct schedule_info {
// schedule_lib_num is compared with dpos lib, but the value is actually current block at time of pending
// After hotstuff is activated, schedule_lib_num is compared to next().next() round for determination of
// After Savanna is activated, schedule_lib_num is compared to next().next() round for determination of
// changing from pending to active.
uint32_t schedule_lib_num = 0; /// block_num of pending
digest_type schedule_hash;
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace eosio::chain {

struct vote_message;

using signer_callback_type = std::function<std::vector<signature_type>(const digest_type&)>;

constexpr std::array weak_bls_sig_postfix = { 'W', 'E', 'A', 'K' };
Expand Down
5 changes: 1 addition & 4 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <eosio/chain/snapshot.hpp>
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/webassembly/eos-vm-oc/config.hpp>
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/finality/vote_message.hpp>

#include <chainbase/pinnable_mapped_file.hpp>

Expand All @@ -26,9 +26,6 @@ namespace eosio::vm { class wasm_allocator; }

namespace eosio::chain {

struct hs_message;
struct finalizer_state;
enum class hs_message_warning;
using bls_pub_priv_key_map_t = std::map<std::string, std::string>;
struct finalizer_policy;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <eosio/chain/block_state.hpp>
#include <eosio/chain/finality/vote_message.hpp>
#include <fc/crypto/bls_utils.hpp>
#include <fc/io/cfile.hpp>
#include <compare>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <eosio/chain/types.hpp>
#include <eosio/chain/hotstuff/finalizer_authority.hpp>
#include <eosio/chain/finality/finalizer_authority.hpp>

namespace eosio::chain {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <eosio/chain/hotstuff/finalizer_policy.hpp>
#include <eosio/chain/hotstuff/proposer_policy.hpp>
#include <eosio/chain/finality_core.hpp>
#include <eosio/chain/finality/finalizer_policy.hpp>
#include <eosio/chain/finality/proposer_policy.hpp>
#include <eosio/chain/finality/finality_core.hpp>

namespace eosio::chain {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <eosio/chain/block_timestamp.hpp>
#include <eosio/chain/finality_core.hpp>
#include <eosio/chain/finality/finality_core.hpp>
#include <fc/crypto/bls_private_key.hpp>
#include <fc/crypto/bls_public_key.hpp>
#include <fc/crypto/bls_signature.hpp>
Expand All @@ -12,28 +12,14 @@

namespace eosio::chain {

inline fc::logger vote_logger{"vote"};

using bls_public_key = fc::crypto::blslib::bls_public_key;
using bls_signature = fc::crypto::blslib::bls_signature;
using bls_aggregate_signature = fc::crypto::blslib::bls_aggregate_signature;
using bls_private_key = fc::crypto::blslib::bls_private_key;

using hs_bitset = boost::dynamic_bitset<uint32_t>;
using vote_bitset = boost::dynamic_bitset<uint32_t>;
using bls_key_map_t = std::map<bls_public_key, bls_private_key>;

struct vote_message {
block_id_type block_id;
bool strong{false};
bls_public_key finalizer_key;
bls_signature sig;

auto operator<=>(const vote_message&) const = default;
bool operator==(const vote_message&) const = default;
};

using vote_message_ptr = std::shared_ptr<vote_message>;

enum class vote_status {
success,
duplicate, // duplicate vote, expected as votes arrive on multiple connections
Expand All @@ -43,18 +29,14 @@ namespace eosio::chain {
max_exceeded // received too many votes for a connection
};

using bls_public_key = fc::crypto::blslib::bls_public_key;
using bls_signature = fc::crypto::blslib::bls_signature;
using bls_private_key = fc::crypto::blslib::bls_private_key;

// valid_quorum_certificate
struct valid_quorum_certificate {
bool is_weak() const { return !!_weak_votes; }
bool is_strong() const { return !_weak_votes; }

std::optional<hs_bitset> _strong_votes;
std::optional<hs_bitset> _weak_votes;
bls_aggregate_signature _sig;
std::optional<vote_bitset> _strong_votes;
std::optional<vote_bitset> _weak_votes;
bls_aggregate_signature _sig;
};

// quorum_certificate
Expand Down Expand Up @@ -93,8 +75,8 @@ namespace eosio::chain {
friend struct fc::has_reflector_init<votes_t>;
friend class pending_quorum_certificate;

hs_bitset _bitset;
bls_aggregate_signature _sig;
vote_bitset _bitset;
bls_aggregate_signature _sig;
std::vector<std::atomic<bool>> _processed; // avoid locking mutex for _bitset duplicate check

void reflector_init();
Expand Down Expand Up @@ -167,7 +149,6 @@ namespace eosio::chain {
} //eosio::chain


FC_REFLECT(eosio::chain::vote_message, (block_id)(strong)(finalizer_key)(sig));
FC_REFLECT_ENUM(eosio::chain::vote_status, (success)(duplicate)(unknown_public_key)(invalid_signature)(unknown_block)(max_exceeded))
FC_REFLECT(eosio::chain::valid_quorum_certificate, (_strong_votes)(_weak_votes)(_sig));
FC_REFLECT(eosio::chain::pending_quorum_certificate, (_valid_qc)(_quorum)(_max_weak_sum_before_weak_final)(_state)(_strong_sum)(_weak_sum)(_weak_votes)(_strong_votes));
Expand Down
29 changes: 29 additions & 0 deletions libraries/chain/include/eosio/chain/finality/vote_message.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <eosio/chain/types.hpp>
#include <fc/crypto/bls_public_key.hpp>
#include <fc/crypto/bls_signature.hpp>


namespace eosio::chain {

inline fc::logger vote_logger{"vote"};

using bls_public_key = fc::crypto::blslib::bls_public_key;
using bls_signature = fc::crypto::blslib::bls_signature;

struct vote_message {
block_id_type block_id;
bool strong{false};
bls_public_key finalizer_key;
bls_signature sig;

auto operator<=>(const vote_message&) const = default;
bool operator==(const vote_message&) const = default;
};

using vote_message_ptr = std::shared_ptr<vote_message>;

} // namespace eosio::chain

FC_REFLECT(eosio::chain::vote_message, (block_id)(strong)(finalizer_key)(sig));
Loading

0 comments on commit 64b77f4

Please sign in to comment.