diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index 49c9a884ec..2670a6fd9a 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -102,51 +102,6 @@ jobs: AWS_DEFAULT_REGION: us-east-2 - linux_rpm_job: - needs: prepare_build - if: ${{ needs.prepare_build.outputs.tag_created == 'true' }} - runs-on: ubuntu-22.04 - timeout-minutes: 90 - strategy: - matrix: - network: ["BETA", "LIVE"] #No path to build TEST exists ci/build-rhel.sh - steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 - with: - submodules: "recursive" - ref: "develop" #build-rhel.sh needs develop branch and then sets the tag - repository: ${{ github.repository }} - - name: Build local/nano-env:rhel - run: ci/actions/linux/install_deps.sh - env: - COMPILER: rhel - DOCKER_REGISTRY: local - - name: RockyLinux 8 Base - run: ci/build-docker-image.sh docker/ci/Dockerfile-rhel local/nano-env:rhel - - name: Build Artifact - run: | - mkdir -p ${GITHUB_WORKSPACE}/artifacts - docker run -v ${GITHUB_WORKSPACE}:/workspace -v ${GITHUB_WORKSPACE}/artifacts:/root/rpmbuild \ - local/nano-env:rhel /bin/bash -c " \ - NETWORK=${{ matrix.network }} \ - TAG=${{ needs.prepare_build.outputs.ci_tag }} \ - REPO_TO_BUILD=${{ github.repository }} \ - RPM_RELEASE=1 \ - ci/build-rhel.sh" - - - name: Deploy Artifacts - run: ci/actions/deploy.sh - env: - LINUX_RPM: 1 - NETWORK: ${{ matrix.network }} - # TAG: ${{ needs.prepare_build.outputs.ci_tag }} # (not used in the deploy script if LINUX_RPM==1 ) - S3_BUCKET_NAME: ${{ vars.S3_BUCKET_NAME }} - S3_BUILD_DIRECTORY: ${{ vars.S3_BUILD_DIRECTORY }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: us-east-2 - - linux_docker_job: needs: prepare_build if: ${{ needs.prepare_build.outputs.tag_created == 'true' }} diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 47fb08abf9..5fafc9b93c 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -143,4 +143,5 @@ jobs: if: steps.build.outcome == 'success' && (success() || failure()) run: ../ci/tests/run-system-tests.sh working-directory: build - shell: bash \ No newline at end of file + shell: bash + continue-on-error: true # FIXME: Investigate why this fails on Windows \ No newline at end of file diff --git a/ci/tests/run-system-tests.sh b/ci/tests/run-system-tests.sh index e5e5394536..496fad7f3e 100755 --- a/ci/tests/run-system-tests.sh +++ b/ci/tests/run-system-tests.sh @@ -1,9 +1,51 @@ #!/bin/bash -set -euo pipefail +set -uo pipefail source "$(dirname "$BASH_SOURCE")/common.sh" -BUILD_DIR=${1-${PWD}} +# Path to the nano-node repository can be provided as an argument +# Otherwise parent directory of working directory is assumed +NANO_REPO_DIR=${1:-../} +NANO_SYSTEST_DIR=${NANO_REPO_DIR}/systest -export NANO_NODE_EXE=${BUILD_DIR}/nano_node$(get_exec_extension) -cd ../systest && ./RUNALL \ No newline at end of file +# Allow TEST_TIMEOUT to be set from an environment variable +TEST_TIMEOUT=${TEST_TIMEOUT:-300s} + +echo "Running systests from: ${NANO_SYSTEST_DIR}" + +# This assumes that the executables are in the current working directory +export NANO_NODE_EXE=./nano_node$(get_exec_extension) +export NANO_RPC_EXE=./nano_rpc$(get_exec_extension) + +overall_status=0 + +for script in ${NANO_SYSTEST_DIR}/*.sh; do + name=$(basename ${script}) + + echo "::group::Running: $name" + + # Redirecting output to a file to prevent it from being mixed with the output of the action + # Using timeout command to enforce time limits + timeout $TEST_TIMEOUT ./$script > "${name}.log" 2>&1 + status=$? + cat "${name}.log" + + echo "::endgroup::" + + if [ $status -eq 0 ]; then + echo "Passed: $name" + elif [ $status -eq 124 ]; then + echo "::error::Systest timed out: $name" + overall_status=1 + else + echo "::error::Systest failed: $name ($status)" + overall_status=1 + fi +done + +if [ $overall_status -eq 0 ]; then + echo "::notice::All systests passed" +else + echo "::error::Some systests failed" + exit 1 +fi diff --git a/nano/core_test/CMakeLists.txt b/nano/core_test/CMakeLists.txt index 6a7013660a..0a9f771fba 100644 --- a/nano/core_test/CMakeLists.txt +++ b/nano/core_test/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable( core_test - core_test_main.cc + entry.cpp fakes/websocket_client.hpp fakes/work_peer.hpp active_transactions.cpp @@ -40,6 +40,7 @@ add_executable( processing_queue.cpp processor_service.cpp rep_crawler.cpp + receivable.cpp peer_container.cpp rep_weight_store.cpp scheduler_buckets.cpp diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 086195ef74..bf930f8875 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -253,7 +253,7 @@ TEST (inactive_votes_cache, basic) node.vote_processor.vote (vote, std::make_shared (node, node)); ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1); node.process_active (send); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.store.tx_begin_read (), send->hash ())); + ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send->hash ())); ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached)); } @@ -430,7 +430,7 @@ TEST (inactive_votes_cache, multiple_votes) ASSERT_TIMELY_EQ (5s, node.vote_cache.find (send1->hash ()).size (), 2); ASSERT_EQ (1, node.vote_cache.size ()); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); std::shared_ptr election; ASSERT_TIMELY (5s, election = node.active.election (send1->qualified_root ())); ASSERT_EQ (3, election->votes ().size ()); // 2 votes and 1 default not_an_acount @@ -534,7 +534,7 @@ TEST (inactive_votes_cache, election_start) // An election is started for send6 but does not ASSERT_FALSE (node.block_confirmed_or_being_confirmed (send3->hash ())); // send7 cannot be voted on but an election should be started from inactive votes - ASSERT_FALSE (node.ledger.dependents_confirmed (node.store.tx_begin_read (), *send4)); + ASSERT_FALSE (node.ledger.dependents_confirmed (node.ledger.tx_begin_read (), *send4)); node.process_active (send4); ASSERT_TIMELY_EQ (5s, 7, node.ledger.cemented_count ()); } @@ -1016,9 +1016,9 @@ TEST (active_transactions, confirmation_consistency) auto block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::public_key (), node.config.receive_minimum.number ())); ASSERT_NE (nullptr, block); system.deadline_set (5s); - while (!node.ledger.block_confirmed (node.store.tx_begin_read (), block->hash ())) + while (!node.ledger.block_confirmed (node.ledger.tx_begin_read (), block->hash ())) { - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); ASSERT_NO_ERROR (system.poll (5ms)); } ASSERT_NO_ERROR (system.poll_until_true (1s, [&node, &block, i] { @@ -1159,19 +1159,19 @@ TEST (active_transactions, activate_account_chain) ASSERT_EQ (nano::block_status::progress, node.process (open)); ASSERT_EQ (nano::block_status::progress, node.process (receive)); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); ASSERT_TIMELY (5s, node.active.election (send->qualified_root ())); auto election1 = node.active.election (send->qualified_root ()); ASSERT_EQ (1, node.active.size ()); ASSERT_EQ (1, election1->blocks ().count (send->hash ())); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); auto election2 = node.active.election (send->qualified_root ()); ASSERT_EQ (election2, election1); election1->force_confirm (); ASSERT_TIMELY (3s, node.block_confirmed (send->hash ())); // On cementing, the next election is started ASSERT_TIMELY (3s, node.active.active (send2->qualified_root ())); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); auto election3 = node.active.election (send2->qualified_root ()); ASSERT_NE (nullptr, election3); ASSERT_EQ (1, election3->blocks ().count (send2->hash ())); @@ -1180,11 +1180,11 @@ TEST (active_transactions, activate_account_chain) // On cementing, the next election is started ASSERT_TIMELY (3s, node.active.active (open->qualified_root ())); ASSERT_TIMELY (3s, node.active.active (send3->qualified_root ())); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); auto election4 = node.active.election (send3->qualified_root ()); ASSERT_NE (nullptr, election4); ASSERT_EQ (1, election4->blocks ().count (send3->hash ())); - node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (key.pub, node.ledger.tx_begin_read ()); auto election5 = node.active.election (open->qualified_root ()); ASSERT_NE (nullptr, election5); ASSERT_EQ (1, election5->blocks ().count (open->hash ())); @@ -1192,7 +1192,7 @@ TEST (active_transactions, activate_account_chain) ASSERT_TIMELY (3s, node.block_confirmed (open->hash ())); // Until send3 is also confirmed, the receive block should not activate std::this_thread::sleep_for (200ms); - node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (key.pub, node.ledger.tx_begin_read ()); election4->force_confirm (); ASSERT_TIMELY (3s, node.block_confirmed (send3->hash ())); ASSERT_TIMELY (3s, node.active.active (receive->qualified_root ())); @@ -1248,9 +1248,9 @@ TEST (active_transactions, activate_inactive) ASSERT_TIMELY (5s, node.block_confirmed (send2->hash ())); ASSERT_TIMELY (5s, node.block_confirmed (send->hash ())); - ASSERT_EQ (1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); - ASSERT_EQ (1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); - ASSERT_EQ (0, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); + ASSERT_ALWAYS_EQ (50ms, 0, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); // The first block was not active so no activation takes place ASSERT_FALSE (node.active.active (open->qualified_root ()) || node.block_confirmed_or_being_confirmed (open->hash ())); @@ -1333,7 +1333,7 @@ TEST (active_transactions, vacancy) ASSERT_EQ (nano::block_status::progress, node.process (send)); ASSERT_EQ (1, node.active.vacancy ()); ASSERT_EQ (0, node.active.size ()); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); ASSERT_TIMELY (1s, updated); updated = false; ASSERT_EQ (0, node.active.vacancy ()); @@ -1523,7 +1523,7 @@ TEST (active_transactions, allow_limited_overflow) // Insert the first part of the blocks into normal election scheduler for (auto const & block : blocks1) { - node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ()); + node.scheduler.priority.activate (block->account (), node.ledger.tx_begin_read ()); } // Ensure number of active elections reaches AEC limit and there is no overfill @@ -1585,7 +1585,7 @@ TEST (active_transactions, allow_limited_overflow_adapt) // Insert the first part of the blocks into normal election scheduler for (auto const & block : blocks1) { - node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ()); + node.scheduler.priority.activate (block->account (), node.ledger.tx_begin_read ()); } // Ensure number of active elections reaches AEC limit and there is no overfill diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index 26d5680a88..9c83f77e1d 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -21,7 +21,7 @@ TEST (backlog, population) nano::test::system system{}; auto & node = *system.add_node (); - node.backlog.activate_callback.add ([&] (nano::store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + node.backlog.activate_callback.add ([&] (nano::secure::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { nano::lock_guard lock{ mutex }; activated.insert (account); diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index c1cf35ab34..20664e1f8d 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -1000,7 +1000,7 @@ TEST (mdb_block_store, sideband_height) nano::stats stats; nano::ledger ledger (store, stats, nano::dev::constants); nano::block_builder builder; - auto transaction (store.tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store.initialize (transaction, ledger.cache, nano::dev::constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; auto send = builder diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index 39214953ee..ae3cb1471c 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -651,7 +651,7 @@ TEST (bootstrap_processor, push_diamond_pruning) ASSERT_EQ (nano::block_status::progress, node1->process (receive)); { - auto transaction (node1->store.tx_begin_write ()); + auto transaction = node1->ledger.tx_begin_write (); node1->ledger.confirm (transaction, open->hash ()); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 2)); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, open->hash (), 1)); diff --git a/nano/core_test/bootstrap_ascending.cpp b/nano/core_test/bootstrap_ascending.cpp index 59c0eb381d..ad18c2432f 100644 --- a/nano/core_test/bootstrap_ascending.cpp +++ b/nano/core_test/bootstrap_ascending.cpp @@ -252,7 +252,7 @@ TEST (bootstrap_ascending, trace_base) // std::cerr << "--------------- Start ---------------\n"; ASSERT_EQ (nano::block_status::progress, node0.process (send1)); ASSERT_EQ (nano::block_status::progress, node0.process (receive1)); - ASSERT_EQ (node1.ledger.receivable_end (), node1.ledger.receivable_upper_bound (node1.store.tx_begin_read (), key.pub, 0)); + ASSERT_EQ (node1.ledger.receivable_end (), node1.ledger.receivable_upper_bound (node1.ledger.tx_begin_read (), key.pub, 0)); // std::cerr << "node0: " << node0.network.endpoint () << std::endl; // std::cerr << "node1: " << node1.network.endpoint () << std::endl; ASSERT_TIMELY (10s, node1.block (receive1->hash ()) != nullptr); diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 7cc7ae91f6..6fe35bebfb 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -94,7 +94,7 @@ TEST (confirmation_callback, observer_callbacks) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); } @@ -133,7 +133,7 @@ TEST (confirmation_callback, confirmed_history) .work (*system.work.generate (latest)) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); } @@ -159,18 +159,18 @@ TEST (confirmation_callback, confirmed_history) ASSERT_EQ (0, node->active.recently_cemented.list ().size ()); ASSERT_TRUE (node->active.empty ()); - auto transaction = node->store.tx_begin_read (); + auto transaction = node->ledger.tx_begin_read (); ASSERT_FALSE (node->ledger.block_confirmed (transaction, send->hash ())); ASSERT_TIMELY (10s, node->store.write_queue.contains (nano::store::writer::confirmation_height)); // Confirm that no inactive callbacks have been called when the confirmation height processor has already iterated over it, waiting to write - ASSERT_EQ (0, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); + ASSERT_ALWAYS_EQ (50ms, 0, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); } ASSERT_TIMELY (10s, !node->store.write_queue.contains (nano::store::writer::confirmation_height)); - auto transaction = node->store.tx_begin_read (); + auto transaction = node->ledger.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, send->hash ())); ASSERT_TIMELY_EQ (10s, node->active.size (), 0); @@ -181,9 +181,9 @@ TEST (confirmation_callback, confirmed_history) ASSERT_TRUE (node->active.empty ()); // Confirm the callback is not called under this circumstance - ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); - ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); - ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); + ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (3, node->ledger.cemented_count ()); ASSERT_EQ (0, node->active.election_winner_details_size ()); } @@ -226,7 +226,7 @@ TEST (confirmation_callback, dependent_election) .work (*system.work.generate (send1->hash ())) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send2)); @@ -244,9 +244,9 @@ TEST (confirmation_callback, dependent_election) // Once the item added to the confirming set no longer exists, callbacks have completed ASSERT_TIMELY (5s, !node->confirming_set.exists (send2->hash ())); - ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); - ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); - ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); + ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); ASSERT_EQ (4, node->ledger.cemented_count ()); ASSERT_EQ (0, node->active.election_winner_details_size ()); diff --git a/nano/core_test/conflicts.cpp b/nano/core_test/conflicts.cpp index a4175a7f3b..a6eb988616 100644 --- a/nano/core_test/conflicts.cpp +++ b/nano/core_test/conflicts.cpp @@ -31,7 +31,7 @@ TEST (conflicts, start_stop) node1.work_generate_blocking (*send1); ASSERT_EQ (nano::block_status::progress, node1.process (send1)); ASSERT_EQ (0, node1.active.size ()); - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); ASSERT_EQ (1, node1.active.size ()); @@ -64,7 +64,7 @@ TEST (conflicts, add_existing) ASSERT_TIMELY (5s, node1.block (send1->hash ())); // instruct the election scheduler to trigger an election for send1 - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); // wait for election to be started before processing send2 ASSERT_TIMELY (5s, node1.active.active (*send1)); diff --git a/nano/core_test/core_test_main.cc b/nano/core_test/core_test_main.cc deleted file mode 100644 index 0abd1cdc3a..0000000000 --- a/nano/core_test/core_test_main.cc +++ /dev/null @@ -1,30 +0,0 @@ -#include "gtest/gtest.h" - -#include -#include -#include - -#include - -constexpr std::size_t OPEN_FILE_DESCRIPTORS_LIMIT = 16384; - -namespace nano -{ -namespace test -{ - void cleanup_dev_directories_on_exit (); -} -void force_nano_dev_network (); -} - -GTEST_API_ int main (int argc, char ** argv) -{ - nano::logger::initialize_for_tests (nano::log_config::tests_default ()); - nano::set_file_descriptor_limit (OPEN_FILE_DESCRIPTORS_LIMIT); - nano::force_nano_dev_network (); - nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; - testing::InitGoogleTest (&argc, argv); - auto res = RUN_ALL_TESTS (); - nano::test::cleanup_dev_directories_on_exit (); - return res; -} diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index 140052cee1..96cee2861c 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -151,7 +151,7 @@ TEST (election, quorum_minimum_confirm_success) .build (); node1.work_generate_blocking (*send1); node1.process_active (send1); - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election = node1.active.election (send1->qualified_root ()); ASSERT_NE (nullptr, election); diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index 48ccac7682..2195ffa308 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -31,8 +31,8 @@ TEST (election_scheduler, activate_one_timely) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), send1); - system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ()); + system.nodes[0]->ledger.process (system.nodes[0]->ledger.tx_begin_write (), send1); + system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->ledger.tx_begin_read ()); ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ())); } @@ -49,8 +49,8 @@ TEST (election_scheduler, activate_one_flush) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), send1); - system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ()); + system.nodes[0]->ledger.process (system.nodes[0]->ledger.tx_begin_write (), send1); + system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->ledger.tx_begin_read ()); ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ())); } @@ -106,6 +106,8 @@ TEST (election_scheduler, no_vacancy) ASSERT_EQ (nano::block_status::progress, node.process (receive)); node.process_confirmed (nano::election_status{ receive }); + ASSERT_TIMELY (5s, nano::test::confirmed (node, { send, receive })); + // Second, process two eligible transactions auto block1 = builder.make_block () .account (nano::dev::genesis_key.pub) @@ -119,7 +121,7 @@ TEST (election_scheduler, no_vacancy) ASSERT_EQ (nano::block_status::progress, node.process (block1)); // There is vacancy so it should be inserted - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); std::shared_ptr election{}; ASSERT_TIMELY (5s, (election = node.active.election (block1->qualified_root ())) != nullptr); @@ -135,7 +137,7 @@ TEST (election_scheduler, no_vacancy) ASSERT_EQ (nano::block_status::progress, node.process (block2)); // There is no vacancy so it should stay queued - node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ()); + node.scheduler.priority.activate (key.pub, node.ledger.tx_begin_read ()); ASSERT_TIMELY_EQ (5s, node.scheduler.priority.size (), 1); ASSERT_EQ (node.active.election (block2->qualified_root ()), nullptr); diff --git a/nano/core_test/entry.cpp b/nano/core_test/entry.cpp index de8f007e3d..423f3731b8 100644 --- a/nano/core_test/entry.cpp +++ b/nano/core_test/entry.cpp @@ -1,6 +1,30 @@ +#include +#include +#include + #include -TEST (basic, basic) +#include + +constexpr std::size_t OPEN_FILE_DESCRIPTORS_LIMIT = 16384; + +namespace nano +{ +namespace test +{ + void cleanup_dev_directories_on_exit (); +} +void force_nano_dev_network (); +} + +GTEST_API_ int main (int argc, char ** argv) { - ASSERT_TRUE (true); + nano::logger::initialize_for_tests (nano::log_config::tests_default ()); + nano::set_file_descriptor_limit (OPEN_FILE_DESCRIPTORS_LIMIT); + nano::force_nano_dev_network (); + nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; + testing::InitGoogleTest (&argc, argv); + auto res = RUN_ALL_TESTS (); + nano::test::cleanup_dev_directories_on_exit (); + return res; } diff --git a/nano/core_test/frontiers_confirmation.cpp b/nano/core_test/frontiers_confirmation.cpp index 08967ce4a9..b8c521b678 100644 --- a/nano/core_test/frontiers_confirmation.cpp +++ b/nano/core_test/frontiers_confirmation.cpp @@ -30,7 +30,7 @@ TEST (frontiers_confirmation, mode) .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); } ASSERT_TIMELY_EQ (5s, node->active.size (), 1); @@ -52,7 +52,7 @@ TEST (frontiers_confirmation, mode) .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); } ASSERT_TIMELY_EQ (5s, node->active.size (), 1); @@ -74,7 +74,7 @@ TEST (frontiers_confirmation, mode) .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); } system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 35d1f419d5..855abea27f 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -39,7 +39,7 @@ TEST (ledger, empty) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); nano::account account; auto balance (ledger.account_balance (transaction, account)); ASSERT_TRUE (balance.is_zero ()); @@ -51,7 +51,7 @@ TEST (ledger, genesis_balance) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto balance = ledger.account_balance (transaction, nano::dev::genesis_key.pub); ASSERT_EQ (nano::dev::constants.genesis_amount, balance); auto info = ledger.account_info (transaction, nano::dev::genesis_key.pub); @@ -84,8 +84,8 @@ TEST (ledger, process_modifies_sideband) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, ledger.process (store.tx_begin_write (), send1)); - ASSERT_EQ (send1->sideband ().timestamp, ledger.block (store.tx_begin_read (), send1->hash ())->sideband ().timestamp); + ASSERT_EQ (nano::block_status::progress, ledger.process (ledger.tx_begin_write (), send1)); + ASSERT_EQ (send1->sideband ().timestamp, ledger.block (ledger.tx_begin_read (), send1->hash ())->sideband ().timestamp); } // Create a send block and publish it. @@ -94,7 +94,7 @@ TEST (ledger, process_send) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -197,7 +197,7 @@ TEST (ledger, process_receive) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -280,7 +280,7 @@ TEST (ledger, rollback_receiver) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -329,7 +329,7 @@ TEST (ledger, rollback_representation) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key5; nano::block_builder builder; @@ -419,7 +419,7 @@ TEST (ledger, receive_rollback) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send = builder @@ -447,7 +447,7 @@ TEST (ledger, process_duplicate) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -481,7 +481,7 @@ TEST (ledger, representative_genesis) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto latest = ledger.latest (transaction, nano::dev::genesis_key.pub); ASSERT_FALSE (latest.is_zero ()); ASSERT_EQ (nano::dev::genesis->hash (), ledger.representative (transaction, latest)); @@ -499,7 +499,7 @@ TEST (ledger, representative_change) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); nano::keypair key2; auto & pool = ctx.pool (); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); @@ -538,7 +538,7 @@ TEST (ledger, send_fork) auto & store = ctx.store (); nano::keypair key2; nano::keypair key3; - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -570,7 +570,7 @@ TEST (ledger, receive_fork) auto & store = ctx.store (); nano::keypair key2; nano::keypair key3; - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -627,7 +627,7 @@ TEST (ledger, open_fork) auto & store = ctx.store (); nano::keypair key2; nano::keypair key3; - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -727,7 +727,7 @@ TEST (ledger, representation) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto & rep_weights = ledger.cache.rep_weights; - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); ASSERT_EQ (nano::dev::constants.genesis_amount, rep_weights.representation_get (nano::dev::genesis_key.pub)); nano::keypair key2; @@ -860,7 +860,7 @@ TEST (ledger, double_open) ASSERT_TRUE (!store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key2; @@ -899,7 +899,7 @@ TEST (ledger, double_receive) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key2; nano::block_builder builder; @@ -949,10 +949,10 @@ TEST (votes, check_signature) .build (); node1.work_generate_blocking (*send1); { - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); } - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); ASSERT_EQ (1, election1->votes ().size ()); @@ -979,7 +979,7 @@ TEST (votes, add_one) .work (0) .build (); node1.work_generate_blocking (*send1); - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); node1.start_election (send1); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); @@ -1022,8 +1022,8 @@ TEST (votes, add_existing) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .build (); node1.work_generate_blocking (*send1); - ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.store.tx_begin_write (), send1)); - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.ledger.tx_begin_write (), send1)); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); auto election1 = node1.active.election (send1->qualified_root ()); auto vote1 = nano::test::make_vote (nano::dev::genesis_key, { send1 }, nano::vote::timestamp_min * 1, 0); @@ -1080,7 +1080,7 @@ TEST (votes, add_old) .work (0) .build (); node1.work_generate_blocking (*send1); - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); node1.start_election (send1); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); @@ -1185,7 +1185,7 @@ TEST (votes, add_cooldown) .work (0) .build (); node1.work_generate_blocking (*send1); - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); node1.start_election (send1); ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ())); @@ -1228,7 +1228,7 @@ TEST (ledger, successor) .work (0) .build (); node1.work_generate_blocking (*send1); - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); ASSERT_EQ (*send1, *node1.ledger.block (transaction, node1.ledger.successor (transaction, nano::qualified_root (nano::root (0), nano::dev::genesis->hash ())).value ())); ASSERT_EQ (*nano::dev::genesis, *node1.ledger.block (transaction, node1.ledger.successor (transaction, nano::dev::genesis->qualified_root ()).value ())); @@ -1240,7 +1240,7 @@ TEST (ledger, fail_change_old) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1262,7 +1262,7 @@ TEST (ledger, fail_change_gap_previous) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1282,7 +1282,7 @@ TEST (ledger, fail_state_bad_signature) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto block = builder @@ -1304,7 +1304,7 @@ TEST (ledger, fail_epoch_bad_signature) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto block = builder @@ -1330,7 +1330,7 @@ TEST (ledger, fail_change_bad_signature) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1350,7 +1350,7 @@ TEST (ledger, fail_change_fork) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1380,7 +1380,7 @@ TEST (ledger, fail_send_old) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1403,7 +1403,7 @@ TEST (ledger, fail_send_gap_previous) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1424,7 +1424,7 @@ TEST (ledger, fail_send_bad_signature) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1445,7 +1445,7 @@ TEST (ledger, fail_send_negative_spend) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1475,7 +1475,7 @@ TEST (ledger, fail_send_fork) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1505,7 +1505,7 @@ TEST (ledger, fail_open_old) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1535,7 +1535,7 @@ TEST (ledger, fail_open_gap_source) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1556,7 +1556,7 @@ TEST (ledger, fail_open_bad_signature) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1586,7 +1586,7 @@ TEST (ledger, fail_open_fork_previous) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1634,7 +1634,7 @@ TEST (ledger, fail_open_account_mismatch) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1665,7 +1665,7 @@ TEST (ledger, fail_receive_old) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1712,7 +1712,7 @@ TEST (ledger, fail_receive_gap_source) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1762,7 +1762,7 @@ TEST (ledger, fail_receive_overreceive) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1802,7 +1802,7 @@ TEST (ledger, fail_receive_bad_signature) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1852,7 +1852,7 @@ TEST (ledger, fail_receive_gap_previous_opened) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1902,7 +1902,7 @@ TEST (ledger, fail_receive_gap_previous_unopened) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -1942,7 +1942,7 @@ TEST (ledger, fail_receive_fork_previous) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -2003,7 +2003,7 @@ TEST (ledger, fail_receive_received_source) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key1; nano::block_builder builder; @@ -2084,7 +2084,7 @@ TEST (ledger, latest_empty) auto & ledger = ctx.ledger (); auto & store = ctx.store (); nano::keypair key; - auto transaction = store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); auto latest = ledger.latest (transaction, key.pub); ASSERT_TRUE (latest.is_zero ()); } @@ -2094,7 +2094,7 @@ TEST (ledger, latest_root) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key; ASSERT_EQ (key.pub, ledger.latest_root (transaction, key.pub).as_account ()); @@ -2118,7 +2118,7 @@ TEST (ledger, change_representative_move_representation) auto & ledger = ctx.ledger (); auto & store = ctx.store (); nano::keypair key1; - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); nano::block_builder builder; @@ -2159,7 +2159,7 @@ TEST (ledger, send_open_receive_rollback) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); @@ -2251,7 +2251,7 @@ TEST (ledger, bootstrap_rep_weight) nano::keypair key2; auto & pool = ctx.pool (); { - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; @@ -2272,7 +2272,7 @@ TEST (ledger, bootstrap_rep_weight) ASSERT_EQ (1000, ledger.weight (key2.pub)); } { - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; @@ -2295,7 +2295,7 @@ TEST (ledger, block_destination_source) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair dest; nano::uint128_t balance (nano::dev::constants.genesis_amount); @@ -2385,7 +2385,7 @@ TEST (ledger, state_account) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2407,7 +2407,7 @@ TEST (ledger, state_send_receive) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2464,7 +2464,7 @@ TEST (ledger, state_receive) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2512,7 +2512,7 @@ TEST (ledger, state_rep_change) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair rep; nano::block_builder builder; @@ -2546,7 +2546,7 @@ TEST (ledger, state_open) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -2601,7 +2601,7 @@ TEST (ledger, send_after_state_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2632,7 +2632,7 @@ TEST (ledger, receive_after_state_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2662,7 +2662,7 @@ TEST (ledger, change_after_state_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2692,7 +2692,7 @@ TEST (ledger, state_unreceivable_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2729,7 +2729,7 @@ TEST (ledger, state_receive_bad_amount_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2766,7 +2766,7 @@ TEST (ledger, state_no_link_amount_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2799,7 +2799,7 @@ TEST (ledger, state_receive_wrong_account_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -2839,7 +2839,7 @@ TEST (ledger, state_open_state_fork) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -2882,7 +2882,7 @@ TEST (ledger, state_state_open_fork) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -2926,7 +2926,7 @@ TEST (ledger, state_open_previous_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -2959,7 +2959,7 @@ TEST (ledger, state_open_source_fail) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -2992,7 +2992,7 @@ TEST (ledger, state_send_change) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair rep; nano::block_builder builder; @@ -3026,7 +3026,7 @@ TEST (ledger, state_receive_change) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -3078,7 +3078,7 @@ TEST (ledger, state_open_old) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -3112,7 +3112,7 @@ TEST (ledger, state_receive_old) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -3165,7 +3165,7 @@ TEST (ledger, state_rollback_send) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -3203,7 +3203,7 @@ TEST (ledger, state_rollback_receive) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -3245,7 +3245,7 @@ TEST (ledger, state_rollback_received_send) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair key; nano::block_builder builder; @@ -3288,7 +3288,7 @@ TEST (ledger, state_rep_change_rollback) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair rep; nano::block_builder builder; @@ -3315,7 +3315,7 @@ TEST (ledger, state_open_rollback) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -3357,7 +3357,7 @@ TEST (ledger, state_send_change_rollback) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair rep; nano::block_builder builder; @@ -3385,7 +3385,7 @@ TEST (ledger, state_receive_change_rollback) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::block_builder builder; auto send1 = builder @@ -3424,7 +3424,7 @@ TEST (ledger, epoch_blocks_v1_general) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -3567,7 +3567,7 @@ TEST (ledger, epoch_blocks_v2_general) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -3732,7 +3732,7 @@ TEST (ledger, epoch_blocks_receive_upgrade) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -3940,7 +3940,7 @@ TEST (ledger, epoch_blocks_fork) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); nano::keypair destination; nano::block_builder builder; @@ -4055,7 +4055,7 @@ TEST (ledger, successor_epoch) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (open->hash ())) .build (); - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open)); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, change)); @@ -4083,7 +4083,7 @@ TEST (ledger, epoch_open_pending) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (key1.pub)) .build (); - auto process_result = node1.ledger.process (node1.store.tx_begin_write (), epoch_open); + auto process_result = node1.ledger.process (node1.ledger.tx_begin_write (), epoch_open); ASSERT_EQ (nano::block_status::gap_epoch_open_pending, process_result); node1.block_processor.add (epoch_open); // Waits for the block to get saved in the database @@ -4245,11 +4245,11 @@ TEST (ledger, unchecked_epoch) } node1.block_processor.add (send1); node1.block_processor.add (open1); - ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.store.tx_begin_read (), epoch1->hash ())); + ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), epoch1->hash ())); { // Waits for the last blocks to pass through block_processor and unchecked.put queues ASSERT_TIMELY_EQ (10s, 0, node1.unchecked.count ()); - auto info = node1.ledger.account_info (node1.store.tx_begin_read (), destination.pub); + auto info = node1.ledger.account_info (node1.ledger.tx_begin_read (), destination.pub); ASSERT_TRUE (info); ASSERT_EQ (info->epoch (), nano::epoch::epoch_1); } @@ -4320,9 +4320,9 @@ TEST (ledger, unchecked_epoch_invalid) node1.block_processor.add (send1); node1.block_processor.add (open1); // Waits for the last blocks to pass through block_processor and unchecked.put queues - ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.store.tx_begin_read (), epoch2->hash ())); + ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), epoch2->hash ())); { - auto transaction = node1.store.tx_begin_read (); + auto transaction = node1.ledger.tx_begin_read (); ASSERT_FALSE (node1.ledger.block_exists (transaction, epoch1->hash ())); auto unchecked_count = node1.unchecked.count (); ASSERT_EQ (unchecked_count, 0); @@ -4387,7 +4387,7 @@ TEST (ledger, unchecked_open) } node1.block_processor.add (send1); // Waits for the send1 block to pass through block_processor and unchecked.put queues - ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.store.tx_begin_read (), open1->hash ())); + ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), open1->hash ())); ASSERT_EQ (0, node1.unchecked.count ()); } @@ -4458,7 +4458,7 @@ TEST (ledger, unchecked_receive) ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send2); - ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.store.tx_begin_read (), receive1->hash ())); + ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), receive1->hash ())); ASSERT_EQ (0, node1.unchecked.count ()); } @@ -4467,7 +4467,7 @@ TEST (ledger, confirmation_height_not_updated) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); auto account_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (account_info); @@ -4517,7 +4517,7 @@ TEST (ledger, zero_rep) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, block1)); ASSERT_EQ (0, node1.ledger.cache.rep_weights.representation_get (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, node1.ledger.cache.rep_weights.representation_get (0)); @@ -4553,9 +4553,9 @@ TEST (ledger, work_validation) { block_a->block_work_set (block_a->block_work () + 1); } - EXPECT_EQ (nano::block_status::insufficient_work, ledger.process (store.tx_begin_write (), block_a)); + EXPECT_EQ (nano::block_status::insufficient_work, ledger.process (ledger.tx_begin_write (), block_a)); block_a->block_work_set (*pool.generate (block_a->root (), threshold)); - EXPECT_EQ (nano::block_status::progress, ledger.process (store.tx_begin_write (), block_a)); + EXPECT_EQ (nano::block_status::progress, ledger.process (ledger.tx_begin_write (), block_a)); }; std::error_code ec; @@ -4629,7 +4629,7 @@ TEST (ledger, dependents_confirmed) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); nano::block_builder builder; ASSERT_TRUE (ledger.dependents_confirmed (transaction, *nano::dev::genesis)); auto & pool = ctx.pool (); @@ -4694,7 +4694,7 @@ TEST (ledger, dependents_confirmed_pruning) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::block_builder builder; nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; @@ -4739,7 +4739,7 @@ TEST (ledger, block_confirmed) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); nano::block_builder builder; ASSERT_TRUE (ledger.block_confirmed (transaction, nano::dev::genesis->hash ())); auto & pool = ctx.pool (); @@ -4790,7 +4790,7 @@ TEST (ledger, cache) }; nano::keypair key; - auto const latest = ledger.latest (store.tx_begin_read (), nano::dev::genesis_key.pub); + auto const latest = ledger.latest (ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto send = builder.state () .account (nano::dev::genesis_key.pub) .previous (latest) @@ -4810,7 +4810,7 @@ TEST (ledger, cache) .work (*pool.generate (key.pub)) .build (); { - auto transaction (store.tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send)); } @@ -4820,7 +4820,7 @@ TEST (ledger, cache) cache_check (nano::ledger (store, stats, nano::dev::constants)); { - auto transaction (store.tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open)); } @@ -4830,7 +4830,7 @@ TEST (ledger, cache) cache_check (nano::ledger (store, stats, nano::dev::constants)); { - auto transaction (store.tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); ledger.confirm (transaction, send->hash ()); ASSERT_TRUE (ledger.block_confirmed (transaction, send->hash ())); } @@ -4840,7 +4840,7 @@ TEST (ledger, cache) cache_check (nano::ledger (store, stats, nano::dev::constants)); { - auto transaction (store.tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); ledger.confirm (transaction, open->hash ()); ASSERT_TRUE (ledger.block_confirmed (transaction, open->hash ())); } @@ -4850,7 +4850,7 @@ TEST (ledger, cache) cache_check (nano::ledger (store, stats, nano::dev::constants)); { - auto transaction (store.tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); ledger.pruning_action (transaction, open->hash (), 1); } ++pruned_count; @@ -4867,7 +4867,7 @@ TEST (ledger, pruning_action) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::block_builder builder; @@ -4953,7 +4953,7 @@ TEST (ledger, pruning_large_chain) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; size_t send_receive_pairs (20); @@ -5009,7 +5009,7 @@ TEST (ledger, pruning_source_rollback) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::block_builder builder; @@ -5098,7 +5098,7 @@ TEST (ledger, pruning_source_rollback_legacy) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::block_builder builder; @@ -5213,7 +5213,7 @@ TEST (ledger, pruning_legacy_blocks) nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; nano::keypair key1; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::block_builder builder; @@ -5299,7 +5299,7 @@ TEST (ledger, pruning_safe_functions) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::block_builder builder; @@ -5351,7 +5351,7 @@ TEST (ledger, hash_root_random) nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); ledger.pruning = true; - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::block_builder builder; @@ -5431,7 +5431,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) auto version = nano::store::component::version_current; { - auto transaction = store.tx_begin_write (); + auto transaction = ledger.tx_begin_write (); store.initialize (transaction, ledger.cache, ledger.constants); ASSERT_FALSE (store.init_error ()); @@ -5512,7 +5512,7 @@ TEST (ledger, head_block) auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); auto & store = ctx.store (); - auto tx = store.tx_begin_read (); + auto tx = ledger.tx_begin_read (); ASSERT_EQ (*nano::dev::genesis, *ledger.head_block (tx, nano::dev::genesis_key.pub)); } @@ -5520,7 +5520,7 @@ TEST (ledger, head_block) TEST (ledger_receivable, upper_bound_account_none) { auto ctx = nano::test::context::ledger_empty (); - ASSERT_EQ (ctx.ledger ().receivable_end (), ctx.ledger ().receivable_upper_bound (ctx.store ().tx_begin_read (), 0)); + ASSERT_EQ (ctx.ledger ().receivable_end (), ctx.ledger ().receivable_upper_bound (ctx.ledger ().tx_begin_read (), 0)); } // Test behavior of ledger::receivable_upper_bound when there are receivable entries for multiple accounts @@ -5539,7 +5539,7 @@ TEST (ledger_receivable, upper_bound_account_key) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*ctx.pool ().generate (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.store ().tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send1)); auto send2 = builder .state () .account (nano::dev::genesis_key.pub) @@ -5550,8 +5550,8 @@ TEST (ledger_receivable, upper_bound_account_key) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*ctx.pool ().generate (send1->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.store ().tx_begin_write (), send2)); - auto tx = ctx.store ().tx_begin_read (); + ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send2)); + auto tx = ctx.ledger ().tx_begin_read (); auto & ledger = ctx.ledger (); auto next1 = ledger.receivable_upper_bound (tx, nano::dev::genesis_key.pub); auto next2 = ledger.receivable_upper_bound (tx, key.pub); @@ -5587,7 +5587,7 @@ TEST (ledger_receivable, key_two) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*ctx.pool ().generate (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.store ().tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send1)); auto send2 = builder .state () .account (nano::dev::genesis_key.pub) @@ -5598,8 +5598,8 @@ TEST (ledger_receivable, key_two) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*ctx.pool ().generate (send1->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.store ().tx_begin_write (), send2)); - auto tx = ctx.store ().tx_begin_read (); + ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send2)); + auto tx = ctx.ledger ().tx_begin_read (); auto & ledger = ctx.ledger (); auto next1 = ledger.receivable_upper_bound (tx, key.pub, 0); ASSERT_TRUE (next1 != ledger.receivable_end () && next1->first.account == key.pub); @@ -5614,7 +5614,7 @@ TEST (ledger_receivable, key_two) TEST (ledger_receivable, any_none) { auto ctx = nano::test::context::ledger_empty (); - ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.store ().tx_begin_read (), nano::dev::genesis_key.pub)); + ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.ledger ().tx_begin_read (), nano::dev::genesis_key.pub)); } TEST (ledger_receivable, any_one) @@ -5632,7 +5632,7 @@ TEST (ledger_receivable, any_one) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*ctx.pool ().generate (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.store ().tx_begin_write (), send1)); - ASSERT_TRUE (ctx.ledger ().receivable_any (ctx.store ().tx_begin_read (), nano::dev::genesis_key.pub)); - ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.store ().tx_begin_read (), key.pub)); + ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send1)); + ASSERT_TRUE (ctx.ledger ().receivable_any (ctx.ledger ().tx_begin_read (), nano::dev::genesis_key.pub)); + ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.ledger ().tx_begin_read (), key.pub)); } diff --git a/nano/core_test/ledger_confirm.cpp b/nano/core_test/ledger_confirm.cpp index 45dccb0f1f..f94b6c8b85 100644 --- a/nano/core_test/ledger_confirm.cpp +++ b/nano/core_test/ledger_confirm.cpp @@ -33,7 +33,7 @@ TEST (ledger_confirm, single) .build (); // Check confirmation heights before, should be uninitialized (1 for genesis). - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (1, node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().height); ASSERT_EQ (nano::dev::genesis->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); @@ -157,7 +157,7 @@ TEST (ledger_confirm, multiple_accounts) .work (*system.work.generate (send6->hash ())) .build (); - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send2)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send3)); @@ -323,7 +323,7 @@ TEST (ledger_confirm, send_receive_between_2_accounts) .build (); // Unpocketed send - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, open1)); @@ -422,7 +422,7 @@ TEST (ledger_confirm, send_receive_self) .work (*system.work.generate (receive3->hash ())) .build (); - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, receive1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send2)); @@ -631,7 +631,7 @@ TEST (ledger_confirm, all_block_types) .work (*system.work.generate (send1->hash ())) .build (); - auto transaction (store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, open)); @@ -700,7 +700,7 @@ TEST (ledger_confirm, conflict_rollback_cemented) .work (*system.work.generate (genesis_hash)) .build (); { - auto transaction = node1->store.tx_begin_write (); + auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1->ledger.process (transaction, fork1a)); node1->ledger.confirm (transaction, fork1a->hash ()); } @@ -744,7 +744,7 @@ TEST (ledger_confirm, observers) .work (*system.work.generate (latest1)) .build (); - auto transaction = node1->store.tx_begin_write (); + auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1->ledger.process (transaction, send1)); node1->ledger.confirm (transaction, send1->hash ()); ASSERT_TRUE (node1->ledger.block_confirmed (transaction, send1->hash ())); @@ -838,7 +838,7 @@ TEST (ledger_confirm, pruned_source) .sign (key2.prv, key2.pub) .work (*pool.generate (key2.pub)) .build (); - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, nano::dev::constants); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); @@ -880,7 +880,7 @@ TEST (ledger_confirmDeathTest, rollback_added_block) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); ASSERT_DEATH_IF_SUPPORTED (ledger.confirm (transaction, send->hash ()), ""); } diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 871bd872af..9ae3e5cb02 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -191,13 +191,13 @@ TEST (network, send_discarded_publish) .work (*system.work.generate (nano::root (1))) .build (); { - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); node1.network.flood_block (block); ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } @@ -217,13 +217,13 @@ TEST (network, send_invalid_publish) .work (*system.work.generate (nano::root (1))) .build (); { - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); node1.network.flood_block (block); ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } @@ -369,7 +369,7 @@ TEST (receivable_processor, confirm_insufficient_pos) .build (); node1.work_generate_blocking (*block1); ASSERT_EQ (nano::block_status::progress, node1.process (block1)); - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); nano::keypair key1; auto vote = nano::test::make_vote (key1, { block1 }, 0, 0); nano::confirm_ack con1{ nano::dev::network_params.network, vote }; @@ -392,7 +392,7 @@ TEST (receivable_processor, confirm_sufficient_pos) .build (); node1.work_generate_blocking (*block1); ASSERT_EQ (nano::block_status::progress, node1.process (block1)); - node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ()); + node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ()); auto vote = nano::test::make_vote (nano::dev::genesis_key, { block1 }, 0, 0); nano::confirm_ack con1{ nano::dev::network_params.network, vote }; auto channel1 = std::make_shared (node1, node1); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 2bc7435b7e..980841a036 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -116,7 +116,7 @@ TEST (node, balance) { nano::test::system system (1); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - auto transaction (system.nodes[0]->store.tx_begin_write ()); + auto transaction = system.nodes[0]->ledger.tx_begin_write (); ASSERT_EQ (std::numeric_limits::max (), system.nodes[0]->ledger.account_balance (transaction, nano::dev::genesis_key.pub)); } @@ -428,13 +428,13 @@ TEST (node, search_receivable_pruned) // Confirmation ASSERT_TIMELY (10s, node1->active.empty () && node2->active.empty ()); - ASSERT_TIMELY (5s, node1->ledger.block_confirmed (node1->store.tx_begin_read (), send2->hash ())); + ASSERT_TIMELY (5s, node1->ledger.block_confirmed (node1->ledger.tx_begin_read (), send2->hash ())); ASSERT_TIMELY_EQ (5s, node2->ledger.cemented_count (), 3); system.wallet (0)->store.erase (node1->wallets.tx_begin_write (), nano::dev::genesis_key.pub); // Pruning { - auto transaction (node2->store.tx_begin_write ()); + auto transaction = node2->ledger.tx_begin_write (); ASSERT_EQ (1, node2->ledger.pruning_action (transaction, send1->hash (), 1)); } ASSERT_EQ (1, node2->ledger.pruned_count ()); @@ -648,14 +648,14 @@ TEST (node, fork_keep) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); node1.process_active (send1); - node2.process_active (send1); + node2.process_active (builder.make_block ().from (*send1).build ()); ASSERT_TIMELY_EQ (5s, 1, node1.active.size ()); ASSERT_TIMELY_EQ (5s, 1, node2.active.size ()); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); // Fill node with forked blocks node1.process_active (send2); ASSERT_TIMELY (5s, node1.active.active (*send2)); - node2.process_active (send2); + node2.process_active (builder.make_block ().from (*send2).build ()); ASSERT_TIMELY (5s, node2.active.active (*send2)); auto election1 (node2.active.election (nano::qualified_root (nano::dev::genesis->hash (), nano::dev::genesis->hash ()))); ASSERT_NE (nullptr, election1); @@ -664,8 +664,8 @@ TEST (node, fork_keep) ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1->hash ())); // Wait until the genesis rep makes a vote ASSERT_TIMELY (1.5min, election1->votes ().size () != 1); - auto transaction0 (node1.store.tx_begin_read ()); - auto transaction1 (node2.store.tx_begin_read ()); + auto transaction0 (node1.ledger.tx_begin_read ()); + auto transaction1 (node2.ledger.tx_begin_read ()); // The vote should be in agreement with what we already have. auto winner (*election1->tally ().begin ()); ASSERT_EQ (*send1, *winner.second); @@ -761,10 +761,10 @@ TEST (node, fork_multi_flip) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send2->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.ledger.tx_begin_write (), send1)); // Node2 has two blocks that will be rolled back by node1's vote - ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.store.tx_begin_write (), send2)); - ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.store.tx_begin_write (), send3)); + ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.ledger.tx_begin_write (), send2)); + ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.ledger.tx_begin_write (), send3)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); // Insert voting key in to node1 auto election = nano::test::start_election (system, node2, send2->hash ()); @@ -811,9 +811,9 @@ TEST (node, fork_bootstrap_flip) .work (*system0.work.generate (latest)) .build (); // Insert but don't rebroadcast, simulating settled blocks - ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.store.tx_begin_write (), send1)); - ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.store.tx_begin_write (), send2)); - ASSERT_TRUE (node2.ledger.block_exists (node2.store.tx_begin_read (), send2->hash ())); + ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.ledger.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.ledger.tx_begin_write (), send2)); + ASSERT_TRUE (node2.ledger.block_exists (node2.ledger.tx_begin_read (), send2->hash ())); node2.bootstrap_initiator.bootstrap (node1.network.endpoint ()); // Additionally add new peer to confirm & replace bootstrap block auto again (true); system0.deadline_set (50s); @@ -822,7 +822,7 @@ TEST (node, fork_bootstrap_flip) { ASSERT_NO_ERROR (system0.poll ()); ASSERT_NO_ERROR (system1.poll ()); - again = !node2.ledger.block_exists (node2.store.tx_begin_read (), send1->hash ()); + again = !node2.ledger.block_exists (node2.ledger.tx_begin_read (), send1->hash ()); } } @@ -972,8 +972,8 @@ TEST (node, fork_open_flip) ASSERT_EQ (nano::dev::constants.genesis_amount - 1, winner.first); // check the correct blocks are in the ledgers - auto transaction1 (node1.store.tx_begin_read ()); - auto transaction2 (node2.store.tx_begin_read ()); + auto transaction1 = node1.ledger.tx_begin_read (); + auto transaction2 = node2.ledger.tx_begin_read (); ASSERT_TRUE (node1.ledger.block_exists (transaction1, open1->hash ())); ASSERT_TRUE (node2.ledger.block_exists (transaction2, open1->hash ())); ASSERT_FALSE (node2.ledger.block_exists (transaction2, open2->hash ())); @@ -984,7 +984,7 @@ TEST (node, coherent_observer) nano::test::system system (1); auto & node1 (*system.nodes[0]); node1.observers.blocks.add ([&node1] (nano::election_status const & status_a, std::vector const &, nano::account const &, nano::uint128_t const &, bool, bool) { - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); ASSERT_TRUE (node1.ledger.block_exists (transaction, status_a.winner->hash ())); }); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); @@ -1170,9 +1170,9 @@ TEST (node, DISABLED_fork_stale) .build (); node1.work_generate_blocking (*send2); { - auto transaction1 (node1.store.tx_begin_write ()); + auto transaction1 = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction1, send1)); - auto transaction2 (node2.store.tx_begin_write ()); + auto transaction2 = node2.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node2.ledger.process (transaction2, send2)); } node1.process_active (send1); @@ -1207,9 +1207,9 @@ TEST (node, DISABLED_broadcast_elected) nano::keypair rep_other; nano::block_builder builder; { - auto transaction0 (node0->store.tx_begin_write ()); - auto transaction1 (node1->store.tx_begin_write ()); - auto transaction2 (node2->store.tx_begin_write ()); + auto transaction0 = node0->ledger.tx_begin_write (); + auto transaction1 = node1->ledger.tx_begin_write (); + auto transaction2 = node2->ledger.tx_begin_write (); auto fund_big = builder.send () .previous (nano::dev::genesis->hash ()) .destination (rep_big.pub) @@ -1362,7 +1362,7 @@ TEST (node, rep_self_vote) ASSERT_EQ (nano::block_status::progress, node0->process (block0)); auto & active = node0->active; auto & scheduler = node0->scheduler; - scheduler.priority.activate (nano::dev::genesis_key.pub, node0->store.tx_begin_read ()); + scheduler.priority.activate (nano::dev::genesis_key.pub, node0->ledger.tx_begin_read ()); ASSERT_TIMELY (5s, active.election (block0->qualified_root ())); auto election1 = active.election (block0->qualified_root ()); ASSERT_NE (nullptr, election1); @@ -1392,7 +1392,7 @@ TEST (node, DISABLED_bootstrap_no_publish) .work (0) .build (); { - auto transaction (node0->store.tx_begin_write ()); + auto transaction = node0->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, send0)); } ASSERT_FALSE (node1->bootstrap_initiator.in_progress ()); @@ -1545,7 +1545,7 @@ TEST (node, bootstrap_confirm_frontiers) // on 2 different systems at once and in sequence and there might be strange timing effects. system0.deadline_set (10s); system1.deadline_set (10s); - while (!node1->ledger.block_confirmed (node1->store.tx_begin_read (), send0->hash ())) + while (!node1->ledger.block_confirmed (node1->ledger.tx_begin_read (), send0->hash ())) { ASSERT_NO_ERROR (system0.poll (std::chrono::milliseconds (1))); ASSERT_NO_ERROR (system1.poll (std::chrono::milliseconds (1))); @@ -1573,9 +1573,9 @@ TEST (node, unconfirmed_send) ASSERT_TIMELY (5s, node2.block_confirmed (send1->hash ())); // wait until receive1 (auto-receive created by wallet) is cemented - ASSERT_TIMELY_EQ (5s, node2.get_confirmation_height (node2.store.tx_begin_read (), key2.pub), 1); + ASSERT_TIMELY_EQ (5s, node2.get_confirmation_height (node2.ledger.tx_begin_read (), key2.pub), 1); ASSERT_EQ (node2.balance (key2.pub), 2 * nano::Mxrb_ratio); - auto recv1 = node2.ledger.find_receive_block_by_send_hash (node2.store.tx_begin_read (), key2.pub, send1->hash ()); + auto recv1 = node2.ledger.find_receive_block_by_send_hash (node2.ledger.tx_begin_read (), key2.pub, send1->hash ()); // create send2 to send from node2 to node1 and save it to node2's ledger without triggering an election (node1 does not hear about it) auto send2 = nano::state_block_builder{} @@ -1908,7 +1908,7 @@ TEST (node, local_votes_cache) .work (*node.work_generate_blocking (send2->hash ())) .build (); { - auto transaction (node.store.tx_begin_write ()); + auto transaction = node.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node.ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node.ledger.process (transaction, send2)); } @@ -1939,7 +1939,7 @@ TEST (node, local_votes_cache) ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes), 2); // Max cache { - auto transaction (node.store.tx_begin_write ()); + auto transaction = node.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node.ledger.process (transaction, send3)); } nano::confirm_req message3{ nano::dev::network_params.network, send3->hash (), send3->root () }; @@ -1978,9 +1978,9 @@ TEST (node, DISABLED_local_votes_cache_batch) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.confirming_set.add (send1->hash ()); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.store.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send1->hash ())); auto send2 = nano::state_block_builder () .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) @@ -1990,7 +1990,7 @@ TEST (node, DISABLED_local_votes_cache_batch) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (send1->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send2)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send2)); auto receive1 = nano::state_block_builder () .account (key1.pub) .previous (0) @@ -2000,7 +2000,7 @@ TEST (node, DISABLED_local_votes_cache_batch) .sign (key1.prv, key1.pub) .work (*node.work_generate_blocking (key1.pub)) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), receive1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), receive1)); std::vector> batch{ { send2->hash (), send2->root () }, { receive1->hash (), receive1->root () } }; nano::confirm_req message{ nano::dev::network_params.network, batch }; auto channel = std::make_shared (node); @@ -2203,7 +2203,7 @@ TEST (node, vote_by_hash_bundle) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); blocks.push_back (block); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), blocks.back ())); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), blocks.back ())); for (auto i = 2; i < 200; ++i) { auto block = builder.make_block () @@ -2214,7 +2214,7 @@ TEST (node, vote_by_hash_bundle) .work (*system.work.generate (blocks.back ()->hash ())) .build (); blocks.push_back (block); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), blocks.back ())); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), blocks.back ())); } // Confirming last block will confirm whole chain and allow us to generate votes for those blocks later @@ -2982,7 +2982,7 @@ TEST (node, bidirectional_tcp) system.deadline_set (10s); while (!confirmed) { - auto transaction2 (node2->store.tx_begin_read ()); + auto transaction2 = node2->ledger.tx_begin_read (); confirmed = node2->ledger.block_confirmed (transaction2, send1->hash ()); ASSERT_NO_ERROR (system.poll ()); } @@ -3015,7 +3015,7 @@ TEST (node, bidirectional_tcp) system.deadline_set (20s); while (!confirmed) { - auto transaction1 (node1->store.tx_begin_read ()); + auto transaction1 = node1->ledger.tx_begin_read (); confirmed = node1->ledger.block_confirmed (transaction1, send2->hash ()); ASSERT_NO_ERROR (system.poll ()); } @@ -3539,7 +3539,7 @@ TEST (node, dependency_graph_frontier) for (auto const & node : system.nodes) { - auto transaction (node->store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, gen_send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, key1_open)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, key1_send1)); @@ -3670,9 +3670,9 @@ TEST (node, deferred_dependent_elections) ASSERT_FALSE (node.active.active (receive->qualified_root ())); election_open->force_confirm (); ASSERT_TIMELY (5s, node.block_confirmed (open->hash ())); - ASSERT_FALSE (node.ledger.dependents_confirmed (node.store.tx_begin_read (), *receive)); + ASSERT_FALSE (node.ledger.dependents_confirmed (node.ledger.tx_begin_read (), *receive)); ASSERT_NEVER (0.5s, node.active.active (receive->qualified_root ())); - ASSERT_FALSE (node.ledger.rollback (node.store.tx_begin_write (), receive->hash ())); + ASSERT_FALSE (node.ledger.rollback (node.ledger.tx_begin_write (), receive->hash ())); ASSERT_FALSE (node.block (receive->hash ())); node.process_local (receive); ASSERT_TIMELY (5s, node.block (receive->hash ())); diff --git a/nano/core_test/peer_container.cpp b/nano/core_test/peer_container.cpp index c0f04d9d91..b55150d583 100644 --- a/nano/core_test/peer_container.cpp +++ b/nano/core_test/peer_container.cpp @@ -68,10 +68,13 @@ TEST (peer_container, tcp_channel_cleanup_works) // Disable the confirm_req messages avoiding them to affect the last_packet_set time node_flags.disable_rep_crawler = true; auto & node1 = *system.add_node (node_config, node_flags); - auto outer_node1 = nano::test::add_outer_node (system, node_flags); - outer_node1->config.network_params.network.keepalive_period = std::chrono::minutes (10); - auto outer_node2 = nano::test::add_outer_node (system, node_flags); - outer_node2->config.network_params.network.keepalive_period = std::chrono::minutes (10); + + auto config1 = node_config; + config1.network_params.network.keepalive_period = std::chrono::minutes (10); + auto outer_node1 = nano::test::add_outer_node (system, config1, node_flags); + auto config2 = config1; + config2.network_params.network.keepalive_period = std::chrono::minutes (10); + auto outer_node2 = nano::test::add_outer_node (system, config2, node_flags); auto now = std::chrono::steady_clock::now (); auto channel1 = nano::test::establish_tcp (system, node1, outer_node1->network.endpoint ()); ASSERT_NE (nullptr, channel1); diff --git a/nano/core_test/processor_service.cpp b/nano/core_test/processor_service.cpp index 959495d1db..5da559f368 100644 --- a/nano/core_test/processor_service.cpp +++ b/nano/core_test/processor_service.cpp @@ -17,7 +17,7 @@ TEST (processor_service, bad_send_signature) ASSERT_FALSE (store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); @@ -43,7 +43,7 @@ TEST (processor_service, bad_receive_signature) ASSERT_FALSE (store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); diff --git a/nano/core_test/receivable.cpp b/nano/core_test/receivable.cpp new file mode 100644 index 0000000000..aef5534fdf --- /dev/null +++ b/nano/core_test/receivable.cpp @@ -0,0 +1,99 @@ +#include +#include + +#include + +using namespace std::chrono_literals; + +// this test sends 3 send blocks in 3 different epochs and checks that +// the pending table records the epochs correctly for each send +TEST (receivable, pending_table_query_epochs) +{ + nano::test::system system{ 1 }; + auto & node = *system.nodes[0]; + nano::keypair key2; + nano::block_builder builder; + + // epoch 0 send + auto send0 = builder + .send () + .previous (nano::dev::genesis->hash ()) + .destination (key2.pub) + .balance (nano::dev::constants.genesis_amount - 1) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*system.work.generate (nano::dev::genesis->hash ())) + .build (); + nano::test::process (node, { send0 }); + ASSERT_TIMELY (5s, nano::test::exists (node, { send0 })); + + auto epoch1 = system.upgrade_genesis_epoch (node, nano::epoch::epoch_1); + ASSERT_TRUE (epoch1); + ASSERT_TIMELY (5s, nano::test::exists (node, { epoch1 })); + + // epoch 1 send + auto send1 = builder + .state () + .account (nano::dev::genesis_key.pub) + .representative (nano::dev::genesis_key.pub) + .previous (epoch1->hash ()) + .link (key2.pub) + .balance (nano::dev::constants.genesis_amount - 11) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*system.work.generate (epoch1->hash ())) + .build (); + ASSERT_TRUE (nano::test::process (node, { send1 })); + ASSERT_TIMELY (5s, nano::test::exists (node, { send1 })); + + auto epoch2 = system.upgrade_genesis_epoch (node, nano::epoch::epoch_2); + ASSERT_TRUE (epoch2); + ASSERT_TIMELY (5s, nano::test::exists (node, { epoch2 })); + + // epoch 2 send + auto send2 = builder + .state () + .account (nano::dev::genesis_key.pub) + .representative (nano::dev::genesis_key.pub) + .previous (epoch2->hash ()) + .link (key2.pub) + .balance (nano::dev::constants.genesis_amount - 111) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*system.work.generate (epoch2->hash ())) + .build (); + nano::test::process (node, { send2 }); + ASSERT_TIMELY (5s, nano::test::exists (node, { send2 })); + + auto tx = node.store.tx_begin_read (); + + // check epoch 0 send + { + nano::pending_key key{ key2.pub, send0->hash () }; + auto opt_info = node.store.pending.get (tx, key); + ASSERT_TRUE (opt_info.has_value ()); + auto info = opt_info.value (); + ASSERT_EQ (info.source, nano::dev::genesis_key.pub); + ASSERT_EQ (info.amount, 1); + ASSERT_EQ (info.epoch, nano::epoch::epoch_0); + } + + // check epoch 1 send + { + nano::pending_key key{ key2.pub, send1->hash () }; + auto opt_info = node.store.pending.get (tx, key); + ASSERT_TRUE (opt_info.has_value ()); + auto info = opt_info.value (); + ASSERT_EQ (info.source, nano::dev::genesis_key.pub); + ASSERT_EQ (info.amount, 10); + ASSERT_EQ (info.epoch, nano::epoch::epoch_1); + } + + // check epoch 2 send + { + nano::pending_key key{ key2.pub, send2->hash () }; + auto opt_info = node.store.pending.get (tx, key); + ASSERT_TRUE (opt_info.has_value ()); + auto info = opt_info.value (); + ASSERT_EQ (info.source, nano::dev::genesis_key.pub); + ASSERT_EQ (info.amount, 100); + ASSERT_EQ (info.epoch, nano::epoch::epoch_2); + } +} \ No newline at end of file diff --git a/nano/core_test/rep_crawler.cpp b/nano/core_test/rep_crawler.cpp index 293733a76a..70fc542fff 100644 --- a/nano/core_test/rep_crawler.cpp +++ b/nano/core_test/rep_crawler.cpp @@ -172,7 +172,7 @@ TEST (rep_crawler, rep_remove) .work (*system.work.generate (keys_rep2.pub)) .build (); { - auto transaction = searching_node.store.tx_begin_write (); + auto transaction = searching_node.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, searching_node.ledger.process (transaction, send_to_rep1)); ASSERT_EQ (nano::block_status::progress, searching_node.ledger.process (transaction, receive_rep1)); ASSERT_EQ (nano::block_status::progress, searching_node.ledger.process (transaction, send_to_rep2)); diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 0730a49da6..adcbaf1f5d 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -42,7 +42,7 @@ TEST (request_aggregator, one) ASSERT_TIMELY (3s, node.aggregator.empty ()); // Not yet in the ledger ASSERT_TIMELY_EQ (3s, 1, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_unknown)); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.aggregator.add (dummy_channel, request); ASSERT_EQ (1, node.aggregator.size ()); // In the ledger but no vote generated yet @@ -79,9 +79,9 @@ TEST (request_aggregator, one_update) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.confirming_set.add (send1->hash ()); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.store.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send1->hash ())); auto send2 = nano::state_block_builder () .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) @@ -91,7 +91,7 @@ TEST (request_aggregator, one_update) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (send1->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send2)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send2)); auto receive1 = nano::state_block_builder () .account (key1.pub) .previous (0) @@ -101,7 +101,7 @@ TEST (request_aggregator, one_update) .sign (key1.prv, key1.pub) .work (*node.work_generate_blocking (key1.pub)) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), receive1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), receive1)); std::vector> request; request.emplace_back (send2->hash (), send2->root ()); auto client = std::make_shared (node); @@ -145,9 +145,9 @@ TEST (request_aggregator, two) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.confirming_set.add (send1->hash ()); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.store.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send1->hash ())); auto send2 = builder.make_block () .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) @@ -166,8 +166,8 @@ TEST (request_aggregator, two) .sign (key1.prv, key1.pub) .work (*node.work_generate_blocking (key1.pub)) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send2)); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), receive1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send2)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), receive1)); std::vector> request; request.emplace_back (send2->hash (), send2->root ()); request.emplace_back (receive1->hash (), receive1->root ()); @@ -224,7 +224,7 @@ TEST (request_aggregator, two_endpoints) .build (); std::vector> request; request.emplace_back (send1->hash (), send1->root ()); - ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.ledger.tx_begin_write (), send1)); auto dummy_channel1 = std::make_shared (node1, node1); auto dummy_channel2 = std::make_shared (node2, node2); ASSERT_NE (nano::transport::map_endpoint_to_v6 (dummy_channel1->get_endpoint ()), nano::transport::map_endpoint_to_v6 (dummy_channel2->get_endpoint ())); @@ -285,14 +285,11 @@ TEST (request_aggregator, split) .build ()); auto const & block = blocks.back (); previous = block->hash (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), block)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), block)); request.emplace_back (block->hash (), block->root ()); } // Confirm all blocks - node.start_election (blocks.back ()); - std::shared_ptr election; - ASSERT_TIMELY (5s, election = node.active.election (blocks.back ()->qualified_root ())); - election->force_confirm (); + node.ledger.confirm (node.ledger.tx_begin_write (), blocks.back ()->hash ()); ASSERT_TIMELY_EQ (5s, max_vbh + 2, node.ledger.cemented_count ()); ASSERT_EQ (max_vbh + 1, request.size ()); auto client = std::make_shared (node); @@ -331,7 +328,7 @@ TEST (request_aggregator, channel_lifetime) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); std::vector> request; request.emplace_back (send1->hash (), send1->root ()); { @@ -362,7 +359,7 @@ TEST (request_aggregator, channel_update) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); std::vector> request; request.emplace_back (send1->hash (), send1->root ()); std::weak_ptr channel1_w; @@ -402,7 +399,7 @@ TEST (request_aggregator, channel_max_queue) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); std::vector> request; request.emplace_back (send1->hash (), send1->root ()); auto client = std::make_shared (node); @@ -430,7 +427,7 @@ TEST (request_aggregator, unique) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); std::vector> request; request.emplace_back (send1->hash (), send1->root ()); auto client = std::make_shared (node); @@ -471,7 +468,7 @@ TEST (request_aggregator, cannot_vote) ASSERT_EQ (nano::block_status::progress, node.process (send1)); ASSERT_EQ (nano::block_status::progress, node.process (send2)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - ASSERT_FALSE (node.ledger.dependents_confirmed (node.store.tx_begin_read (), *send2)); + ASSERT_FALSE (node.ledger.dependents_confirmed (node.ledger.tx_begin_read (), *send2)); std::vector> request; // Correct hash, correct root @@ -509,7 +506,7 @@ TEST (request_aggregator, cannot_vote) std::shared_ptr election; ASSERT_TIMELY (5s, election = node.active.election (send1->qualified_root ())); election->force_confirm (); - ASSERT_TIMELY (3s, node.ledger.dependents_confirmed (node.store.tx_begin_read (), *send2)); + ASSERT_TIMELY (3s, node.ledger.dependents_confirmed (node.ledger.tx_begin_read (), *send2)); node.aggregator.add (dummy_channel, request); ASSERT_EQ (1, node.aggregator.size ()); ASSERT_TIMELY (3s, node.aggregator.empty ()); diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index ffd860180f..486a1fd543 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -31,7 +31,7 @@ TEST (system, system_genesis) nano::test::system system (2); for (auto & i : system.nodes) { - auto transaction (i->store.tx_begin_read ()); + auto transaction = i->ledger.tx_begin_read (); ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.account_balance (transaction, nano::dev::genesis_key.pub)); } } @@ -44,14 +44,14 @@ TEST (system, DISABLED_generate_send_existing) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair stake_preserver; auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); - auto info1 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub); + auto info1 = node1.ledger.account_info (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub); ASSERT_TRUE (info1); std::vector accounts; accounts.push_back (nano::dev::genesis_key.pub); system.generate_send_existing (node1, accounts); // Have stake_preserver receive funds after generate_send_existing so it isn't chosen as the destination { - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); nano::block_builder builder; auto open_block = builder .open () @@ -65,21 +65,21 @@ TEST (system, DISABLED_generate_send_existing) ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open_block)); } ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis_key.pub)); - auto info2 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub); + auto info2 = node1.ledger.account_info (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_NE (info1->head, info2->head); system.deadline_set (15s); while (info2->block_count < info1->block_count + 2) { ASSERT_NO_ERROR (system.poll ()); - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); } ASSERT_EQ (info1->block_count + 2, info2->block_count); ASSERT_EQ (info2->balance, nano::dev::constants.genesis_amount / 3); { - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); ASSERT_NE (node1.ledger.amount (transaction, info2->head), 0); } system.stop (); @@ -102,7 +102,7 @@ TEST (system, DISABLED_generate_send_new) nano::keypair stake_preserver; auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); { - auto transaction (node1.store.tx_begin_write ()); + auto transaction = node1.ledger.tx_begin_write (); nano::block_builder builder; auto open_block = builder .open () diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 3c08618ac5..9a16945468 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -172,12 +172,12 @@ TEST (vote_spacing, vote_generator) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); ASSERT_EQ (0, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts)); node.generator.add (nano::dev::genesis->hash (), send1->hash ()); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts), 1); - ASSERT_FALSE (node.ledger.rollback (node.store.tx_begin_write (), send1->hash ())); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send2)); + ASSERT_FALSE (node.ledger.rollback (node.ledger.tx_begin_write (), send1->hash ())); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send2)); node.generator.add (nano::dev::genesis->hash (), send2->hash ()); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_spacing), 1); ASSERT_EQ (1, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts)); @@ -216,11 +216,11 @@ TEST (vote_spacing, rapid) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send1)); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.generator.add (nano::dev::genesis->hash (), send1->hash ()); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts), 1); - ASSERT_FALSE (node.ledger.rollback (node.store.tx_begin_write (), send1->hash ())); - ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.store.tx_begin_write (), send2)); + ASSERT_FALSE (node.ledger.rollback (node.ledger.tx_begin_write (), send1->hash ())); + ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send2)); node.generator.add (nano::dev::genesis->hash (), send2->hash ()); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_spacing), 1); ASSERT_TIMELY_EQ (3s, 1, node.stats.count (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts)); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 05d49392fa..17284f3b2e 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -182,7 +182,7 @@ TEST (wallet, spend_all_one) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key2; ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, std::numeric_limits::max ())); - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_NE (latest1, info2->head); auto block = node1.ledger.block (transaction, info2->head); @@ -216,7 +216,7 @@ TEST (wallet, spend) // Sending from empty accounts should always be an error. Accounts need to be opened with an open block, not a send block. ASSERT_EQ (nullptr, system.wallet (0)->send_action (0, key2.pub, 0)); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, std::numeric_limits::max ())); - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_NE (latest1, info2->head); @@ -241,7 +241,7 @@ TEST (wallet, spend_no_previous) nano::test::system system (1); { system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - auto transaction (system.nodes[0]->store.tx_begin_read ()); + auto transaction = system.nodes[0]->ledger.tx_begin_read (); auto info1 = system.nodes[0]->ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); for (auto i (0); i < 50; ++i) @@ -645,19 +645,18 @@ TEST (wallet, work_generate) wallet->insert_adhoc (nano::dev::genesis_key.prv); nano::account account1; { - auto transaction (node1.wallets.tx_begin_read ()); + auto transaction = node1.wallets.tx_begin_read (); account1 = system.account (transaction, 0); } nano::keypair key; auto block (wallet->send_action (nano::dev::genesis_key.pub, key.pub, 100)); - auto transaction (node1.store.tx_begin_read ()); - ASSERT_TIMELY (10s, node1.ledger.account_balance (transaction, nano::dev::genesis_key.pub) != amount1); + ASSERT_TIMELY (10s, node1.ledger.account_balance (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub) != amount1); system.deadline_set (10s); auto again (true); while (again) { ASSERT_NO_ERROR (system.poll ()); - auto block_transaction (node1.store.tx_begin_read ()); + auto block_transaction = node1.ledger.tx_begin_read (); auto transaction (system.wallet (0)->wallets.tx_begin_read ()); again = wallet->store.work_get (transaction, account1, work1) || nano::dev::network_params.work.difficulty (block->work_version (), node1.ledger.latest_root (block_transaction, account1), work1) < node1.default_difficulty (block->work_version ()); } @@ -672,7 +671,7 @@ TEST (wallet, work_cache_delayed) wallet->insert_adhoc (nano::dev::genesis_key.prv); nano::account account1; { - auto transaction (node1.wallets.tx_begin_read ()); + auto transaction = node1.wallets.tx_begin_read (); account1 = system.account (transaction, 0); } nano::keypair key; @@ -1189,7 +1188,7 @@ TEST (wallet, search_receivable) ASSERT_EQ (2, node.ledger.block_count ()); ASSERT_FALSE (wallet.search_receivable (wallet.wallets.tx_begin_read ())); ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); - auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis_key.pub); + auto receive_hash = node.ledger.latest (node.ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); @@ -1222,17 +1221,17 @@ TEST (wallet, receive_pruned) // Pruning ASSERT_TIMELY_EQ (5s, node2.ledger.cemented_count (), 3); { - auto transaction = node2.store.tx_begin_write (); + auto transaction = node2.ledger.tx_begin_write (); ASSERT_EQ (1, node2.ledger.pruning_action (transaction, send1->hash (), 2)); } ASSERT_EQ (1, node2.ledger.pruned_count ()); ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_FALSE (node2.ledger.block_exists (node2.store.tx_begin_read (), send1->hash ())); + ASSERT_FALSE (node2.ledger.block_exists (node2.ledger.tx_begin_read (), send1->hash ())); wallet2.insert_adhoc (key.prv, false); auto open1 = wallet2.receive_action (send1->hash (), key.pub, amount, send1->destination (), 1); ASSERT_NE (nullptr, open1); - ASSERT_EQ (amount, node2.ledger.balance (node2.store.tx_begin_read (), open1->hash ())); + ASSERT_EQ (amount, node2.ledger.balance (node2.ledger.tx_begin_read (), open1->hash ())); ASSERT_TIMELY_EQ (5s, node2.ledger.cemented_count (), 4); } diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index c692b177f2..8de340f84a 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -254,7 +254,7 @@ TEST (wallets, search_receivable) node.wallets.search_receivable (wallet_id); } ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); - auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis_key.pub); + auto receive_hash = node.ledger.latest (node.ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); diff --git a/nano/lib/blockbuilders.cpp b/nano/lib/blockbuilders.cpp index d8fa600f8f..034abbe3af 100644 --- a/nano/lib/blockbuilders.cpp +++ b/nano/lib/blockbuilders.cpp @@ -516,6 +516,21 @@ nano::send_block_builder::send_block_builder () make_block (); } +nano::send_block_builder & nano::send_block_builder::from (nano::send_block const & other_block) +{ + block->work = other_block.work; + build_state |= build_flags::work_present; + block->signature = other_block.signature; + build_state |= build_flags::signature_present; + block->hashables.balance = other_block.hashables.balance; + build_state |= build_flags::balance_present; + block->hashables.destination = other_block.hashables.destination; + build_state |= build_flags::link_present; + block->hashables.previous = other_block.hashables.previous; + build_state |= build_flags::previous_present; + return *this; +} + nano::send_block_builder & nano::send_block_builder::make_block () { construct_block (); diff --git a/nano/lib/blockbuilders.hpp b/nano/lib/blockbuilders.hpp index 1471c9bb20..6f625c330b 100644 --- a/nano/lib/blockbuilders.hpp +++ b/nano/lib/blockbuilders.hpp @@ -199,6 +199,8 @@ class send_block_builder : public abstract_builder +#include #include #include @@ -10,7 +11,8 @@ nano::signal_manager::signal_manager () : work (boost::asio::make_work_guard (ioc)) { - smthread = boost::thread ([&ioc = ioc] () { + thread = std::thread ([&ioc = ioc] () { + nano::thread_role::set (nano::thread_role::name::signal_manager); ioc.run (); }); } @@ -21,7 +23,7 @@ nano::signal_manager::~signal_manager () /// io_context::run() function will exit once all other work has completed. work.reset (); ioc.stop (); - smthread.join (); + thread.join (); } nano::signal_manager::signal_descriptor::signal_descriptor (std::shared_ptr sigset_a, signal_manager & sigman_a, std::function handler_func_a, bool repeat_a) : @@ -46,14 +48,16 @@ void nano::signal_manager::register_signal_handler (int signum, std::functionclear (); } - - descriptor.sigman.log (boost::str (boost::format ("Signal processed: %d") % signum)); } else { - descriptor.sigman.log (boost::str (boost::format ("Signal error: %d (%s)") % error.value () % error.message ())); + logger.debug (nano::log::type::signal_manager, "Signal error: {} ({})", ec.message (), to_signal_name (signum)); + } +} + +std::string nano::to_signal_name (int signum) +{ + switch (signum) + { + case SIGINT: + return "SIGINT"; + case SIGTERM: + return "SIGTERM"; + case SIGSEGV: + return "SIGSEGV"; + case SIGABRT: + return "SIGABRT"; + case SIGILL: + return "SIGILL"; } + return std::to_string (signum); } diff --git a/nano/lib/signal_manager.hpp b/nano/lib/signal_manager.hpp index 5012de52fb..89fce59c77 100644 --- a/nano/lib/signal_manager.hpp +++ b/nano/lib/signal_manager.hpp @@ -1,14 +1,15 @@ #pragma once +#include #include #include #include -#include #include #include #include +#include #include namespace nano @@ -51,18 +52,14 @@ class signal_manager final bool repeat; }; - /** - * Logging function of signal manager. It does nothing at the moment, it throws away the log. - * I expect to revisit this in the future. It also makes it easy to manually introduce logs, if needed temporarily. - */ - void log (std::string const &){}; - /** * This is the actual handler that is registered with boost asio. * It calls the caller supplied function (if one is given) and sets the handler to repeat (or not). */ static void base_handler (nano::signal_manager::signal_descriptor descriptor, boost::system::error_code const & error, int signum); + nano::logger logger; + /** boost asio context to use */ boost::asio::io_context ioc; @@ -73,7 +70,8 @@ class signal_manager final std::vector descriptor_list; /** thread to service the signal manager io context */ - boost::thread smthread; + std::thread thread; }; +std::string to_signal_name (int signum); } diff --git a/nano/lib/thread_roles.cpp b/nano/lib/thread_roles.cpp index 9053897088..dac854bcb0 100644 --- a/nano/lib/thread_roles.cpp +++ b/nano/lib/thread_roles.cpp @@ -125,6 +125,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role) case nano::thread_role::name::network_reachout: thread_role_name_string = "Net reachout"; break; + case nano::thread_role::name::signal_manager: + thread_role_name_string = "Signal manager"; + break; case nano::thread_role::name::tcp_listener: thread_role_name_string = "TCP listener"; break; diff --git a/nano/lib/thread_roles.hpp b/nano/lib/thread_roles.hpp index b54815cf4d..f40d80fb15 100644 --- a/nano/lib/thread_roles.hpp +++ b/nano/lib/thread_roles.hpp @@ -48,6 +48,7 @@ enum class name network_cleanup, network_keepalive, network_reachout, + signal_manager, tcp_listener, }; diff --git a/nano/lib/thread_runner.cpp b/nano/lib/thread_runner.cpp index 62a7625cd1..5f36c82a82 100644 --- a/nano/lib/thread_runner.cpp +++ b/nano/lib/thread_runner.cpp @@ -24,7 +24,7 @@ nano::thread_runner::thread_runner (std::shared_ptr io_ try { logger.debug (nano::log::type::thread_runner, "Thread #{} ({}) started", i, to_string (role)); - run (*io_ctx); + run (); logger.debug (nano::log::type::thread_runner, "Thread #{} ({}) stopped", i, to_string (role)); } catch (std::exception const & ex) @@ -49,28 +49,30 @@ nano::thread_runner::~thread_runner () join (); } -void nano::thread_runner::run (boost::asio::io_context & io_ctx_a) +void nano::thread_runner::run () { -#if NANO_ASIO_HANDLER_TRACKING == 0 - io_ctx_a.run (); -#else - nano::timer<> timer; - timer.start (); - while (true) + if constexpr (nano::asio_handler_tracking_threshold () == 0) { - timer.restart (); - // Run at most 1 completion handler and record the time it took to complete (non-blocking) - auto count = io_ctx_a.poll_one (); - if (count == 1 && timer.since_start ().count () >= NANO_ASIO_HANDLER_TRACKING) + io_ctx->run (); + } + else + { + nano::timer<> timer; + timer.start (); + while (true) { - auto timestamp = std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()).count (); - std::cout << (boost::format ("[%1%] io_thread held for %2%ms") % timestamp % timer.since_start ().count ()).str () << std::endl; + timer.restart (); + // Run at most 1 completion handler and record the time it took to complete (non-blocking) + auto count = io_ctx->poll_one (); + if (count == 1 && timer.since_start ().count () >= nano::asio_handler_tracking_threshold ()) + { + logger.warn (nano::log::type::system, "Async handler processing took too long: {}ms", timer.since_start ().count ()); + } + // Sleep for a bit to give more time slices to other threads + std::this_thread::sleep_for (std::chrono::milliseconds (5)); + std::this_thread::yield (); } - // Sleep for a bit to give more time slices to other threads - std::this_thread::sleep_for (std::chrono::milliseconds (5)); - std::this_thread::yield (); } -#endif } void nano::thread_runner::join () diff --git a/nano/lib/thread_runner.hpp b/nano/lib/thread_runner.hpp index 116a1aa65b..f1d557a883 100644 --- a/nano/lib/thread_runner.hpp +++ b/nano/lib/thread_runner.hpp @@ -31,6 +31,15 @@ class thread_runner final std::vector threads; private: - void run (boost::asio::io_context &); + void run (); }; + +constexpr unsigned asio_handler_tracking_threshold () +{ +#if NANO_ASIO_HANDLER_TRACKING == 0 + return 0; +#else + return NANO_ASIO_HANDLER_TRACKING; +#endif +} } // namespace nano diff --git a/nano/lib/tomlconfig.cpp b/nano/lib/tomlconfig.cpp index ee8d9e6f28..3cace0d655 100644 --- a/nano/lib/tomlconfig.cpp +++ b/nano/lib/tomlconfig.cpp @@ -186,15 +186,7 @@ void nano::tomlconfig::erase_default_values (tomlconfig & defaults_a) erase_defaults (defaults_l.get_tree (), self.get_tree (), get_tree ()); } -std::string nano::tomlconfig::to_string () -{ - std::stringstream ss; - cpptoml::toml_writer writer{ ss, "" }; - tree->accept (writer); - return ss.str (); -} - -std::string nano::tomlconfig::to_string_commented_entries () +std::string nano::tomlconfig::to_string (bool comment_values) { std::stringstream ss, ss_processed; cpptoml::toml_writer writer{ ss, "" }; @@ -202,9 +194,16 @@ std::string nano::tomlconfig::to_string_commented_entries () std::string line; while (std::getline (ss, line, '\n')) { - if (!line.empty () && line[0] != '#' && line[0] != '[') + if (!line.empty () && line[0] != '[') { - line = "#" + line; + if (line[0] == '#') // Already commented + { + line = "\t" + line; + } + else + { + line = comment_values ? "\t# " + line : "\t" + line; + } } ss_processed << line << std::endl; } diff --git a/nano/lib/tomlconfig.hpp b/nano/lib/tomlconfig.hpp index 140e1b0ab9..41ac0647b1 100644 --- a/nano/lib/tomlconfig.hpp +++ b/nano/lib/tomlconfig.hpp @@ -47,8 +47,7 @@ class tomlconfig : public nano::configbase tomlconfig & erase (std::string const & key_a); std::shared_ptr create_array (std::string const & key, boost::optional documentation_a); void erase_default_values (tomlconfig & defaults_a); - std::string to_string (); - std::string to_string_commented_entries (); + std::string to_string (bool comment_values); /** Set value for the given key. Any existing value will be overwritten. */ template diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index c47989fd63..a70ccab4d1 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -595,13 +596,14 @@ int main (int argc, char * const * argv) std::shared_ptr ioc_shared = std::make_shared (); boost::asio::io_context & ioc{ *ioc_shared }; - debug_assert (!nano::signal_handler_impl); - nano::signal_handler_impl = [&ioc] () { + nano::signal_manager sigman; + + auto signal_handler = [&ioc] (int signum) { ioc.stop (); }; - std::signal (SIGINT, &nano::signal_handler); - std::signal (SIGTERM, &nano::signal_handler); + sigman.register_signal_handler (SIGINT, signal_handler, true); + sigman.register_signal_handler (SIGTERM, signal_handler, false); tcp::resolver resolver{ ioc }; auto const primary_node_results = resolver.resolve ("::1", std::to_string (rpc_port_start)); diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 0ed9ee7053..da66fc8e4f 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -14,11 +14,11 @@ #include #include -#include #include #include #include +#include #include @@ -56,8 +56,6 @@ void install_abort_signal_handler () #endif } -volatile sig_atomic_t sig_int_or_term = 0; - constexpr std::size_t OPEN_FILE_DESCRIPTORS_LIMIT = 16384; } @@ -146,16 +144,28 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag logger.info (nano::log::type::daemon, "Database backend: {}", node->store.vendor_get ()); logger.info (nano::log::type::daemon, "Start time: {:%c} UTC", fmt::gmtime (dateTime)); + // IO context runner should be started first and stopped last to allow asio handlers to execute during node start/stop + runner = std::make_unique (io_ctx, node->config.io_threads); + node->start (); - nano::ipc::ipc_server ipc_server (*node, config.rpc); + std::atomic stopped{ false }; + + std::unique_ptr ipc_server = std::make_unique (*node, config.rpc); std::unique_ptr rpc_process; - std::shared_ptr rpc; std::unique_ptr rpc_handler; + std::shared_ptr rpc; + if (config.rpc_enable) { if (!config.rpc.child_process.enable) { + auto stop_callback = [this, &stopped] () { + logger.warn (nano::log::type::daemon, "RPC stop request received, stopping..."); + stopped = true; + stopped.notify_all (); + }; + // Launch rpc in-process nano::rpc_config rpc_config{ config.node.network_params.network }; auto error = nano::read_rpc_config_toml (data_path, rpc_config, flags.rpc_config_overrides); @@ -166,16 +176,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag } rpc_config.tls_config = tls_config; - rpc_handler = std::make_unique (*node, ipc_server, config.rpc, - [&ipc_server, &workers = node->workers, io_ctx_w = std::weak_ptr{ io_ctx }] () { - ipc_server.stop (); - workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::seconds (3), [io_ctx_w] () { - if (auto io_ctx_l = io_ctx_w.lock ()) - { - io_ctx_l->stop (); - } - }); - }); + rpc_handler = std::make_unique (*node, *ipc_server, config.rpc, stop_callback); rpc = nano::get_rpc (io_ctx, rpc_config, *rpc_handler); rpc->start (); } @@ -191,39 +192,35 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag rpc_process = std::make_unique (config.rpc.child_process.rpc_path, "--daemon", "--data_path", data_path.string (), "--network", network); } + debug_assert (rpc || rpc_process); } - debug_assert (!nano::signal_handler_impl); - nano::signal_handler_impl = [this, io_ctx_w = std::weak_ptr{ io_ctx }] () { - logger.warn (nano::log::type::daemon, "Interrupt signal received, stopping..."); - - if (auto io_ctx_l = io_ctx_w.lock ()) - { - io_ctx_l->stop (); - } - sig_int_or_term = 1; + auto signal_handler = [this, &stopped] (int signum) { + logger.warn (nano::log::type::daemon, "Interrupt signal received ({}), stopping...", to_signal_name (signum)); + stopped = true; + stopped.notify_all (); }; nano::signal_manager sigman; - // keep trapping Ctrl-C to avoid a second Ctrl-C interrupting tasks started by the first - sigman.register_signal_handler (SIGINT, &nano::signal_handler, true); - + sigman.register_signal_handler (SIGINT, signal_handler, true); // sigterm is less likely to come in bunches so only trap it once - sigman.register_signal_handler (SIGTERM, &nano::signal_handler, false); + sigman.register_signal_handler (SIGTERM, signal_handler, false); - runner = std::make_unique (io_ctx, node->config.io_threads); - runner->join (); + // Keep running until stopped flag is set + stopped.wait (false); - if (sig_int_or_term == 1) + logger.info (nano::log::type::daemon, "Stopping..."); + + if (rpc) { - ipc_server.stop (); - node->stop (); - if (rpc) - { - rpc->stop (); - } + rpc->stop (); } + ipc_server->stop (); + node->stop (); + io_ctx->stop (); + runner->join (); + if (rpc_process) { rpc_process->wait (); @@ -244,5 +241,5 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag logger.critical (nano::log::type::daemon, "Error deserializing config: {}", error.get_message ()); } - logger.info (nano::log::type::daemon, "Daemon exiting"); + logger.info (nano::log::type::daemon, "Daemon stopped"); } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 06fe4b9a96..934c0ad8ab 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1024,7 +1024,7 @@ int main (int argc, char * const * argv) nano::uint128_t balance ((node->config.online_weight_minimum.number () / num_representatives) + 1); for (auto i (0); i != num_representatives; ++i) { - auto transaction (node->store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); genesis_balance = genesis_balance - balance; auto send = builder.state () @@ -1379,7 +1379,7 @@ int main (int argc, char * const * argv) for (auto i (0U); i < threads_count; ++i) { threads.emplace_back ([&function_a, node, &mutex, &condition, &finished, &deque_a] () { - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); nano::unique_lock lock{ mutex }; while (!deque_a.empty () || !finished) { @@ -1400,7 +1400,7 @@ int main (int argc, char * const * argv) } }; - auto check_account = [&print_error_message, &silent, &count, &block_count] (std::shared_ptr const & node, nano::store::read_transaction const & transaction, nano::account const & account, nano::account_info const & info) { + auto check_account = [&print_error_message, &silent, &count, &block_count] (std::shared_ptr const & node, nano::secure::read_transaction const & transaction, nano::account const & account, nano::account_info const & info) { ++count; if (!silent && (count % 20000) == 0) { @@ -1627,7 +1627,7 @@ int main (int argc, char * const * argv) std::cout << boost::str (boost::format ("Performing %1% threads blocks hash, signature, work validation...\n") % threads_count); } size_t const accounts_deque_overflow (32 * 1024); - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) { { @@ -1673,7 +1673,7 @@ int main (int argc, char * const * argv) finished = false; std::deque> pending; - auto check_pending = [&print_error_message, &silent, &count] (std::shared_ptr const & node, nano::store::read_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & info) { + auto check_pending = [&print_error_message, &silent, &count] (std::shared_ptr const & node, nano::secure::read_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & info) { ++count; if (!silent && (count % 500000) == 0) { @@ -1793,7 +1793,7 @@ int main (int argc, char * const * argv) node_flags.generate_cache.block_count = true; nano::inactive_node inactive_node (data_path, node_flags); auto source_node = inactive_node.node; - auto transaction (source_node->store.tx_begin_read ()); + auto transaction = source_node->ledger.tx_begin_read (); block_count = source_node->ledger.block_count (); std::cout << boost::str (boost::format ("Performing bootstrap emulation, %1% blocks in ledger...") % block_count) << std::endl; for (auto i (source_node->store.account.begin (transaction)), n (source_node->store.account.end ()); i != n; ++i) diff --git a/nano/nano_rpc/entry.cpp b/nano/nano_rpc/entry.cpp index b198d20820..6f1c6080b2 100644 --- a/nano/nano_rpc/entry.cpp +++ b/nano/nano_rpc/entry.cpp @@ -15,10 +15,10 @@ #include #include +#include + namespace { -volatile sig_atomic_t sig_int_or_term = 0; - nano::logger logger{ "rpc_daemon" }; void run (std::filesystem::path const & data_path, std::vector const & config_overrides) @@ -41,7 +41,7 @@ void run (std::filesystem::path const & data_path, std::vector cons error = nano::read_tls_config_toml (data_path, *tls_config, logger); if (error) { - logger.critical (nano::log::type::daemon, "Error reading RPC TLS config: {}", error.get_message ()); + logger.critical (nano::log::type::daemon_rpc, "Error reading RPC TLS config: {}", error.get_message ()); std::exit (1); } else @@ -51,43 +51,43 @@ void run (std::filesystem::path const & data_path, std::vector cons std::shared_ptr io_ctx = std::make_shared (); - nano::signal_manager sigman; + runner = std::make_unique (io_ctx, rpc_config.rpc_process.io_threads); + try { nano::ipc_rpc_processor ipc_rpc_processor (*io_ctx, rpc_config); auto rpc = nano::get_rpc (io_ctx, rpc_config, ipc_rpc_processor); rpc->start (); - debug_assert (!nano::signal_handler_impl); - nano::signal_handler_impl = [io_ctx_w = std::weak_ptr{ io_ctx }] () { - logger.warn (nano::log::type::daemon, "Interrupt signal received, stopping..."); + std::atomic stopped{ false }; - if (auto io_ctx_l = io_ctx_w.lock ()) - { - io_ctx_l->stop (); - } - sig_int_or_term = 1; + auto signal_handler = [&stopped] (int signum) { + logger.warn (nano::log::type::daemon_rpc, "Interrupt signal received ({}), stopping...", nano::to_signal_name (signum)); + stopped = true; + stopped.notify_all (); }; - sigman.register_signal_handler (SIGINT, &nano::signal_handler, true); - sigman.register_signal_handler (SIGTERM, &nano::signal_handler, false); + nano::signal_manager sigman; + sigman.register_signal_handler (SIGINT, signal_handler, true); + sigman.register_signal_handler (SIGTERM, signal_handler, false); - runner = std::make_unique (io_ctx, rpc_config.rpc_process.io_threads); - runner->join (); + // Keep running until stopped flag is set + stopped.wait (false); + + logger.info (nano::log::type::daemon_rpc, "Stopping..."); - if (sig_int_or_term == 1) - { - rpc->stop (); - } + rpc->stop (); + io_ctx->stop (); + runner->join (); } catch (std::runtime_error const & e) { - logger.critical (nano::log::type::daemon, "Error while running RPC: {}", e.what ()); + logger.critical (nano::log::type::daemon_rpc, "Error while running RPC: {}", e.what ()); } } else { - logger.critical (nano::log::type::daemon, "Error deserializing config: {}", error.get_message ()); + logger.critical (nano::log::type::daemon_rpc, "Error deserializing config: {}", error.get_message ()); } logger.info (nano::log::type::daemon_rpc, "Daemon stopped (RPC)"); diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 5a95e0b8d6..6e3d473c1c 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -109,7 +109,7 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr= node.ledger.bootstrap_weight_max_blocks; bool was_active = status.type == nano::election_status_type::active_confirmed_quorum || status.type == nano::election_status_type::active_confirmation_height; @@ -121,7 +121,7 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr const & votes) +void nano::active_transactions::notify_observers (nano::secure::read_transaction const & transaction, nano::election_status const & status, std::vector const & votes) { auto block = status.winner; auto account = block->account (); @@ -140,7 +140,7 @@ void nano::active_transactions::notify_observers (nano::store::read_transaction } } -void nano::active_transactions::activate_successors (nano::store::read_transaction const & transaction, std::shared_ptr const & block) +void nano::active_transactions::activate_successors (nano::secure::read_transaction const & transaction, std::shared_ptr const & block) { node.scheduler.priority.activate (block->account (), transaction); diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 7fded5f623..1fd12ae26f 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -33,7 +33,7 @@ class election; class vote; class stats; } -namespace nano::store +namespace nano::secure { class read_transaction; } @@ -203,8 +203,8 @@ class active_transactions final nano::stat::type completion_type (nano::election const & election) const; // Returns a list of elections sorted by difficulty, mutex must be locked std::vector> list_active_impl (std::size_t) const; - void activate_successors (nano::store::read_transaction const & transaction, std::shared_ptr const & block); - void notify_observers (nano::store::read_transaction const & transaction, nano::election_status const & status, std::vector const & votes); + void activate_successors (nano::secure::read_transaction const & transaction, std::shared_ptr const & block); + void notify_observers (nano::secure::read_transaction const & transaction, nano::election_status const & status, std::vector const & votes); bool trigger_vote_cache (nano::block_hash); private: // Dependencies diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index f459b50697..fe5b7aea1e 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -2,13 +2,14 @@ #include #include #include +#include #include #include #include -nano::backlog_population::backlog_population (const config & config_a, nano::store::component & store_a, nano::stats & stats_a) : +nano::backlog_population::backlog_population (const config & config_a, nano::ledger & ledger, nano::stats & stats_a) : config_m{ config_a }, - store{ store_a }, + ledger{ ledger }, stats{ stats_a } { } @@ -90,11 +91,11 @@ void nano::backlog_population::populate_backlog (nano::unique_lock lock.unlock (); { - auto transaction = store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); auto count = 0u; - auto i = store.account.begin (transaction, next); - auto const end = store.account.end (); + auto i = ledger.store.account.begin (transaction, next); + auto const end = ledger.store.account.end (); for (; i != end && count < chunk_size; ++i, ++count, ++total) { transaction.refresh_if_needed (); @@ -105,7 +106,7 @@ void nano::backlog_population::populate_backlog (nano::unique_lock activate (transaction, account); next = account.number () + 1; } - done = store.account.begin (transaction, next) == end; + done = ledger.store.account.begin (transaction, next) == end; } lock.lock (); @@ -115,18 +116,18 @@ void nano::backlog_population::populate_backlog (nano::unique_lock } } -void nano::backlog_population::activate (store::transaction const & transaction, nano::account const & account) +void nano::backlog_population::activate (secure::transaction const & transaction, nano::account const & account) { debug_assert (!activate_callback.empty ()); - auto const maybe_account_info = store.account.get (transaction, account); + auto const maybe_account_info = ledger.store.account.get (transaction, account); if (!maybe_account_info) { return; } auto const account_info = *maybe_account_info; - auto const maybe_conf_info = store.confirmation_height.get (transaction, account); + auto const maybe_conf_info = ledger.store.confirmation_height.get (transaction, account); auto const conf_info = maybe_conf_info.value_or (nano::confirmation_height_info{}); // If conf info is empty then it means then it means nothing is confirmed yet diff --git a/nano/node/backlog_population.hpp b/nano/node/backlog_population.hpp index 7bc1a6d00e..3ea9d88ec4 100644 --- a/nano/node/backlog_population.hpp +++ b/nano/node/backlog_population.hpp @@ -8,15 +8,15 @@ #include #include -namespace nano::store +namespace nano::secure { -class component; class transaction; } namespace nano { class account_info; class election_scheduler; +class ledger; class stats; class backlog_population final @@ -34,7 +34,7 @@ class backlog_population final unsigned frequency; }; - backlog_population (const config &, store::component &, nano::stats &); + backlog_population (const config &, ledger &, nano::stats &); ~backlog_population (); void start (); @@ -50,11 +50,11 @@ class backlog_population final /** * Callback called for each backlogged account */ - using callback_t = nano::observer_set; + using callback_t = nano::observer_set; callback_t activate_callback; private: // Dependencies - nano::store::component & store; + nano::ledger & ledger; nano::stats & stats; config config_m; @@ -64,7 +64,7 @@ class backlog_population final bool predicate () const; void populate_backlog (nano::unique_lock & lock); - void activate (store::transaction const &, nano::account const &); + void activate (secure::transaction const &, nano::account const &); /** This is a manual trigger, the ongoing backlog population does not use this. * It can be triggered even when backlog population (frontiers confirmation) is disabled. */ diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index bc10d115c8..4899da88cd 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -201,7 +201,7 @@ bool nano::block_processor::add_impl (context ctx, std::shared_ptr & lock processed_batch_t processed; auto scoped_write_guard = node.store.write_queue.wait (nano::store::writer::process_batch); - auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights })); + auto transaction = node.ledger.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); nano::timer timer_l; lock_a.lock (); @@ -355,7 +355,7 @@ auto nano::block_processor::process_batch (nano::unique_lock & lock return processed; } -nano::block_status nano::block_processor::process_one (store::write_transaction const & transaction_a, context const & context, bool const forced_a) +nano::block_status nano::block_processor::process_one (secure::write_transaction const & transaction_a, context const & context, bool const forced_a) { auto block = context.block; auto const hash = block->hash (); @@ -452,7 +452,7 @@ nano::block_status nano::block_processor::process_one (store::write_transaction return result; } -void nano::block_processor::queue_unchecked (store::write_transaction const & transaction_a, nano::hash_or_account const & hash_or_account_a) +void nano::block_processor::queue_unchecked (secure::write_transaction const & transaction_a, nano::hash_or_account const & hash_or_account_a) { node.unchecked.trigger (hash_or_account_a); } diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index 2e01d591ca..7311cf6dfc 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -16,7 +16,7 @@ class block; class node; } -namespace nano::store +namespace nano::secure { class write_transaction; } @@ -116,9 +116,9 @@ class block_processor final private: void run (); // Roll back block in the ledger that conflicts with 'block' - void rollback_competitor (store::write_transaction const &, nano::block const & block); - nano::block_status process_one (store::write_transaction const &, context const &, bool forced = false); - void queue_unchecked (store::write_transaction const &, nano::hash_or_account const &); + void rollback_competitor (secure::write_transaction const &, nano::block const & block); + nano::block_status process_one (secure::write_transaction const &, context const &, bool forced = false); + void queue_unchecked (secure::write_transaction const &, nano::hash_or_account const &); processed_batch_t process_batch (nano::unique_lock &); context next (); bool add_impl (context, std::shared_ptr const & channel = nullptr); diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 65f392b580..53c5ead036 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -364,7 +364,7 @@ void nano::bulk_pull_server::set_current_end () } include_start = false; debug_assert (request != nullptr); - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); if (!node->ledger.block_exists (transaction, request->end)) { node->logger.debug (nano::log::type::bulk_pull_server, "Bulk pull end block doesn't exist: {}, sending everything", request->end.to_string ()); @@ -650,7 +650,7 @@ void nano::bulk_pull_account_server::send_frontier () } if (!invalid_request) { - auto stream_transaction (node->store.tx_begin_read ()); + auto stream_transaction = node->ledger.tx_begin_read (); // Get account balance and frontier block hash auto account_frontier_hash (node->ledger.latest (stream_transaction, request->account)); @@ -753,7 +753,7 @@ std::pair, std::unique_ptrstore.tx_begin_read (); + auto tx = node->ledger.tx_begin_read (); auto & ledger = node->ledger; auto stream = ledger.receivable_upper_bound (tx, current_key.account, current_key.hash); diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 4646cbaa68..247d003d62 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -125,7 +125,7 @@ void nano::bootstrap_attempt_lazy::lazy_pull_flush (nano::unique_lockstore.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); while (!lazy_pulls.empty () && count < max_pulls) { auto pull_start (lazy_pulls.front ()); @@ -165,7 +165,7 @@ bool nano::bootstrap_attempt_lazy::lazy_finished () } bool result (true); uint64_t read_count (0); - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); for (auto it (lazy_keys.begin ()), end (lazy_keys.end ()); it != end && !stopped;) { if (node->ledger.block_or_pruned_exists (transaction, *it)) @@ -333,7 +333,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptr block_l (std::static_pointer_cast (block_a)); if (block_l != nullptr) { - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); nano::uint128_t balance (block_l->hashables.balance.number ()); auto const & link (block_l->hashables.link); // If link is not epoch link or 0. And if block from link is unknown @@ -418,7 +418,7 @@ void nano::bootstrap_attempt_lazy::lazy_backlog_cleanup () return; } uint64_t read_count (0); - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); for (auto it (lazy_state_backlog.begin ()), end (lazy_state_backlog.end ()); it != end && !stopped;) { if (node->ledger.block_or_pruned_exists (transaction, it->first)) diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index 3128b9ad20..d43cd04210 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -148,7 +148,7 @@ void nano::bootstrap_server::respond (nano::asc_pull_ack & response, std::shared void nano::bootstrap_server::process_batch (std::deque & batch) { - auto transaction = store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); for (auto & [request, channel] : batch) { @@ -166,12 +166,12 @@ void nano::bootstrap_server::process_batch (std::deque & batch) } } -nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & transaction, const nano::asc_pull_req & message) +nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & transaction, nano::asc_pull_req const & message) { return std::visit ([this, &transaction, &message] (auto && request) { return process (transaction, message.id, request); }, message.payload); } -nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction &, nano::asc_pull_req::id_t id, const nano::empty_payload & request) +nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const &, nano::asc_pull_req::id_t id, nano::empty_payload const & request) { // Empty payload should never be possible, but return empty response anyway debug_assert (false, "missing payload"); @@ -185,7 +185,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction &, * Blocks request */ -nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & transaction, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request) +nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & transaction, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request) { const std::size_t count = std::min (static_cast (request.count), max_blocks); @@ -215,7 +215,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & t return prepare_empty_blocks_response (id); } -nano::asc_pull_ack nano::bootstrap_server::prepare_response (store::transaction const & transaction, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count) +nano::asc_pull_ack nano::bootstrap_server::prepare_response (secure::transaction const & transaction, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count) { debug_assert (count <= max_blocks); // Should be filtered out earlier @@ -247,7 +247,7 @@ nano::asc_pull_ack nano::bootstrap_server::prepare_empty_blocks_response (nano:: return response; } -std::vector> nano::bootstrap_server::prepare_blocks (store::transaction const & transaction, nano::block_hash start_block, std::size_t count) const +std::vector> nano::bootstrap_server::prepare_blocks (secure::transaction const & transaction, nano::block_hash start_block, std::size_t count) const { debug_assert (count <= max_blocks); // Should be filtered out earlier @@ -270,7 +270,7 @@ std::vector> nano::bootstrap_server::prepare_blocks * Account info request */ -nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & transaction, nano::asc_pull_req::id_t id, const nano::asc_pull_req::account_info_payload & request) +nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & transaction, nano::asc_pull_req::id_t id, nano::asc_pull_req::account_info_payload const & request) { nano::asc_pull_ack response{ network_constants }; response.id = id; @@ -320,7 +320,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & t * Frontiers request */ -nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & transaction, nano::asc_pull_req::id_t id, const nano::asc_pull_req::frontiers_payload & request) +nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & transaction, nano::asc_pull_req::id_t id, nano::asc_pull_req::frontiers_payload const & request) { debug_assert (request.count <= max_frontiers); // Should be filtered out earlier diff --git a/nano/node/bootstrap/bootstrap_server.hpp b/nano/node/bootstrap/bootstrap_server.hpp index e1358b4c3c..e8217eadfc 100644 --- a/nano/node/bootstrap/bootstrap_server.hpp +++ b/nano/node/bootstrap/bootstrap_server.hpp @@ -7,7 +7,7 @@ #include #include -namespace nano::store +namespace nano::secure { class transaction; } @@ -51,28 +51,28 @@ class bootstrap_server final private: void process_batch (std::deque & batch); - nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req const & message); + nano::asc_pull_ack process (secure::transaction const &, nano::asc_pull_req const & message); void respond (nano::asc_pull_ack &, std::shared_ptr &); - nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::empty_payload const & request); + nano::asc_pull_ack process (secure::transaction const &, nano::asc_pull_req::id_t id, nano::empty_payload const & request); /* * Blocks request */ - nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request); - nano::asc_pull_ack prepare_response (store::transaction const &, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count); + nano::asc_pull_ack process (secure::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::blocks_payload const & request); + nano::asc_pull_ack prepare_response (secure::transaction const &, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count); nano::asc_pull_ack prepare_empty_blocks_response (nano::asc_pull_req::id_t id); - std::vector> prepare_blocks (store::transaction const &, nano::block_hash start_block, std::size_t count) const; + std::vector> prepare_blocks (secure::transaction const &, nano::block_hash start_block, std::size_t count) const; /* * Account info request */ - nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::account_info_payload const & request); + nano::asc_pull_ack process (secure::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::account_info_payload const & request); /* * Frontiers request */ - nano::asc_pull_ack process (store::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::frontiers_payload const & request); + nano::asc_pull_ack process (secure::transaction const &, nano::asc_pull_req::id_t id, nano::asc_pull_req::frontiers_payload const & request); /* * Checks if the request should be dropped early on diff --git a/nano/node/bootstrap_ascending/iterators.cpp b/nano/node/bootstrap_ascending/iterators.cpp index c940218a36..708906b84e 100644 --- a/nano/node/bootstrap_ascending/iterators.cpp +++ b/nano/node/bootstrap_ascending/iterators.cpp @@ -21,7 +21,7 @@ nano::account nano::bootstrap_ascending::database_iterator::operator* () const return current; } -void nano::bootstrap_ascending::database_iterator::next (store::transaction & tx) +void nano::bootstrap_ascending::database_iterator::next (secure::transaction & tx) { switch (table) { @@ -95,7 +95,7 @@ void nano::bootstrap_ascending::buffered_iterator::fill () debug_assert (buffer.empty ()); // Fill half from accounts table and half from pending table - auto transaction = ledger.store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); for (int n = 0; n < size / 2; ++n) { diff --git a/nano/node/bootstrap_ascending/iterators.hpp b/nano/node/bootstrap_ascending/iterators.hpp index e963164de5..09b0c1c730 100644 --- a/nano/node/bootstrap_ascending/iterators.hpp +++ b/nano/node/bootstrap_ascending/iterators.hpp @@ -9,9 +9,8 @@ namespace nano class ledger; } -namespace nano::store +namespace nano::secure { -class component; class transaction; } @@ -28,7 +27,7 @@ class database_iterator explicit database_iterator (nano::ledger & ledger, table_type); nano::account operator* () const; - void next (nano::store::transaction & tx); + void next (secure::transaction & tx); private: nano::ledger & ledger; diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 66510ba272..4fe38aed3c 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -34,7 +34,7 @@ nano::bootstrap_ascending::service::service (nano::node_config & config_a, nano: { nano::lock_guard lock{ mutex }; - auto transaction = ledger.store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); for (auto const & [result, context] : batch) { debug_assert (context.block != nullptr); @@ -125,7 +125,7 @@ std::size_t nano::bootstrap_ascending::service::score_size () const - Marks an account as blocked if the result code is gap source as there is no reason request additional blocks for this account until the dependency is resolved - Marks an account as forwarded if it has been recently referenced by a block that has been inserted. */ -void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, nano::block_status const & result, nano::block const & block) +void nano::bootstrap_ascending::service::inspect (secure::transaction const & tx, nano::block_status const & result, nano::block const & block) { auto const hash = block.hash (); diff --git a/nano/node/bootstrap_ascending/service.hpp b/nano/node/bootstrap_ascending/service.hpp index 4b7ed0e1ed..ccb2ea66cd 100644 --- a/nano/node/bootstrap_ascending/service.hpp +++ b/nano/node/bootstrap_ascending/service.hpp @@ -21,6 +21,11 @@ namespace mi = boost::multi_index; +namespace nano::secure +{ +class transaction; +} + namespace nano { class block_processor; @@ -88,7 +93,7 @@ namespace bootstrap_ascending private: /* Inspects a block that has been processed by the block processor */ - void inspect (store::transaction const &, nano::block_status const & result, nano::block const & block); + void inspect (secure::transaction const &, nano::block_status const & result, nano::block const & block); void throttle_if_needed (nano::unique_lock & lock); void run (); diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index df480e560b..f58722cfc2 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -703,11 +703,11 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map if (vm.count ("use_defaults")) { - std::cout << toml.to_string () << std::endl; + std::cout << toml.to_string (false) << std::endl; } else { - std::cout << toml.to_string_commented_entries () << std::endl; + std::cout << toml.to_string (true) << std::endl; } } } diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index f9c9101e57..7ca417439c 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -72,7 +72,7 @@ void nano::confirming_set::run () { lock.unlock (); // Waiting for db write is potentially slow auto guard = ledger.store.write_queue.wait (nano::store::writer::confirmation_height); - auto tx = ledger.store.tx_begin_write ({ nano::tables::confirmation_height }); + auto tx = ledger.tx_begin_write ({ nano::tables::confirmation_height }); lock.lock (); // Process items in the back buffer within a single transaction for a limited amount of time for (auto timeout = std::chrono::steady_clock::now () + batch_time; !stopped && std::chrono::steady_clock::now () < timeout && i != n; ++i) diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 6f8b61ca6f..834af89e07 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -118,6 +118,10 @@ class election final : public std::enable_shared_from_this nano::vote_info get_last_vote (nano::account const & account); void set_last_vote (nano::account const & account, nano::vote_info vote_info); nano::election_status get_status () const; + std::chrono::steady_clock::time_point get_election_start () const + { + return election_start; + } private: // Dependencies nano::node & node; diff --git a/nano/node/epoch_upgrader.cpp b/nano/node/epoch_upgrader.cpp index c4f683d498..d5a23cad4e 100644 --- a/nano/node/epoch_upgrader.cpp +++ b/nano/node/epoch_upgrader.cpp @@ -134,9 +134,8 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc uint64_t attempts (0); for (auto i (accounts_list.get ().begin ()), n (accounts_list.get ().end ()); i != n && attempts < upgrade_batch_size && attempts < count_limit && !stopped; ++i) { - auto transaction (store.tx_begin_read ()); nano::account const & account (i->account); - auto info = ledger.account_info (transaction, account); + auto info = ledger.account_info (ledger.tx_begin_read (), account); if (info && info->epoch () < epoch_a) { ++attempts; @@ -210,11 +209,10 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc std::atomic upgraded_pending (0); uint64_t workers (0); uint64_t attempts (0); - auto transaction = store.tx_begin_read (); - for (auto current = ledger.receivable_upper_bound (transaction, 0), end = ledger.receivable_end (); current != end && attempts < upgrade_batch_size && attempts < count_limit && !stopped;) + for (auto current = ledger.receivable_upper_bound (ledger.tx_begin_read (), 0), end = ledger.receivable_end (); current != end && attempts < upgrade_batch_size && attempts < count_limit && !stopped;) { auto const & [key, info] = *current; - if (!store.account.exists (transaction, key.account)) + if (!store.account.exists (ledger.tx_begin_read (), key.account)) { if (info.epoch < epoch_a) { @@ -257,7 +255,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc } } // Move to next pending item - current = ledger.receivable_upper_bound (transaction, key.account, key.hash); + current = ledger.receivable_upper_bound (ledger.tx_begin_read (), key.account, key.hash); } else { @@ -268,7 +266,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc } else { - current = ledger.receivable_upper_bound (transaction, key.account); + current = ledger.receivable_upper_bound (ledger.tx_begin_read (), key.account); } } } diff --git a/nano/node/fair_queue.hpp b/nano/node/fair_queue.hpp index e13ed847c0..bf7e7f4b4f 100644 --- a/nano/node/fair_queue.hpp +++ b/nano/node/fair_queue.hpp @@ -340,7 +340,7 @@ class fair_queue final private: std::map queues; - std::map::iterator iterator{ queues.end () }; + typename std::map::iterator iterator{ queues.end () }; size_t counter{ 0 }; std::chrono::steady_clock::time_point last_update{}; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 7d226c4656..66bdaa6c55 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -27,7 +28,7 @@ void construct_json (nano::container_info_component * component, boost::property using ipc_json_handler_no_arg_func_map = std::unordered_map>; ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map (); auto ipc_json_handler_no_arg_funcs = create_ipc_json_handler_no_arg_func_map (); -bool block_confirmed (nano::node & node, nano::store::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed); +bool block_confirmed (nano::node & node, nano::secure::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed); char const * epoch_as_string (nano::epoch); } @@ -261,7 +262,7 @@ nano::account nano::json_handler::account_impl (std::string account_text, std::e return result; } -nano::account_info nano::json_handler::account_info_impl (store::transaction const & transaction_a, nano::account const & account_a) +nano::account_info nano::json_handler::account_info_impl (secure::transaction const & transaction_a, nano::account const & account_a) { nano::account_info result; if (!ec) @@ -395,7 +396,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) { nano::block_details details (nano::epoch::epoch_0, false, false, false); bool details_found (false); - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); // Previous block find std::shared_ptr block_previous (nullptr); auto previous (block_a.previous ()); @@ -549,7 +550,7 @@ void nano::json_handler::account_block_count () auto account (account_impl ()); if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto info (account_info_impl (transaction, account)); if (!ec) { @@ -626,7 +627,7 @@ void nano::json_handler::account_info () bool const pending = request.get ("pending", false); bool const receivable = request.get ("receivable", pending); bool const include_confirmed = request.get ("include_confirmed", false); - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto info (account_info_impl (transaction, account)); nano::confirmation_height_info confirmation_height_info; node.store.confirmation_height.get (transaction, account, confirmation_height_info); @@ -795,7 +796,7 @@ void nano::json_handler::account_remove () auto account (rpc_l->account_impl ()); if (!rpc_l->ec) { - auto transaction (rpc_l->node.wallets.tx_begin_write ()); + auto transaction = rpc_l->node.wallets.tx_begin_write (); rpc_l->wallet_locked_impl (transaction, wallet); rpc_l->wallet_account_impl (transaction, wallet, account); if (!rpc_l->ec) @@ -813,7 +814,7 @@ void nano::json_handler::account_representative () auto account (account_impl ()); if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto info (account_info_impl (transaction, account)); if (!ec) { @@ -835,12 +836,12 @@ void nano::json_handler::account_representative_set () auto work (rpc_l->work_optional_impl ()); if (!rpc_l->ec && work) { - auto transaction (rpc_l->node.wallets.tx_begin_write ()); + auto transaction = rpc_l->node.wallets.tx_begin_write (); rpc_l->wallet_locked_impl (transaction, wallet); rpc_l->wallet_account_impl (transaction, wallet, account); if (!rpc_l->ec) { - auto block_transaction (rpc_l->node.store.tx_begin_read ()); + auto block_transaction = rpc_l->node.ledger.tx_begin_read (); auto info (rpc_l->account_info_impl (block_transaction, account)); if (!rpc_l->ec) { @@ -938,7 +939,7 @@ void nano::json_handler::accounts_representatives () { boost::property_tree::ptree representatives; boost::property_tree::ptree errors; - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); for (auto & account_from_request : request.get_child ("accounts")) { auto account = account_impl (account_from_request.second.data ()); @@ -995,7 +996,7 @@ void nano::json_handler::accounts_frontiers () { boost::property_tree::ptree frontiers; boost::property_tree::ptree errors; - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); for (auto & account_from_request : request.get_child ("accounts")) { auto account = account_impl (account_from_request.second.data ()); @@ -1043,7 +1044,7 @@ void nano::json_handler::accounts_receivable () bool const sorting = request.get ("sorting", false); auto simple (threshold.is_zero () && !source && !sorting); // if simple, response is a list of hashes for each account boost::property_tree::ptree pending; - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); for (auto & accounts : request.get_child ("accounts")) { auto account (account_impl (accounts.second.data ())); @@ -1148,7 +1149,7 @@ void nano::json_handler::block_info () auto hash (hash_impl ()); if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto block = node.ledger.block (transaction, hash); if (block != nullptr) { @@ -1199,7 +1200,7 @@ void nano::json_handler::block_confirm () auto hash (hash_impl ()); if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto block_l = node.ledger.block (transaction, hash); if (block_l != nullptr) { @@ -1245,7 +1246,7 @@ void nano::json_handler::blocks () { bool const json_block_l = request.get ("json_block", false); boost::property_tree::ptree blocks; - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); for (boost::property_tree::ptree::value_type & hashes : request.get_child ("hashes")) { if (!ec) @@ -1296,7 +1297,7 @@ void nano::json_handler::blocks_info () boost::property_tree::ptree blocks; boost::property_tree::ptree blocks_not_found; - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); for (boost::property_tree::ptree::value_type & hashes : request.get_child ("hashes")) { if (!ec) @@ -1430,7 +1431,7 @@ void nano::json_handler::block_account () auto hash (hash_impl ()); if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto block = node.ledger.block (transaction, hash); if (block) { @@ -1522,8 +1523,8 @@ void nano::json_handler::block_create () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto transaction = node.wallets.tx_begin_read (); + auto block_transaction = node.ledger.tx_begin_read (); wallet_locked_impl (transaction, existing->second); wallet_account_impl (transaction, existing->second, account); if (!ec) @@ -1643,14 +1644,14 @@ void nano::json_handler::block_create () // Fetching account balance & previous for send blocks (if aren't given directly) if (!previous_text.is_initialized () && !balance_text.is_initialized ()) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); previous = node.ledger.latest (transaction, pub); balance = node.ledger.account_balance (transaction, pub); } // Double check current balance if previous block is specified else if (previous_text.is_initialized () && balance_text.is_initialized () && type == "send") { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); if (node.ledger.block_exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ()) { ec = nano::error_rpc::block_create_balance_mismatch; @@ -1941,7 +1942,7 @@ void nano::json_handler::chain (bool successors) if (!ec) { boost::property_tree::ptree blocks; - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); while (!hash.is_zero () && blocks.size () < count) { auto block_l = node.ledger.block (transaction, hash); @@ -2009,10 +2010,18 @@ void nano::json_handler::election_statistics () unsigned hinted_count = 0; unsigned optimistic_count = 0; unsigned total_count = 0; + std::chrono::steady_clock::duration total_age{}; + auto now = std::chrono::steady_clock::now (); + std::chrono::steady_clock::time_point oldest_election_start = now; for (auto const & election : active_elections) { total_count++; + auto election_start = election->get_election_start (); + auto age = now - election_start; + total_age += age; + oldest_election_start = std::min (oldest_election_start, election->get_election_start ()); + switch (election->behavior ()) { case election_behavior::normal: @@ -2028,14 +2037,19 @@ void nano::json_handler::election_statistics () } auto utilization_percentage = (static_cast (total_count * 100) / node.config.active_elections_size); - std::stringstream stream; - stream << std::fixed << std::setprecision (2) << utilization_percentage; + auto max_election_age = std::chrono::duration_cast (now - oldest_election_start).count (); + auto average_election_age = total_count ? std::chrono::duration_cast (total_age).count () / total_count : 0; + + std::stringstream stream_utilization; + stream_utilization << std::fixed << std::setprecision (2) << utilization_percentage; response_l.put ("normal", normal_count); response_l.put ("hinted", hinted_count); response_l.put ("optimistic", optimistic_count); response_l.put ("total", total_count); - response_l.put ("aec_utilization_percentage", stream.str ()); + response_l.put ("aec_utilization_percentage", stream_utilization.str ()); + response_l.put ("max_election_age", max_election_age); + response_l.put ("average_election_age", average_election_age); response_errors (); } @@ -2399,7 +2413,7 @@ namespace class history_visitor : public nano::block_visitor { public: - history_visitor (nano::json_handler & handler_a, bool raw_a, nano::store::transaction & transaction_a, boost::property_tree::ptree & tree_a, nano::block_hash const & hash_a, std::vector const & accounts_filter_a) : + history_visitor (nano::json_handler & handler_a, bool raw_a, nano::secure::transaction & transaction_a, boost::property_tree::ptree & tree_a, nano::block_hash const & hash_a, std::vector const & accounts_filter_a) : handler (handler_a), raw (raw_a), transaction (transaction_a), @@ -2588,7 +2602,7 @@ class history_visitor : public nano::block_visitor } nano::json_handler & handler; bool raw; - nano::store::transaction & transaction; + nano::secure::transaction & transaction; boost::property_tree::ptree & tree; nano::block_hash const & hash; std::vector const & accounts_filter; @@ -2618,7 +2632,7 @@ void nano::json_handler::account_history () nano::block_hash hash; bool reverse (request.get_optional ("reverse") == true); auto head_str (request.get_optional ("head")); - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto count (count_impl ()); auto offset (offset_optional_impl (0)); if (head_str) @@ -2776,7 +2790,7 @@ void nano::json_handler::ledger () bool const pending = request.get ("pending", false); bool const receivable = request.get ("receivable", pending); boost::property_tree::ptree accounts; - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); if (!ec && !sorting) // Simple { for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n && accounts.size () < count; ++i) @@ -3077,7 +3091,7 @@ void nano::json_handler::receivable () { auto offset_counter = offset; boost::property_tree::ptree peers_l; - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); // The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used. std::vector> hash_ptree_pairs; std::vector> hash_amount_pairs; @@ -3181,7 +3195,7 @@ void nano::json_handler::receivable_exists () bool const include_only_confirmed = request.get ("include_only_confirmed", true); if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto block = node.ledger.block (transaction, hash); if (block != nullptr) { @@ -3214,7 +3228,7 @@ void nano::json_handler::process () if (!subtype_text.empty ()) { std::shared_ptr block_state (std::static_pointer_cast (block)); - auto transaction (rpc_l->node.store.tx_begin_read ()); + auto transaction = rpc_l->node.ledger.tx_begin_read (); if (!block_state->hashables.previous.is_zero () && !rpc_l->node.ledger.block_exists (transaction, block_state->hashables.previous)) { rpc_l->ec = nano::error_process::gap_previous; @@ -3425,7 +3439,7 @@ void nano::json_handler::receive () wallet_account_impl (wallet_transaction, wallet, account); if (!ec) { - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); if (node.ledger.block_or_pruned_exists (block_transaction, hash)) { auto pending_info = node.ledger.pending_info (block_transaction, nano::pending_key (account, hash)); @@ -3654,7 +3668,7 @@ void nano::json_handler::republish () if (!ec) { boost::property_tree::ptree blocks; - auto transaction (node.store.tx_begin_read ()); + auto transaction = node.ledger.tx_begin_read (); auto block = node.ledger.block (transaction, hash); if (block != nullptr) { @@ -3793,7 +3807,7 @@ void nano::json_handler::send () if (!ec) { auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); wallet_locked_impl (transaction, wallet); wallet_account_impl (transaction, wallet, source); auto info (account_info_impl (block_transaction, source)); @@ -4272,7 +4286,7 @@ void nano::json_handler::unopened () } if (!ec) { - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); auto & ledger = node.ledger; boost::property_tree::ptree accounts; for (auto iterator = ledger.receivable_upper_bound (transaction, start, 0), end = ledger.receivable_end (); iterator != end && accounts.size () < count;) @@ -4405,7 +4419,7 @@ void nano::json_handler::wallet_info () uint64_t deterministic_count (0); uint64_t adhoc_count (0); auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { @@ -4462,7 +4476,7 @@ void nano::json_handler::wallet_balances () { boost::property_tree::ptree balances; auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -4613,7 +4627,7 @@ void nano::json_handler::wallet_frontiers () { boost::property_tree::ptree frontiers; auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -4644,7 +4658,7 @@ void nano::json_handler::wallet_history () { std::multimap> entries; auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -4718,7 +4732,7 @@ void nano::json_handler::wallet_ledger () { boost::property_tree::ptree accounts; auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -4794,7 +4808,7 @@ void nano::json_handler::wallet_receivable () { boost::property_tree::ptree pending; auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction = node.store.tx_begin_read (); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -4884,7 +4898,7 @@ void nano::json_handler::wallet_representative_set () std::vector accounts; { auto transaction (rpc_l->node.wallets.tx_begin_read ()); - auto block_transaction (rpc_l->node.store.tx_begin_read ()); + auto block_transaction = rpc_l->node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -4918,7 +4932,7 @@ void nano::json_handler::wallet_republish () boost::property_tree::ptree blocks; std::deque> republish_bundle; auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_read ()); + auto block_transaction = node.ledger.tx_begin_read (); for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); @@ -5088,7 +5102,7 @@ void nano::json_handler::work_generate () if (!account_opt.is_initialized ()) { // Fetch account from block if not given - auto transaction_l (node.store.tx_begin_read ()); + auto transaction_l = node.ledger.tx_begin_read (); if (node.ledger.block_exists (transaction_l, hash)) { account = node.ledger.account (transaction_l, hash).value (); @@ -5444,7 +5458,7 @@ ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map () } /** Due to the asynchronous nature of updating confirmation heights, it can also be necessary to check active roots */ -bool block_confirmed (nano::node & node, nano::store::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed) +bool block_confirmed (nano::node & node, nano::secure::transaction & transaction, nano::block_hash const & hash, bool include_active, bool include_only_confirmed) { bool is_confirmed = false; if (include_active && !include_only_confirmed) diff --git a/nano/node/json_handler.hpp b/nano/node/json_handler.hpp index 33eca6c6c1..6e96a5bc3f 100644 --- a/nano/node/json_handler.hpp +++ b/nano/node/json_handler.hpp @@ -10,6 +10,11 @@ #include #include +namespace nano::secure +{ +class transaction; +} + namespace nano { namespace ipc @@ -158,7 +163,7 @@ class json_handler : public std::enable_shared_from_this bool wallet_locked_impl (store::transaction const &, std::shared_ptr const &); bool wallet_account_impl (store::transaction const &, std::shared_ptr const &, nano::account const &); nano::account account_impl (std::string = "", std::error_code = nano::error_common::bad_account_number); - nano::account_info account_info_impl (store::transaction const &, nano::account const &); + nano::account_info account_info_impl (secure::transaction const &, nano::account const &); nano::amount amount_impl (); std::shared_ptr block_impl (bool = true); nano::block_hash hash_impl (std::string = "hash"); diff --git a/nano/node/local_block_broadcaster.cpp b/nano/node/local_block_broadcaster.cpp index 59c0e4dffd..4e97d1eb50 100644 --- a/nano/node/local_block_broadcaster.cpp +++ b/nano/node/local_block_broadcaster.cpp @@ -5,6 +5,7 @@ #include #include #include +#include nano::local_block_broadcaster::local_block_broadcaster (nano::node & node_a, nano::block_processor & block_processor_a, nano::network & network_a, nano::stats & stats_a, bool enabled_a) : node{ node_a }, @@ -143,7 +144,7 @@ void nano::local_block_broadcaster::cleanup () } // TODO: Mutex is held during IO, but it should be fine since it's not performance critical - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); erase_if (local_blocks, [this, &transaction] (auto const & entry) { transaction.refresh_if_needed (); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3744f9dcba..31bbb2f89e 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -193,7 +193,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy scheduler{ *scheduler_impl }, aggregator (config, stats, generator, final_generator, history, ledger, wallets, active), wallets (wallets_store.init_error (), *this), - backlog{ nano::backlog_population_config (config), store, stats }, + backlog{ nano::backlog_population_config (config), ledger, stats }, ascendboot{ config, block_processor, ledger, network, stats }, websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger }, epoch_upgrader{ *this, ledger, store, network_params, logger }, @@ -214,7 +214,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy return ledger.weight (rep); }; - backlog.activate_callback.add ([this] (store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + backlog.activate_callback.add ([this] (secure::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { scheduler.priority.activate (account, transaction); scheduler.optimistic.activate (account, account_info, conf_info); }); @@ -469,8 +469,9 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy confirming_set.cemented_observers.add ([this] (auto const & block) { if (block->is_send ()) { - auto transaction = store.tx_begin_read (); - receive_confirmed (transaction, block->hash (), block->destination ()); + workers.push_task ([this, hash = block->hash (), destination = block->destination ()] () { + wallets.receive_confirmed (hash, destination); + }); } }); } @@ -589,7 +590,7 @@ void nano::node::process_active (std::shared_ptr const & incoming) block_processor.add (incoming); } -[[nodiscard]] nano::block_status nano::node::process (store::write_transaction const & transaction, std::shared_ptr block) +[[nodiscard]] nano::block_status nano::node::process (secure::write_transaction const & transaction, std::shared_ptr block) { auto status = ledger.process (transaction, block); logger.debug (nano::log::type::node, "Directly processed block: {} (status: {})", block->hash ().to_string (), to_string (status)); @@ -598,7 +599,7 @@ void nano::node::process_active (std::shared_ptr const & incoming) nano::block_status nano::node::process (std::shared_ptr block) { - auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); + auto const transaction = ledger.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); return process (transaction, block); } @@ -752,25 +753,23 @@ void nano::node::keepalive_preconfigured () nano::block_hash nano::node::latest (nano::account const & account_a) { - auto const transaction (store.tx_begin_read ()); - return ledger.latest (transaction, account_a); + return ledger.latest (ledger.tx_begin_read (), account_a); } nano::uint128_t nano::node::balance (nano::account const & account_a) { - auto const transaction (store.tx_begin_read ()); - return ledger.account_balance (transaction, account_a); + return ledger.account_balance (ledger.tx_begin_read (), account_a); } std::shared_ptr nano::node::block (nano::block_hash const & hash_a) { - return ledger.block (store.tx_begin_read (), hash_a); + return ledger.block (ledger.tx_begin_read (), hash_a); } std::pair nano::node::balance_pending (nano::account const & account_a, bool only_confirmed_a) { std::pair result; - auto const transaction (store.tx_begin_read ()); + auto const transaction = ledger.tx_begin_read (); result.first = ledger.account_balance (transaction, account_a, only_confirmed_a); result.second = ledger.account_receivable (transaction, account_a, only_confirmed_a); return result; @@ -778,7 +777,7 @@ std::pair nano::node::balance_pending (nano::a nano::uint128_t nano::node::weight (nano::account const & account_a) { - auto txn{ ledger.store.tx_begin_read () }; + auto txn = ledger.tx_begin_read (); return ledger.weight_exact (txn, account_a); } @@ -936,7 +935,7 @@ bool nano::node::collect_ledger_pruning_targets (std::deque & { uint64_t read_operations (0); bool finish_transaction (false); - auto const transaction (store.tx_begin_read ()); + auto const transaction = ledger.tx_begin_read (); for (auto i (store.confirmation_height.begin (transaction, last_account_a)), n (store.confirmation_height.end ()); i != n && !finish_transaction;) { ++read_operations; @@ -1006,7 +1005,7 @@ void nano::node::ledger_pruning (uint64_t const batch_size_a, bool bootstrap_wei if (!pruning_targets.empty () && !stopped) { auto scoped_write_guard = store.write_queue.wait (nano::store::writer::pruning); - auto write_transaction (store.tx_begin_write ({ tables::blocks, tables::pruned })); + auto write_transaction = ledger.tx_begin_write ({ tables::blocks, tables::pruned }); while (!pruning_targets.empty () && transaction_write_count < batch_size_a && !stopped) { auto const & pruning_hash (pruning_targets.front ()); @@ -1182,18 +1181,17 @@ void nano::node::start_election (std::shared_ptr const & block) bool nano::node::block_confirmed (nano::block_hash const & hash_a) { - auto transaction (store.tx_begin_read ()); - return ledger.block_confirmed (transaction, hash_a); + return ledger.block_confirmed (ledger.tx_begin_read (), hash_a); } -bool nano::node::block_confirmed_or_being_confirmed (nano::store::transaction const & transaction, nano::block_hash const & hash_a) +bool nano::node::block_confirmed_or_being_confirmed (nano::secure::transaction const & transaction, nano::block_hash const & hash_a) { return confirming_set.exists (hash_a) || ledger.block_confirmed (transaction, hash_a); } bool nano::node::block_confirmed_or_being_confirmed (nano::block_hash const & hash_a) { - return block_confirmed_or_being_confirmed (store.tx_begin_read (), hash_a); + return block_confirmed_or_being_confirmed (ledger.tx_begin_read (), hash_a); } void nano::node::ongoing_online_weight_calculation_queue () @@ -1218,45 +1216,11 @@ void nano::node::ongoing_online_weight_calculation () ongoing_online_weight_calculation_queue (); } -void nano::node::receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a) -{ - nano::unique_lock lk{ wallets.mutex }; - auto wallets_l = wallets.get_wallets (); - auto wallet_transaction = wallets.tx_begin_read (); - lk.unlock (); - for ([[maybe_unused]] auto const & [id, wallet] : wallets_l) - { - if (wallet->store.exists (wallet_transaction, destination_a)) - { - nano::account representative; - representative = wallet->store.representative (wallet_transaction); - auto pending = ledger.pending_info (block_transaction_a, nano::pending_key (destination_a, hash_a)); - if (pending) - { - auto amount (pending->amount.number ()); - wallet->receive_async (hash_a, representative, amount, destination_a, [] (std::shared_ptr const &) {}); - } - else - { - if (!ledger.block_or_pruned_exists (block_transaction_a, hash_a)) - { - logger.warn (nano::log::type::node, "Confirmed block is missing: {}", hash_a.to_string ()); - debug_assert (false, "Confirmed block is missing"); - } - else - { - logger.warn (nano::log::type::node, "Block has already been received: {}", hash_a.to_string ()); - } - } - } - } -} - void nano::node::process_confirmed (nano::election_status const & status_a, uint64_t iteration_a) { auto hash (status_a.winner->hash ()); decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; - if (auto block_l = ledger.block (ledger.store.tx_begin_read (), hash)) + if (auto block_l = ledger.block (ledger.tx_begin_read (), hash)) { logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block_l }); @@ -1377,4 +1341,4 @@ std::string nano::node::make_logger_identifier (const nano::keypair & node_id) { // Node identifier consists of first 10 characters of node id return node_id.pub.to_node_id ().substr (0, 10); -} \ No newline at end of file +} diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 5eeb08c1c5..c90f2ef338 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -87,7 +87,6 @@ class node final : public std::enable_shared_from_this void stop (); std::shared_ptr shared (); int store_version (); - void receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a); void process_confirmed (nano::election_status const &, uint64_t = 0); void process_active (std::shared_ptr const &); std::optional process_local (std::shared_ptr const &); @@ -119,7 +118,7 @@ class node final : public std::enable_shared_from_this void add_initial_peers (); void start_election (std::shared_ptr const & block); bool block_confirmed (nano::block_hash const &); - bool block_confirmed_or_being_confirmed (nano::store::transaction const &, nano::block_hash const &); + bool block_confirmed_or_being_confirmed (nano::secure::transaction const &, nano::block_hash const &); bool block_confirmed_or_being_confirmed (nano::block_hash const &); void do_rpc_callback (boost::asio::ip::tcp::resolver::iterator i_a, std::string const &, uint16_t, std::shared_ptr const &, std::shared_ptr const &, std::shared_ptr const &); void ongoing_online_weight_calculation (); @@ -221,7 +220,7 @@ class node final : public std::enable_shared_from_this Transaction is comitted before function return */ [[nodiscard]] nano::block_status process (std::shared_ptr block); - [[nodiscard]] nano::block_status process (store::write_transaction const &, std::shared_ptr block); + [[nodiscard]] nano::block_status process (secure::write_transaction const &, std::shared_ptr block); nano::block_hash latest (nano::account const &); nano::uint128_t balance (nano::account const &); @@ -237,4 +236,4 @@ std::unique_ptr collect_container_info (node & node, s nano::node_flags const & inactive_node_flag_defaults (); -} \ No newline at end of file +} diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index f0d457dbef..6d1d66ec77 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include nano::process_live_dispatcher::process_live_dispatcher (nano::ledger & ledger, nano::scheduler::priority & scheduler, nano::vote_cache & vote_cache, nano::websocket_server & websocket) : @@ -19,7 +20,7 @@ nano::process_live_dispatcher::process_live_dispatcher (nano::ledger & ledger, n void nano::process_live_dispatcher::connect (nano::block_processor & block_processor) { block_processor.batch_processed.add ([this] (auto const & batch) { - auto const transaction = ledger.store.tx_begin_read (); + auto const transaction = ledger.tx_begin_read (); for (auto const & [result, context] : batch) { debug_assert (context.block != nullptr); @@ -28,7 +29,7 @@ void nano::process_live_dispatcher::connect (nano::block_processor & block_proce }); } -void nano::process_live_dispatcher::inspect (nano::block_status const & result, nano::block const & block, store::transaction const & transaction) +void nano::process_live_dispatcher::inspect (nano::block_status const & result, nano::block const & block, secure::transaction const & transaction) { switch (result) { @@ -40,7 +41,7 @@ void nano::process_live_dispatcher::inspect (nano::block_status const & result, } } -void nano::process_live_dispatcher::process_live (nano::block const & block, store::transaction const & transaction) +void nano::process_live_dispatcher::process_live (nano::block const & block, secure::transaction const & transaction) { // Start collecting quorum on block if (ledger.dependents_confirmed (transaction, block)) diff --git a/nano/node/process_live_dispatcher.hpp b/nano/node/process_live_dispatcher.hpp index 210656eb7c..9ba71f9668 100644 --- a/nano/node/process_live_dispatcher.hpp +++ b/nano/node/process_live_dispatcher.hpp @@ -1,6 +1,6 @@ #pragma once -namespace nano::store +namespace nano::secure { class transaction; } @@ -28,8 +28,8 @@ class process_live_dispatcher private: // Block_processor observer - void inspect (nano::block_status const & result, nano::block const & block, store::transaction const & transaction); - void process_live (nano::block const & block, store::transaction const & transaction); + void inspect (nano::block_status const & result, nano::block const & block, secure::transaction const & transaction); + void process_live (nano::block const & block, secure::transaction const & transaction); nano::ledger & ledger; nano::scheduler::priority & scheduler; diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index 42f6d210d7..3097cfade4 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -272,7 +272,7 @@ auto nano::rep_crawler::prepare_query_target () -> std::optional { constexpr int max_attempts = 4; - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); std::optional> hash_root; diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 1c399bc9c0..698c1a244d 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -177,7 +177,7 @@ void nano::request_aggregator::erase_duplicates (std::vector>, std::vector>> nano::request_aggregator::aggregate (std::vector> const & requests_a, std::shared_ptr & channel_a) const { - auto transaction (ledger.store.tx_begin_read ()); + auto transaction = ledger.tx_begin_read (); std::vector> to_generate; std::vector> to_generate_final; std::vector> cached_votes; diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index 0d971aa1e8..cfedab11e8 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -67,7 +67,7 @@ bool nano::scheduler::hinted::predicate () const return active.vacancy (nano::election_behavior::hinted) > 0; } -void nano::scheduler::hinted::activate (const nano::store::read_transaction & transaction, const nano::block_hash & hash, bool check_dependents) +void nano::scheduler::hinted::activate (secure::read_transaction const & transaction, nano::block_hash const & hash, bool check_dependents) { const int max_iterations = 64; @@ -133,7 +133,7 @@ void nano::scheduler::hinted::run_iterative () // Get the list before db transaction starts to avoid unnecessary slowdowns auto tops = vote_cache.top (minimum_tally); - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); for (auto const & entry : tops) { diff --git a/nano/node/scheduler/hinted.hpp b/nano/node/scheduler/hinted.hpp index 9e8fd425ac..a31be55765 100644 --- a/nano/node/scheduler/hinted.hpp +++ b/nano/node/scheduler/hinted.hpp @@ -24,6 +24,11 @@ class active_transactions; class vote_cache; class online_reps; } +namespace nano::secure +{ +class transaction; +class read_transaction; +} namespace nano::scheduler { @@ -66,7 +71,7 @@ class hinted final bool predicate () const; void run (); void run_iterative (); - void activate (nano::store::read_transaction const &, nano::block_hash const & hash, bool check_dependents); + void activate (secure::read_transaction const &, nano::block_hash const & hash, bool check_dependents); nano::uint128_t tally_threshold () const; nano::uint128_t final_tally_threshold () const; diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index cda2866651..7714dce73d 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -127,7 +127,7 @@ void nano::scheduler::optimistic::run () if (predicate ()) { - auto transaction = ledger.store.tx_begin_read (); + auto transaction = ledger.tx_begin_read (); while (predicate ()) { @@ -149,13 +149,13 @@ void nano::scheduler::optimistic::run () } } -void nano::scheduler::optimistic::run_one (store::transaction const & transaction, entry const & candidate) +void nano::scheduler::optimistic::run_one (secure::transaction const & transaction, entry const & candidate) { auto block = ledger.head_block (transaction, candidate.account); if (block) { // Ensure block is not already confirmed - if (!node.block_confirmed_or_being_confirmed (block->hash ())) + if (!node.block_confirmed_or_being_confirmed (transaction, block->hash ())) { // Try to insert it into AEC // We check for AEC vacancy inside our predicate diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index 547bd7e8c1..f7093f23cd 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -74,7 +74,7 @@ class optimistic final bool predicate () const; void run (); - void run_one (store::transaction const &, entry const & candidate); + void run_one (secure::transaction const &, entry const & candidate); private: // Dependencies optimistic_config const & config; diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index c6eb0d9961..c83a209bdf 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -39,7 +39,7 @@ void nano::scheduler::priority::stop () nano::join_or_pass (thread); } -bool nano::scheduler::priority::activate (nano::account const & account_a, store::transaction const & transaction) +bool nano::scheduler::priority::activate (nano::account const & account_a, secure::transaction const & transaction) { debug_assert (!account_a.is_zero ()); auto info = node.ledger.account_info (transaction, account_a); diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 693200217b..31c220ed3a 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -17,7 +17,7 @@ class container_info_component; class node; class stats; } -namespace nano::store +namespace nano::secure { class transaction; } @@ -38,7 +38,7 @@ class priority final * Activates the first unconfirmed block of \p account_a * @return true if account was activated */ - bool activate (nano::account const &, store::transaction const &); + bool activate (nano::account const &, secure::transaction const &); void notify (); std::size_t size () const; bool empty () const; diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index addc721921..bcaf7cd37f 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -39,7 +39,7 @@ nano::vote_generator::~vote_generator () stop (); } -bool nano::vote_generator::should_vote (store::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) +bool nano::vote_generator::should_vote (secure::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) { auto block = ledger.block (transaction, hash_a); bool should_vote = false; @@ -94,7 +94,8 @@ void nano::vote_generator::process_batch (std::deque & batch) { std::deque candidates_new; { - auto transaction = ledger.store.tx_begin_write ({ tables::final_votes }); + auto guard = ledger.store.write_queue.wait (is_final ? nano::store::writer::voting_final : nano::store::writer::voting); + auto transaction = ledger.tx_begin_write ({ tables::final_votes }); for (auto & [root, hash] : batch) { @@ -121,7 +122,7 @@ std::size_t nano::vote_generator::generate (std::vectorledger.dependents_confirmed (transaction, *block_a); }; diff --git a/nano/node/vote_generator.hpp b/nano/node/vote_generator.hpp index 4fc3d65e12..0d04cd67c1 100644 --- a/nano/node/vote_generator.hpp +++ b/nano/node/vote_generator.hpp @@ -32,6 +32,11 @@ class vote_processor; class vote_spacing; class wallets; } +namespace nano::secure +{ +class transaction; +class write_transaction; +} namespace nano::transport { class channel; @@ -73,7 +78,7 @@ class vote_generator final * @param transaction : needs `tables::final_votes` lock * @return: Should vote */ - bool should_vote (store::write_transaction const &, nano::root const &, nano::block_hash const &); + bool should_vote (secure::write_transaction const &, nano::root const &, nano::block_hash const &); private: std::function const &, std::shared_ptr &)> reply_action; // must be set only during initialization by using set_reply_action diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 696d7b4b68..96d5b1e993 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -767,7 +767,7 @@ nano::public_key nano::wallet::insert_adhoc (nano::raw_key const & key_a, bool g if (store.valid_password (transaction)) { key = store.insert_adhoc (transaction, key_a); - auto block_transaction (wallets.node.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); if (generate_work_a) { work_ensure (key, wallets.node.ledger.latest_root (block_transaction, key)); @@ -841,7 +841,7 @@ std::shared_ptr nano::wallet::receive_action (nano::block_hash cons details.is_receive = true; if (wallets.node.config.receive_minimum.number () <= amount_a.number ()) { - auto block_transaction (wallets.node.ledger.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); auto transaction (wallets.tx_begin_read ()); if (wallets.node.ledger.block_or_pruned_exists (block_transaction, send_hash_a)) { @@ -904,7 +904,7 @@ std::shared_ptr nano::wallet::change_action (nano::account const & nano::block_details details; { auto transaction (wallets.tx_begin_read ()); - auto block_transaction (wallets.node.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); if (store.valid_password (transaction)) { auto existing (store.find (transaction, source_a)); @@ -945,7 +945,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so } auto prepare_send = [&id_mdb_val, &wallets = this->wallets, &store = this->store, &source_a, &amount_a, &work_a, &account_a] (auto const & transaction) { - auto block_transaction (wallets.node.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); auto error (false); auto cached_block (false); std::shared_ptr block; @@ -1137,7 +1137,7 @@ void nano::wallet::work_update (store::transaction const & transaction_a, nano:: { debug_assert (!wallets.node.network_params.work.validate_entry (nano::work_version::work_1, root_a, work_a)); debug_assert (store.exists (transaction_a, account_a)); - auto block_transaction (wallets.node.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); auto latest (wallets.node.ledger.latest_root (block_transaction, account_a)); if (latest == root_a) { @@ -1178,7 +1178,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact for (auto i (store.begin (wallet_transaction_a)), n (store.end ()); i != n; ++i) { - auto block_transaction (wallets.node.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); nano::account const & account (i->first); // Don't search pending for watch-only accounts if (!nano::wallet_value (i->second).key.is_zero ()) @@ -1232,7 +1232,7 @@ void nano::wallet::init_free_accounts (store::transaction const & transaction_a) uint32_t nano::wallet::deterministic_check (store::transaction const & transaction_a, uint32_t index) { - auto block_transaction (wallets.node.store.tx_begin_read ()); + auto block_transaction = wallets.node.ledger.tx_begin_read (); for (uint32_t i (index + 1), n (index + 64); i < n; ++i) { auto prv = store.deterministic_key (transaction_a, i); @@ -1538,7 +1538,7 @@ void nano::wallets::foreach_representative (std::function> action_accounts_l; { auto transaction_l (tx_begin_read ()); - auto ledger_txn{ node.ledger.store.tx_begin_read () }; + auto ledger_txn = node.ledger.tx_begin_read (); nano::lock_guard lock{ mutex }; for (auto i (items.begin ()), n (items.end ()); i != n; ++i) { @@ -1644,12 +1644,7 @@ nano::wallet_representatives nano::wallets::reps () const bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t const & half_principal_weight_a, bool const acquire_lock_a) { - nano::uint128_t weight; - { - auto ledger_txn{ node.ledger.store.tx_begin_read () }; - weight = node.ledger.weight_exact (ledger_txn, account_a); - } - + auto weight = node.ledger.weight (account_a); if (weight < node.config.vote_minimum.number ()) { return false; // account not a representative @@ -1712,6 +1707,40 @@ void nano::wallets::ongoing_compute_reps () }); } +void nano::wallets::receive_confirmed (nano::block_hash const & hash_a, nano::account const & destination_a) +{ + nano::unique_lock lk{ mutex }; + auto wallets_l = get_wallets (); + auto wallet_transaction = tx_begin_read (); + lk.unlock (); + for ([[maybe_unused]] auto const & [id, wallet] : wallets_l) + { + if (wallet->store.exists (wallet_transaction, destination_a)) + { + nano::account representative; + representative = wallet->store.representative (wallet_transaction); + auto pending = node.ledger.pending_info (node.ledger.tx_begin_read (), nano::pending_key (destination_a, hash_a)); + if (pending) + { + auto amount (pending->amount.number ()); + wallet->receive_async (hash_a, representative, amount, destination_a, [] (std::shared_ptr const &) {}); + } + else + { + if (!node.ledger.block_or_pruned_exists (node.ledger.tx_begin_read (), hash_a)) + { + node.logger.warn (nano::log::type::wallet, "Confirmed block is missing: {}", hash_a.to_string ()); + debug_assert (false, "Confirmed block is missing"); + } + else + { + node.logger.warn (nano::log::type::wallet, "Block has already been received: {}", hash_a.to_string ()); + } + } + } + } +} + std::unordered_map> nano::wallets::get_wallets () { debug_assert (!mutex.try_lock ()); diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 40409f5e35..7366ec4702 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -220,6 +220,7 @@ class wallets final bool check_rep (nano::account const &, nano::uint128_t const &, bool const = true); void compute_reps (); void ongoing_compute_reps (); + void receive_confirmed (nano::block_hash const & hash_a, nano::account const & destination_a); std::unordered_map> get_wallets (); nano::network_params & network_params; std::function observer; diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 3742c308e4..07b5963baf 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -263,7 +263,7 @@ nano_qt::accounts::accounts (nano_qt::wallet & wallet_a) : void nano_qt::accounts::refresh_wallet_balance () { auto transaction (this->wallet.wallet_m->wallets.tx_begin_read ()); - auto block_transaction (this->wallet.node.store.tx_begin_read ()); + auto block_transaction = this->wallet.node.ledger.tx_begin_read (); nano::uint128_t balance (0); nano::uint128_t pending (0); for (auto i (this->wallet.wallet_m->store.begin (transaction)), j (this->wallet.wallet_m->store.end ()); i != j; ++i) @@ -289,7 +289,7 @@ void nano_qt::accounts::refresh () { model->removeRows (0, model->rowCount ()); auto transaction (wallet.wallet_m->wallets.tx_begin_read ()); - auto block_transaction (this->wallet.node.store.tx_begin_read ()); + auto block_transaction = this->wallet.node.ledger.tx_begin_read (); QBrush brush; for (auto i (wallet.wallet_m->store.begin (transaction)), j (wallet.wallet_m->store.end ()); i != j; ++i) { @@ -516,7 +516,7 @@ namespace class short_text_visitor : public nano::block_visitor { public: - short_text_visitor (nano::store::transaction const & transaction_a, nano::ledger & ledger_a) : + short_text_visitor (nano::secure::transaction const & transaction_a, nano::ledger & ledger_a) : transaction (transaction_a), ledger (ledger_a) { @@ -623,7 +623,7 @@ class short_text_visitor : public nano::block_visitor amount = balance - previous_balance.value (); } } - nano::store::transaction const & transaction; + nano::secure::transaction const & transaction; nano::ledger & ledger; std::string type; nano::uint128_t amount; @@ -633,7 +633,7 @@ class short_text_visitor : public nano::block_visitor void nano_qt::history::refresh () { - auto transaction (ledger.store.tx_begin_read ()); + auto transaction = ledger.tx_begin_read (); model->removeRows (0, model->rowCount ()); auto hash (ledger.latest (transaction, account)); short_text_visitor visitor (transaction, ledger); @@ -688,7 +688,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : nano::block_hash hash_l; if (!hash_l.decode_hex (hash->text ().toStdString ())) { - auto transaction (this->wallet.node.store.tx_begin_read ()); + auto transaction = this->wallet.node.ledger.tx_begin_read (); auto block_l (this->wallet.node.ledger.block (transaction, hash_l)); if (block_l != nullptr) { @@ -713,7 +713,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : auto error (block.decode_hex (hash->text ().toStdString ())); if (!error) { - auto transaction (this->wallet.node.store.tx_begin_read ()); + auto transaction = this->wallet.node.ledger.tx_begin_read (); if (this->wallet.node.ledger.block_exists (transaction, block)) { rebroadcast->setEnabled (false); @@ -734,7 +734,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : void nano_qt::block_viewer::rebroadcast_action (nano::block_hash const & hash_a) { auto done (true); - auto transaction (wallet.node.ledger.store.tx_begin_read ()); + auto transaction = wallet.node.ledger.tx_begin_read (); auto block (wallet.node.ledger.block (transaction, hash_a)); if (block != nullptr) { @@ -2240,7 +2240,7 @@ void nano_qt::block_creation::create_send () if (!error) { auto transaction (wallet.node.wallets.tx_begin_read ()); - auto block_transaction (wallet.node.store.tx_begin_read ()); + auto block_transaction = wallet.node.ledger.tx_begin_read (); nano::raw_key key; if (!wallet.wallet_m->store.fetch (transaction, account_l, key)) { @@ -2316,7 +2316,7 @@ void nano_qt::block_creation::create_receive () if (!error) { auto transaction (wallet.node.wallets.tx_begin_read ()); - auto block_transaction (wallet.node.store.tx_begin_read ()); + auto block_transaction = wallet.node.ledger.tx_begin_read (); auto block_l (wallet.node.ledger.block (block_transaction, source_l)); if (block_l != nullptr) { @@ -2480,7 +2480,7 @@ void nano_qt::block_creation::create_open () if (!error) { auto transaction (wallet.node.wallets.tx_begin_read ()); - auto block_transaction (wallet.node.store.tx_begin_read ()); + auto block_transaction = wallet.node.ledger.tx_begin_read (); auto block_l (wallet.node.ledger.block (block_transaction, source_l)); if (block_l != nullptr) { diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 16f7306cbb..e458eda32a 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -389,7 +389,7 @@ TEST (wallet, DISABLED_process_block) QTest::keyClicks (wallet->block_entry.block, QString::fromStdString (block_json)); QTest::mouseClick (wallet->block_entry.process, Qt::LeftButton); { - auto transaction (system.nodes[0]->store.tx_begin_read ()); + auto transaction (system.nodes[0]->ledger.tx_begin_read ()); system.deadline_set (10s); while (system.nodes[0]->ledger.block_exists (transaction, send.hash ())) { @@ -529,7 +529,7 @@ TEST (history, short_text) ASSERT_TRUE (!store->init_error ()); nano::ledger ledger (*store, system.nodes[0]->stats, nano::dev::constants); { - auto transaction (store->tx_begin_write ()); + auto transaction (ledger.tx_begin_write ()); store->initialize (transaction, ledger.cache, ledger.constants); nano::keypair key; auto latest (ledger.latest (transaction, nano::dev::genesis_key.pub)); @@ -570,7 +570,7 @@ TEST (history, pruned_source) nano::block_hash next_pruning; // Basic pruning for legacy blocks. Previous block is pruned, source is pruned { - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, nano::dev::constants); auto latest (ledger.latest (transaction, nano::dev::genesis_key.pub)); auto send1 = std::make_shared (latest, nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); @@ -593,7 +593,7 @@ TEST (history, pruned_source) ASSERT_EQ (1, history2.model->rowCount ()); // Additional legacy test { - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); ledger.confirm (transaction, next_pruning); ASSERT_EQ (1, ledger.pruning_action (transaction, next_pruning, 2)); } @@ -603,7 +603,7 @@ TEST (history, pruned_source) ASSERT_EQ (1, history2.model->rowCount ()); // Pruning for state blocks. Previous block is pruned, source is pruned { - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); auto latest (ledger.latest (transaction, nano::dev::genesis_key.pub)); auto send = std::make_shared (nano::dev::genesis_key.pub, latest, nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - 200, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send)); @@ -720,7 +720,7 @@ TEST (wallet, republish) nano::keypair key; nano::block_hash hash; { - auto transaction (system.nodes[0]->store.tx_begin_write ()); + auto transaction = system.nodes[0]->ledger.tx_begin_write (); auto latest (system.nodes[0]->ledger.latest (transaction, nano::dev::genesis_key.pub)); auto block = std::make_shared (latest, key.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); hash = block->hash (); @@ -851,7 +851,7 @@ TEST (wallet, seed_work_generation) system.wallet (0)->store.work_get (transaction, pub, work); ASSERT_NO_ERROR (ec); } - auto transaction (system.nodes[0]->store.tx_begin_read ()); + auto transaction = system.nodes[0]->ledger.tx_begin_read (); ASSERT_GE (nano::dev::network_params.work.difficulty (nano::work_version::work_1, system.nodes[0]->ledger.latest_root (transaction, pub), work), system.nodes[0]->default_difficulty (nano::work_version::work_1)); } @@ -920,7 +920,7 @@ TEST (wallet, DISABLED_synchronizing) auto wallet (std::make_shared (*test_application, processor, *system0.nodes[0], system0.wallet (0), key1)); wallet->start (); { - auto transaction (system1.nodes[0]->store.tx_begin_write ()); + auto transaction = system1.nodes[0]->ledger.tx_begin_write (); auto latest (system1.nodes[0]->ledger.latest (transaction, nano::dev::genesis_key.pub)); auto send = std::make_shared (latest, key1, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system1.work.generate (latest)); system1.nodes[0]->ledger.process (transaction, send); diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index e73221bd52..bc39f85c57 100644 --- a/nano/rpc_test/receivable.cpp +++ b/nano/rpc_test/receivable.cpp @@ -194,7 +194,7 @@ TEST (rpc, receivable_offset_and_sorting) auto block6 = system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 300); // check that all blocks got confirmed - ASSERT_TIMELY_EQ (5s, node->ledger.account_receivable (node->store.tx_begin_read (), key1.pub, true), 1600); + ASSERT_TIMELY_EQ (5s, node->ledger.account_receivable (node->ledger.tx_begin_read (), key1.pub, true), 1600); // check confirmation height is as expected, there is no perfect clarity yet when confirmation height updates after a block get confirmed nano::confirmation_height_info confirmation_height_info; @@ -371,7 +371,7 @@ TEST (rpc, search_receivable) .work (*node->work_generate_blocking (latest)) .build (); { - auto transaction (node->store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, block)); } auto const rpc_ctx = add_rpc (system, node); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 3b9168a000..f69ce1d36d 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -355,20 +355,17 @@ TEST (rpc, send_idempotent) ASSERT_EQ (std::error_code (nano::error_common::insufficient_balance).message (), response3.get ("error")); } -// Test disabled because it's failing intermittently. -// PR in which it got disabled: https://github.com/nanocurrency/nano-node/pull/3560 -// Issue for investigating it: https://github.com/nanocurrency/nano-node/issues/3561 -// CI run in which it failed: https://github.com/nanocurrency/nano-node/runs/4280938039?check_suite_focus=true#step:5:1895 -TEST (rpc, DISABLED_send_epoch_2) +TEST (rpc, send_epoch_2) { nano::test::system system; auto node = add_ipc_enabled_node (system); // Upgrade the genesis account to epoch 2 - ASSERT_NE (nullptr, system.upgrade_genesis_epoch (*node, nano::epoch::epoch_1)); - ASSERT_NE (nullptr, system.upgrade_genesis_epoch (*node, nano::epoch::epoch_2)); - + std::shared_ptr epoch1, epoch2; + ASSERT_TRUE (epoch1 = system.upgrade_genesis_epoch (*node, nano::epoch::epoch_1)); + ASSERT_TRUE (epoch2 = system.upgrade_genesis_epoch (*node, nano::epoch::epoch_2)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv, false); + ASSERT_TIMELY (5s, nano::test::confirmed (*node, { epoch1, epoch2 })); auto target_difficulty = nano::dev::network_params.work.threshold (nano::work_version::work_1, nano::block_details (nano::epoch::epoch_2, true, false, false)); ASSERT_LT (node->network_params.work.entry, target_difficulty); @@ -558,7 +555,7 @@ TEST (rpc, wallet_representative_set_force) nano::account representative{}; while (representative != key.pub) { - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); auto info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub); if (info) { @@ -965,7 +962,7 @@ TEST (rpc, history) .work (*node0->work_generate_blocking (ureceive->hash ())) .build (); { - auto transaction (node0->store.tx_begin_write ()); + auto transaction = node0->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, usend)); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, ureceive)); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, uchange)); @@ -1049,7 +1046,7 @@ TEST (rpc, account_history) .work (*node0->work_generate_blocking (ureceive->hash ())) .build (); { - auto transaction (node0->store.tx_begin_write ()); + auto transaction = node0->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, usend)); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, ureceive)); ASSERT_EQ (nano::block_status::progress, node0->ledger.process (transaction, uchange)); @@ -1267,7 +1264,7 @@ TEST (rpc, history_pruning) // Prune block "change" { - auto transaction (node0->store.tx_begin_write ()); + auto transaction = node0->ledger.tx_begin_write (); ASSERT_EQ (1, node0->ledger.pruning_action (transaction, change->hash (), 1)); } @@ -1287,7 +1284,7 @@ TEST (rpc, history_pruning) // Prune block "send" { - auto transaction (node0->store.tx_begin_write ()); + auto transaction = node0->ledger.tx_begin_write (); ASSERT_EQ (1, node0->ledger.pruning_action (transaction, send->hash (), 1)); } @@ -1306,7 +1303,7 @@ TEST (rpc, history_pruning) // Prune block "receive" { - auto transaction (node0->store.tx_begin_write ()); + auto transaction = node0->ledger.tx_begin_write (); ASSERT_EQ (1, node0->ledger.pruning_action (transaction, receive->hash (), 1)); } @@ -2249,7 +2246,7 @@ TEST (rpc, block_count_pruning) ASSERT_TIMELY (5s, node1->block_confirmed (receive1->hash ())); // Pruning action { - auto transaction (node1->store.tx_begin_write ()); + auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); } auto const rpc_ctx = add_rpc (system, node1); @@ -2402,8 +2399,8 @@ TEST (rpc, account_representative_set) nano::keypair key2; wallet.insert_adhoc (key2.prv); auto key2_open_block_hash = wallet.send_sync (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()); - ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), key2_open_block_hash)); - auto key2_open_block = node->ledger.block (node->store.tx_begin_read (), key2_open_block_hash); + ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), key2_open_block_hash)); + auto key2_open_block = node->ledger.block (node->ledger.tx_begin_read (), key2_open_block_hash); ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative_field ().value ()); // now change the representative of key2 to be genesis @@ -2420,9 +2417,9 @@ TEST (rpc, account_representative_set) nano::block_hash hash; ASSERT_FALSE (hash.decode_hex (block_text1)); ASSERT_FALSE (hash.is_zero ()); - auto block = node->ledger.block (node->store.tx_begin_read (), hash); + auto block = node->ledger.block (node->ledger.tx_begin_read (), hash); ASSERT_NE (block, nullptr); - ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), hash)); + ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), hash)); ASSERT_EQ (key2.pub, block->representative_field ().value ()); } @@ -2457,7 +2454,7 @@ TEST (rpc, account_representative_set_epoch_2_insufficient_work) ASSERT_NE (nullptr, system.upgrade_genesis_epoch (*node, nano::epoch::epoch_2)); // speed up the cementing process, otherwise the node waits for frontiers confirmation to notice the unconfirmed epoch blocks, which takes time - node->scheduler.priority.activate (nano::dev::genesis_key.pub, node->store.tx_begin_read ()); + node->scheduler.priority.activate (nano::dev::genesis_key.pub, node->ledger.tx_begin_read ()); // wait for the epoch blocks to be cemented ASSERT_TIMELY_EQ (5s, node->get_confirmation_height (node->store.tx_begin_read (), nano::dev::genesis_key.pub), 3); @@ -2476,7 +2473,7 @@ TEST (rpc, account_representative_set_epoch_2_insufficient_work) request.put ("representative", nano::keypair ().pub.to_account ()); // Test that the correct error is given if there is insufficient work - auto latest = node->ledger.latest (node->store.tx_begin_read (), nano::dev::genesis_key.pub); + auto latest = node->ledger.latest (node->ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto insufficient = system.work_generate_limited (latest, min_difficulty, target_difficulty); request.put ("work", nano::to_string_hex (insufficient)); { @@ -2504,7 +2501,7 @@ TEST (rpc, bootstrap) .work (*node1->work_generate_blocking (latest)) .build (); { - auto transaction (node1->store.tx_begin_write ()); + auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1->ledger.process (transaction, send)); } auto const rpc_ctx = add_rpc (system0, node); @@ -2789,7 +2786,7 @@ TEST (rpc, bootstrap_any) .work (*system1.nodes[0]->work_generate_blocking (latest)) .build (); { - auto transaction (system1.nodes[0]->store.tx_begin_write ()); + auto transaction = system1.nodes[0]->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, system1.nodes[0]->ledger.process (transaction, send)); } auto const rpc_ctx = add_rpc (system0, node); @@ -3005,7 +3002,7 @@ TEST (rpc, accounts_balances_unopened_account_with_receivables) .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); } ASSERT_TIMELY (5s, node->block (send->hash ())); @@ -3316,7 +3313,7 @@ TEST (rpc, pending_exists) request.put ("hash", hash0.to_string ()); ASSERT_TRUE (pending_exists ("0")); - node->ledger.pending_info (node->store.tx_begin_read (), nano::pending_key{ nano::dev::genesis_key.pub, block1->hash () }); + node->ledger.pending_info (node->ledger.tx_begin_read (), nano::pending_key{ nano::dev::genesis_key.pub, block1->hash () }); request.put ("hash", block1->hash ().to_string ()); ASSERT_TRUE (pending_exists ("1")); @@ -3538,7 +3535,7 @@ TEST (rpc, search_receivable_all) .work (*node->work_generate_blocking (latest)) .build (); { - auto transaction (node->store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, block)); } auto const rpc_ctx = add_rpc (system, node); @@ -4145,7 +4142,7 @@ TEST (rpc, blocks_info_receive_hash) }; ASSERT_TIMELY (5s, all_blocks_cemented ()); - ASSERT_EQ (node->ledger.account_balance (node->store.tx_begin_read (), key1.pub, true), 10); + ASSERT_EQ (node->ledger.account_balance (node->ledger.tx_begin_read (), key1.pub, true), 10); // create the RPC request boost::property_tree::ptree request; @@ -4294,7 +4291,7 @@ TEST (rpc, block_info_pruning) ASSERT_TIMELY (5s, node1->block_confirmed (receive1->hash ())); // Pruning action { - auto transaction (node1->store.tx_begin_write ()); + auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ())); } @@ -4360,7 +4357,7 @@ TEST (rpc, pruned_exists) ASSERT_TIMELY (5s, node1->block_confirmed (receive1->hash ())); // Pruning action { - auto transaction (node1->store.tx_begin_write ()); + auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ())); } @@ -5279,7 +5276,7 @@ TEST (rpc, block_confirm) .work (*node->work_generate_blocking (nano::dev::genesis->hash ())) .build (); { - auto transaction (node->store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); } auto const rpc_ctx = add_rpc (system, node); @@ -5314,7 +5311,7 @@ TEST (rpc, block_confirm_confirmed) config.callback_target = "/"; auto node = add_ipc_enabled_node (system, config); { - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); ASSERT_TRUE (node->ledger.block_confirmed (transaction, nano::dev::genesis->hash ())); } ASSERT_EQ (0, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out)); @@ -5587,24 +5584,19 @@ TEST (rpc, uptime) ASSERT_LE (1, response.get ("seconds")); } -// Test disabled because it's failing intermittently. -// PR in which it got disabled: https://github.com/nanocurrency/nano-node/pull/3512 -// Issue for investigating it: https://github.com/nanocurrency/nano-node/issues/3514 -TEST (rpc, DISABLED_wallet_history) +TEST (rpc, wallet_history) { nano::test::system system; nano::node_config node_config = system.default_config (); node_config.enable_voting = false; auto node = add_ipc_enabled_node (system, node_config); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - auto timestamp1 = nano::seconds_since_epoch (); + uint64_t timestamp = nano::seconds_since_epoch (); auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto timestamp2 = nano::seconds_since_epoch (); auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->destination ())); ASSERT_NE (nullptr, receive); nano::keypair key; - auto timestamp3 = nano::seconds_since_epoch (); auto send2 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key.pub, node->config.receive_minimum.number ())); ASSERT_NE (nullptr, send2); system.deadline_set (10s); @@ -5625,19 +5617,22 @@ TEST (rpc, DISABLED_wallet_history) ASSERT_EQ (node->config.receive_minimum.to_string_dec (), std::get<2> (history_l[0])); ASSERT_EQ (send2->hash ().to_string (), std::get<3> (history_l[0])); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), std::get<4> (history_l[0])); - ASSERT_EQ (std::to_string (timestamp3), std::get<5> (history_l[0])); + ASSERT_LE (timestamp, std::stoull (std::get<5> (history_l[0]))); + ASSERT_GT (timestamp + 5, std::stoull (std::get<5> (history_l[0]))); ASSERT_EQ ("receive", std::get<0> (history_l[1])); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), std::get<1> (history_l[1])); ASSERT_EQ (node->config.receive_minimum.to_string_dec (), std::get<2> (history_l[1])); ASSERT_EQ (receive->hash ().to_string (), std::get<3> (history_l[1])); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), std::get<4> (history_l[1])); - ASSERT_EQ (std::to_string (timestamp2), std::get<5> (history_l[1])); + ASSERT_LE (timestamp, std::stoull (std::get<5> (history_l[1]))); + ASSERT_GT (timestamp + 5, std::stoull (std::get<5> (history_l[1]))); ASSERT_EQ ("send", std::get<0> (history_l[2])); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), std::get<1> (history_l[2])); ASSERT_EQ (node->config.receive_minimum.to_string_dec (), std::get<2> (history_l[2])); ASSERT_EQ (send->hash ().to_string (), std::get<3> (history_l[2])); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), std::get<4> (history_l[2])); - ASSERT_EQ (std::to_string (timestamp1), std::get<5> (history_l[2])); + ASSERT_LE (timestamp, std::stoull (std::get<5> (history_l[2]))); + ASSERT_GT (timestamp + 5, std::stoull (std::get<5> (history_l[2]))); // Genesis block ASSERT_EQ ("receive", std::get<0> (history_l[3])); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), std::get<1> (history_l[3])); @@ -5775,8 +5770,8 @@ TEST (rpc, block_confirmed) // Open an account directly in the ledger { - auto transaction = node->store.tx_begin_write (); - nano::block_hash latest (node->latest (nano::dev::genesis_key.pub)); + auto transaction = node->ledger.tx_begin_write (); + nano::block_hash latest (node->ledger.latest (transaction, nano::dev::genesis_key.pub)); auto send1 = builder .send () .previous (latest) @@ -5817,7 +5812,7 @@ TEST (rpc, block_confirmed) ASSERT_TRUE (nano::test::start_elections (system, *node, { send }, true)); // Wait until the confirmation height has been set - ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), send->hash ()) && !node->confirming_set.exists (send->hash ())); + ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), send->hash ()) && !node->confirming_set.exists (send->hash ())); // Requesting confirmation for this should now succeed request.put ("hash", send->hash ().to_string ()); @@ -6193,7 +6188,7 @@ TEST (rpc, epoch_upgrade) ASSERT_EQ (nano::block_status::progress, node->process (send7)); { // Check pending entry - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); auto info = node->ledger.pending_info (transaction, nano::pending_key (key3.pub, send7->hash ())); ASSERT_TRUE (info); ASSERT_EQ (nano::epoch::epoch_1, info->epoch); @@ -6357,7 +6352,7 @@ TEST (rpc, epoch_upgrade_multithreaded) ASSERT_EQ (nano::block_status::progress, node->process (send7)); { // Check pending entry - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); auto info = node->ledger.pending_info (transaction, nano::pending_key (key3.pub, send7->hash ())); ASSERT_TRUE (info); ASSERT_EQ (nano::epoch::epoch_1, info->epoch); @@ -6460,7 +6455,7 @@ TEST (rpc, receive) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node->ledger.account_info (node->store.tx_begin_read (), key1.pub); + auto info = node->ledger.account_info (node->ledger.tx_begin_read (), key1.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, nano::block_hash{ receive_text }); } @@ -6489,8 +6484,8 @@ TEST (rpc, receive_unopened) nano::keypair key1; auto send1 (wallet->send_action (nano::dev::genesis_key.pub, key1.pub, node->config.receive_minimum.number () - 1, *node->work_generate_blocking (nano::dev::genesis->hash ()))); ASSERT_TIMELY (5s, !node->balance (nano::dev::genesis_key.pub) != nano::dev::constants.genesis_amount); - ASSERT_FALSE (node->store.account.exists (node->store.tx_begin_read (), key1.pub)); - ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send1->hash ())); + ASSERT_FALSE (node->store.account.exists (node->ledger.tx_begin_read (), key1.pub)); + ASSERT_TRUE (node->ledger.block_exists (node->ledger.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); // should not auto receive, amount sent was lower than minimum auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -6501,7 +6496,7 @@ TEST (rpc, receive_unopened) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node->ledger.account_info (node->store.tx_begin_read (), key1.pub); + auto info = node->ledger.account_info (node->ledger.tx_begin_read (), key1.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, info->open_block); ASSERT_EQ (info->head.to_string (), receive_text); @@ -6513,8 +6508,8 @@ TEST (rpc, receive_unopened) auto prev_amount (node->balance (nano::dev::genesis_key.pub)); auto send2 (wallet->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number () - 1, *node->work_generate_blocking (send1->hash ()))); ASSERT_TIMELY (5s, !node->balance (nano::dev::genesis_key.pub) != prev_amount); - ASSERT_FALSE (node->store.account.exists (node->store.tx_begin_read (), key2.pub)); - ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send2->hash ())); + ASSERT_FALSE (node->store.account.exists (node->ledger.tx_begin_read (), key2.pub)); + ASSERT_TRUE (node->ledger.block_exists (node->ledger.tx_begin_read (), send2->hash ())); nano::public_key rep; wallet->store.representative_set (node->wallets.tx_begin_write (), rep); wallet->insert_adhoc (key2.prv); // should not auto receive, amount sent was lower than minimum @@ -6523,7 +6518,7 @@ TEST (rpc, receive_unopened) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node->ledger.account_info (node->store.tx_begin_read (), key2.pub); + auto info = node->ledger.account_info (node->ledger.tx_begin_read (), key2.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, info->open_block); ASSERT_EQ (info->head.to_string (), receive_text); @@ -6548,8 +6543,8 @@ TEST (rpc, receive_work_disabled) auto send1 (wallet->send_action (nano::dev::genesis_key.pub, key1.pub, node->config.receive_minimum.number () - 1, *worker_node.work_generate_blocking (nano::dev::genesis->hash ()), false)); ASSERT_NE (send1, nullptr); ASSERT_TIMELY (5s, node->balance (nano::dev::genesis_key.pub) != nano::dev::constants.genesis_amount); - ASSERT_FALSE (node->store.account.exists (node->store.tx_begin_read (), key1.pub)); - ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send1->hash ())); + ASSERT_FALSE (node->store.account.exists (node->ledger.tx_begin_read (), key1.pub)); + ASSERT_TRUE (node->ledger.block_exists (node->ledger.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -6589,14 +6584,14 @@ TEST (rpc, receive_pruned) // Pruning ASSERT_TIMELY (5s, node2->block_confirmed (send3->hash ())); { - auto transaction (node2->store.tx_begin_write ()); + auto transaction = node2->ledger.tx_begin_write (); ASSERT_EQ (2, node2->ledger.pruning_action (transaction, send2->hash (), 1)); } ASSERT_EQ (2, node2->ledger.pruned_count ()); ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_FALSE (node2->ledger.block_exists (node2->store.tx_begin_read (), send1->hash ())); + ASSERT_FALSE (node2->ledger.block_exists (node2->ledger.tx_begin_read (), send1->hash ())); ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send2->hash ())); - ASSERT_FALSE (node2->ledger.block_exists (node2->store.tx_begin_read (), send2->hash ())); + ASSERT_FALSE (node2->ledger.block_exists (node2->ledger.tx_begin_read (), send2->hash ())); ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send3->hash ())); auto const rpc_ctx = add_rpc (system, node2); @@ -6608,7 +6603,7 @@ TEST (rpc, receive_pruned) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node2->ledger.account_info (node2->store.tx_begin_read (), key1.pub); + auto info = node2->ledger.account_info (node2->ledger.tx_begin_read (), key1.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, nano::block_hash{ receive_text }); } @@ -6872,12 +6867,34 @@ TEST (rpc, election_statistics) nano::test::system system; auto node1 = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node1); - boost::property_tree::ptree request1; - request1.put ("action", "election_statistics"); - auto response1 (wait_response (system, rpc_ctx, request1)); - ASSERT_EQ ("0", response1.get ("normal")); - ASSERT_EQ ("0", response1.get ("hinted")); - ASSERT_EQ ("0", response1.get ("optimistic")); - ASSERT_EQ ("0", response1.get ("total")); - ASSERT_EQ ("0.00", response1.get ("aec_utilization_percentage")); + + // process block and wait for election to start, the election will not be completed because there are no voters on the network + nano::block_builder builder; + auto send1 = builder + .send () + .previous (nano::dev::genesis->hash ()) + .destination (nano::public_key ()) + .balance (nano::dev::constants.genesis_amount - 100) + .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) + .work (*system.work.generate (nano::dev::genesis->hash ())) + .build (); + node1->process_active (send1); + ASSERT_TIMELY_EQ (5s, node1->active.size (), 1); + + // delay to ensure returned age is not rounded down to zero + system.delay_ms (20ms); + + boost::property_tree::ptree request; + request.put ("action", "election_statistics"); + + auto response = wait_response (system, rpc_ctx, request); + ASSERT_EQ ("1", response.get ("normal")); + ASSERT_EQ ("0", response.get ("hinted")); + ASSERT_EQ ("0", response.get ("optimistic")); + ASSERT_EQ ("1", response.get ("total")); + ASSERT_NE ("0.00", response.get ("aec_utilization_percentage")); + ASSERT_GT (response.get ("max_election_age"), 0); + ASSERT_GT (response.get ("average_election_age"), 0); + ASSERT_LT (response.get ("max_election_age"), 5000); + ASSERT_LT (response.get ("average_election_age"), 5000); } diff --git a/nano/secure/CMakeLists.txt b/nano/secure/CMakeLists.txt index cdb5adae02..2825a08c84 100644 --- a/nano/secure/CMakeLists.txt +++ b/nano/secure/CMakeLists.txt @@ -55,6 +55,7 @@ add_library( pending_info.cpp rep_weights.hpp rep_weights.cpp + transaction.hpp utility.hpp utility.cpp vote.hpp diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 85313fa625..9be416b241 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -32,7 +32,7 @@ namespace class rollback_visitor : public nano::block_visitor { public: - rollback_visitor (nano::store::write_transaction const & transaction_a, nano::ledger & ledger_a, std::vector> & list_a) : + rollback_visitor (nano::secure::write_transaction const & transaction_a, nano::ledger & ledger_a, std::vector> & list_a) : transaction (transaction_a), ledger (ledger_a), list (list_a) @@ -173,7 +173,7 @@ class rollback_visitor : public nano::block_visitor } ledger.store.block.del (transaction, hash); } - nano::store::write_transaction const & transaction; + nano::secure::write_transaction const & transaction; nano::ledger & ledger; std::vector> & list; bool error{ false }; @@ -182,7 +182,7 @@ class rollback_visitor : public nano::block_visitor class ledger_processor : public nano::mutable_block_visitor { public: - ledger_processor (nano::ledger &, nano::store::write_transaction const &); + ledger_processor (nano::ledger &, nano::secure::write_transaction const &); virtual ~ledger_processor () = default; void send_block (nano::send_block &) override; void receive_block (nano::receive_block &) override; @@ -192,7 +192,7 @@ class ledger_processor : public nano::mutable_block_visitor void state_block_impl (nano::state_block &); void epoch_block_impl (nano::state_block &); nano::ledger & ledger; - nano::store::write_transaction const & transaction; + nano::secure::write_transaction const & transaction; nano::block_status result; private: @@ -639,7 +639,7 @@ void ledger_processor::open_block (nano::open_block & block_a) } } -ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::store::write_transaction const & transaction_a) : +ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::secure::write_transaction const & transaction_a) : ledger (ledger_a), transaction (transaction_a) { @@ -651,7 +651,7 @@ ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::store::write_ class representative_visitor final : public nano::block_visitor { public: - representative_visitor (nano::store::transaction const & transaction_a, nano::ledger & ledger); + representative_visitor (nano::secure::transaction const & transaction_a, nano::ledger & ledger); ~representative_visitor () = default; void compute (nano::block_hash const & hash_a); void send_block (nano::send_block const & block_a) override; @@ -659,13 +659,13 @@ class representative_visitor final : public nano::block_visitor void open_block (nano::open_block const & block_a) override; void change_block (nano::change_block const & block_a) override; void state_block (nano::state_block const & block_a) override; - nano::store::transaction const & transaction; + nano::secure::transaction const & transaction; nano::ledger & ledger; nano::block_hash current; nano::block_hash result; }; -representative_visitor::representative_visitor (nano::store::transaction const & transaction_a, nano::ledger & ledger) : +representative_visitor::representative_visitor (nano::secure::transaction const & transaction_a, nano::ledger & ledger) : transaction{ transaction_a }, ledger{ ledger }, result{ 0 } @@ -722,6 +722,16 @@ nano::ledger::ledger (nano::store::component & store_a, nano::stats & stat_a, na } } +auto nano::ledger::tx_begin_write (std::vector const & tables_to_lock, std::vector const & tables_no_lock) const -> secure::write_transaction +{ + return secure::write_transaction{ store.tx_begin_write (tables_to_lock, tables_no_lock) }; +} + +auto nano::ledger::tx_begin_read () const -> secure::read_transaction +{ + return secure::read_transaction{ store.tx_begin_read () }; +} + void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache_flags_a) { if (generate_cache_flags_a.reps || generate_cache_flags_a.account_count || generate_cache_flags_a.block_count) @@ -769,7 +779,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache } // Balance for account containing hash -std::optional nano::ledger::balance (store::transaction const & transaction, nano::block_hash const & hash) const +std::optional nano::ledger::balance (secure::transaction const & transaction, nano::block_hash const & hash) const { if (hash.is_zero ()) { @@ -783,18 +793,18 @@ std::optional nano::ledger::balance (store::transaction const & return block->balance ().number (); } -std::shared_ptr nano::ledger::block (store::transaction const & transaction, nano::block_hash const & hash) const +std::shared_ptr nano::ledger::block (secure::transaction const & transaction, nano::block_hash const & hash) const { return store.block.get (transaction, hash); } -bool nano::ledger::block_exists (store::transaction const & transaction, nano::block_hash const & hash) const +bool nano::ledger::block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const { return store.block.exists (transaction, hash); } // Balance for an account by account number -nano::uint128_t nano::ledger::account_balance (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) +nano::uint128_t nano::ledger::account_balance (secure::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) const { nano::uint128_t result (0); if (only_confirmed_a) @@ -816,7 +826,7 @@ nano::uint128_t nano::ledger::account_balance (store::transaction const & transa return result; } -nano::uint128_t nano::ledger::account_receivable (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) +nano::uint128_t nano::ledger::account_receivable (secure::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { nano::uint128_t result{ 0 }; for (auto i = receivable_upper_bound (transaction_a, account_a, 0), n = receivable_end (); i != n; ++i) @@ -830,12 +840,12 @@ nano::uint128_t nano::ledger::account_receivable (store::transaction const & tra return result; } -std::optional nano::ledger::pending_info (store::transaction const & transaction, nano::pending_key const & key) const +std::optional nano::ledger::pending_info (secure::transaction const & transaction, nano::pending_key const & key) const { return store.pending.get (transaction, key); } -std::deque> nano::ledger::confirm (nano::store::write_transaction const & transaction, nano::block_hash const & hash) +std::deque> nano::ledger::confirm (secure::write_transaction const & transaction, nano::block_hash const & hash) { std::deque> result; std::stack stack; @@ -870,7 +880,7 @@ std::deque> nano::ledger::confirm (nano::store::wri return result; } -void nano::ledger::confirm (nano::store::write_transaction const & transaction, nano::block const & block) +void nano::ledger::confirm (secure::write_transaction const & transaction, nano::block const & block) { debug_assert ((!store.confirmation_height.get (transaction, block.account ()) && block.sideband ().height == 1) || store.confirmation_height.get (transaction, block.account ()).value ().height + 1 == block.sideband ().height); confirmation_height_info info{ block.sideband ().height, block.hash () }; @@ -879,7 +889,7 @@ void nano::ledger::confirm (nano::store::write_transaction const & transaction, stats.inc (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed); } -nano::block_status nano::ledger::process (store::write_transaction const & transaction_a, std::shared_ptr block_a) +nano::block_status nano::ledger::process (secure::write_transaction const & transaction_a, std::shared_ptr block_a) { debug_assert (!constants.work.validate_entry (*block_a) || constants.genesis == nano::dev::genesis); ledger_processor processor (*this, transaction_a); @@ -891,14 +901,14 @@ nano::block_status nano::ledger::process (store::write_transaction const & trans return processor.result; } -nano::block_hash nano::ledger::representative (store::transaction const & transaction_a, nano::block_hash const & hash_a) +nano::block_hash nano::ledger::representative (secure::transaction const & transaction_a, nano::block_hash const & hash_a) { auto result (representative_calculated (transaction_a, hash_a)); debug_assert (result.is_zero () || block_exists (transaction_a, result)); return result; } -nano::block_hash nano::ledger::representative_calculated (store::transaction const & transaction_a, nano::block_hash const & hash_a) +nano::block_hash nano::ledger::representative_calculated (secure::transaction const & transaction_a, nano::block_hash const & hash_a) { representative_visitor visitor (transaction_a, *this); visitor.compute (hash_a); @@ -907,10 +917,10 @@ nano::block_hash nano::ledger::representative_calculated (store::transaction con bool nano::ledger::block_or_pruned_exists (nano::block_hash const & hash_a) const { - return block_or_pruned_exists (store.tx_begin_read (), hash_a); + return block_or_pruned_exists (tx_begin_read (), hash_a); } -bool nano::ledger::block_or_pruned_exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const +bool nano::ledger::block_or_pruned_exists (secure::transaction const & transaction_a, nano::block_hash const & hash_a) const { if (store.pruned.exists (transaction_a, hash_a)) { @@ -927,7 +937,7 @@ std::string nano::ledger::block_text (char const * hash_a) std::string nano::ledger::block_text (nano::block_hash const & hash_a) { std::string result; - auto transaction (store.tx_begin_read ()); + auto transaction = tx_begin_read (); auto block_l = block (transaction, hash_a); if (block_l != nullptr) { @@ -936,7 +946,7 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a) return result; } -std::pair nano::ledger::hash_root_random (store::transaction const & transaction_a) const +std::pair nano::ledger::hash_root_random (secure::transaction const & transaction_a) const { nano::block_hash hash (0); nano::root root (0); @@ -986,13 +996,13 @@ nano::uint128_t nano::ledger::weight (nano::account const & account_a) const return cache.rep_weights.representation_get (account_a); } -nano::uint128_t nano::ledger::weight_exact (store::transaction const & txn_a, nano::account const & representative_a) const +nano::uint128_t nano::ledger::weight_exact (secure::transaction const & txn_a, nano::account const & representative_a) const { return store.rep_weight.get (txn_a, representative_a); } // Rollback blocks until `block_a' doesn't exist or it tries to penetrate the confirmation height -bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) +bool nano::ledger::rollback (secure::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) { debug_assert (block_exists (transaction_a, block_a)); auto account_l = account (transaction_a, block_a).value (); @@ -1024,13 +1034,13 @@ bool nano::ledger::rollback (store::write_transaction const & transaction_a, nan return error; } -bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a) +bool nano::ledger::rollback (secure::write_transaction const & transaction_a, nano::block_hash const & block_a) { std::vector> rollback_list; return rollback (transaction_a, block_a, rollback_list); } -std::optional nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const +std::optional nano::ledger::account (secure::transaction const & transaction, nano::block_hash const & hash) const { auto block_l = block (transaction, hash); if (!block_l) @@ -1040,12 +1050,12 @@ std::optional nano::ledger::account (store::transaction const & t return block_l->account (); } -std::optional nano::ledger::account_info (store::transaction const & transaction, nano::account const & account) const +std::optional nano::ledger::account_info (secure::transaction const & transaction, nano::account const & account) const { return store.account.get (transaction, account); } -std::optional nano::ledger::amount (store::transaction const & transaction_a, nano::block_hash const & hash_a) +std::optional nano::ledger::amount (secure::transaction const & transaction_a, nano::block_hash const & hash_a) { auto block_l = block (transaction_a, hash_a); if (!block_l) @@ -1066,14 +1076,14 @@ std::optional nano::ledger::amount (store::transaction const & } // Return latest block for account -nano::block_hash nano::ledger::latest (store::transaction const & transaction_a, nano::account const & account_a) +nano::block_hash nano::ledger::latest (secure::transaction const & transaction_a, nano::account const & account_a) { auto info = account_info (transaction_a, account_a); return !info ? 0 : info->head; } // Return latest root for account, account number if there are no blocks for this account. -nano::root nano::ledger::latest_root (store::transaction const & transaction_a, nano::account const & account_a) +nano::root nano::ledger::latest_root (secure::transaction const & transaction_a, nano::account const & account_a) { auto info = account_info (transaction_a, account_a); if (!info) @@ -1088,7 +1098,7 @@ nano::root nano::ledger::latest_root (store::transaction const & transaction_a, void nano::ledger::dump_account_chain (nano::account const & account_a, std::ostream & stream) { - auto transaction (store.tx_begin_read ()); + auto transaction = tx_begin_read (); auto hash (latest (transaction, account_a)); while (!hash.is_zero ()) { @@ -1099,7 +1109,7 @@ void nano::ledger::dump_account_chain (nano::account const & account_a, std::ost } } -bool nano::ledger::dependents_confirmed (store::transaction const & transaction_a, nano::block const & block_a) const +bool nano::ledger::dependents_confirmed (secure::transaction const & transaction_a, nano::block const & block_a) const { auto dependencies (dependent_blocks (transaction_a, block_a)); return std::all_of (dependencies.begin (), dependencies.end (), [this, &transaction_a] (nano::block_hash const & hash_a) { @@ -1120,7 +1130,7 @@ bool nano::ledger::is_epoch_link (nano::link const & link_a) const class dependent_block_visitor : public nano::block_visitor { public: - dependent_block_visitor (nano::ledger const & ledger_a, nano::store::transaction const & transaction_a) : + dependent_block_visitor (nano::ledger const & ledger_a, nano::secure::transaction const & transaction_a) : ledger (ledger_a), transaction (transaction_a), result ({ 0, 0 }) @@ -1151,14 +1161,14 @@ class dependent_block_visitor : public nano::block_visitor result[0] = block_a.hashables.previous; result[1] = block_a.hashables.link.as_block_hash (); // ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped - if (ledger.is_epoch_link (block_a.hashables.link) || is_send (transaction, block_a)) + if (ledger.is_epoch_link (block_a.hashables.link) || is_send (block_a)) { result[1].clear (); } } // This function is used in place of block->is_send () as it is tolerant to the block not having the sideband information loaded // This is needed for instance in vote generation on forks which have not yet had sideband information attached - bool is_send (nano::store::transaction const & transaction, nano::state_block const & block) const + bool is_send (nano::state_block const & block) const { if (block.previous ().is_zero ()) { @@ -1171,11 +1181,11 @@ class dependent_block_visitor : public nano::block_visitor return block.balance_field ().value () < ledger.balance (transaction, block.previous ()); } nano::ledger const & ledger; - nano::store::transaction const & transaction; + nano::secure::transaction const & transaction; std::array result; }; -std::array nano::ledger::dependent_blocks (store::transaction const & transaction_a, nano::block const & block_a) const +std::array nano::ledger::dependent_blocks (secure::transaction const & transaction_a, nano::block const & block_a) const { dependent_block_visitor visitor (*this, transaction_a); block_a.visit (visitor); @@ -1186,7 +1196,7 @@ std::array nano::ledger::dependent_blocks (store::transacti * The send block hash is not checked in any way, it is assumed to be correct. * @return Return the receive block on success and null on failure */ -std::shared_ptr nano::ledger::find_receive_block_by_send_hash (store::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash) +std::shared_ptr nano::ledger::find_receive_block_by_send_hash (secure::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash) { std::shared_ptr result; debug_assert (send_block_hash != 0); @@ -1225,7 +1235,7 @@ nano::link const & nano::ledger::epoch_link (nano::epoch epoch_a) const return constants.epochs.link (epoch_a); } -void nano::ledger::update_account (store::write_transaction const & transaction_a, nano::account const & account_a, nano::account_info const & old_a, nano::account_info const & new_a) +void nano::ledger::update_account (secure::write_transaction const & transaction_a, nano::account const & account_a, nano::account_info const & old_a, nano::account_info const & new_a) { if (!new_a.head.is_zero ()) { @@ -1249,7 +1259,7 @@ void nano::ledger::update_account (store::write_transaction const & transaction_ } } -std::optional nano::ledger::successor (store::transaction const & transaction_a, nano::qualified_root const & root_a) const noexcept +std::optional nano::ledger::successor (secure::transaction const & transaction_a, nano::qualified_root const & root_a) const noexcept { if (!root_a.previous ().is_zero ()) { @@ -1269,12 +1279,12 @@ std::optional nano::ledger::successor (store::transaction cons } } -std::optional nano::ledger::successor (store::transaction const & transaction, nano::block_hash const & hash) const noexcept +std::optional nano::ledger::successor (secure::transaction const & transaction, nano::block_hash const & hash) const noexcept { return successor (transaction, { hash, hash }); } -std::shared_ptr nano::ledger::forked_block (store::transaction const & transaction_a, nano::block const & block_a) +std::shared_ptr nano::ledger::forked_block (secure::transaction const & transaction_a, nano::block const & block_a) { debug_assert (!block_exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); @@ -1295,7 +1305,7 @@ std::shared_ptr nano::ledger::forked_block (store::transaction cons return result; } -std::shared_ptr nano::ledger::head_block (store::transaction const & transaction, nano::account const & account) +std::shared_ptr nano::ledger::head_block (secure::transaction const & transaction, nano::account const & account) { auto info = store.account.get (transaction, account); if (info) @@ -1305,7 +1315,7 @@ std::shared_ptr nano::ledger::head_block (store::transaction const return nullptr; } -bool nano::ledger::block_confirmed (store::transaction const & transaction_a, nano::block_hash const & hash_a) const +bool nano::ledger::block_confirmed (secure::transaction const & transaction_a, nano::block_hash const & hash_a) const { if (store.pruned.exists (transaction_a, hash_a)) { @@ -1322,7 +1332,7 @@ bool nano::ledger::block_confirmed (store::transaction const & transaction_a, na return false; } -uint64_t nano::ledger::pruning_action (store::write_transaction & transaction_a, nano::block_hash const & hash_a, uint64_t const batch_size_a) +uint64_t nano::ledger::pruning_action (secure::write_transaction & transaction_a, nano::block_hash const & hash_a, uint64_t const batch_size_a) { uint64_t pruned_count (0); nano::block_hash hash (hash_a); @@ -1503,7 +1513,7 @@ nano::epoch nano::ledger::version (nano::block const & block) return nano::epoch::epoch_0; } -nano::epoch nano::ledger::version (store::transaction const & transaction, nano::block_hash const & hash) const +nano::epoch nano::ledger::version (secure::transaction const & transaction, nano::block_hash const & hash) const { auto block_l = block (transaction, hash); if (block_l == nullptr) @@ -1513,19 +1523,19 @@ nano::epoch nano::ledger::version (store::transaction const & transaction, nano: return version (*block_l); } -uint64_t nano::ledger::height (store::transaction const & transaction, nano::block_hash const & hash) const +uint64_t nano::ledger::height (secure::transaction const & transaction, nano::block_hash const & hash) const { auto block_l = block (transaction, hash); return block_l->sideband ().height; } -bool nano::ledger::receivable_any (store::transaction const & tx, nano::account const & account) const +bool nano::ledger::receivable_any (secure::transaction const & tx, nano::account const & account) const { auto next = receivable_upper_bound (tx, account, 0); return next != receivable_end (); } -std::optional> nano::ledger::receivable_lower_bound (store::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const +std::optional> nano::ledger::receivable_lower_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const { auto result = store.pending.begin (tx, { account, hash }); if (result == store.pending.end ()) @@ -1540,12 +1550,12 @@ nano::receivable_iterator nano::ledger::receivable_end () const return nano::receivable_iterator{}; } -nano::receivable_iterator nano::ledger::receivable_upper_bound (store::transaction const & tx, nano::account const & account) const +nano::receivable_iterator nano::ledger::receivable_upper_bound (secure::transaction const & tx, nano::account const & account) const { return receivable_iterator{ *this, tx, receivable_lower_bound (tx, account.number () + 1, 0) }; } -nano::receivable_iterator nano::ledger::receivable_upper_bound (store::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const +nano::receivable_iterator nano::ledger::receivable_upper_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const { auto result = receivable_lower_bound (tx, account, hash.number () + 1); if (!result || result.value ().first.account != account) diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index a3e7f127a3..465b029eac 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -13,8 +14,6 @@ namespace nano::store { class component; -class transaction; -class write_transaction; } namespace nano @@ -33,66 +32,71 @@ class ledger final public: ledger (nano::store::component &, nano::stats &, nano::ledger_constants & constants, nano::generate_cache_flags const & = nano::generate_cache_flags{}, nano::uint128_t min_rep_weight_a = 0); + + /** Start read-write transaction */ + secure::write_transaction tx_begin_write (std::vector const & tables_to_lock = {}, std::vector const & tables_no_lock = {}) const; + /** Start read-only transaction */ + secure::read_transaction tx_begin_read () const; /** * Returns the account for a given hash * Returns std::nullopt if the block doesn't exist or has been pruned */ - std::optional account (store::transaction const &, nano::block_hash const &) const; - std::optional account_info (store::transaction const & transaction, nano::account const & account) const; - std::optional amount (store::transaction const &, nano::block_hash const &); - std::optional balance (store::transaction const &, nano::block_hash const &) const; - std::shared_ptr block (store::transaction const & transaction, nano::block_hash const & hash) const; - bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const; - nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false); - nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false); + std::optional account (secure::transaction const &, nano::block_hash const &) const; + std::optional account_info (secure::transaction const & transaction, nano::account const & account) const; + std::optional amount (secure::transaction const &, nano::block_hash const &); + std::optional balance (secure::transaction const &, nano::block_hash const &) const; + std::shared_ptr block (secure::transaction const & transaction, nano::block_hash const & hash) const; + bool block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const; + nano::uint128_t account_balance (secure::transaction const &, nano::account const &, bool = false) const; + nano::uint128_t account_receivable (secure::transaction const &, nano::account const &, bool = false); /** * Returns the cached vote weight for the given representative. * If the weight is below the cache limit it returns 0. * During bootstrap it returns the preconfigured bootstrap weights. */ nano::uint128_t weight (nano::account const &) const; - std::optional successor (store::transaction const &, nano::qualified_root const &) const noexcept; - std::optional successor (store::transaction const & transaction, nano::block_hash const & hash) const noexcept; + std::optional successor (secure::transaction const &, nano::qualified_root const &) const noexcept; + std::optional successor (secure::transaction const & transaction, nano::block_hash const & hash) const noexcept; /* Returns the exact vote weight for the given representative by doing a database lookup */ - nano::uint128_t weight_exact (store::transaction const &, nano::account const &) const; - std::shared_ptr forked_block (store::transaction const &, nano::block const &); - std::shared_ptr head_block (store::transaction const &, nano::account const &); - bool block_confirmed (store::transaction const &, nano::block_hash const &) const; - nano::block_hash latest (store::transaction const &, nano::account const &); - nano::root latest_root (store::transaction const &, nano::account const &); - nano::block_hash representative (store::transaction const &, nano::block_hash const &); - nano::block_hash representative_calculated (store::transaction const &, nano::block_hash const &); + nano::uint128_t weight_exact (secure::transaction const &, nano::account const &) const; + std::shared_ptr forked_block (secure::transaction const &, nano::block const &); + std::shared_ptr head_block (secure::transaction const &, nano::account const &); + bool block_confirmed (secure::transaction const &, nano::block_hash const &) const; + nano::block_hash latest (secure::transaction const &, nano::account const &); + nano::root latest_root (secure::transaction const &, nano::account const &); + nano::block_hash representative (secure::transaction const &, nano::block_hash const &); + nano::block_hash representative_calculated (secure::transaction const &, nano::block_hash const &); bool block_or_pruned_exists (nano::block_hash const &) const; - bool block_or_pruned_exists (store::transaction const &, nano::block_hash const &) const; + bool block_or_pruned_exists (secure::transaction const &, nano::block_hash const &) const; std::string block_text (char const *); std::string block_text (nano::block_hash const &); - std::pair hash_root_random (store::transaction const &) const; - std::optional pending_info (store::transaction const & transaction, nano::pending_key const & key) const; - std::deque> confirm (nano::store::write_transaction const & transaction, nano::block_hash const & hash); - nano::block_status process (store::write_transaction const & transaction, std::shared_ptr block); - bool rollback (store::write_transaction const &, nano::block_hash const &, std::vector> &); - bool rollback (store::write_transaction const &, nano::block_hash const &); - void update_account (store::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &); - uint64_t pruning_action (store::write_transaction &, nano::block_hash const &, uint64_t const); + std::pair hash_root_random (secure::transaction const &) const; + std::optional pending_info (secure::transaction const & transaction, nano::pending_key const & key) const; + std::deque> confirm (secure::write_transaction const & transaction, nano::block_hash const & hash); + nano::block_status process (secure::write_transaction const & transaction, std::shared_ptr block); + bool rollback (secure::write_transaction const &, nano::block_hash const &, std::vector> &); + bool rollback (secure::write_transaction const &, nano::block_hash const &); + void update_account (secure::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &); + uint64_t pruning_action (secure::write_transaction &, nano::block_hash const &, uint64_t const); void dump_account_chain (nano::account const &, std::ostream & = std::cout); - bool dependents_confirmed (store::transaction const &, nano::block const &) const; + bool dependents_confirmed (secure::transaction const &, nano::block const &) const; bool is_epoch_link (nano::link const &) const; - std::array dependent_blocks (store::transaction const &, nano::block const &) const; - std::shared_ptr find_receive_block_by_send_hash (store::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash); + std::array dependent_blocks (secure::transaction const &, nano::block const &) const; + std::shared_ptr find_receive_block_by_send_hash (secure::transaction const & transaction, nano::account const & destination, nano::block_hash const & send_block_hash); nano::account const & epoch_signer (nano::link const &) const; nano::link const & epoch_link (nano::epoch) const; bool migrate_lmdb_to_rocksdb (std::filesystem::path const &) const; bool bootstrap_weight_reached () const; static nano::epoch version (nano::block const & block); - nano::epoch version (store::transaction const & transaction, nano::block_hash const & hash) const; - uint64_t height (store::transaction const & transaction, nano::block_hash const & hash) const; + nano::epoch version (secure::transaction const & transaction, nano::block_hash const & hash) const; + uint64_t height (secure::transaction const & transaction, nano::block_hash const & hash) const; // Returns whether there are any receivable entries for 'account' - bool receivable_any (store::transaction const & tx, nano::account const & account) const; + bool receivable_any (secure::transaction const & tx, nano::account const & account) const; nano::receivable_iterator receivable_end () const; // Returns the next receivable entry for an account greater than 'account' - nano::receivable_iterator receivable_upper_bound (store::transaction const & tx, nano::account const & account) const; + nano::receivable_iterator receivable_upper_bound (secure::transaction const & tx, nano::account const & account) const; // Returns the next receivable entry for the account 'account' with hash greater than 'hash' - nano::receivable_iterator receivable_upper_bound (store::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; + nano::receivable_iterator receivable_upper_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; std::unique_ptr collect_container_info (std::string const & name) const; uint64_t cemented_count () const; uint64_t block_count () const; @@ -110,8 +114,8 @@ class ledger final private: // Returns the next receivable entry equal or greater than 'key' - std::optional> receivable_lower_bound (store::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; + std::optional> receivable_lower_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; void initialize (nano::generate_cache_flags const &); - void confirm (nano::store::write_transaction const & transaction, nano::block const & block); + void confirm (secure::write_transaction const & transaction, nano::block const & block); }; } diff --git a/nano/secure/pending_info.cpp b/nano/secure/pending_info.cpp index 61241f2162..72c8ed3735 100644 --- a/nano/secure/pending_info.cpp +++ b/nano/secure/pending_info.cpp @@ -72,7 +72,7 @@ bool nano::pending_key::operator< (nano::pending_key const & other_a) const return account == other_a.account ? hash < other_a.hash : account < other_a.account; } -nano::receivable_iterator::receivable_iterator (nano::ledger const & ledger, nano::store::transaction const & tx, std::optional> item) : +nano::receivable_iterator::receivable_iterator (nano::ledger const & ledger, nano::secure::transaction const & tx, std::optional> item) : ledger{ &ledger }, tx{ &tx }, item{ item } diff --git a/nano/secure/pending_info.hpp b/nano/secure/pending_info.hpp index 0136da020d..30faff2d11 100644 --- a/nano/secure/pending_info.hpp +++ b/nano/secure/pending_info.hpp @@ -9,7 +9,7 @@ namespace nano class ledger; } -namespace nano::store +namespace nano::secure { class transaction; } @@ -18,6 +18,7 @@ namespace nano { /** * Information on an uncollected send + * This class captures the data stored in a pending table entry */ class pending_info final { @@ -27,10 +28,20 @@ class pending_info final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info const &) const; - nano::account source{}; - nano::amount amount{ 0 }; - nano::epoch epoch{ nano::epoch::epoch_0 }; + nano::account source{}; // the account sending the funds + nano::amount amount{ 0 }; // amount receivable in this transaction + nano::epoch epoch{ nano::epoch::epoch_0 }; // epoch of sending block, this info is stored here to make it possible to prune the send block + + friend std::ostream & operator<< (std::ostream & os, const nano::pending_info & info) + { + const int epoch = nano::normalized_epoch (info.epoch); + os << "Source: " << info.source << ", Amount: " << info.amount.to_string_dec () << " Epoch: " << epoch; + return os; + } }; + +// This class represents the data written into the pending (receivable) database table key +// the receiving account and hash of the send block identify a pending db table entry class pending_key final { public: @@ -40,15 +51,22 @@ class pending_key final bool operator== (nano::pending_key const &) const; bool operator< (nano::pending_key const &) const; nano::account const & key () const; - nano::account account{}; - nano::block_hash hash{ 0 }; + nano::account account{}; // receiving account + nano::block_hash hash{ 0 }; // hash of the send block + + friend std::ostream & operator<< (std::ostream & os, const nano::pending_key & key) + { + os << "Account: " << key.account << ", Hash: " << key.hash; + return os; + } }; + // This class iterates receivable enttries for an account class receivable_iterator { public: receivable_iterator () = default; - receivable_iterator (nano::ledger const & ledger, nano::store::transaction const & tx, std::optional> item); + receivable_iterator (nano::ledger const & ledger, nano::secure::transaction const & tx, std::optional> item); bool operator== (receivable_iterator const & other) const; bool operator!= (receivable_iterator const & other) const; // Advances to the next receivable entry for the same account @@ -58,7 +76,7 @@ class receivable_iterator private: nano::ledger const * ledger{ nullptr }; - nano::store::transaction const * tx{ nullptr }; + nano::secure::transaction const * tx{ nullptr }; nano::account account{ 0 }; std::optional> item; }; diff --git a/nano/secure/transaction.hpp b/nano/secure/transaction.hpp new file mode 100644 index 0000000000..619fdb37b4 --- /dev/null +++ b/nano/secure/transaction.hpp @@ -0,0 +1,113 @@ +#pragma once + +#include // Correct include for nano::store transaction classes + +#include // For std::move + +namespace nano::secure +{ + +class transaction +{ +public: + transaction () = default; + virtual ~transaction () = default; + + // Deleting copy and assignment operations + transaction (const transaction &) = delete; + transaction & operator= (const transaction &) = delete; + + // Default move operations + transaction (transaction &&) noexcept = default; + transaction & operator= (transaction &&) noexcept = default; + + // Pure virtual function to get a const reference to the base store transaction + virtual const nano::store::transaction & base_txn () const = 0; + + // Conversion operator to const nano::store::transaction& + virtual operator const nano::store::transaction & () const = 0; +}; + +class write_transaction : public transaction +{ + nano::store::write_transaction txn; + +public: + explicit write_transaction (nano::store::write_transaction && t) noexcept : + txn (std::move (t)) + { + } + + // Override to return a reference to the encapsulated write_transaction + const nano::store::transaction & base_txn () const override + { + return txn; + } + + void commit () + { + txn.commit (); + } + + void renew () + { + txn.renew (); + } + + void refresh () + { + txn.refresh (); + } + + // Conversion operator to const nano::store::transaction& + operator const nano::store::transaction & () const override + { + return txn; + } + + // Additional conversion operator specific to nano::store::write_transaction + operator const nano::store::write_transaction & () const + { + return txn; + } +}; + +class read_transaction : public transaction +{ + nano::store::read_transaction txn; + +public: + explicit read_transaction (nano::store::read_transaction && t) noexcept : + txn (std::move (t)) + { + } + + // Override to return a reference to the encapsulated read_transaction + const nano::store::transaction & base_txn () const override + { + return txn; + } + + void refresh () const + { + txn.refresh (); + } + + void refresh_if_needed (std::chrono::milliseconds max_age = std::chrono::milliseconds{ 500 }) const + { + txn.refresh_if_needed (max_age); + } + + // Conversion operator to const nano::store::transaction& + operator const nano::store::transaction & () const override + { + return txn; + } + + // Additional conversion operator specific to nano::store::read_transaction + operator const nano::store::read_transaction & () const + { + return txn; + } +}; +} // namespace nano::secure diff --git a/nano/secure/utility.cpp b/nano/secure/utility.cpp index 07d6472462..bec147eae1 100644 --- a/nano/secure/utility.cpp +++ b/nano/secure/utility.cpp @@ -74,16 +74,3 @@ void nano::remove_temporary_directories () } } } - -namespace nano -{ -/** A wrapper for handling signals */ -std::function signal_handler_impl; -void signal_handler (int sig) -{ - if (signal_handler_impl != nullptr) - { - signal_handler_impl (); - } -} -} diff --git a/nano/secure/utility.hpp b/nano/secure/utility.hpp index 96f93d6edd..8cd446c90a 100644 --- a/nano/secure/utility.hpp +++ b/nano/secure/utility.hpp @@ -13,7 +13,4 @@ std::filesystem::path working_path (nano::networks network = nano::network_const std::filesystem::path unique_path (nano::networks network = nano::network_constants::active_network); // Remove all unique tmp directories created by the process void remove_temporary_directories (); -// Generic signal handler declarations -extern std::function signal_handler_impl; -void signal_handler (int sig); } diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index a1a1230831..fe22bb3868 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -103,7 +103,7 @@ TEST (system, receive_while_synchronizing) ASSERT_NE (nullptr, nano::test::establish_tcp (system, *node1, node->network.endpoint ())); node1->workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::milliseconds (200), ([&system, &key] () { auto hash (system.wallet (0)->send_sync (nano::dev::genesis_key.pub, key.pub, system.nodes[0]->config.receive_minimum.number ())); - auto transaction (system.nodes[0]->store.tx_begin_read ()); + auto transaction = system.nodes[0]->ledger.tx_begin_read (); auto block = system.nodes[0]->ledger.block (transaction, hash); std::string block_text; block->serialize_json (block_text); @@ -126,7 +126,7 @@ TEST (ledger, deep_account_compute) ASSERT_FALSE (store->init_error ()); nano::stats stats; nano::ledger ledger (*store, stats, nano::dev::constants); - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key; @@ -648,7 +648,7 @@ TEST (confirmation_height, many_accounts_single_confirmation) nano::block_builder builder; auto last_open_hash = node->latest (nano::dev::genesis_key.pub); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); for (auto i = num_accounts - 1; i > 0; --i) { nano::keypair key; @@ -687,7 +687,7 @@ TEST (confirmation_height, many_accounts_single_confirmation) election->force_confirm (); } - ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->store.tx_begin_read (), last_open_hash)); + ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), last_open_hash)); // All frontiers (except last) should have 2 blocks and both should be confirmed auto transaction = node->store.tx_begin_read (); @@ -731,7 +731,7 @@ TEST (confirmation_height, many_accounts_many_confirmations) nano::block_builder builder; std::vector> open_blocks; { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); for (auto i = num_accounts - 1; i > 0; --i) { nano::keypair key; @@ -825,7 +825,7 @@ TEST (confirmation_height, long_chains) .work (*system.work.generate (key1.pub)) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, open)); } @@ -834,7 +834,7 @@ TEST (confirmation_height, long_chains) auto previous_genesis_chain_hash = send->hash (); auto previous_destination_chain_hash = open->hash (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); for (auto i = num_blocks - 1; i > 0; --i) { auto send = builder @@ -894,7 +894,7 @@ TEST (confirmation_height, long_chains) .build (); { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, receive1)); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send2)); @@ -908,9 +908,9 @@ TEST (confirmation_height, long_chains) election->force_confirm (); } - ASSERT_TIMELY (30s, node->ledger.block_confirmed (node->store.tx_begin_read (), receive1->hash ())); + ASSERT_TIMELY (30s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), receive1->hash ())); - auto transaction (node->store.tx_begin_read ()); + auto transaction = node->ledger.tx_begin_read (); auto info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info); nano::confirmation_height_info confirmation_height_info; @@ -967,7 +967,7 @@ TEST (confirmation_height, dynamic_algorithm) state_blocks.push_back (send); } { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); for (auto const & block : state_blocks) { ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, block)); @@ -1009,7 +1009,7 @@ TEST (confirmation_height, many_accounts_send_receive_self) nano::block_builder builder; std::vector> open_blocks; { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); for (auto i = 0; i < num_accounts; ++i) { nano::keypair key; @@ -1155,7 +1155,7 @@ TEST (confirmation_height, many_accounts_send_receive_self_no_elections) nano::test::system system; { - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); // Send from genesis account to all other accounts and create open block for them @@ -1203,7 +1203,7 @@ TEST (confirmation_height, many_accounts_send_receive_self_no_elections) // Now add all send/receive blocks { - auto transaction (store->tx_begin_write ()); + auto transaction = ledger.tx_begin_write (); for (int i = 0; i < open_blocks.size (); ++i) { auto open_block = open_blocks[i]; @@ -1595,7 +1595,7 @@ TEST (telemetry, many_nodes) .build (); for (auto node : system.nodes) { - auto transaction (node->store.tx_begin_write ()); + auto transaction = node->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send)); } @@ -1964,7 +1964,7 @@ TEST (node, aggressive_flooding) auto all_received = [&nodes_wallets] () { return std::all_of (nodes_wallets.begin (), nodes_wallets.end (), [] (auto const & node_wallet) { auto local_representative (node_wallet.second->store.representative (node_wallet.first->wallets.tx_begin_read ())); - return node_wallet.first->ledger.account_balance (node_wallet.first->store.tx_begin_read (), local_representative) > 0; + return node_wallet.first->ledger.account_balance (node_wallet.first->ledger.tx_begin_read (), local_representative) > 0; }); }; @@ -1979,7 +1979,7 @@ TEST (node, aggressive_flooding) nano::state_block_builder builder; std::shared_ptr block{}; { - auto transaction (node1.store.tx_begin_read ()); + auto transaction = node1.ledger.tx_begin_read (); block = builder.make_block () .account (nano::dev::genesis_key.pub) .representative (nano::dev::genesis_key.pub) @@ -2043,7 +2043,7 @@ TEST (node, wallet_create_block_confirm_conflicts) auto latest = nano::dev::genesis->hash (); nano::keypair key1; { - auto transaction = node->store.tx_begin_write (); + auto transaction = node->ledger.tx_begin_write (); for (auto i = num_blocks - 1; i > 0; --i) { auto send = builder @@ -2070,14 +2070,14 @@ TEST (node, wallet_create_block_confirm_conflicts) // Call block confirm on the top level send block which will confirm everything underneath on both accounts. { - auto block = node->ledger.block (node->store.tx_begin_read (), latest); + auto block = node->ledger.block (node->ledger.tx_begin_read (), latest); node->scheduler.manual.push (block); std::shared_ptr election; ASSERT_TIMELY (10s, (election = node->active.election (block->qualified_root ())) != nullptr); election->force_confirm (); } - ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->store.tx_begin_read (), latest) && node->confirming_set.size () == 0); + ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), latest) && node->confirming_set.size () == 0); done = true; t.join (); } diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index e5d2f448bc..32cde114f2 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -276,10 +276,10 @@ void nano::store::lmdb::component::upgrade_v22_to_v23 (store::write_transaction processed_accounts++; if (processed_accounts % 250000 == 0) { - logger.info (nano::log::type::lmdb, "processed {} accounts", processed_accounts); + logger.info (nano::log::type::lmdb, "Processed {} accounts", processed_accounts); } } - logger.info (nano::log::type::lmdb, "processed {} accounts", processed_accounts); + logger.info (nano::log::type::lmdb, "Processed {} accounts", processed_accounts); version.put (transaction_a, 23); logger.info (nano::log::type::lmdb, "Upgrading database from v22 to v23 completed"); } diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index 92fafe6934..c804ddeade 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -309,10 +309,10 @@ void nano::store::rocksdb::component::upgrade_v22_to_v23 (store::write_transacti processed_accounts++; if (processed_accounts % 250000 == 0) { - logger.info (nano::log::type::lmdb, "processed {} accounts", processed_accounts); + logger.info (nano::log::type::lmdb, "Processed {} accounts", processed_accounts); } } - logger.info (nano::log::type::lmdb, "processed {} accounts", processed_accounts); + logger.info (nano::log::type::lmdb, "Processed {} accounts", processed_accounts); version.put (transaction_a, 23); logger.info (nano::log::type::rocksdb, "Upgrading database from v22 to v23 completed"); } diff --git a/nano/store/write_queue.cpp b/nano/store/write_queue.cpp index cdc7f41ff8..b50809a32c 100644 --- a/nano/store/write_queue.cpp +++ b/nano/store/write_queue.cpp @@ -73,18 +73,14 @@ nano::store::write_guard nano::store::write_queue::wait (writer writer) } nano::unique_lock lk (mutex); + debug_assert (std::none_of (queue.cbegin (), queue.cend (), [writer] (auto const & item) { return item == writer; })); // Add writer to the end of the queue if it's not already waiting auto exists = std::find (queue.cbegin (), queue.cend (), writer) != queue.cend (); if (!exists) { queue.push_back (writer); } - - while (queue.front () != writer) - { - cv.wait (lk); - } - + cv.wait (lk, [&] () { return queue.front () == writer; }); return write_guard (guard_finish_callback); } diff --git a/nano/store/write_queue.hpp b/nano/store/write_queue.hpp index 674a7742bc..e01a6bf360 100644 --- a/nano/store/write_queue.hpp +++ b/nano/store/write_queue.hpp @@ -14,6 +14,8 @@ enum class writer confirmation_height, process_batch, pruning, + voting, + voting_final, testing // Used in tests to emulate a write lock }; diff --git a/nano/test_common/ledger.cpp b/nano/test_common/ledger.cpp index 3f3f21b65c..076b29c3de 100644 --- a/nano/test_common/ledger.cpp +++ b/nano/test_common/ledger.cpp @@ -10,7 +10,7 @@ nano::test::context::ledger_context::ledger_context (std::dequeinit_error ()); - auto tx = store_m->tx_begin_write (); + auto tx = ledger_m.tx_begin_write (); store_m->initialize (tx, ledger_m.cache, ledger_m.constants); for (auto const & i : blocks_m) { diff --git a/nano/test_common/network.cpp b/nano/test_common/network.cpp index 80ec2065c0..bb37ff12d7 100644 --- a/nano/test_common/network.cpp +++ b/nano/test_common/network.cpp @@ -24,11 +24,21 @@ std::shared_ptr nano::test::establish_tcp (nano::t return result; } +// TODO: merge with make_disconnected_node +std::shared_ptr nano::test::add_outer_node (nano::test::system & system_a, nano::node_config const & config_a, nano::node_flags flags_a) +{ + auto outer_node = std::make_shared (system_a.io_ctx, nano::unique_path (), config_a, system_a.work, flags_a); + outer_node->start (); + system_a.disconnected_nodes.push_back (outer_node); + return outer_node; +} + +// TODO: merge with make_disconnected_node std::shared_ptr nano::test::add_outer_node (nano::test::system & system_a, nano::node_flags flags_a) { auto outer_node = std::make_shared (system_a.io_ctx, system_a.get_available_port (), nano::unique_path (), system_a.work, flags_a); outer_node->start (); - system_a.nodes.push_back (outer_node); + system_a.disconnected_nodes.push_back (outer_node); return outer_node; } @@ -55,4 +65,4 @@ uint16_t nano::test::speculatively_choose_a_free_tcp_bind_port () acceptor.close (); return port; -} \ No newline at end of file +} diff --git a/nano/test_common/network.hpp b/nano/test_common/network.hpp index c8835139fe..db90344f56 100644 --- a/nano/test_common/network.hpp +++ b/nano/test_common/network.hpp @@ -19,6 +19,9 @@ namespace test /** Waits until a TCP connection is established and returns the TCP channel on success*/ std::shared_ptr establish_tcp (nano::test::system &, nano::node &, nano::endpoint const &); + /** Adds a node to the system without establishing connections */ + std::shared_ptr add_outer_node (nano::test::system & system, nano::node_config const & config_a, nano::node_flags = nano::node_flags ()); + /** Adds a node to the system without establishing connections */ std::shared_ptr add_outer_node (nano::test::system & system, nano::node_flags = nano::node_flags ()); diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index a736a6fa96..02a0499bb8 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -106,7 +107,7 @@ std::shared_ptr nano::test::system::add_node (nano::node_config cons auto node (std::make_shared (io_ctx, nano::unique_path (), node_config_a, work, node_flags_a, node_sequence++)); for (auto i : initialization_blocks) { - auto result = node->ledger.process (node->store.tx_begin_write (), i); + auto result = node->ledger.process (node->ledger.tx_begin_write (), i); debug_assert (result == nano::block_status::progress); } debug_assert (!node->init_error ()); @@ -201,7 +202,7 @@ std::shared_ptr nano::test::system::make_disconnected_node (std::opt auto node = std::make_shared (io_ctx, nano::unique_path (), node_config, work, flags); for (auto i : initialization_blocks) { - auto result = node->ledger.process (node->store.tx_begin_write (), i); + auto result = node->ledger.process (node->ledger.tx_begin_write (), i); debug_assert (result == nano::block_status::progress); } debug_assert (!node->init_error ()); @@ -296,7 +297,7 @@ uint64_t nano::test::system::work_generate_limited (nano::block_hash const & roo */ std::shared_ptr nano::test::upgrade_epoch (nano::work_pool & pool_a, nano::ledger & ledger_a, nano::epoch epoch_a) { - auto transaction (ledger_a.store.tx_begin_write ()); + auto transaction = ledger_a.tx_begin_write (); auto dev_genesis_key = nano::dev::genesis_key; auto account = dev_genesis_key.pub; auto latest = ledger_a.latest (transaction, account); @@ -335,22 +336,24 @@ void nano::test::system::deadline_set (std::chrono::duration std::error_code nano::test::system::poll (std::chrono::nanoseconds const & wait_time) { -#if NANO_ASIO_HANDLER_TRACKING == 0 - io_ctx->run_one_for (wait_time); -#else - nano::timer<> timer; - timer.start (); - auto count = io_ctx.poll_one (); - if (count == 0) + if constexpr (nano::asio_handler_tracking_threshold () == 0) { - std::this_thread::sleep_for (wait_time); + io_ctx->run_one_for (wait_time); } - else if (count == 1 && timer.since_start ().count () >= NANO_ASIO_HANDLER_TRACKING) + else { - auto timestamp = std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()).count (); - std::cout << (boost::format ("[%1%] io_thread held for %2%ms") % timestamp % timer.since_start ().count ()).str () << std::endl; + nano::timer<> timer; + timer.start (); + auto count = io_ctx->poll_one (); + if (count == 0) + { + std::this_thread::sleep_for (wait_time); + } + else if (count == 1 && timer.since_start ().count () >= nano::asio_handler_tracking_threshold ()) + { + logger.warn (nano::log::type::system, "Async handler processing took too long: {}ms", timer.since_start ().count ()); + } } -#endif std::error_code ec; if (std::chrono::steady_clock::now () > deadline) @@ -436,7 +439,7 @@ void nano::test::system::generate_usage_traffic (uint32_t count_a, uint32_t wait void nano::test::system::generate_rollback (nano::node & node_a, std::vector & accounts_a) { - auto transaction (node_a.store.tx_begin_write ()); + auto transaction = node_a.ledger.tx_begin_write (); debug_assert (std::numeric_limits::max () > accounts_a.size ()); auto index (random_pool::generate_word32 (0, static_cast (accounts_a.size () - 1))); auto account (accounts_a[index]); @@ -464,7 +467,7 @@ void nano::test::system::generate_receive (nano::node & node_a) { std::shared_ptr send_block; { - auto transaction (node_a.store.tx_begin_read ()); + auto transaction = node_a.ledger.tx_begin_read (); nano::account random_account; random_pool::generate_block (random_account.bytes.data (), sizeof (random_account.bytes)); auto item = node_a.ledger.receivable_upper_bound (transaction, random_account); @@ -517,7 +520,7 @@ nano::account nano::test::system::get_random_account (std::vector return result; } -nano::uint128_t nano::test::system::get_random_amount (store::transaction const & transaction_a, nano::node & node_a, nano::account const & account_a) +nano::uint128_t nano::test::system::get_random_amount (secure::transaction const & transaction_a, nano::node & node_a, nano::account const & account_a) { nano::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a)); nano::uint128_union random_amount; @@ -533,7 +536,7 @@ void nano::test::system::generate_send_existing (nano::node & node_a, std::vecto { nano::account account; random_pool::generate_block (account.bytes.data (), sizeof (account.bytes)); - auto transaction (node_a.store.tx_begin_read ()); + auto transaction = node_a.ledger.tx_begin_read (); store::iterator entry (node_a.store.account.begin (transaction, account)); if (entry == node_a.store.account.end ()) { @@ -583,7 +586,7 @@ void nano::test::system::generate_send_new (nano::node & node_a, std::vector &); - nano::uint128_t get_random_amount (store::transaction const &, nano::node &, nano::account const &); + nano::uint128_t get_random_amount (secure::transaction const &, nano::node &, nano::account const &); void generate_rollback (nano::node &, std::vector &); void generate_change_known (nano::node &, std::vector &); void generate_change_unknown (nano::node &, std::vector &); diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 0ae32d3c6f..b5dfe5c200 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ nano::account nano::test::random_account () bool nano::test::process (nano::node & node, std::vector> blocks) { - auto const transaction = node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); + auto const transaction = node.ledger.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }); for (auto & block : blocks) { auto result = node.process (transaction, block); @@ -122,7 +123,7 @@ bool nano::test::exists (nano::node & node, std::vector hashes) { - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); return std::all_of (hashes.begin (), hashes.end (), [&] (const auto & hash) { return node.ledger.block_or_pruned_exists (transaction, hash); @@ -136,7 +137,7 @@ bool nano::test::block_or_pruned_all_exists (nano::node & node, std::vector hashes) { - auto transaction = node.store.tx_begin_read (); + auto transaction = node.ledger.tx_begin_read (); return std::none_of (hashes.begin (), hashes.end (), [&] (const auto & hash) { return node.ledger.block_or_pruned_exists (transaction, hash); @@ -280,7 +281,7 @@ bool nano::test::start_elections (nano::test::system & system_a, nano::node & no nano::account_info nano::test::account_info (nano::node const & node, nano::account const & acc) { - auto const tx = node.ledger.store.tx_begin_read (); + auto const tx = node.ledger.tx_begin_read (); auto opt = node.ledger.account_info (tx, acc); if (opt.has_value ()) { @@ -291,7 +292,7 @@ nano::account_info nano::test::account_info (nano::node const & node, nano::acco uint64_t nano::test::account_height (nano::node const & node, nano::account const & acc) { - auto const tx = node.ledger.store.tx_begin_read (); + auto const tx = node.ledger.tx_begin_read (); nano::confirmation_height_info height_info; if (node.ledger.store.confirmation_height.get (tx, acc, height_info)) { @@ -300,20 +301,33 @@ uint64_t nano::test::account_height (nano::node const & node, nano::account cons return height_info.height; } -void nano::test::print_all_account_info (nano::node & node) +void nano::test::print_all_receivable_entries (const nano::store::component & store) +{ + std::cout << "Printing all receivable entries:\n"; + auto const tx = store.tx_begin_read (); + auto const end = store.pending.end (); + for (auto i = store.pending.begin (tx); i != end; ++i) + { + std::cout << "Key: " << i->first << std::endl; + std::cout << "Info: " << i->second << std::endl; + } +} + +void nano::test::print_all_account_info (const nano::ledger & ledger) { - auto const tx = node.ledger.store.tx_begin_read (); - auto const end = node.ledger.store.account.end (); - for (auto i = node.ledger.store.account.begin (tx); i != end; ++i) + std::cout << "Printing all account info:\n"; + auto const tx = ledger.tx_begin_read (); + auto const end = ledger.store.account.end (); + for (auto i = ledger.store.account.begin (tx); i != end; ++i) { nano::account acc = i->first; nano::account_info acc_info = i->second; nano::confirmation_height_info height_info; std::cout << "Account: " << acc.to_account () << std::endl; std::cout << " Unconfirmed Balance: " << acc_info.balance.to_string_dec () << std::endl; - std::cout << " Confirmed Balance: " << node.ledger.account_balance (tx, acc, true) << std::endl; + std::cout << " Confirmed Balance: " << ledger.account_balance (tx, acc, true) << std::endl; std::cout << " Block Count: " << acc_info.block_count << std::endl; - if (!node.ledger.store.confirmation_height.get (tx, acc, height_info)) + if (!ledger.store.confirmation_height.get (tx, acc, height_info)) { std::cout << " Conf. Height: " << height_info.height << std::endl; std::cout << " Conf. Frontier: " << height_info.frontier.to_string () << std::endl; @@ -321,11 +335,11 @@ void nano::test::print_all_account_info (nano::node & node) } } -void nano::test::print_all_blocks (nano::node & node) +void nano::test::print_all_blocks (const nano::store::component & store) { - auto tx = node.store.tx_begin_read (); - auto i = node.store.block.begin (tx); - auto end = node.store.block.end (); + auto tx = store.tx_begin_read (); + auto i = store.block.begin (tx); + auto end = store.block.end (); std::cout << "Listing all blocks" << std::endl; for (; i != end; ++i) { diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 01bc60d042..77c848d8fb 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -169,6 +169,7 @@ class network_params; class vote; class block; class election; +class ledger; extern nano::uint128_t const & genesis_amount; @@ -418,14 +419,19 @@ namespace test uint64_t account_height (nano::node const & node, nano::account const & acc); /** - * \brief Debugging function to print all accounts in a ledger. Intented to be used to debug unit tests. + * \brief Debugging function to print all entries in the pending table. Intended to be used to debug unit tests. */ - void print_all_account_info (nano::node & node); + void print_all_receivable_entries (const nano::store::component & store); /** - * \brief Debugging function to print all blocks in a node. Intented to be used to debug unit tests. + * \brief Debugging function to print all accounts in a ledger. Intended to be used to debug unit tests. */ - void print_all_blocks (nano::node & node); + void print_all_account_info (const nano::ledger & ledger); + + /** + * \brief Debugging function to print all blocks in a node. Intended to be used to debug unit tests. + */ + void print_all_blocks (const nano::store::component & store); /** * Returns all blocks in the ledger diff --git a/systest/.gitignore b/systest/.gitignore deleted file mode 100644 index 72d072bebc..0000000000 --- a/systest/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/data.systest diff --git a/systest/cli_wallet_create.sh b/systest/cli_wallet_create.sh index 45aecc851f..d4f125c02c 100755 --- a/systest/cli_wallet_create.sh +++ b/systest/cli_wallet_create.sh @@ -1,26 +1,10 @@ -#!/bin/sh +#!/bin/bash +set -eux -set -e -x - -DATADIR=data.systest +DATADIR=$(mktemp -d) SEED=CEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEED -# the caller should set the env var NANO_NODE_EXE to point to the nano_node executable -# if NANO_NODE_EXE is unser ot empty then "../../build/nano_node" is used -NANO_NODE_EXE=${NANO_NODE_EXE:-../../build/nano_node} - -clean_data_dir() { - rm -f $DATADIR/log/log_*.log - rm -f $DATADIR/wallets.ldb* - rm -f $DATADIR/data.ldb* - rm -f $DATADIR/config-*.toml - rm -rf "$DATADIR"/rocksdb/ -} - -mkdir -p $DATADIR/log -clean_data_dir - # initialise data directory $NANO_NODE_EXE --initialize --data_path $DATADIR @@ -34,5 +18,4 @@ $NANO_NODE_EXE --wallet_decrypt_unsafe --wallet $wallet_id --data_path $DATADIR $NANO_NODE_EXE --wallet_list --data_path $DATADIR | grep -q "Wallet ID: $wallet_id" # if it got this far then it is a pass -echo $0: PASSED exit 0 diff --git a/systest/daemon_interrupt.sh b/systest/daemon_interrupt.sh new file mode 100755 index 0000000000..ec17244a8f --- /dev/null +++ b/systest/daemon_interrupt.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -eux + +DATADIR=$(mktemp -d) + +# Start the node in daemon mode in the background +$NANO_NODE_EXE --daemon --network dev --data_path $DATADIR & +NODE_PID=$! + +# Allow some time for the node to start up completely +sleep 10 + +# Send an interrupt signal to the node process +kill -SIGINT $NODE_PID + +# Check if the process has stopped using a timeout to avoid infinite waiting +if wait $NODE_PID; then + echo "Node stopped successfully" +else + echo "Node did not stop as expected" + exit 1 +fi diff --git a/systest/node_initialize.sh b/systest/node_initialize.sh index 70e98f3598..9d1faf6536 100755 --- a/systest/node_initialize.sh +++ b/systest/node_initialize.sh @@ -1,28 +1,13 @@ -#!/bin/sh +#!/bin/bash +set -eux -set -e - -DATADIR=data.systest - -# the caller should set the env var NANO_NODE_EXE to point to the nano_node executable -# if NANO_NODE_EXE is unser ot empty then "../../build/nano_node" is used -NANO_NODE_EXE=${NANO_NODE_EXE:-../../build/nano_node} - -clean_data_dir() { - rm -f "$DATADIR"/log/log_*.log - rm -f "$DATADIR"/wallets.ldb* - rm -f "$DATADIR"/data.ldb* - rm -f "$DATADIR"/config-*.toml - rm -rf "$DATADIR"/rocksdb/ -} - -test_initialize_cmd() { +test_cmd() { netmatch="$1" netcmd="$2" netarg="$3" genesishash="$4" - clean_data_dir + DATADIR=$(mktemp -d) # initialise data directory $NANO_NODE_EXE --initialize --data_path "$DATADIR" "$netcmd" "$netarg" @@ -37,13 +22,9 @@ test_initialize_cmd() { $NANO_NODE_EXE --debug_block_dump --data_path "$DATADIR" "$netcmd" "$netarg" | head -n 1 | grep -qi "$genesishash" } -mkdir -p "$DATADIR/log" - -#test_initialize_cmd "live" "" "" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948" -test_initialize_cmd "live" "--network" "live" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948" -test_initialize_cmd "beta" "--network" "beta" "E1227CF974C1455A8B630433D94F3DDBF495EEAC9ADD2481A4A1D90A0D00F488" -test_initialize_cmd "test" "--network" "test" "B1D60C0B886B57401EF5A1DAA04340E53726AA6F4D706C085706F31BBD100CEE" +test_cmd "live" "--network" "live" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948" +test_cmd "beta" "--network" "beta" "E1227CF974C1455A8B630433D94F3DDBF495EEAC9ADD2481A4A1D90A0D00F488" +test_cmd "test" "--network" "test" "B1D60C0B886B57401EF5A1DAA04340E53726AA6F4D706C085706F31BBD100CEE" # if it got this far then it is a pass -echo $0: PASSED exit 0