From 9cb6b5f38d832780d37fecc687e1bf7538a6913a Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 10 Apr 2019 20:48:49 +0200 Subject: [PATCH] Fixed endianness in block_database index file --- libraries/chain/block_database.cpp | 39 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/libraries/chain/block_database.cpp b/libraries/chain/block_database.cpp index c5fa6636a8..a483e0314f 100644 --- a/libraries/chain/block_database.cpp +++ b/libraries/chain/block_database.cpp @@ -24,14 +24,19 @@ #include #include #include +#include namespace graphene { namespace chain { struct index_entry { - uint64_t block_pos = 0; - uint32_t block_size = 0; - block_id_type block_id; + index_entry() { + block_pos = 0; + block_size = 0; + }; + boost::endian::little_uint64_buf_t block_pos; + boost::endian::little_uint32_buf_t block_size; + block_id_type block_id; }; }} FC_REFLECT( graphene::chain::index_entry, (block_pos)(block_size)(block_id) ); @@ -125,7 +130,7 @@ bool block_database::contains( const block_id_type& id )const _block_num_to_pos.seekg( index_pos ); _block_num_to_pos.read( (char*)&e, sizeof(e) ); - return e.block_id == id && e.block_size > 0; + return e.block_id == id && e.block_size.value() > 0; } block_id_type block_database::fetch_block_id( uint32_t block_num )const @@ -159,10 +164,10 @@ optional block_database::fetch_optional( const block_id_type& id ) if( e.block_id != id ) return optional(); - vector data( e.block_size ); - _blocks.seekg( e.block_pos ); - if (e.block_size) - _blocks.read( data.data(), e.block_size ); + vector data( e.block_size.value() ); + _blocks.seekg( e.block_pos.value() ); + if (e.block_size.value()) + _blocks.read( data.data(), e.block_size.value() ); auto result = fc::raw::unpack(data); FC_ASSERT( result.id() == e.block_id ); return result; @@ -189,9 +194,9 @@ optional block_database::fetch_by_number( uint32_t block_num )cons _block_num_to_pos.seekg( index_pos, _block_num_to_pos.beg ); _block_num_to_pos.read( (char*)&e, sizeof(e) ); - vector data( e.block_size ); - _blocks.seekg( e.block_pos ); - _blocks.read( data.data(), e.block_size ); + vector data( e.block_size.value() ); + _blocks.seekg( e.block_pos.value() ); + _blocks.read( data.data(), e.block_size.value() ); auto result = fc::raw::unpack(data); FC_ASSERT( result.id() == e.block_id ); return result; @@ -224,14 +229,14 @@ optional block_database::last_index_entry()const { pos -= sizeof(index_entry); _block_num_to_pos.seekg( pos ); _block_num_to_pos.read( (char*)&e, sizeof(e) ); - if( _block_num_to_pos.gcount() == sizeof(e) && e.block_size > 0 - && int64_t(e.block_pos + e.block_size) <= blocks_size ) + if( _block_num_to_pos.gcount() == sizeof(e) && e.block_size.value() > 0 + && int64_t(e.block_pos.value() + e.block_size.value()) <= blocks_size ) try { - vector data( e.block_size ); - _blocks.seekg( e.block_pos ); - _blocks.read( data.data(), e.block_size ); - if( _blocks.gcount() == long(e.block_size) ) + vector data( e.block_size.value() ); + _blocks.seekg( e.block_pos.value() ); + _blocks.read( data.data(), e.block_size.value() ); + if( _blocks.gcount() == long(e.block_size.value()) ) { const signed_block block = fc::raw::unpack(data); if( block.id() == e.block_id )