Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Resolve #13: Fix simulated network propagation
Browse files Browse the repository at this point in the history
The simulated network was recursively calling push_block when
propagating blocks, which caused a lock timeout. Fix this issue by not
pushing a new block to the database that created it.

Also, replace the currently_propagating_block flag with boost's slot
blocker.
  • Loading branch information
nathanielhourt committed Apr 26, 2017
1 parent 169c6a1 commit 288f489
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
5 changes: 0 additions & 5 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ std::vector<block_id_type> database::get_block_ids_on_fork(block_id_type head_of
*/
bool database::push_block(const signed_block& new_block, uint32_t skip)
{ try {
/// TODO: the simulated network code will cause push_block to be called
/// recursively which in turn will cause the write lock to hang
if( new_block.block_num() == head_block_num() && new_block.id() == head_block_id() )
return false;

return with_skip_flags( skip, [&](){
return without_pending_transactions( [&]() {
return with_write_lock( [&]() {
Expand Down
15 changes: 8 additions & 7 deletions tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
#include <boost/test/unit_test.hpp>
#include <boost/program_options.hpp>
#include <boost/signals2/shared_connection_block.hpp>

#include <eos/chain/account_object.hpp>
#include <eos/chain/producer_object.hpp>
Expand Down Expand Up @@ -151,9 +152,8 @@ void testing_network::connect_database(testing_database& new_database) {
}

// The new database is now in sync with any old ones; go ahead and connect the propagation signal.
databases[&new_database] = new_database.applied_block.connect([this](const signed_block& block) {
if (!currently_propagating_block)
propagate_block(block);
databases[&new_database] = new_database.applied_block.connect([this, &new_database](const signed_block& block) {
propagate_block(block, new_database);
});
}

Expand All @@ -165,11 +165,12 @@ void testing_network::disconnect_all() {
databases.clear();
}

void testing_network::propagate_block(const signed_block& block) {
currently_propagating_block = true;
for (const auto& pair : databases)
void testing_network::propagate_block(const signed_block& block, const testing_database& skip_db) {
for (const auto& pair : databases) {
if (pair.first == &skip_db) continue;
boost::signals2::shared_connection_block blocker(pair.second);
pair.first->push_block(block);
currently_propagating_block = false;
}
}

} } // eos::chain
3 changes: 1 addition & 2 deletions tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,10 @@ class testing_network {
* @brief Send a block to all databases in this network
* @param block The block to send
*/
void propagate_block(const signed_block& block);
void propagate_block(const signed_block& block, const testing_database& skip_db);

protected:
std::map<testing_database*, fc::scoped_connection> databases;
bool currently_propagating_block = false;
};

/// Some helpful macros to reduce boilerplate when making a testing_network and connecting some testing_databases @{
Expand Down

0 comments on commit 288f489

Please sign in to comment.