Skip to content

Commit

Permalink
Merge branch 'main' of github.com:armoniax/amax.meta.chain
Browse files Browse the repository at this point in the history
  • Loading branch information
amaxcoredev committed Oct 16, 2024
2 parents 2bb75a7 + 520f701 commit dd423bc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
3 changes: 1 addition & 2 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,8 @@ namespace eosio { namespace chain {
fc::raw::unpack(ds, bh);
}

full_signed_block_ptr block_log::read_block_by_num(uint32_t block_num ,bool is_backup)const {
full_signed_block_ptr block_log::read_block_by_num(uint32_t block_num)const {
try {
if( is_backup ) ++block_num;
full_signed_block_ptr b;
uint64_t pos = get_block_pos(block_num);
if (pos != npos) {
Expand Down
28 changes: 18 additions & 10 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3142,17 +3142,15 @@ const global_property_object& controller::get_global_properties()const {
signed_block_ptr controller::fetch_block_by_id( block_id_type id )const {
auto state = my->fork_db.get_block(id);
if( state && state->block ) return state->block;
auto bptr = fetch_block_by_number( block_header::num_from_id(id) );

auto block_num = block_header::num_from_id(id);
auto bptr = fetch_block_by_number( block_num );
if( bptr && bptr->id() == id ){
return bptr;
}else{
bptr = fetch_block_by_number( block_header::num_from_id(id) , true );
fc_dlog(_backup_block_trace_log,"[BACKUP_TRACE] fetch backup block by id in controller, find: ${found}",("found",bptr != nullptr? true: false));
if( bptr ){
//fc_dlog(_backup_block_trace_log,"[BACKUP_TRACE] found id: ${fid}: wanted: ${wid}",("fid",bptr->id())("wid",id));
if( bptr->id() == id ){
return bptr;
}
if( bptr && bptr->id() == id ){
return bptr;
}
}
return signed_block_ptr();
Expand All @@ -3163,9 +3161,19 @@ signed_block_ptr controller::fetch_block_by_number( uint32_t block_num , bool is
if( blk_state ) {
return blk_state->block;
}
full_signed_block_ptr candinate = my->blog.read_block_by_num(block_num , is_backup);
if( !candinate ) return signed_block_ptr();
return !is_backup ? candinate->main_block : candinate->backup_block;

if (!is_backup) {
auto fb = my->blog.read_block_by_num(block_num);
if (fb) {
return fb->main_block;
}
} else { // backup block
auto fb = my->blog.read_block_by_num(block_num + 1);
if (fb) {
return fb->backup_block;
}
}
return signed_block_ptr();
} FC_CAPTURE_AND_RETHROW( (block_num) ) }

block_state_ptr controller::fetch_block_state_by_id( block_id_type id )const {
Expand Down
16 changes: 1 addition & 15 deletions libraries/chain/include/eosio/chain/block_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,8 @@ namespace eosio { namespace chain {

full_signed_block_ptr read_block(uint64_t file_pos)const;
void read_block_header(block_header& bh, uint64_t file_pos)const;
full_signed_block_ptr read_block_by_num(uint32_t block_num , bool is_backup = false)const;
full_signed_block_ptr read_block_by_num(uint32_t block_num)const;
block_id_type read_block_id_by_num(uint32_t block_num)const;
signed_block_ptr read_block_by_id(const block_id_type& id)const {
auto block_num = block_header::num_from_id(id);
full_signed_block_ptr block = read_block_by_num( block_num );
if( block ){
return block->main_block;
}

block = read_block_by_num( block_num+1 );
if( block ){
return block->backup_block;
}

return nullptr;
}

/**
* Return offset of block in file, or block_log::npos if it does not exist.
Expand Down
9 changes: 7 additions & 2 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,10 @@ std::string itoh(I n, size_t hlen = sizeof(I)<<1) {
read_only::get_info_results read_only::get_info(const read_only::get_info_params&) const {
const auto& rm = db.get_resource_limits_manager();
auto hbs = db.head_block_state();
optional<previous_backup_info> previous_backup;
if (hbs && hbs->block) {
previous_backup = hbs->block->backup_ext().previous_backup;
}
return {
itoh(static_cast<uint32_t>(app().version())),
db.get_chain_id(),
Expand All @@ -1542,7 +1546,7 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params
db.fork_db_pending_head_block_num(),
db.fork_db_pending_head_block_id(),
app().full_version_string(),
hbs->block->backup_ext().previous_backup
previous_backup
};
}

Expand Down Expand Up @@ -2208,8 +2212,9 @@ fc::variant read_only::get_block(const read_only::get_block_params& params) cons
block_num = fc::to_uint64(params.block_num_or_id);
} catch( ... ) {}

bool is_backup = params.is_backup.valid() ? *params.is_backup : false;
if( block_num.valid() ) {
block = db.fetch_block_by_number( *block_num, *(params.is_backup) );
block = db.fetch_block_by_number( *block_num, is_backup );
} else {
try {
block = db.fetch_block_by_id( fc::variant(params.block_num_or_id).as<block_id_type>() );
Expand Down
2 changes: 1 addition & 1 deletion plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ void producer_plugin_impl::produce_block() {
block_state_ptr head_bs = chain.head_block_state();
bool is_head = !new_bs->is_backup() && ( new_bs == head_bs || new_bs->id == head_bs->id );
ilog("Produced block ${id}... #${n} @ ${t} signed by ${p} [trxs: ${count}, lib: ${lib}, "
"confirmed: ${confs}, is_backup: ${is_backup}, is_head=${is_head}]",
"confirmed: ${confs}, is_backup: ${is_backup}, is_head: ${is_head}]",
("p",new_bs->header.producer)("id",new_bs->id.str().substr(8,16))
("n",new_bs->block_num)("t",new_bs->header.timestamp)
("count",new_bs->block->transactions.size())
Expand Down
5 changes: 2 additions & 3 deletions programs/amax-blocklog/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ void blocklog::read_log() {
next = temp->main_block;
if (as_json_array && contains_obj)
*out << ",";
if( !next->previous_backup_id().empty() ){
backup_of_next = block_logger.read_block_by_num( block_num-1 , true)->backup_block;
print_block( backup_of_next );
if( !next->previous_backup_id().empty() && temp->backup_block ){
print_block( temp->backup_block );
*out << ",";
}
print_block(next);
Expand Down

0 comments on commit dd423bc

Please sign in to comment.