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

Fix issue with reported fork head vs retrieval of block from fork db #774

Merged
merged 6 commits into from
Mar 5, 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
42 changes: 11 additions & 31 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3011,35 +3011,19 @@ block_state_ptr controller::head_block_state()const {
}

uint32_t controller::fork_db_head_block_num()const {
return my->fork_db.head()->block_num;
if( my->read_mode == db_read_mode::IRREVERSIBLE ) {
return my->fork_db.pending_head()->block_num;
} else {
return my->fork_db.head()->block_num;
}
}

block_id_type controller::fork_db_head_block_id()const {
return my->fork_db.head()->id;
}

time_point controller::fork_db_head_block_time()const {
return my->fork_db.head()->header.timestamp;
}

account_name controller::fork_db_head_block_producer()const {
return my->fork_db.head()->header.producer;
}

uint32_t controller::fork_db_pending_head_block_num()const {
return my->fork_db.pending_head()->block_num;
}

block_id_type controller::fork_db_pending_head_block_id()const {
return my->fork_db.pending_head()->id;
}

time_point controller::fork_db_pending_head_block_time()const {
return my->fork_db.pending_head()->header.timestamp;
}

account_name controller::fork_db_pending_head_block_producer()const {
return my->fork_db.pending_head()->header.producer;
if( my->read_mode == db_read_mode::IRREVERSIBLE ) {
return my->fork_db.pending_head()->id;
} else {
return my->fork_db.head()->id;
}
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
}

time_point controller::pending_block_time()const {
Expand Down Expand Up @@ -3126,11 +3110,7 @@ block_state_ptr controller::fetch_block_state_by_id( block_id_type id )const {
}

block_state_ptr controller::fetch_block_state_by_number( uint32_t block_num )const { try {
if( my->read_mode == db_read_mode::IRREVERSIBLE ) {
return my->fork_db.search_on_branch( my->fork_db.pending_head()->id, block_num );
} else {
return my->fork_db.search_on_branch( my->fork_db.head()->id, block_num );
}
return my->fork_db.search_on_branch( fork_db_head_block_id(), block_num );
} FC_CAPTURE_AND_RETHROW( (block_num) ) }

block_id_type controller::get_block_id_for_num( uint32_t block_num )const { try {
Expand Down
7 changes: 0 additions & 7 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,6 @@ namespace eosio { namespace chain {

uint32_t fork_db_head_block_num()const;
block_id_type fork_db_head_block_id()const;
time_point fork_db_head_block_time()const;
account_name fork_db_head_block_producer()const;

uint32_t fork_db_pending_head_block_num()const;
block_id_type fork_db_pending_head_block_id()const;
time_point fork_db_pending_head_block_time()const;
account_name fork_db_pending_head_block_producer()const;

time_point pending_block_time()const;
account_name pending_block_producer()const;
Expand Down
4 changes: 2 additions & 2 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,8 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params
//std::bitset<64>(db.get_dynamic_global_properties().recent_slots_filled).to_string(),
//__builtin_popcountll(db.get_dynamic_global_properties().recent_slots_filled) / 64.0,
app().version_string(),
db.fork_db_pending_head_block_num(),
db.fork_db_pending_head_block_id(),
db.fork_db_head_block_num(),
db.fork_db_head_block_id(),
app().full_version_string(),
rm.get_total_cpu_weight(),
rm.get_total_net_weight(),
Expand Down
4 changes: 2 additions & 2 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2728,8 +2728,8 @@ namespace eosio {
chain_lib_id = cc.last_irreversible_block_id();
chain_head_blk_num = cc.head_block_num();
chain_head_blk_id = cc.head_block_id();
chain_fork_head_blk_num = cc.fork_db_pending_head_block_num();
chain_fork_head_blk_id = cc.fork_db_pending_head_block_id();
chain_fork_head_blk_num = cc.fork_db_head_block_num();
chain_fork_head_blk_id = cc.fork_db_head_block_id();
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
fc_dlog( logger, "updating chain info lib ${lib}, head ${head}, fork ${fork}",
("lib", chain_lib_num)("head", chain_head_blk_num)("fork", chain_fork_head_blk_num) );
}
Expand Down
6 changes: 3 additions & 3 deletions unittests/fork_test_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public_key_type get_public_key( name keyname, string role ){
}

void push_blocks( tester& from, tester& to, uint32_t block_num_limit ) {
while( to.control->fork_db_pending_head_block_num()
< std::min( from.control->fork_db_pending_head_block_num(), block_num_limit ) )
while( to.control->fork_db_head_block_num()
< std::min( from.control->fork_db_head_block_num(), block_num_limit ) )
{
auto fb = from.control->fetch_block_by_number( to.control->fork_db_pending_head_block_num()+1 );
auto fb = from.control->fetch_block_by_number( to.control->fork_db_head_block_num()+1 );
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
to.push_block( fb );
}
}
Expand Down
9 changes: 4 additions & 5 deletions unittests/forked_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ BOOST_AUTO_TEST_CASE( read_modes ) try {

tester irreversible(setup_policy::none, db_read_mode::IRREVERSIBLE);
push_blocks(c, irreversible);
BOOST_CHECK_EQUAL(head_block_num, irreversible.control->fork_db_pending_head_block_num());
BOOST_CHECK_EQUAL(last_irreversible_block_num, irreversible.control->fork_db_head_block_num());
BOOST_CHECK_EQUAL(head_block_num, irreversible.control->fork_db_head_block_num());
BOOST_CHECK_EQUAL(last_irreversible_block_num, irreversible.control->head_block_num());

} FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -471,13 +470,13 @@ BOOST_AUTO_TEST_CASE( irreversible_mode ) try {

push_blocks( main, irreversible, hbn1 );

BOOST_CHECK_EQUAL( irreversible.control->fork_db_pending_head_block_num(), hbn1 );
BOOST_CHECK_EQUAL( irreversible.control->fork_db_head_block_num(), hbn1 );
BOOST_CHECK_EQUAL( irreversible.control->head_block_num(), lib1 );
BOOST_CHECK_EQUAL( does_account_exist( irreversible, "alice"_n ), false );

push_blocks( other, irreversible, hbn4 );

BOOST_CHECK_EQUAL( irreversible.control->fork_db_pending_head_block_num(), hbn4 );
BOOST_CHECK_EQUAL( irreversible.control->fork_db_head_block_num(), hbn4 );
BOOST_CHECK_EQUAL( irreversible.control->head_block_num(), lib4 );
BOOST_CHECK_EQUAL( does_account_exist( irreversible, "alice"_n ), false );

Expand All @@ -487,7 +486,7 @@ BOOST_AUTO_TEST_CASE( irreversible_mode ) try {
irreversible.push_block( fb );
}

BOOST_CHECK_EQUAL( irreversible.control->fork_db_pending_head_block_num(), hbn3 );
BOOST_CHECK_EQUAL( irreversible.control->fork_db_head_block_num(), hbn3 );
BOOST_CHECK_EQUAL( irreversible.control->head_block_num(), lib3 );
BOOST_CHECK_EQUAL( does_account_exist( irreversible, "alice"_n ), true );

Expand Down
6 changes: 3 additions & 3 deletions unittests/state_history_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ BOOST_AUTO_TEST_CASE(test_splitted_log) {
}

void push_blocks( tester& from, tester& to ) {
while( to.control->fork_db_pending_head_block_num()
< from.control->fork_db_pending_head_block_num() )
while( to.control->fork_db_head_block_num()
< from.control->fork_db_head_block_num() )
{
auto fb = from.control->fetch_block_by_number( to.control->fork_db_pending_head_block_num()+1 );
auto fb = from.control->fetch_block_by_number( to.control->fork_db_head_block_num()+1 );
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
to.push_block( fb );
}
}
Expand Down