Skip to content

Commit

Permalink
Rebroadcast the mem pool every 3-6 blocks steemit#1661
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Oct 16, 2017
1 parent 12d90a0 commit b5117f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 17 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ namespace detail {
class application_impl : public graphene::net::node_delegate
{
public:
uint32_t _next_rebroadcast = -1;
boost::signals2::connection _rebroadcast_con;
fc::optional<fc::temp_file> _lock_file;
bool _is_block_producer = false;
bool _force_validate = false;
Expand Down Expand Up @@ -234,6 +236,18 @@ namespace detail {
c->set_session_data( session );
}

void rebroadcast_pending_tx()
{
if( _chain_db->head_block_num() >= _next_rebroadcast )
{
_next_rebroadcast += 3 + ( rand() % 4 ); // Every 3-6 blocks, rebroadcast. Do this randomly to prevent simultaneous p2p spam.
for( const auto& trx : _chain_db->_pending_tx )
{
_p2p_network->broadcast( graphene::net::trx_message( trx ) );
}
}
}

application_impl(application* self)
: _self(self),
//_pending_trx_db(std::make_shared<graphene::db::object_database>()),
Expand Down Expand Up @@ -351,6 +365,9 @@ namespace detail {
}
_chain_db->show_free_memory( true );

_next_rebroadcast = _chain_db->head_block_num() + 3 + rand() % 4;
_rebroadcast_con = _chain_db->applied_block.connect( [&]( const signed_block& b ){ rebroadcast_pending_tx(); } );

if( _options->count("api-user") )
{
for( const std::string& api_access_str : _options->at("api-user").as< std::vector<std::string> >() )
Expand Down
3 changes: 1 addition & 2 deletions libraries/chain/include/steemit/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ namespace steemit { namespace chain {
/** when popping a block, the transactions that were removed get cached here so they
* can be reapplied at the proper time */
std::deque< signed_transaction > _popped_tx;

vector< signed_transaction > _pending_tx;

bool apply_order( const limit_order_object& new_order_object );
bool fill_order( const limit_order_object& order, const asset& pays, const asset& receives );
Expand Down Expand Up @@ -450,7 +450,6 @@ namespace steemit { namespace chain {

std::unique_ptr< database_impl > _my;

vector< signed_transaction > _pending_tx;
fork_database _fork_db;
fc::time_point_sec _hardfork_times[ STEEMIT_NUM_HARDFORKS + 1 ];
protocol::hardfork_version _hardfork_versions[ STEEMIT_NUM_HARDFORKS + 1 ];
Expand Down

0 comments on commit b5117f9

Please sign in to comment.