Prevent losing transactions after broadcast #625
4 changed files with 59 additions and 14 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -1,4 +1,4 @@
|
|||
FROM ubuntu:18.04
|
||||
FROM ubuntu:20.04
|
||||
MAINTAINER PeerPlays Blockchain Standards Association
|
||||
|
||||
ENV LANG en_US.UTF-8
|
||||
|
|
@ -59,7 +59,7 @@ RUN \
|
|||
cd build/release && \
|
||||
cmake \
|
||||
-DBOOST_ROOT="$BOOST_ROOT" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
../.. && \
|
||||
make witness_node cli_wallet && \
|
||||
install -s programs/witness_node/witness_node programs/cli_wallet/cli_wallet /usr/local/bin && \
|
||||
|
|
@ -82,10 +82,16 @@ VOLUME ["/var/lib/peerplays", "/etc/peerplays"]
|
|||
# rpc service:
|
||||
EXPOSE 8090
|
||||
# p2p service:
|
||||
EXPOSE 1776
|
||||
EXPOSE 9777
|
||||
EXPOSE 19777
|
||||
EXPOSE 29777
|
||||
EXPOSE 39777
|
||||
EXPOSE 49777
|
||||
EXPOSE 59777
|
||||
|
||||
# default exec/config files
|
||||
ADD docker/default_config.ini /etc/peerplays/config.ini
|
||||
ADD docker/logging.ini /etc/peerplays/logging.ini
|
||||
ADD docker/peerplaysentry.sh /usr/local/bin/peerplaysentry.sh
|
||||
RUN chmod a+x /usr/local/bin/peerplaysentry.sh
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ fi
|
|||
## Link the peerplays config file into home
|
||||
## This link has been created in Dockerfile, already
|
||||
ln -f -s /etc/peerplays/config.ini /var/lib/peerplays
|
||||
ln -f -s /etc/peerplays/logging.ini /var/lib/peerplays
|
||||
|
||||
# Plugins need to be provided in a space-separated list, which
|
||||
# makes it necessary to write it like this
|
||||
|
|
|
|||
|
|
@ -103,8 +103,15 @@ void block_database::remove( const block_id_type& id )
|
|||
index_entry e;
|
||||
auto index_pos = sizeof(e)*block_header::num_from_id(id);
|
||||
_block_num_to_pos.seekg( 0, _block_num_to_pos.end );
|
||||
if ( _block_num_to_pos.tellg() <= index_pos )
|
||||
|
||||
std::streampos s_pos = _block_num_to_pos.tellg();
|
||||
if (-1 == s_pos){
|
||||
FC_THROW_EXCEPTION(fc::key_not_found_exception, "Block ${id} not contained in block database, _block_num_to_pos.tellg failed", ("id", id));
|
||||
}
|
||||
|
||||
if ( static_cast<uint32_t>(s_pos) <= index_pos ){
|
||||
FC_THROW_EXCEPTION(fc::key_not_found_exception, "Block ${id} not contained in block database", ("id", id));
|
||||
}
|
||||
|
||||
_block_num_to_pos.seekg( index_pos );
|
||||
_block_num_to_pos.read( (char*)&e, sizeof(e) );
|
||||
|
|
@ -118,20 +125,27 @@ void block_database::remove( const block_id_type& id )
|
|||
} FC_CAPTURE_AND_RETHROW( (id) ) }
|
||||
|
||||
bool block_database::contains( const block_id_type& id )const
|
||||
{
|
||||
{ try {
|
||||
if( id == block_id_type() )
|
||||
return false;
|
||||
|
||||
index_entry e;
|
||||
auto index_pos = sizeof(e)*block_header::num_from_id(id);
|
||||
_block_num_to_pos.seekg( 0, _block_num_to_pos.end );
|
||||
if ( _block_num_to_pos.tellg() < index_pos + sizeof(e) )
|
||||
|
||||
std::streampos s_pos = _block_num_to_pos.tellg();
|
||||
if (-1 == s_pos){
|
||||
FC_THROW_EXCEPTION(fc::key_not_found_exception, "Block ${id} not contained in block database, _block_num_to_pos.tellg failed", ("id", id));
|
||||
}
|
||||
|
||||
if ( static_cast<uint32_t>(s_pos) < index_pos + sizeof(e) )
|
||||
return false;
|
||||
|
||||
_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;
|
||||
}
|
||||
} FC_CAPTURE_AND_RETHROW( (id) ) }
|
||||
|
||||
block_id_type block_database::fetch_block_id( uint32_t block_num )const
|
||||
{
|
||||
|
|
@ -156,7 +170,13 @@ optional<signed_block> block_database::fetch_optional( const block_id_type& id )
|
|||
index_entry e;
|
||||
auto index_pos = sizeof(e)*block_header::num_from_id(id);
|
||||
_block_num_to_pos.seekg( 0, _block_num_to_pos.end );
|
||||
if ( _block_num_to_pos.tellg() <= index_pos )
|
||||
std::streampos s_pos = _block_num_to_pos.tellg();
|
||||
|
||||
if (-1 == s_pos){
|
||||
FC_THROW_EXCEPTION(fc::key_not_found_exception, "Block ${id} not contained in block database, _block_num_to_pos.tellg failed", ("id", id));
|
||||
}
|
||||
|
||||
if ( static_cast<uint32_t>(s_pos) <= index_pos )
|
||||
return {};
|
||||
|
||||
_block_num_to_pos.seekg( index_pos );
|
||||
|
|
@ -188,7 +208,12 @@ optional<signed_block> block_database::fetch_by_number( uint32_t block_num )cons
|
|||
index_entry e;
|
||||
auto index_pos = sizeof(e)*block_num;
|
||||
_block_num_to_pos.seekg( 0, _block_num_to_pos.end );
|
||||
if ( _block_num_to_pos.tellg() <= index_pos )
|
||||
std::streampos s_pos = _block_num_to_pos.tellg();
|
||||
if (-1 == s_pos){
|
||||
FC_THROW_EXCEPTION(fc::key_not_found_exception, "Block ${block_num} not contained in block database, _block_num_to_pos.tellg failed", ("block_num", block_num));
|
||||
}
|
||||
|
||||
if ( static_cast<uint32_t>(s_pos) <= index_pos )
|
||||
return {};
|
||||
|
||||
_block_num_to_pos.seekg( index_pos, _block_num_to_pos.beg );
|
||||
|
|
@ -217,7 +242,11 @@ optional<index_entry> block_database::last_index_entry()const {
|
|||
|
||||
_block_num_to_pos.seekg( 0, _block_num_to_pos.end );
|
||||
std::streampos pos = _block_num_to_pos.tellg();
|
||||
if( pos < sizeof(index_entry) )
|
||||
if (-1 == pos){
|
||||
FC_THROW_EXCEPTION(fc::key_not_found_exception, "last_index_entry tellg failed");
|
||||
}
|
||||
|
||||
if( static_cast<size_t>(pos) < sizeof(index_entry) )
|
||||
return optional<index_entry>();
|
||||
|
||||
pos -= pos % sizeof(index_entry);
|
||||
|
|
@ -230,7 +259,7 @@ optional<index_entry> block_database::last_index_entry()const {
|
|||
_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
|
||||
&& e.block_pos + e.block_size <= blocks_size )
|
||||
&& e.block_pos + static_cast<uint64_t>(e.block_size) <= static_cast<uint64_t>(blocks_size) )
|
||||
try
|
||||
{
|
||||
vector<char> data( e.block_size );
|
||||
|
|
|
|||
|
|
@ -477,6 +477,7 @@ namespace graphene { namespace net { namespace detail {
|
|||
// @{
|
||||
fc::promise<void>::ptr _retrigger_advertise_inventory_loop_promise;
|
||||
fc::future<void> _advertise_inventory_loop_done;
|
||||
fc::mutex _new_inventory_mutex; /// mutex to protect _new_inventory
|
||||
std::unordered_set<item_id> _new_inventory; /// list of items we have received but not yet advertised to our peers
|
||||
// @}
|
||||
|
||||
|
|
@ -1239,7 +1240,11 @@ namespace graphene { namespace net { namespace detail {
|
|||
dlog("beginning an iteration of advertise inventory");
|
||||
// swap inventory into local variable, clearing the node's copy
|
||||
std::unordered_set<item_id> inventory_to_advertise;
|
||||
inventory_to_advertise.swap(_new_inventory);
|
||||
|
||||
{
|
||||
fc::scoped_lock<fc::mutex> lock(_new_inventory_mutex);
|
||||
inventory_to_advertise.swap(_new_inventory);
|
||||
}
|
||||
|
||||
// process all inventory to advertise and construct the inventory messages we'll send
|
||||
// first, then send them all in a batch (to avoid any fiber interruption points while
|
||||
|
|
@ -1295,7 +1300,8 @@ namespace graphene { namespace net { namespace detail {
|
|||
iter->first->send_message(iter->second);
|
||||
inventory_messages_to_send.clear();
|
||||
|
||||
if (_new_inventory.empty())
|
||||
fc::scoped_lock<fc::mutex> lock(_new_inventory_mutex);
|
||||
if (_new_inventory.empty())
|
||||
{
|
||||
_retrigger_advertise_inventory_loop_promise = fc::promise<void>::ptr(new fc::promise<void>("graphene::net::retrigger_advertise_inventory_loop"));
|
||||
_retrigger_advertise_inventory_loop_promise->wait();
|
||||
|
|
@ -4964,7 +4970,10 @@ namespace graphene { namespace net { namespace detail {
|
|||
message_hash_type hash_of_item_to_broadcast = item_to_broadcast.id();
|
||||
|
||||
_message_cache.cache_message( item_to_broadcast, hash_of_item_to_broadcast, propagation_data, hash_of_message_contents );
|
||||
_new_inventory.insert( item_id(item_to_broadcast.msg_type, hash_of_item_to_broadcast ) );
|
||||
{
|
||||
fc::scoped_lock<fc::mutex> lock(_new_inventory_mutex);
|
||||
_new_inventory.insert( item_id(item_to_broadcast.msg_type, hash_of_item_to_broadcast ) );
|
||||
}
|
||||
trigger_advertise_inventory_loop();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue