block_database.cpp: Argument validation and logging in store() and fetch_block_id()
This commit is contained in:
parent
6372b25dea
commit
32b18f6c20
1 changed files with 9 additions and 1 deletions
|
|
@ -68,8 +68,14 @@ void block_database::flush()
|
|||
_block_num_to_pos.flush();
|
||||
}
|
||||
|
||||
void block_database::store( const block_id_type& id, const signed_block& b )
|
||||
void block_database::store( const block_id_type& _id, const signed_block& b )
|
||||
{
|
||||
block_id_type id = _id;
|
||||
if( id == block_id_type() )
|
||||
{
|
||||
id = b.id();
|
||||
elog( "id argument of block_database::store() was not initialized for block ${id}", ("id", id) );
|
||||
}
|
||||
auto num = block_header::num_from_id(id);
|
||||
_block_num_to_pos.seekp( sizeof( index_entry ) * num );
|
||||
index_entry e;
|
||||
|
|
@ -116,6 +122,7 @@ bool block_database::contains( const block_id_type& id )const
|
|||
|
||||
block_id_type block_database::fetch_block_id( uint32_t block_num )const
|
||||
{
|
||||
assert( block_num != 0 );
|
||||
index_entry e;
|
||||
auto index_pos = sizeof(e)*block_num;
|
||||
_block_num_to_pos.seekg( 0, _block_num_to_pos.end );
|
||||
|
|
@ -125,6 +132,7 @@ block_id_type block_database::fetch_block_id( uint32_t block_num )const
|
|||
_block_num_to_pos.seekg( index_pos );
|
||||
_block_num_to_pos.read( (char*)&e, sizeof(e) );
|
||||
|
||||
FC_ASSERT( e.block_id != block_id_type(), "Empty block_id in block_database (maybe corrupt on disk?)" );
|
||||
return e.block_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue