diff --git a/rai/core_test/block_synchronization.cpp b/rai/core_test/block_synchronization.cpp index 312e61dfc7..055ecb6369 100644 --- a/rai/core_test/block_synchronization.cpp +++ b/rai/core_test/block_synchronization.cpp @@ -13,6 +13,7 @@ TEST (pull_synchronization, empty) rai::pull_synchronization sync (test_log, [&blocks] (MDB_txn *, rai::block const & block_a) { blocks.push_back (block_a.clone ()); + return false; }, store); { rai::transaction transaction (store.environment, nullptr, true); @@ -37,6 +38,7 @@ TEST (pull_synchronization, one) rai::pull_synchronization sync (test_log, [&blocks] (MDB_txn *, rai::block const & block_a) { blocks.push_back (block_a.clone ()); + return false; }, store); { rai::transaction transaction (store.environment, nullptr, true); @@ -62,10 +64,11 @@ TEST (pull_synchronization, send_dependencies) store.unchecked_put (transaction, block3.hash (), block3); } rai::pull_synchronization sync (test_log, [&blocks, &store] (MDB_txn * transaction_a, rai::block const & block_a) - { - store.block_put (transaction_a, block_a.hash (), block_a); - blocks.push_back (block_a.clone ()); - }, store); + { + store.block_put (transaction_a, block_a.hash (), block_a); + blocks.push_back (block_a.clone ()); + return false; + }, store); rai::transaction transaction (store.environment, nullptr, true); ASSERT_FALSE (sync.synchronize (transaction, block3.hash ())); ASSERT_EQ (2, blocks.size ()); @@ -89,10 +92,11 @@ TEST (pull_synchronization, change_dependencies) store.unchecked_put (transaction, block3.hash (), block3); } rai::pull_synchronization sync (test_log, [&blocks, &store] (MDB_txn * transaction_a, rai::block const & block_a) - { - store.block_put (transaction_a, block_a.hash (), block_a); - blocks.push_back (block_a.clone ()); - }, store); + { + store.block_put (transaction_a, block_a.hash (), block_a); + blocks.push_back (block_a.clone ()); + return false; + }, store); { rai::transaction transaction (store.environment, nullptr, true); ASSERT_FALSE (sync.synchronize (transaction, block3.hash ())); @@ -118,10 +122,11 @@ TEST (pull_synchronization, open_dependencies) store.unchecked_put (transaction, block3.hash (), block3); } rai::pull_synchronization sync (test_log, [&blocks, &store] (MDB_txn * transaction_a, rai::block const & block_a) - { - store.block_put (transaction_a, block_a.hash (), block_a); - blocks.push_back (block_a.clone ()); - }, store); + { + store.block_put (transaction_a, block_a.hash (), block_a); + blocks.push_back (block_a.clone ()); + return false; + }, store); { rai::transaction transaction (store.environment, nullptr, true); ASSERT_FALSE (sync.synchronize (transaction, block3.hash ())); @@ -151,10 +156,11 @@ TEST (pull_synchronization, receive_dependencies) store.unchecked_put (transaction, block5.hash (), block5); } rai::pull_synchronization sync (test_log, [&blocks, &store] (MDB_txn * transaction_a, rai::block const & block_a) - { - store.block_put (transaction_a, block_a.hash (), block_a); - blocks.push_back (block_a.clone ()); - }, store); + { + store.block_put (transaction_a, block_a.hash (), block_a); + blocks.push_back (block_a.clone ()); + return false; + }, store); { rai::transaction transaction (store.environment, nullptr, true); ASSERT_FALSE (sync.synchronize (transaction, block5.hash ())); @@ -190,10 +196,11 @@ TEST (pull_synchronization, ladder_dependencies) store.unchecked_put (transaction, block7.hash (), block7); } rai::pull_synchronization sync (test_log, [&blocks, &store] (MDB_txn * transaction_a, rai::block const & block_a) - { - store.block_put (transaction_a, block_a.hash (), block_a); - blocks.push_back (block_a.clone ()); - }, store); + { + store.block_put (transaction_a, block_a.hash (), block_a); + blocks.push_back (block_a.clone ()); + return false; + }, store); { rai::transaction transaction (store.environment, nullptr, true); ASSERT_FALSE (sync.synchronize (transaction, block7.hash ())); @@ -216,6 +223,7 @@ TEST (push_synchronization, empty) rai::push_synchronization sync (test_log, [&blocks] (MDB_txn * transaction_a, rai::block const & block_a) { blocks.push_back (block_a.clone ()); + return false; }, store); { rai::transaction transaction (store.environment, nullptr, true); @@ -238,10 +246,11 @@ TEST (push_synchronization, one) store.block_put (transaction, block2.hash (), block2); } rai::push_synchronization sync (test_log, [&blocks, &store] (MDB_txn * transaction_a, rai::block const & block_a) - { - store.block_put (transaction_a, block_a.hash (), block_a); - blocks.push_back (block_a.clone ()); - }, store); + { + store.block_put (transaction_a, block_a.hash (), block_a); + blocks.push_back (block_a.clone ()); + return false; + }, store); { rai::transaction transaction (store.environment, nullptr, true); store.unsynced_put (transaction, block2.hash ()); @@ -273,6 +282,7 @@ TEST (pull_synchronization, dependent_fork) store.unchecked_put (transaction, send3.hash (), send3); rai::pull_synchronization sync (test_log, [] (MDB_txn *, rai::block const & block_a) { + return false; }, store); ASSERT_FALSE (sync.synchronize (transaction, send3.hash ())); } diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index 3cfb95fe42..7b8e686bf1 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -5,7 +5,7 @@ #include -rai::block_synchronization::block_synchronization (boost::log::sources::logger_mt & log_a, std::function const & target_a, rai::block_store & store_a) : +rai::block_synchronization::block_synchronization (boost::log::sources::logger_mt & log_a, std::function const & target_a, rai::block_store & store_a) : log (log_a), target (target_a), store (store_a) @@ -102,7 +102,7 @@ bool rai::block_synchronization::synchronize_one (MDB_txn * transaction_a) auto block (retrieve (transaction_a, hash)); if (block != nullptr) { - target (transaction_a, *block); + result = target (transaction_a, *block); } else { @@ -125,7 +125,7 @@ bool rai::block_synchronization::synchronize (MDB_txn * transaction_a, rai::bloc return result; } -rai::pull_synchronization::pull_synchronization (boost::log::sources::logger_mt & log_a, std::function const & target_a, rai::block_store & store_a) : +rai::pull_synchronization::pull_synchronization (boost::log::sources::logger_mt & log_a, std::function const & target_a, rai::block_store & store_a) : block_synchronization (log_a, target_a, store_a) { } @@ -140,7 +140,7 @@ bool rai::pull_synchronization::synchronized (MDB_txn * transaction_a, rai::bloc return store.block_exists (transaction_a, hash_a) || attempted.count (hash_a) != 0; } -rai::push_synchronization::push_synchronization (boost::log::sources::logger_mt & log_a, std::function const & target_a, rai::block_store & store_a) : +rai::push_synchronization::push_synchronization (boost::log::sources::logger_mt & log_a, std::function const & target_a, rai::block_store & store_a) : block_synchronization (log_a, target_a, store_a) { } @@ -598,6 +598,7 @@ connection (connection_a), synchronization (connection->connection->node->log, [this] (MDB_txn * transaction_a, rai::block const & block_a) { push_block (block_a); + return false; }, connection_a->connection->node->store) { } diff --git a/rai/node/bootstrap.hpp b/rai/node/bootstrap.hpp index 86ea0e929b..e66d065695 100644 --- a/rai/node/bootstrap.hpp +++ b/rai/node/bootstrap.hpp @@ -14,7 +14,7 @@ namespace rai class block_synchronization { public: - block_synchronization (boost::log::sources::logger_mt &, std::function const &, rai::block_store &); + block_synchronization (boost::log::sources::logger_mt &, std::function const &, rai::block_store &); ~block_synchronization (); // Return true if target already has block virtual bool synchronized (MDB_txn *, rai::block_hash const &) = 0; @@ -26,21 +26,21 @@ class block_synchronization bool synchronize (MDB_txn *, rai::block_hash const &); std::unordered_set sent; boost::log::sources::logger_mt & log; - std::function target; + std::function target; rai::block_store & store; std::unordered_set attempted; }; class pull_synchronization : public rai::block_synchronization { public: - pull_synchronization (boost::log::sources::logger_mt &, std::function const &, rai::block_store &); + pull_synchronization (boost::log::sources::logger_mt &, std::function const &, rai::block_store &); bool synchronized (MDB_txn *, rai::block_hash const &) override; std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) override; }; class push_synchronization : public rai::block_synchronization { public: - push_synchronization (boost::log::sources::logger_mt &, std::function const &, rai::block_store &); + push_synchronization (boost::log::sources::logger_mt &, std::function const &, rai::block_store &); bool synchronized (MDB_txn *, rai::block_hash const &) override; std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) override; }; diff --git a/rai/node/node.cpp b/rai/node/node.cpp index b50a3e77e0..c9368c33aa 100755 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -1758,12 +1758,14 @@ void rai::node::process_unchecked (std::shared_ptr atte rai::block_hash block (1); // 1 is a sentinal initial value rai::pull_synchronization synchronization (log, [this, &block, attempt_a] (MDB_txn * transaction_a, rai::block const & block_a) { - process_receive_many (transaction_a, block_a, [this, transaction_a, &block, attempt_a] (rai::process_return result_a, rai::block const & block_a) + auto result (true); + process_receive_many (transaction_a, block_a, [this, transaction_a, &block, attempt_a, &result] (rai::process_return result_a, rai::block const & block_a) { switch (result_a.code) { case rai::process_result::progress: case rai::process_result::old: + result = false; // It definitely doesn't need to be in unchecked because it's in the ledger store.unchecked_del (transaction_a, block_a.hash ()); break; @@ -1797,6 +1799,7 @@ void rai::node::process_unchecked (std::shared_ptr atte break; } }); + return result; }, store); while (!block.is_zero ()) {