diff --git a/libraries/chain/include/eosio/chain/producer_schedule.hpp b/libraries/chain/include/eosio/chain/producer_schedule.hpp index 014501950b..d9f7e0587f 100644 --- a/libraries/chain/include/eosio/chain/producer_schedule.hpp +++ b/libraries/chain/include/eosio/chain/producer_schedule.hpp @@ -334,15 +334,15 @@ namespace eosio { namespace chain { shared_finalizer_authority& operator= ( shared_finalizer_authority && ) = default; shared_finalizer_authority& operator= ( const shared_finalizer_authority & ) = default; - shared_finalizer_authority( const name& finalizer_name, const uint64_t fweight, shared_block_signing_authority&& authority ) + shared_finalizer_authority( const name& finalizer_name, const uint64_t fweight, const public_key_type& public_key ) :finalizer_name(finalizer_name) ,fweight(fweight) - ,authority(std::move(authority)) + ,public_key(public_key) {} name finalizer_name; uint64_t fweight; - shared_block_signing_authority authority; + public_key_type public_key; }; struct shared_finalizer_schedule { @@ -365,48 +365,17 @@ namespace eosio { namespace chain { name finalizer_name; uint64_t fweight; // weight that this finalizer's vote has for meeting fthreshold - block_signing_authority authority; - - template - static void for_each_key( const block_signing_authority& authority, Op&& op ) { - std::visit([&op](const auto &a){ - a.for_each_key(std::forward(op)); - }, authority); - } - - template - void for_each_key( Op&& op ) const { - for_each_key(authority, std::forward(op)); - } - - static std::pair keys_satisfy_and_relevant( const std::set& keys, const block_signing_authority& authority ) { - return std::visit([&keys](const auto &a){ - return a.keys_satisfy_and_relevant(keys); - }, authority); - } - - std::pair keys_satisfy_and_relevant( const std::set& presented_keys ) const { - return keys_satisfy_and_relevant(presented_keys, authority); - } + public_key_type public_key; auto to_shared(chainbase::allocator alloc) const { - auto shared_auth = std::visit([&alloc](const auto& a) { - return a.to_shared(alloc); - }, authority); - - return shared_finalizer_authority(finalizer_name, fweight, std::move(shared_auth)); + return shared_finalizer_authority(finalizer_name, fweight, public_key); } static auto from_shared( const shared_finalizer_authority& src ) { finalizer_authority result; result.finalizer_name = src.finalizer_name; result.fweight = src.fweight; - result.authority = std::visit(overloaded { - [](const shared_block_signing_authority_v0& a) { - return block_signing_authority_v0::from_shared(a); - } - }, src.authority); - + result.public_key = src.public_key; return result; } @@ -425,10 +394,10 @@ namespace eosio { namespace chain { fc::variant get_abi_variant() const; friend bool operator == ( const finalizer_authority& lhs, const finalizer_authority& rhs ) { - return tie( lhs.finalizer_name, lhs.fweight, lhs.authority ) == tie( rhs.finalizer_name, rhs.fweight, rhs.authority ); + return tie( lhs.finalizer_name, lhs.fweight, lhs.public_key ) == tie( rhs.finalizer_name, rhs.fweight, rhs.public_key ); } friend bool operator != ( const finalizer_authority& lhs, const finalizer_authority& rhs ) { - return tie( lhs.finalizer_name, lhs.fweight, lhs.authority ) != tie( rhs.finalizer_name, rhs.fweight, rhs.authority ); + return tie( lhs.finalizer_name, lhs.fweight, lhs.public_key ) != tie( rhs.finalizer_name, rhs.fweight, rhs.public_key ); } }; @@ -502,7 +471,7 @@ FC_REFLECT( eosio::chain::shared_producer_authority, (producer_name)(authority) FC_REFLECT( eosio::chain::shared_producer_authority_schedule, (version)(producers) ) // TODO: move to finalizers.hpp -FC_REFLECT( eosio::chain::finalizer_authority, (finalizer_name)(fweight)(authority) ) +FC_REFLECT( eosio::chain::finalizer_authority, (finalizer_name)(fweight)(public_key) ) FC_REFLECT( eosio::chain::finalizer_schedule, (version)(fthreshold)(finalizers) ) -FC_REFLECT( eosio::chain::shared_finalizer_authority, (finalizer_name)(fweight)(authority) ) +FC_REFLECT( eosio::chain::shared_finalizer_authority, (finalizer_name)(fweight)(public_key) ) FC_REFLECT( eosio::chain::shared_finalizer_schedule, (version)(fthreshold)(finalizers) ) diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index f080c5e52b..cc86c230b8 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -196,9 +196,9 @@ namespace eosio { namespace chain { namespace webassembly { } finalizer_authority { - name finalizer_name; - uint64 fweight; (among all finalizers) - block_signing_authority authority; // block_signing_authority object ( { int threshold, vector<> keys } ) is existing infrastructure + name finalizer_name; + uint64 fweight; (among all finalizers) + block_finalization_authority authority; // NEW: just one key per finalizer } */ @@ -213,30 +213,16 @@ namespace eosio { namespace chain { namespace webassembly { const size_t num_supported_key_types = context.db.get().num_supported_key_types; - // check that finalizers are unique + // check that finalizers are unique and that the keys are valid BLS keys std::set unique_finalizers; for (const auto& f: finalizers) { EOS_ASSERT( context.is_account(f.finalizer_name), wasm_execution_error, "Finalizer schedule includes a nonexisting account" ); - std::visit([&f, num_supported_key_types](const auto& a) { - uint32_t sum_weights = 0; - std::set unique_keys; - for (const auto& kw: a.keys ) { - EOS_ASSERT( kw.key.which() < num_supported_key_types, unactivated_key_type, "Unactivated key type used in proposed finalizer schedule" ); - EOS_ASSERT( kw.key.valid(), wasm_execution_error, "Finalizer schedule includes an invalid key" ); - - if (std::numeric_limits::max() - sum_weights <= kw.weight) { - sum_weights = std::numeric_limits::max(); - } else { - sum_weights += kw.weight; - } - - unique_keys.insert(kw.key); - } + EOS_ASSERT( f.public_key.which() < num_supported_key_types, unactivated_key_type, "Unactivated key type used in proposed finalizer schedule" ); + EOS_ASSERT( f.public_key.valid(), wasm_execution_error, "Finalizer schedule includes an invalid key" ); - EOS_ASSERT( a.keys.size() == unique_keys.size(), wasm_execution_error, "Finalizer schedule includes a duplicated key for ${account}", ("account", f.finalizer_name)); - EOS_ASSERT( a.threshold > 0, wasm_execution_error, "Finalizer schedule includes an authority with a threshold of 0 for ${account}", ("account", f.finalizer_name)); - EOS_ASSERT( sum_weights >= a.threshold, wasm_execution_error, "Finalizer schedule includes an unsatisfiable authority for ${account}", ("account", f.finalizer_name)); - }, f.authority); + // ------------------------------------------- + // FIXME/TODO: check for BLS/aggsig key type here + // ------------------------------------------- unique_finalizers.insert(f.finalizer_name); } diff --git a/libraries/hotstuff/qc_chain.cpp b/libraries/hotstuff/qc_chain.cpp index 5e278a8045..c6a23980a6 100644 --- a/libraries/hotstuff/qc_chain.cpp +++ b/libraries/hotstuff/qc_chain.cpp @@ -507,14 +507,14 @@ namespace eosio { namespace hotstuff { //TODO: check for duplicate or invalid vote. We will return in either case, but keep proposals for evidence of double signing - bool am_leader = am_i_leader(); - - if (!am_leader) + // only leader need to take action on votes + if (! am_i_leader()) return; + #ifdef QC_CHAIN_TRACE_DEBUG ilog(" === Process vote from ${finalizer} : current bitset ${value}" , ("finalizer", vote.finalizer)("value", _current_qc.active_finalizers)); #endif - // only leader need to take action on votes + if (vote.proposal_id != _current_qc.proposal_id) return;