Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix bug in get_block of chain_plugin that would lead to unnecessary failures for some block numbers #6904

Merged
merged 1 commit into from
Mar 9, 2019
Merged
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
26 changes: 18 additions & 8 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ uint64_t convert_to_type(const string& str, const string& desc) {
try {
return boost::lexical_cast<uint64_t>(str.c_str(), str.size());
} catch( ... ) { }

try {
auto trimmed_str = str;
boost::trim(trimmed_str);
Expand All @@ -1138,7 +1138,7 @@ uint64_t convert_to_type(const string& str, const string& desc) {
return symb.value();
} catch( ... ) { }
}

try {
return ( eosio::chain::string_to_symbol( 0, str.c_str() ) >> 8 );
} catch( ... ) {
Expand Down Expand Up @@ -1529,14 +1529,24 @@ read_only::get_scheduled_transactions( const read_only::get_scheduled_transactio

fc::variant read_only::get_block(const read_only::get_block_params& params) const {
signed_block_ptr block;
EOS_ASSERT(!params.block_num_or_id.empty() && params.block_num_or_id.size() <= 64, chain::block_id_type_exception, "Invalid Block number or ID, must be greater than 0 and less than 64 characters" );
optional<uint64_t> block_num;

EOS_ASSERT( !params.block_num_or_id.empty() && params.block_num_or_id.size() <= 64,
chain::block_id_type_exception,
"Invalid Block number or ID, must be greater than 0 and less than 64 characters"
);

try {
block = db.fetch_block_by_id(fc::variant(params.block_num_or_id).as<block_id_type>());
if (!block) {
block = db.fetch_block_by_number(fc::to_uint64(params.block_num_or_id));
}
block_num = fc::to_uint64(params.block_num_or_id);
} catch( ... ) {}

} EOS_RETHROW_EXCEPTIONS(chain::block_id_type_exception, "Invalid block ID: ${block_num_or_id}", ("block_num_or_id", params.block_num_or_id))
if( block_num.valid() ) {
block = db.fetch_block_by_number( *block_num );
} else {
try {
block = db.fetch_block_by_id( fc::variant(params.block_num_or_id).as<block_id_type>() );
} EOS_RETHROW_EXCEPTIONS(chain::block_id_type_exception, "Invalid block ID: ${block_num_or_id}", ("block_num_or_id", params.block_num_or_id))
}

EOS_ASSERT( block, unknown_block_exception, "Could not find block: ${block}", ("block", params.block_num_or_id));

Expand Down