Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename block_header_state and block_state to block_header_state_legacy and block_state_legacy in preparation for Instant Fininality #1951

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ add_library( eosio_chain
transaction.cpp
block.cpp
block_header.cpp
block_header_state.cpp
block_state.cpp
block_header_state_legacy.cpp
block_state_legacy.cpp
fork_database.cpp
controller.cpp
authorization_manager.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <eosio/chain/block_header_state.hpp>
#include <eosio/chain/block_header_state_legacy.hpp>
#include <eosio/chain/exceptions.hpp>
#include <limits>

Expand All @@ -15,13 +15,13 @@ namespace eosio { namespace chain {
}
}

producer_authority block_header_state::get_scheduled_producer( block_timestamp_type t )const {
producer_authority block_header_state_legacy::get_scheduled_producer( block_timestamp_type t )const {
auto index = t.slot % (active_schedule.producers.size() * config::producer_repetitions);
index /= config::producer_repetitions;
return active_schedule.producers[index];
}

uint32_t block_header_state::calc_dpos_last_irreversible( account_name producer_of_next_block )const {
uint32_t block_header_state_legacy::calc_dpos_last_irreversible( account_name producer_of_next_block )const {
vector<uint32_t> blocknums; blocknums.reserve( producer_to_last_implied_irb.size() );
for( auto& i : producer_to_last_implied_irb ) {
blocknums.push_back( (i.first == producer_of_next_block) ? dpos_proposed_irreversible_blocknum : i.second);
Expand All @@ -35,8 +35,8 @@ namespace eosio { namespace chain {
return blocknums[ index ];
}

pending_block_header_state block_header_state::next( block_timestamp_type when,
uint16_t num_prev_blocks_to_confirm )const
pending_block_header_state block_header_state_legacy::next( block_timestamp_type when,
uint16_t num_prev_blocks_to_confirm )const
{
pending_block_header_state result;

Expand Down Expand Up @@ -221,7 +221,7 @@ namespace eosio { namespace chain {
return h;
}

block_header_state pending_block_header_state::_finish_next(
block_header_state_legacy pending_block_header_state::_finish_next(
const signed_block_header& h,
const protocol_feature_set& pfs,
const std::function<void( block_timestamp_type,
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace eosio { namespace chain {

auto block_number = block_num;

block_header_state result( std::move( *static_cast<detail::block_header_state_common*>(this) ) );
block_header_state_legacy result( std::move( *static_cast<detail::block_header_state_legacy_common*>(this) ) );

result.id = h.calculate_id();
result.header = h;
Expand All @@ -317,7 +317,7 @@ namespace eosio { namespace chain {
return result;
}

block_header_state pending_block_header_state::finish_next(
block_header_state_legacy pending_block_header_state::finish_next(
const signed_block_header& h,
vector<signature_type>&& additional_signatures,
const protocol_feature_set& pfs,
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace eosio { namespace chain {
return result;
}

block_header_state pending_block_header_state::finish_next(
block_header_state_legacy pending_block_header_state::finish_next(
signed_block_header& h,
const protocol_feature_set& pfs,
const std::function<void( block_timestamp_type,
Expand Down Expand Up @@ -378,7 +378,7 @@ namespace eosio { namespace chain {
*
* If the header specifies new_producers then apply them accordingly.
*/
block_header_state block_header_state::next(
block_header_state_legacy block_header_state_legacy::next(
const signed_block_header& h,
vector<signature_type>&& _additional_signatures,
const protocol_feature_set& pfs,
Expand All @@ -390,12 +390,12 @@ namespace eosio { namespace chain {
return next( h.timestamp, h.confirmed ).finish_next( h, std::move(_additional_signatures), pfs, validator, skip_validate_signee );
}

digest_type block_header_state::sig_digest()const {
digest_type block_header_state_legacy::sig_digest()const {
auto header_bmroot = digest_type::hash( std::make_pair( header.digest(), blockroot_merkle.get_root() ) );
return digest_type::hash( std::make_pair(header_bmroot, pending_schedule.schedule_hash) );
}

void block_header_state::sign( const signer_callback_type& signer ) {
void block_header_state_legacy::sign( const signer_callback_type& signer ) {
auto d = sig_digest();
auto sigs = signer( d );

Expand All @@ -408,7 +408,7 @@ namespace eosio { namespace chain {
verify_signee();
}

void block_header_state::verify_signee( )const {
void block_header_state_legacy::verify_signee( )const {

auto num_keys_in_authority = std::visit([](const auto &a){ return a.keys.size(); }, valid_block_signing_authority);
EOS_ASSERT(1 + additional_signatures.size() <= num_keys_in_authority, wrong_signing_key,
Expand Down Expand Up @@ -444,7 +444,7 @@ namespace eosio { namespace chain {
/**
* Reference cannot outlive *this. Assumes header_exts is not mutated after instatiation.
*/
const vector<digest_type>& block_header_state::get_new_protocol_feature_activations()const {
const vector<digest_type>& block_header_state_legacy::get_new_protocol_feature_activations()const {
static const vector<digest_type> no_activations{};

if( header_exts.count(protocol_feature_activation::extension_id()) == 0 )
Expand All @@ -453,7 +453,7 @@ namespace eosio { namespace chain {
return std::get<protocol_feature_activation>(header_exts.lower_bound(protocol_feature_activation::extension_id())->second).protocol_features;
}

block_header_state::block_header_state( legacy::snapshot_block_header_state_v2&& snapshot )
block_header_state_legacy::block_header_state_legacy( legacy::snapshot_block_header_state_v2&& snapshot )
{
block_num = snapshot.block_num;
dpos_proposed_irreversible_blocknum = snapshot.dpos_proposed_irreversible_blocknum;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <eosio/chain/block_state.hpp>
#include <eosio/chain/block_state_legacy.hpp>
#include <eosio/chain/exceptions.hpp>

namespace eosio { namespace chain {
Expand Down Expand Up @@ -47,13 +47,13 @@ namespace eosio { namespace chain {
*/

template<typename ...Extras>
block_header_state inject_additional_signatures( pending_block_header_state&& cur,
signed_block& b,
const protocol_feature_set& pfs,
Extras&& ... extras )
block_header_state_legacy inject_additional_signatures( pending_block_header_state&& cur,
signed_block& b,
const protocol_feature_set& pfs,
Extras&& ... extras )
{
auto pfa = cur.prev_activated_protocol_features;
block_header_state result = std::move(cur).finish_next(b, pfs, std::forward<Extras>(extras)...);
block_header_state_legacy result = std::move(cur).finish_next(b, pfs, std::forward<Extras>(extras)...);

if (!result.additional_signatures.empty()) {
bool wtmsig_enabled = detail::is_builtin_activated(pfa, pfs, builtin_protocol_feature_t::wtmsig_block_signatures);
Expand All @@ -74,28 +74,28 @@ namespace eosio { namespace chain {

}

block_state::block_state( const block_header_state& prev,
signed_block_ptr b,
const protocol_feature_set& pfs,
const std::function<void( block_timestamp_type,
block_state_legacy::block_state_legacy( const block_header_state_legacy& prev,
signed_block_ptr b,
const protocol_feature_set& pfs,
const std::function<void( block_timestamp_type,
const flat_set<digest_type>&,
const vector<digest_type>& )>& validator,
bool skip_validate_signee
)
:block_header_state( prev.next( *b, extract_additional_signatures(b, pfs, prev.activated_protocol_features), pfs, validator, skip_validate_signee ) )
:block_header_state_legacy( prev.next( *b, extract_additional_signatures(b, pfs, prev.activated_protocol_features), pfs, validator, skip_validate_signee ) )
,block( std::move(b) )
{}

block_state::block_state( pending_block_header_state&& cur,
signed_block_ptr&& b,
deque<transaction_metadata_ptr>&& trx_metas,
const protocol_feature_set& pfs,
const std::function<void( block_timestamp_type,
block_state_legacy::block_state_legacy( pending_block_header_state&& cur,
signed_block_ptr&& b,
deque<transaction_metadata_ptr>&& trx_metas,
const protocol_feature_set& pfs,
const std::function<void( block_timestamp_type,
const flat_set<digest_type>&,
const vector<digest_type>& )>& validator,
const signer_callback_type& signer
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
)
:block_header_state( inject_additional_signatures( std::move(cur), *b, pfs, validator, signer ) )
:block_header_state_legacy( inject_additional_signatures( std::move(cur), *b, pfs, validator, signer ) )
,block( std::move(b) )
,_pub_keys_recovered( true ) // called by produce_block so signature recovery of trxs must have been done
,_cached_trxs( std::move(trx_metas) )
Expand Down
Loading