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

IF: Rename existing block_header_state and block_state to block_header_state_legacy and block_state_legacy #1947

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ add_library( eosio_chain
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
518 changes: 8 additions & 510 deletions libraries/chain/block_header_state.cpp

Large diffs are not rendered by default.

508 changes: 508 additions & 0 deletions libraries/chain/block_header_state_legacy.cpp

Large diffs are not rendered by default.

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,29 +74,29 @@ namespace eosio { namespace chain {

}

block_state::block_state( const block_header_state& prev,
signed_block_ptr b,
const protocol_feature_set& pfs,
bool hotstuff_activated,
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,
bool hotstuff_activated,
const std::function<void( block_timestamp_type,
const flat_set<digest_type>&,
const vector<digest_type>& )>& validator,
bool skip_validate_signee
bool skip_validate_signee
)
:block_header_state( prev.next( *b, extract_additional_signatures(b, pfs, prev.activated_protocol_features), pfs, hotstuff_activated, validator, skip_validate_signee ) )
:block_header_state_legacy( prev.next( *b, extract_additional_signatures(b, pfs, prev.activated_protocol_features), pfs, hotstuff_activated, 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
const signer_callback_type& signer
)
: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
79 changes: 42 additions & 37 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class maybe_session {
};

struct building_block {
building_block( const block_header_state& prev,
building_block( const block_header_state_legacy& prev,
block_timestamp_type when,
bool hotstuff_activated,
uint16_t num_prev_blocks_to_confirm,
Expand Down Expand Up @@ -148,13 +148,13 @@ struct assembled_block {
};

struct completed_block {
block_state_ptr _block_state;
block_state_legacy_ptr _block_state;
};

using block_stage_type = std::variant<building_block, assembled_block, completed_block>;

struct pending_state {
pending_state( maybe_session&& s, const block_header_state& prev,
pending_state( maybe_session&& s, const block_header_state_legacy& prev,
block_timestamp_type when,
bool hotstuff_activated,
uint16_t num_prev_blocks_to_confirm,
Expand Down Expand Up @@ -238,7 +238,7 @@ struct controller_impl {
chainbase::database db;
block_log blog;
std::optional<pending_state> pending;
block_state_ptr head;
block_state_legacy_ptr head;
fork_database fork_db;
std::optional<chain_pacemaker> pacemaker;
std::atomic<uint32_t> hs_irreversible_block_num{0};
Expand Down Expand Up @@ -350,7 +350,7 @@ struct controller_impl {
set_activation_handler<builtin_protocol_feature_t::disable_deferred_trxs_stage_2>();
set_activation_handler<builtin_protocol_feature_t::instant_finality>();

self.irreversible_block.connect([this](const block_state_ptr& bsp) {
self.irreversible_block.connect([this](const block_state_legacy_ptr& bsp) {
wasmif.current_lib(bsp->block_num);
});

Expand Down Expand Up @@ -489,7 +489,7 @@ struct controller_impl {
producer_authority_schedule initial_schedule = { 0, { producer_authority{config::system_account_name, block_signing_authority_v0{ 1, {{genesis.initial_key, 1}} } } } };
legacy::producer_schedule_type initial_legacy_schedule{ 0, {{config::system_account_name, genesis.initial_key}} };

block_header_state genheader;
block_header_state_legacy genheader;
genheader.active_schedule = initial_schedule;
genheader.pending_schedule.schedule = initial_schedule;
// NOTE: if wtmsig block signatures are enabled at genesis time this should be the hash of a producer authority schedule
Expand All @@ -499,8 +499,8 @@ struct controller_impl {
genheader.id = genheader.header.calculate_id();
genheader.block_num = genheader.header.block_num();

head = std::make_shared<block_state>();
static_cast<block_header_state&>(*head) = genheader;
head = std::make_shared<block_state_legacy>();
static_cast<block_header_state_legacy&>(*head) = genheader;
head->activated_protocol_features = std::make_shared<protocol_feature_activation_set>();
head->block = std::make_shared<signed_block>(genheader.header);
db.set_revision( head->block_num );
Expand Down Expand Up @@ -856,8 +856,8 @@ struct controller_impl {
section.add_row(chain_snapshot_header(), db);
});

snapshot->write_section<block_state>([this]( auto &section ){
section.template add_row<block_header_state>(*head, db);
snapshot->write_section<block_state_legacy>([this]( auto &section ){
section.template add_row<block_header_state_legacy>(*head, db);
});

controller_index_set::walk_indices([this, &snapshot]( auto utils ){
Expand Down Expand Up @@ -907,17 +907,22 @@ struct controller_impl {
});

{ /// load and upgrade the block header state
block_header_state head_header_state;
block_header_state_legacy head_header_state;
using v2 = legacy::snapshot_block_header_state_v2;

if (std::clamp(header.version, v2::minimum_version, v2::maximum_version) == header.version ) {
snapshot->read_section<block_state>([this, &head_header_state]( auto &section ) {
snapshot->read_section("eosio::chain::block_state", [this, &head_header_state]( auto &section ) {
legacy::snapshot_block_header_state_v2 legacy_header_state;
section.read_row(legacy_header_state, db);
head_header_state = block_header_state(std::move(legacy_header_state));
head_header_state = block_header_state_legacy(std::move(legacy_header_state));
});
} else if ( header.version <= chain_snapshot_header::last_block_state_legacy_version ) {
snapshot->read_section("eosio::chain::block_state", [this,&head_header_state]( auto &section ){
section.read_row(head_header_state, db);
});
} else {
snapshot->read_section<block_state>([this,&head_header_state]( auto &section ){
#warning change block_state_legacy to new block_state when updating snapshot for IF
snapshot->read_section<block_state_legacy>([this,&head_header_state]( auto &section ){
section.read_row(head_header_state, db);
});
}
Expand All @@ -931,8 +936,8 @@ struct controller_impl {
("block_log_last_num", blog_end)
);

head = std::make_shared<block_state>();
static_cast<block_header_state&>(*head) = head_header_state;
head = std::make_shared<block_state_legacy>();
static_cast<block_header_state_legacy&>(*head) = head_header_state;
}

controller_index_set::walk_indices([this, &snapshot, &header]( auto utils ){
Expand Down Expand Up @@ -2090,7 +2095,7 @@ struct controller_impl {
}


void apply_block( controller::block_report& br, const block_state_ptr& bsp, controller::block_status s,
void apply_block( controller::block_report& br, const block_state_legacy_ptr& bsp, controller::block_status s,
const trx_meta_cache_lookup& trx_lookup )
{ try {
try {
Expand Down Expand Up @@ -2190,7 +2195,7 @@ struct controller_impl {
if( !use_bsp_cached ) {
bsp->set_trxs_metas( std::move( ab._trx_metas ), !skip_auth_checks );
}
// create completed_block with the existing block_state as we just verified it is the same as assembled_block
// create completed_block with the existing block_state_legacy as we just verified it is the same as assembled_block
pending->_block_stage = completed_block{ bsp };

br = pending->_block_report; // copy before commit block destroys pending
Expand All @@ -2214,13 +2219,13 @@ struct controller_impl {


// thread safe, expected to be called from thread other than the main thread
block_state_ptr create_block_state_i( const block_id_type& id, const signed_block_ptr& b, const block_header_state& prev ) {
block_state_legacy_ptr create_block_state_i( const block_id_type& id, const signed_block_ptr& b, const block_header_state_legacy& prev ) {
auto trx_mroot = calculate_trx_merkle( b->transactions );
EOS_ASSERT( b->transaction_mroot == trx_mroot, block_validate_exception,
"invalid block transaction merkle root ${b} != ${c}", ("b", b->transaction_mroot)("c", trx_mroot) );

const bool skip_validate_signee = false;
auto bsp = std::make_shared<block_state>(
auto bsp = std::make_shared<block_state_legacy>(
prev,
b,
protocol_features.get_protocol_feature_set(),
Expand All @@ -2237,11 +2242,11 @@ struct controller_impl {
return bsp;
}

std::future<block_state_ptr> create_block_state_future( const block_id_type& id, const signed_block_ptr& b ) {
std::future<block_state_legacy_ptr> create_block_state_future( const block_id_type& id, const signed_block_ptr& b ) {
EOS_ASSERT( b, block_validate_exception, "null block" );

return post_async_task( thread_pool.get_executor(), [b, id, control=this]() {
// no reason for a block_state if fork_db already knows about block
// no reason for a block_state_legacy if fork_db already knows about block
auto existing = control->fork_db.get_block( id );
EOS_ASSERT( !existing, fork_database_exception, "we already know about this block: ${id}", ("id", id) );

Expand All @@ -2254,10 +2259,10 @@ struct controller_impl {
}

// thread safe, expected to be called from thread other than the main thread
block_state_ptr create_block_state( const block_id_type& id, const signed_block_ptr& b ) {
block_state_legacy_ptr create_block_state( const block_id_type& id, const signed_block_ptr& b ) {
EOS_ASSERT( b, block_validate_exception, "null block" );

// no reason for a block_state if fork_db already knows about block
// no reason for a block_state_legacy if fork_db already knows about block
auto existing = fork_db.get_block( id );
EOS_ASSERT( !existing, fork_database_exception, "we already know about this block: ${id}", ("id", id) );

Expand All @@ -2269,7 +2274,7 @@ struct controller_impl {
}

void push_block( controller::block_report& br,
const block_state_ptr& bsp,
const block_state_legacy_ptr& bsp,
const forked_branch_callback& forked_branch_cb,
const trx_meta_cache_lookup& trx_lookup )
{
Expand Down Expand Up @@ -2327,7 +2332,7 @@ struct controller_impl {
emit( self.pre_accepted_block, b );
const bool skip_validate_signee = !conf.force_all_checks;

auto bsp = std::make_shared<block_state>(
auto bsp = std::make_shared<block_state_legacy>(
*head,
b,
protocol_features.get_protocol_feature_set(),
Expand Down Expand Up @@ -2366,7 +2371,7 @@ struct controller_impl {
} FC_LOG_AND_RETHROW( )
}

void maybe_switch_forks( controller::block_report& br, const block_state_ptr& new_head, controller::block_status s,
void maybe_switch_forks( controller::block_report& br, const block_state_legacy_ptr& new_head, controller::block_status s,
const forked_branch_callback& forked_branch_cb, const trx_meta_cache_lookup& trx_lookup )
{
bool head_changed = true;
Expand Down Expand Up @@ -2745,7 +2750,7 @@ struct controller_impl {
wasmif.code_block_num_last_used(code_hash, vm_type, vm_version, block_num);
}

block_state_ptr fork_db_head() const;
block_state_legacy_ptr fork_db_head() const;
}; /// controller_impl

thread_local platform_timer controller_impl::timer;
Expand Down Expand Up @@ -2973,14 +2978,14 @@ void controller::start_block( block_timestamp_type when,
bs, std::optional<block_id_type>(), deadline );
}

block_state_ptr controller::finalize_block( block_report& br, const signer_callback_type& signer_callback ) {
block_state_legacy_ptr controller::finalize_block( block_report& br, const signer_callback_type& signer_callback ) {
validate_db_available_size();

my->finalize_block();

auto& ab = std::get<assembled_block>(my->pending->_block_stage);

auto bsp = std::make_shared<block_state>(
auto bsp = std::make_shared<block_state_legacy>(
std::move( ab._pending_block_header_state ),
std::move( ab._unsigned_block ),
std::move( ab._trx_metas ),
Expand Down Expand Up @@ -3012,16 +3017,16 @@ boost::asio::io_context& controller::get_thread_pool() {
return my->thread_pool.get_executor();
}

std::future<block_state_ptr> controller::create_block_state_future( const block_id_type& id, const signed_block_ptr& b ) {
std::future<block_state_legacy_ptr> controller::create_block_state_future( const block_id_type& id, const signed_block_ptr& b ) {
return my->create_block_state_future( id, b );
}

block_state_ptr controller::create_block_state( const block_id_type& id, const signed_block_ptr& b ) const {
block_state_legacy_ptr controller::create_block_state( const block_id_type& id, const signed_block_ptr& b ) const {
return my->create_block_state( id, b );
}

void controller::push_block( controller::block_report& br,
const block_state_ptr& bsp,
const block_state_legacy_ptr& bsp,
const forked_branch_callback& forked_branch_cb,
const trx_meta_cache_lookup& trx_lookup )
{
Expand Down Expand Up @@ -3109,11 +3114,11 @@ account_name controller::head_block_producer()const {
const block_header& controller::head_block_header()const {
return my->head->header;
}
block_state_ptr controller::head_block_state()const {
block_state_legacy_ptr controller::head_block_state()const {
return my->head;
}

block_state_ptr controller_impl::fork_db_head() const {
block_state_legacy_ptr controller_impl::fork_db_head() const {
if( read_mode == db_read_mode::IRREVERSIBLE ) {
// When in IRREVERSIBLE mode fork_db blocks are marked valid when they become irreversible so that
// fork_db.head() returns irreversible block
Expand Down Expand Up @@ -3237,12 +3242,12 @@ std::optional<signed_block_header> controller::fetch_block_header_by_number( uin
return my->blog.read_block_header_by_num(block_num);
} FC_CAPTURE_AND_RETHROW( (block_num) ) }

block_state_ptr controller::fetch_block_state_by_id( block_id_type id )const {
block_state_legacy_ptr controller::fetch_block_state_by_id( block_id_type id )const {
auto state = my->fork_db.get_block(id);
return state;
}

block_state_ptr controller::fetch_block_state_by_number( uint32_t block_num )const { try {
block_state_legacy_ptr controller::fetch_block_state_by_number( uint32_t block_num )const { try {
return my->fork_db.search_on_branch( fork_db_head_block_id(), block_num );
} FC_CAPTURE_AND_RETHROW( (block_num) ) }

Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/deep_mind.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <eosio/chain/deep_mind.hpp>
#include <eosio/chain/block_state.hpp>
#include <eosio/chain/block_state_legacy.hpp>
#include <eosio/chain/generated_transaction_object.hpp>
#include <eosio/chain/contract_table_objects.hpp>
#include <eosio/chain/resource_limits_private.hpp>
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace eosio::chain {
fc_dlog(_logger, "START_BLOCK ${block_num}", ("block_num", block_num));
}

void deep_mind_handler::on_accepted_block(const std::shared_ptr<block_state>& bsp)
void deep_mind_handler::on_accepted_block(const std::shared_ptr<block_state_legacy>& bsp)
{
auto packed_blk = fc::raw::pack(*bsp);

Expand Down
Loading