Skip to content

Commit

Permalink
Explicitly name sentinel value steemit#606
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Dec 9, 2016
1 parent bbb61ba commit fbbc80e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace steemit { namespace chain {
{
optional< signed_block > b;
uint64_t pos = get_block_pos( block_num );
if( ~pos )
if( pos != npos )
b = read_block( pos ).first;
return b;
}
Expand All @@ -214,7 +214,7 @@ namespace steemit { namespace chain {
my->check_index_read();

if( !( my->head && block_num <= protocol::block_header::num_from_id( my->head_id ) ) )
return ~0;
return npos;
my->index_stream.seekg( sizeof( uint64_t ) * ( block_num - 1 ) );
uint64_t pos;
my->index_stream.read( (char*)&pos, sizeof( pos ) );
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/include/steemit/chain/block_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ namespace steemit { namespace chain {
void flush();
std::pair< signed_block, uint64_t > read_block( uint64_t file_pos )const;
optional< signed_block > read_block_by_num( uint32_t block_num )const;

/**
* Return offset of block in file, or block_log::npos if it does not exist.
*/
uint64_t get_block_pos( uint32_t block_num ) const;
signed_block read_head()const;
const optional< signed_block >& head()const;

static const uint64_t npos = std::numeric_limits<uint64_t>::max();

private:
void construct_index( uint64_t start_pos );

Expand Down
18 changes: 15 additions & 3 deletions libraries/plugins/debug_node/debug_node_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,25 @@ uint32_t debug_node_api_impl::debug_push_blocks( const std::string& src_filename
for( uint32_t i=0; i<count; i++ )
{
//fc::optional< steemit::chain::signed_block > block = log.read_block( log.get_block_pos( first_block + i ) );
auto result = log.read_block( log.get_block_pos( first_block + i ) );

if( result.second == ~0 )
uint64_t block_pos = log.get_block_pos( first_block + i );
if( block_pos == steemit::chain::block_log::npos )
{
wlog( "Block database ${fn} only contained ${i} of ${n} requested blocks", ("i", i)("n", count)("fn", src_filename) );
return i;
}

decltype( log.read_block(0) ) result;

try
{
result = log.read_block( block_pos );
}
catch( const fc::exception& e )
{
elog( "Could not read block ${i} of ${n}", ("i", i)("n", count) );
continue;
}

try
{
db->push_block( result.first, skip_flags );
Expand Down

0 comments on commit fbbc80e

Please sign in to comment.