├── .clang-format ├── .github ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── feature-request.yml │ └── node-issue.yml ├── actions │ └── restore-git-mtimes │ │ └── action.yml └── workflows │ ├── analyzers.yml │ ├── build_deploy.yml │ ├── changelog.yml │ ├── code_sanitizers.yml │ ├── coverage.yml │ ├── flamegraphs.yml │ ├── prepare_release.yml │ └── unit_tests.yml ├── .gitignore ├── .gitlab-ci.yml ├── .gitmodules ├── CL ├── cl.h ├── cl.hpp ├── cl2.hpp ├── cl_d3d10.h ├── cl_d3d11.h ├── cl_dx9_media_sharing.h ├── cl_egl.h ├── cl_ext.h ├── cl_gl.h ├── cl_gl_ext.h ├── cl_platform.h └── opencl.h ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Info.plist.in ├── LICENSE ├── Nano.icns ├── Nano.ico ├── Nano.rc ├── README.md ├── SECURITY.md ├── api └── flatbuffers │ └── nanoapi.fbs ├── asan_blacklist ├── asan_suppressions ├── boost_checkout_lite.sh ├── ci ├── actions │ ├── deploy.sh │ ├── dev-build-tag-gen.sh │ ├── generate_next_git_tag.sh │ ├── linux │ │ ├── docker-build.sh │ │ ├── docker-deploy-env.sh │ │ ├── docker-deploy.sh │ │ ├── docker-impl │ │ │ └── docker-common.sh │ │ ├── ghcr-deploy-env.sh │ │ ├── ghcr-deploy.sh │ │ └── install_deps.sh │ ├── osx │ │ └── install_deps.sh │ └── windows │ │ ├── build.bat │ │ ├── build.ps1 │ │ ├── configure.bat │ │ ├── deploy.ps1 │ │ ├── disable_windows_defender.ps1 │ │ ├── install_deps.ps1 │ │ ├── run.bat │ │ ├── run.ps1 │ │ └── signing.ps1 ├── build-ci.sh ├── build-deploy.sh ├── build-docker-image.sh ├── build-gitlab.sh ├── build-node.sh ├── build-rhel.sh ├── build-tests.sh ├── build.sh ├── clang-format-check.sh ├── clang-format-do.sh ├── cmake-format-check.sh ├── cmake-format-do.sh ├── code-inspector-check.sh ├── custom-timeout.sh ├── impl │ ├── clang-format.sh │ ├── cmake-format.sh │ ├── code-inspector.sh │ └── common.sh ├── prepare │ ├── linux │ │ ├── prepare-clang.sh │ │ ├── prepare-gcc.sh │ │ └── prepare.sh │ ├── macos │ │ └── prepare.sh │ └── windows │ │ ├── disable-defender.ps1 │ │ ├── install-qt.ps1 │ │ └── prepare.ps1 ├── test.sh └── tests │ ├── common.sh │ ├── run-core-tests.sh │ ├── run-flamegraph-tests.sh │ ├── run-qt-tests.sh │ ├── run-rpc-tests.sh │ ├── run-system-tests.sh │ ├── run-tests.sh │ ├── show-core-dumps.sh │ └── show-sanitizer-reports.sh ├── cmake ├── Modules │ └── CoverageTest.cmake └── legacyModules │ └── FindBoost.cmake ├── coverage └── CMakeLists.txt ├── crypto ├── blake2 │ ├── COPYING │ ├── README.md │ ├── blake2-config.h │ ├── blake2-impl.h │ ├── blake2.h │ ├── blake2b-compress-avx2.h │ ├── blake2b-load-avx2-simple.h │ ├── blake2b-load-avx2.h │ ├── blake2b-load-sse2.h │ ├── blake2b-load-sse41.h │ ├── blake2b-ref.c │ ├── blake2b-round.h │ └── blake2b.c └── ed25519-donna │ ├── CMakeLists.txt │ ├── README.md │ ├── curve25519-donna-32bit.h │ ├── curve25519-donna-64bit.h │ ├── curve25519-donna-helpers.h │ ├── curve25519-donna-sse2.h │ ├── ed25519-donna-32bit-sse2.h │ ├── ed25519-donna-32bit-tables.h │ ├── ed25519-donna-64bit-sse2.h │ ├── ed25519-donna-64bit-tables.h │ ├── ed25519-donna-64bit-x86-32bit.h │ ├── ed25519-donna-64bit-x86.h │ ├── ed25519-donna-basepoint-table.h │ ├── ed25519-donna-batchverify.h │ ├── ed25519-donna-impl-base.h │ ├── ed25519-donna-impl-sse2.h │ ├── ed25519-donna-portable-identify.h │ ├── ed25519-donna-portable.h │ ├── ed25519-donna.h │ ├── ed25519-hash-custom.h │ ├── ed25519-hash.h │ ├── ed25519-randombytes-custom.h │ ├── ed25519-randombytes.h │ ├── ed25519.c │ ├── ed25519.h │ ├── fuzz │ ├── README.md │ ├── build-nix.php │ ├── curve25519-ref10.c │ ├── curve25519-ref10.h │ ├── ed25519-donna-sse2.c │ ├── ed25519-donna.c │ ├── ed25519-donna.h │ ├── ed25519-ref10.c │ ├── ed25519-ref10.h │ ├── fuzz-curve25519.c │ └── fuzz-ed25519.c │ ├── modm-donna-32bit.h │ ├── modm-donna-64bit.h │ ├── regression.h │ ├── test-internals.c │ ├── test-ticks.h │ └── test.c ├── debian-control ├── postinst.in └── postrm.in ├── doc └── diagram │ └── .empty ├── docker ├── ci │ ├── Dockerfile-base │ ├── Dockerfile-clang │ ├── Dockerfile-gcc │ ├── Dockerfile-rhel │ └── build.sh ├── node │ ├── Dockerfile │ ├── build.sh │ ├── config │ │ ├── config-node.toml │ │ └── config-rpc.toml │ └── entry.sh └── sign │ ├── Dockerfile-signer │ ├── README.MD │ └── entry.sh ├── doxygen.config ├── doxygen └── MAIN_PAGE.md ├── etc ├── gpg │ ├── argakiig.asc │ ├── clemahieu.asc │ ├── dsiganos.asc │ ├── guilhermelawless.asc │ ├── sergiysw.asc │ ├── theohax.asc │ ├── thsfs.asc │ ├── wezrule.asc │ └── zhyatt.asc └── systemd │ ├── nanocurrency-beta.service │ ├── nanocurrency-test.service │ └── nanocurrency.service ├── images ├── attack.png ├── confirmation - complex.gif ├── confirmation - easy.gif ├── confirmation - simple.gif ├── fan.png ├── fork.gif ├── logo.svg └── transaction.gif ├── logo.png ├── nano ├── benchmarks │ ├── CMakeLists.txt │ ├── entry.cpp │ ├── ledger.cpp │ └── stats.cpp ├── boost │ ├── asio │ │ ├── basic_stream_socket.hpp │ │ ├── bind_executor.hpp │ │ ├── buffer.hpp │ │ ├── connect.hpp │ │ ├── deadline_timer.hpp │ │ ├── dispatch.hpp │ │ ├── executor_work_guard.hpp │ │ ├── io_context.hpp │ │ ├── ip │ │ │ ├── address.hpp │ │ │ ├── address_v6.hpp │ │ │ ├── network_v6.hpp │ │ │ └── tcp.hpp │ │ ├── local │ │ │ └── stream_protocol.hpp │ │ ├── post.hpp │ │ ├── read.hpp │ │ ├── spawn.hpp │ │ ├── steady_timer.hpp │ │ ├── strand.hpp │ │ ├── thread_pool.hpp │ │ └── write.hpp │ ├── beast │ │ ├── core.hpp │ │ ├── core │ │ │ └── flat_buffer.hpp │ │ ├── http.hpp │ │ ├── http │ │ │ ├── message.hpp │ │ │ └── string_body.hpp │ │ ├── version.hpp │ │ └── websocket.hpp │ ├── private │ │ └── macro_warnings.hpp │ ├── process │ │ └── child.hpp │ └── readme.txt ├── core_test │ ├── CMakeLists.txt │ ├── active_elections.cpp │ ├── assert.cpp │ ├── async.cpp │ ├── backlog.cpp │ ├── block.cpp │ ├── block_processor.cpp │ ├── block_store.cpp │ ├── bootstrap.cpp │ ├── bootstrap_frontier_scan.cpp │ ├── bootstrap_server.cpp │ ├── bucketing.cpp │ ├── cementing_set.cpp │ ├── cli.cpp │ ├── confirmation_solicitor.cpp │ ├── conflicts.cpp │ ├── difficulty.cpp │ ├── distributed_work.cpp │ ├── election.cpp │ ├── election_scheduler.cpp │ ├── entry.cpp │ ├── enums.cpp │ ├── epochs.cpp │ ├── fair_queue.cpp │ ├── fakes │ │ ├── websocket_client.hpp │ │ └── work_peer.hpp │ ├── fork_cache.cpp │ ├── ipc.cpp │ ├── ledger.cpp │ ├── ledger_confirm.cpp │ ├── ledger_priority.cpp │ ├── locks.cpp │ ├── logging.cpp │ ├── memory_pool.cpp │ ├── message.cpp │ ├── message_deserializer.cpp │ ├── network.cpp │ ├── network_filter.cpp │ ├── network_functions.cpp │ ├── node.cpp │ ├── numbers.cpp │ ├── object_stream.cpp │ ├── observer_set.cpp │ ├── online_reps.cpp │ ├── optimistic_scheduler.cpp │ ├── peer_container.cpp │ ├── peer_history.cpp │ ├── processing_queue.cpp │ ├── processor_service.cpp │ ├── random.cpp │ ├── random_pool.cpp │ ├── rate_limiting.cpp │ ├── receivable.cpp │ ├── rep_crawler.cpp │ ├── rep_weight_store.cpp │ ├── request_aggregator.cpp │ ├── scheduler_buckets.cpp │ ├── signal_manager.cpp │ ├── socket.cpp │ ├── stacktrace.cpp │ ├── stats.cpp │ ├── system.cpp │ ├── tcp_listener.cpp │ ├── telemetry.cpp │ ├── thread_pool.cpp │ ├── throttle.cpp │ ├── timer.cpp │ ├── toml.cpp │ ├── unchecked_map.cpp │ ├── utility.cpp │ ├── vote_cache.cpp │ ├── vote_processor.cpp │ ├── vote_rebroadcaster.cpp │ ├── voting.cpp │ ├── wallet.cpp │ ├── wallets.cpp │ ├── websocket.cpp │ └── work_pool.cpp ├── crypto │ ├── blake2 │ │ └── blake2.h │ └── readme.txt ├── crypto_lib │ ├── CMakeLists.txt │ ├── interface.cpp │ ├── random_pool.cpp │ ├── random_pool.hpp │ ├── random_pool_shuffle.hpp │ ├── secure_memory.cpp │ └── secure_memory.hpp ├── fuzzer_test │ ├── CMakeLists.txt │ ├── fuzz_bignum.cpp │ ├── fuzz_buffer.cpp │ └── fuzz_endpoint_parsing.cpp ├── ipc_flatbuffers_lib │ ├── CMakeLists.txt │ ├── flatbuffer_producer.cpp │ └── flatbuffer_producer.hpp ├── ipc_flatbuffers_test │ ├── CMakeLists.txt │ └── entry.cpp ├── lib │ ├── CMakeLists.txt │ ├── asio.cpp │ ├── asio.hpp │ ├── assert.cpp │ ├── assert.hpp │ ├── async.hpp │ ├── block_sideband.cpp │ ├── block_sideband.hpp │ ├── block_type.cpp │ ├── block_type.hpp │ ├── block_uniquer.hpp │ ├── blockbuilders.cpp │ ├── blockbuilders.hpp │ ├── blocks.cpp │ ├── blocks.hpp │ ├── char_traits.hpp │ ├── cli.cpp │ ├── cli.hpp │ ├── common.hpp │ ├── config.cpp │ ├── config.hpp │ ├── configbase.hpp │ ├── constants.cpp │ ├── constants.hpp │ ├── container_info.cpp │ ├── container_info.hpp │ ├── diagnosticsconfig.cpp │ ├── diagnosticsconfig.hpp │ ├── enum_util.hpp │ ├── env.cpp │ ├── env.hpp │ ├── epoch.cpp │ ├── epoch.hpp │ ├── epochs.cpp │ ├── epochs.hpp │ ├── errors.cpp │ ├── errors.hpp │ ├── files.cpp │ ├── files.hpp │ ├── formatting.cpp │ ├── formatting.hpp │ ├── function.hpp │ ├── fwd.hpp │ ├── id_dispenser.hpp │ ├── interval.hpp │ ├── ipc.cpp │ ├── ipc.hpp │ ├── ipc_client.cpp │ ├── ipc_client.hpp │ ├── json_error_response.hpp │ ├── jsonconfig.cpp │ ├── jsonconfig.hpp │ ├── lmdbconfig.cpp │ ├── lmdbconfig.hpp │ ├── locks.cpp │ ├── locks.hpp │ ├── logging.cpp │ ├── logging.hpp │ ├── logging_enums.cpp │ ├── logging_enums.hpp │ ├── memory.cpp │ ├── memory.hpp │ ├── network_filter.cpp │ ├── network_filter.hpp │ ├── numbers.cpp │ ├── numbers.hpp │ ├── numbers_templ.hpp │ ├── object_stream.cpp │ ├── object_stream.hpp │ ├── object_stream_adapters.hpp │ ├── observer_set.hpp │ ├── optional_ptr.hpp │ ├── plat │ │ ├── darwin │ │ │ └── thread_role.cpp │ │ ├── default │ │ │ ├── debugging.cpp │ │ │ └── priority.cpp │ │ ├── freebsd │ │ │ └── thread_role.cpp │ │ ├── linux │ │ │ ├── debugging.cpp │ │ │ ├── priority.cpp │ │ │ └── thread_role.cpp │ │ ├── posix │ │ │ └── perms.cpp │ │ └── windows │ │ │ ├── perms.cpp │ │ │ ├── priority.cpp │ │ │ ├── registry.cpp │ │ │ └── thread_role.cpp │ ├── processing_queue.hpp │ ├── random.hpp │ ├── rate_limiting.cpp │ ├── rate_limiting.hpp │ ├── relaxed_atomic.hpp │ ├── rocksdbconfig.cpp │ ├── rocksdbconfig.hpp │ ├── rpc_handler_interface.hpp │ ├── rpcconfig.cpp │ ├── rpcconfig.hpp │ ├── signal_manager.cpp │ ├── signal_manager.hpp │ ├── stacktrace.cpp │ ├── stacktrace.hpp │ ├── stats.cpp │ ├── stats.hpp │ ├── stats_enums.cpp │ ├── stats_enums.hpp │ ├── stats_sinks.hpp │ ├── stream.hpp │ ├── thread_pool.hpp │ ├── thread_roles.cpp │ ├── thread_roles.hpp │ ├── thread_runner.cpp │ ├── thread_runner.hpp │ ├── threading.cpp │ ├── threading.hpp │ ├── timer.cpp │ ├── timer.hpp │ ├── tomlconfig.cpp │ ├── tomlconfig.hpp │ ├── uniquer.hpp │ ├── utility.cpp │ ├── utility.hpp │ ├── walletconfig.cpp │ ├── walletconfig.hpp │ ├── work.cpp │ ├── work.hpp │ └── work_version.hpp ├── load_test │ ├── CMakeLists.txt │ └── entry.cpp ├── nano_node │ ├── CMakeLists.txt │ ├── daemon.cpp │ ├── daemon.hpp │ └── entry.cpp ├── nano_rpc │ ├── CMakeLists.txt │ └── entry.cpp ├── nano_wallet │ ├── .DS_Store │ ├── entry.cpp │ ├── entry_com.cpp │ ├── icon.hpp │ └── plat │ │ ├── default │ │ └── icon.cpp │ │ └── windows │ │ └── icon.cpp ├── node │ ├── CMakeLists.txt │ ├── active_elections.cpp │ ├── active_elections.hpp │ ├── backlog_scan.cpp │ ├── backlog_scan.hpp │ ├── bandwidth_limiter.cpp │ ├── bandwidth_limiter.hpp │ ├── block_context.hpp │ ├── block_processor.cpp │ ├── block_processor.hpp │ ├── block_source.cpp │ ├── block_source.hpp │ ├── bootstrap │ │ ├── account_sets.cpp │ │ ├── account_sets.hpp │ │ ├── bootstrap_config.cpp │ │ ├── bootstrap_config.hpp │ │ ├── bootstrap_server.cpp │ │ ├── bootstrap_server.hpp │ │ ├── bootstrap_service.cpp │ │ ├── bootstrap_service.hpp │ │ ├── common.hpp │ │ ├── crawlers.hpp │ │ ├── database_scan.cpp │ │ ├── database_scan.hpp │ │ ├── frontier_scan.cpp │ │ ├── frontier_scan.hpp │ │ ├── peer_scoring.cpp │ │ ├── peer_scoring.hpp │ │ ├── throttle.cpp │ │ └── throttle.hpp │ ├── bootstrap_weights_beta.hpp │ ├── bootstrap_weights_live.hpp │ ├── bounded_backlog.cpp │ ├── bounded_backlog.hpp │ ├── bucketing.cpp │ ├── bucketing.hpp │ ├── cementing_set.cpp │ ├── cementing_set.hpp │ ├── cli.cpp │ ├── cli.hpp │ ├── confirmation_solicitor.cpp │ ├── confirmation_solicitor.hpp │ ├── daemonconfig.cpp │ ├── daemonconfig.hpp │ ├── distributed_work.cpp │ ├── distributed_work.hpp │ ├── distributed_work_factory.cpp │ ├── distributed_work_factory.hpp │ ├── election.cpp │ ├── election.hpp │ ├── election_behavior.hpp │ ├── election_insertion_result.hpp │ ├── election_status.hpp │ ├── endpoint.cpp │ ├── endpoint.hpp │ ├── endpoint_templ.hpp │ ├── epoch_upgrader.cpp │ ├── epoch_upgrader.hpp │ ├── fair_queue.hpp │ ├── fork_cache.cpp │ ├── fork_cache.hpp │ ├── fwd.hpp │ ├── inactive_node.cpp │ ├── inactive_node.hpp │ ├── ipc │ │ ├── action_handler.cpp │ │ ├── action_handler.hpp │ │ ├── flatbuffers_handler.cpp │ │ ├── flatbuffers_handler.hpp │ │ ├── flatbuffers_util.cpp │ │ ├── flatbuffers_util.hpp │ │ ├── ipc_access_config.cpp │ │ ├── ipc_access_config.hpp │ │ ├── ipc_broker.cpp │ │ ├── ipc_broker.hpp │ │ ├── ipc_config.cpp │ │ ├── ipc_config.hpp │ │ ├── ipc_server.cpp │ │ └── ipc_server.hpp │ ├── json_handler.cpp │ ├── json_handler.hpp │ ├── ledger_notifications.cpp │ ├── ledger_notifications.hpp │ ├── local_block_broadcaster.cpp │ ├── local_block_broadcaster.hpp │ ├── local_vote_history.cpp │ ├── local_vote_history.hpp │ ├── make_store.cpp │ ├── make_store.hpp │ ├── message_processor.cpp │ ├── message_processor.hpp │ ├── messages.cpp │ ├── messages.hpp │ ├── monitor.cpp │ ├── monitor.hpp │ ├── network.cpp │ ├── network.hpp │ ├── node.cpp │ ├── node.hpp │ ├── node_observers.cpp │ ├── node_observers.hpp │ ├── node_rpc_config.cpp │ ├── node_rpc_config.hpp │ ├── node_wrapper.cpp │ ├── node_wrapper.hpp │ ├── nodeconfig.cpp │ ├── nodeconfig.hpp │ ├── online_reps.cpp │ ├── online_reps.hpp │ ├── openclconfig.cpp │ ├── openclconfig.hpp │ ├── openclwork.cpp │ ├── openclwork.hpp │ ├── peer_exclusion.cpp │ ├── peer_exclusion.hpp │ ├── peer_history.cpp │ ├── peer_history.hpp │ ├── plat │ │ ├── posix │ │ │ └── openclapi.cpp │ │ └── windows │ │ │ └── openclapi.cpp │ ├── portmapping.cpp │ ├── portmapping.hpp │ ├── pruning.cpp │ ├── pruning.hpp │ ├── recently_cemented_cache.cpp │ ├── recently_cemented_cache.hpp │ ├── recently_confirmed_cache.cpp │ ├── recently_confirmed_cache.hpp │ ├── rep_tiers.cpp │ ├── rep_tiers.hpp │ ├── repcrawler.cpp │ ├── repcrawler.hpp │ ├── request_aggregator.cpp │ ├── request_aggregator.hpp │ ├── rpc_callbacks.cpp │ ├── rpc_callbacks.hpp │ ├── scheduler │ │ ├── bucket.cpp │ │ ├── bucket.hpp │ │ ├── component.cpp │ │ ├── component.hpp │ │ ├── hinted.cpp │ │ ├── hinted.hpp │ │ ├── manual.cpp │ │ ├── manual.hpp │ │ ├── optimistic.cpp │ │ ├── optimistic.hpp │ │ ├── priority.cpp │ │ └── priority.hpp │ ├── telemetry.cpp │ ├── telemetry.hpp │ ├── transport │ │ ├── block_deserializer.cpp │ │ ├── block_deserializer.hpp │ │ ├── channel.cpp │ │ ├── channel.hpp │ │ ├── common.hpp │ │ ├── fake.cpp │ │ ├── fake.hpp │ │ ├── fwd.hpp │ │ ├── inproc.cpp │ │ ├── inproc.hpp │ │ ├── loopback.cpp │ │ ├── loopback.hpp │ │ ├── message_deserializer.cpp │ │ ├── message_deserializer.hpp │ │ ├── tcp_channel.cpp │ │ ├── tcp_channel.hpp │ │ ├── tcp_channels.cpp │ │ ├── tcp_channels.hpp │ │ ├── tcp_config.cpp │ │ ├── tcp_config.hpp │ │ ├── tcp_listener.cpp │ │ ├── tcp_listener.hpp │ │ ├── tcp_server.cpp │ │ ├── tcp_server.hpp │ │ ├── tcp_socket.cpp │ │ ├── tcp_socket.hpp │ │ ├── test_channel.cpp │ │ ├── test_channel.hpp │ │ ├── traffic_type.cpp │ │ ├── traffic_type.hpp │ │ ├── transport.cpp │ │ └── transport.hpp │ ├── unchecked_map.cpp │ ├── unchecked_map.hpp │ ├── vote_cache.cpp │ ├── vote_cache.hpp │ ├── vote_generator.cpp │ ├── vote_generator.hpp │ ├── vote_processor.cpp │ ├── vote_processor.hpp │ ├── vote_rebroadcaster.cpp │ ├── vote_rebroadcaster.hpp │ ├── vote_router.cpp │ ├── vote_router.hpp │ ├── vote_spacing.cpp │ ├── vote_spacing.hpp │ ├── vote_with_weight_info.hpp │ ├── wallet.cpp │ ├── wallet.hpp │ ├── websocket.cpp │ ├── websocket.hpp │ ├── websocket_stream.cpp │ ├── websocket_stream.hpp │ ├── websocketconfig.cpp │ ├── websocketconfig.hpp │ └── xorshift.hpp ├── qt │ ├── qt.cpp │ └── qt.hpp ├── qt_test │ ├── QTest │ ├── entry.cpp │ └── qt.cpp ├── rpc │ ├── CMakeLists.txt │ ├── rpc.cpp │ ├── rpc.hpp │ ├── rpc_connection.cpp │ ├── rpc_connection.hpp │ ├── rpc_handler.cpp │ ├── rpc_handler.hpp │ ├── rpc_request_processor.cpp │ └── rpc_request_processor.hpp ├── rpc_test │ ├── CMakeLists.txt │ ├── common.cpp │ ├── common.hpp │ ├── entry.cpp │ ├── receivable.cpp │ ├── rpc.cpp │ ├── rpc_context.cpp │ ├── rpc_context.hpp │ ├── test_response.cpp │ └── test_response.hpp ├── secure │ ├── CMakeLists.txt │ ├── account_info.cpp │ ├── account_info.hpp │ ├── account_iterator.cpp │ ├── account_iterator.hpp │ ├── account_iterator_impl.hpp │ ├── common.cpp │ ├── common.hpp │ ├── fwd.hpp │ ├── generate_cache_flags.cpp │ ├── generate_cache_flags.hpp │ ├── ledger.cpp │ ├── ledger.hpp │ ├── ledger_cache.cpp │ ├── ledger_cache.hpp │ ├── ledger_set_any.cpp │ ├── ledger_set_any.hpp │ ├── ledger_set_confirmed.cpp │ ├── ledger_set_confirmed.hpp │ ├── parallel_traversal.hpp │ ├── pending_info.cpp │ ├── pending_info.hpp │ ├── plat │ │ ├── osx │ │ │ └── working.mm │ │ ├── posix │ │ │ └── working.cpp │ │ └── windows │ │ │ └── working.cpp │ ├── receivable_iterator.cpp │ ├── receivable_iterator.hpp │ ├── receivable_iterator_impl.hpp │ ├── rep_weights.cpp │ ├── rep_weights.hpp │ ├── transaction.hpp │ ├── utility.cpp │ ├── utility.hpp │ ├── vote.cpp │ ├── vote.hpp │ └── working.hpp ├── slow_test │ ├── CMakeLists.txt │ ├── bootstrap.cpp │ ├── entry.cpp │ ├── flamegraph.cpp │ ├── ledger.cpp │ ├── node.cpp │ ├── vote_cache.cpp │ └── vote_processor.cpp ├── store │ ├── CMakeLists.txt │ ├── account.cpp │ ├── account.hpp │ ├── block.cpp │ ├── block.hpp │ ├── block_w_sideband.hpp │ ├── component.cpp │ ├── component.hpp │ ├── confirmation_height.cpp │ ├── confirmation_height.hpp │ ├── db_val.cpp │ ├── db_val.hpp │ ├── db_val_impl.hpp │ ├── final_vote.cpp │ ├── final_vote.hpp │ ├── fwd.hpp │ ├── iterator.cpp │ ├── iterator.hpp │ ├── lmdb │ │ ├── account.cpp │ │ ├── account.hpp │ │ ├── block.cpp │ │ ├── block.hpp │ │ ├── confirmation_height.cpp │ │ ├── confirmation_height.hpp │ │ ├── db_val.cpp │ │ ├── db_val.hpp │ │ ├── final_vote.cpp │ │ ├── final_vote.hpp │ │ ├── iterator.cpp │ │ ├── iterator.hpp │ │ ├── lmdb.cpp │ │ ├── lmdb.hpp │ │ ├── lmdb_env.cpp │ │ ├── lmdb_env.hpp │ │ ├── online_weight.cpp │ │ ├── online_weight.hpp │ │ ├── peer.cpp │ │ ├── peer.hpp │ │ ├── pending.cpp │ │ ├── pending.hpp │ │ ├── pruned.cpp │ │ ├── pruned.hpp │ │ ├── rep_weight.cpp │ │ ├── rep_weight.hpp │ │ ├── transaction.cpp │ │ ├── transaction_impl.hpp │ │ ├── version.cpp │ │ ├── version.hpp │ │ ├── wallet_value.cpp │ │ └── wallet_value.hpp │ ├── online_weight.cpp │ ├── online_weight.hpp │ ├── peer.cpp │ ├── peer.hpp │ ├── pending.cpp │ ├── pending.hpp │ ├── pruned.cpp │ ├── pruned.hpp │ ├── rep_weight.cpp │ ├── rep_weight.hpp │ ├── reverse_iterator.hpp │ ├── reverse_iterator_templ.hpp │ ├── rocksdb │ │ ├── account.cpp │ │ ├── account.hpp │ │ ├── block.cpp │ │ ├── block.hpp │ │ ├── confirmation_height.cpp │ │ ├── confirmation_height.hpp │ │ ├── db_val.cpp │ │ ├── db_val.hpp │ │ ├── final_vote.cpp │ │ ├── final_vote.hpp │ │ ├── iterator.cpp │ │ ├── iterator.hpp │ │ ├── online_weight.cpp │ │ ├── online_weight.hpp │ │ ├── peer.cpp │ │ ├── peer.hpp │ │ ├── pending.cpp │ │ ├── pending.hpp │ │ ├── pruned.cpp │ │ ├── pruned.hpp │ │ ├── rep_weight.cpp │ │ ├── rep_weight.hpp │ │ ├── rocksdb.cpp │ │ ├── rocksdb.hpp │ │ ├── transaction.cpp │ │ ├── transaction_impl.hpp │ │ ├── utility.cpp │ │ ├── utility.hpp │ │ ├── version.cpp │ │ └── version.hpp │ ├── tables.hpp │ ├── transaction.cpp │ ├── transaction.hpp │ ├── typed_iterator.cpp │ ├── typed_iterator.hpp │ ├── typed_iterator_templ.hpp │ ├── version.cpp │ ├── version.hpp │ ├── versioning.cpp │ ├── versioning.hpp │ ├── write_queue.cpp │ └── write_queue.hpp └── test_common │ ├── CMakeLists.txt │ ├── chains.cpp │ ├── chains.hpp │ ├── ledger_context.cpp │ ├── ledger_context.hpp │ ├── make_store.cpp │ ├── make_store.hpp │ ├── network.cpp │ ├── network.hpp │ ├── rate_observer.cpp │ ├── rate_observer.hpp │ ├── system.cpp │ ├── system.hpp │ ├── telemetry.cpp │ ├── telemetry.hpp │ ├── testutil.cpp │ └── testutil.hpp ├── nanocurrency-beta.spec.in ├── nanocurrency.spec.in ├── qt.conf ├── record_rep_weights.py ├── resources.qrc ├── sanitize_ignorelist ├── sanitize_ignorelist_asan ├── sanitize_ignorelist_tsan ├── sanitize_ignorelist_ubsan ├── systest ├── RUNALL ├── cli_wallet_create.sh ├── daemon_interrupt.sh ├── node_initialize.sh ├── rpc_stop.sh └── set_bandwidth_params.sh.disabled ├── tsan_clang_blacklist ├── tsan_suppressions ├── util ├── build_prep │ ├── common.sh │ ├── macosx │ │ └── build_qt.sh │ ├── rhel │ │ └── prep.sh.in │ └── update-common ├── changelog.py ├── changelog_generator └── makesrc ├── valgrind.supp └── valgrind └── valgrind.h /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Report a security vulnerability 4 | url: https://docs.nano.org/node-implementation/contributing/#security-vulnerability-disclosure 5 | about: DO NOT SUBMIT SECURITY VULNERABILITIES IN PUBLIC REPOSITORIES - find out how to privately submit in our documentation. 6 | - name: Nano Community Forum 7 | url: https://forum.nano.org 8 | about: Ask questions, get wallet or other support, and discuss Nano with the community. 9 | 10 | -------------------------------------------------------------------------------- /.github/actions/restore-git-mtimes/action.yml: -------------------------------------------------------------------------------- 1 | name: "restore-git-mtimes" 2 | description: "Restore file modification timestamps from git commit timestamps" 3 | runs: 4 | using: "composite" 5 | steps: 6 | - uses: actions/checkout@v4 7 | with: 8 | repository: "MestreLion/git-tools" 9 | ref: a42a069bc755f0fa81316965335cb33dbf22a968 # pin latest commit 10 | path: "git-tools" 11 | - run: $GITHUB_WORKSPACE/git-tools/git-restore-mtime 12 | shell: bash 13 | - run: git submodule foreach --recursive '$GITHUB_WORKSPACE/git-tools/git-restore-mtime' 14 | shell: bash 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Doxygen built HTML 19 | /doc-build 20 | 21 | # Executables 22 | *.exe 23 | *.out 24 | *.app 25 | *.dmg 26 | *.DS_Store 27 | core_test 28 | !core_test/ 29 | rpc_test 30 | !rpc_test/ 31 | qt_test 32 | !qt_test/ 33 | nano_node 34 | !nano_node/ 35 | nano_wallet 36 | !nano_wallet/ 37 | slow_test 38 | !slow_test/ 39 | nano_rpc 40 | !nano_rpc/ 41 | 42 | # IDEs 43 | .idea 44 | .vscode 45 | *.plist 46 | 47 | # Visual Studio 48 | *.vcxproj 49 | *.vcxproj.filters 50 | *.vcxproj.user 51 | *.sln 52 | *.qrc.depends 53 | *.dir 54 | Debug 55 | Release 56 | .vs 57 | *.aps 58 | *.db 59 | *.opendb 60 | 61 | # Autogenerated Qt artifacts 62 | packaging 63 | qrc_resources.cpp 64 | resources.qrc.depends 65 | 66 | # Autogenerated Flatbuffers source files 67 | nano/ipc_flatbuffers_lib/generated/flatbuffers/nanoapi_generated.h 68 | 69 | # CMake artifacts 70 | _CPack_Packages 71 | CPack* 72 | cmake_install.cmake 73 | CMakeCache.txt 74 | CMakeFiles 75 | CMakeScripts 76 | compile_commands.json 77 | CTestTestfile.cmake 78 | install_manifest.txt 79 | Makefile 80 | Testing 81 | 82 | # Autogenerated Build Prep artifacts 83 | util/build_prep/*/prep.sh 84 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you for contributing to the nano node and protocol core development. For details on contributing, please see https://docs.nano.org/core-development/overview/, which includes: 4 | 5 | - [Security vulnerability reporting details](https://docs.nano.org/core-development/overview/#security-vulnerability-reporting) 6 | - [Collaboration process information](https://docs.nano.org/core-development/collaboration-process/) 7 | - [Code standards](https://docs.nano.org/core-development/code-standards/) 8 | - Further information to help [understand the code](https://docs.nano.org/core-development/understanding-the-code/) -------------------------------------------------------------------------------- /Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrincipalClass 6 | NSApplication 7 | NSHighResolutionCapable 8 | True 9 | CFBundleExecutable 10 | nano_wallet 11 | CFBundleName 12 | @NANO_OSX_PACKAGE_NAME@ 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleIconFile 16 | Nano.icns 17 | CFBundleIdentifier 18 | org.nano.nano_wallet 19 | CFBundleShortVersionString 20 | @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@ 21 | CFBundleVersion 22 | @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@ 23 | NSRequiresAquaSystemAppearance 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Nano.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/Nano.icns -------------------------------------------------------------------------------- /Nano.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/Nano.ico -------------------------------------------------------------------------------- /Nano.rc: -------------------------------------------------------------------------------- 1 | 1 ICON "Nano.ico" -------------------------------------------------------------------------------- /asan_blacklist: -------------------------------------------------------------------------------- 1 | src:*ed25519* -------------------------------------------------------------------------------- /asan_suppressions: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/asan_suppressions -------------------------------------------------------------------------------- /ci/actions/linux/docker-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | source "$(dirname "$BASH_SOURCE")/docker-impl/docker-common.sh" 7 | 8 | docker_build 9 | -------------------------------------------------------------------------------- /ci/actions/linux/docker-deploy-env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | source "$(dirname "$BASH_SOURCE")/docker-impl/docker-common.sh" 7 | 8 | docker_deploy_env 9 | -------------------------------------------------------------------------------- /ci/actions/linux/docker-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | source "$(dirname "$BASH_SOURCE")/docker-impl/docker-common.sh" 7 | 8 | docker_deploy 9 | -------------------------------------------------------------------------------- /ci/actions/linux/ghcr-deploy-env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | source "$(dirname "$BASH_SOURCE")/docker-impl/docker-common.sh" 7 | 8 | ghcr_deploy_env -------------------------------------------------------------------------------- /ci/actions/linux/ghcr-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | source "$(dirname "$BASH_SOURCE")/docker-impl/docker-common.sh" 7 | 8 | ghcr_deploy -------------------------------------------------------------------------------- /ci/actions/linux/install_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | DOCKER_REGISTRY="${DOCKER_REGISTRY:-nanocurrency}" 6 | 7 | echo "Script ci/actions/linux/install_deps.sh starting COMPILER=\"$COMPILER\"" 8 | 9 | # This enables IPv6 support in docker, needed to run node tests inside docker container 10 | sudo mkdir -p /etc/docker && echo '{"ipv6":true,"fixed-cidr-v6":"2001:db8:1::/64"}' | sudo tee /etc/docker/daemon.json && sudo service docker restart 11 | 12 | ci/build-docker-image.sh docker/ci/Dockerfile-base ${DOCKER_REGISTRY}/nano-env:base 13 | if [[ "${COMPILER:-}" != "" ]]; then 14 | ci/build-docker-image.sh docker/ci/Dockerfile-${COMPILER} ${DOCKER_REGISTRY}/nano-env:${COMPILER} 15 | else 16 | ci/build-docker-image.sh docker/ci/Dockerfile-gcc ${DOCKER_REGISTRY}/nano-env:gcc 17 | ci/build-docker-image.sh docker/ci/Dockerfile-clang ${DOCKER_REGISTRY}/nano-env:clang 18 | ci/build-docker-image.sh docker/ci/Dockerfile-rhel ${DOCKER_REGISTRY}/nano-env:rhel 19 | fi 20 | 21 | echo "Script ci/actions/linux/install_deps.sh finished" 22 | -------------------------------------------------------------------------------- /ci/actions/osx/install_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | brew update 4 | brew install coreutils 5 | brew cask install xquartz 6 | util/build_prep/macosx/build_qt.sh 7 | -------------------------------------------------------------------------------- /ci/actions/windows/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set exit_code=0 3 | 4 | goto %RUN% 5 | 6 | :test 7 | cmake --build . ^ 8 | --target core_test ^ 9 | --config %BUILD_TYPE% ^ 10 | -- /m:2 11 | set exit_code=%errorlevel% 12 | if %exit_code% neq 0 goto exit 13 | cmake --build . ^ 14 | --target rpc_test ^ 15 | --config %BUILD_TYPE% ^ 16 | -- /m:2 17 | set exit_code=%errorlevel% 18 | goto exit 19 | 20 | :artifact 21 | cmake --build . ^ 22 | --target INSTALL ^ 23 | --config %BUILD_TYPE% ^ 24 | -- /m:2 25 | set exit_code=%errorlevel% 26 | 27 | echo "Packaging NSIS" 28 | call "%cmake_path%\cpack.exe" -C %BUILD_TYPE% 29 | echo "Packaging ZIP" 30 | call "%cmake_path%\cpack.exe" -G ZIP -C %BUILD_TYPE% 31 | 32 | goto exit 33 | 34 | :exit 35 | exit /B %exit_code% 36 | -------------------------------------------------------------------------------- /ci/actions/windows/configure.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set exit_code=0 3 | 4 | echo "BUILD TYPE %BUILD_TYPE%" 5 | echo "RUN %RUN%" 6 | 7 | cmake .. ^ 8 | -Ax64 ^ 9 | %NANO_TEST% ^ 10 | %CI% ^ 11 | %ROCKS_LIB% ^ 12 | -DPORTABLE=1 ^ 13 | -DQt5_DIR="c:\qt\5.15.2\msvc2019_64\lib\cmake\Qt5" ^ 14 | -DNANO_GUI=ON ^ 15 | -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^ 16 | -DACTIVE_NETWORK=nano_%NETWORK_CFG%_network ^ 17 | -DNANO_SIMD_OPTIMIZATIONS=TRUE ^ 18 | -Dgtest_force_shared_crt=on 19 | 20 | set exit_code=%errorlevel% 21 | if %exit_code% neq 0 goto exit 22 | 23 | :exit 24 | exit /B %exit_code% 25 | -------------------------------------------------------------------------------- /ci/actions/windows/disable_windows_defender.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Continue" 2 | 3 | Set-MpPreference -DisableArchiveScanning $true 4 | Set-MpPreference -DisableRealtimeMonitoring $true 5 | Set-MpPreference -DisableBehaviorMonitoring $true -------------------------------------------------------------------------------- /ci/actions/windows/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | set exit_code=0 4 | 5 | call %BUILD_TYPE%\core_test.exe 6 | set core_code=%errorlevel% 7 | 8 | call %BUILD_TYPE%\rpc_test.exe 9 | set rpc_code=%errorlevel% 10 | 11 | echo Core Test return code: %core_code% 12 | echo RPC Test return code: %rpc_code% 13 | 14 | if not %core_code%==0 ( 15 | echo Core Test fail 16 | set exit_code=1 17 | ) 18 | 19 | if not %rpc_code%==0 ( 20 | echo RPC Test fail 21 | set exit_code=1 22 | ) 23 | 24 | if %exit_code%==0 ( 25 | echo Success 26 | exit /b 0 27 | ) else ( 28 | echo Failed 29 | exit /b 1 30 | ) -------------------------------------------------------------------------------- /ci/actions/windows/run.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Continue" 2 | 3 | $env:BUILD_TYPE = "Debug" 4 | $env:NETWORK_CFG = "dev" 5 | 6 | Push-Location build 7 | 8 | & ..\ci\actions\windows\run.bat 9 | if (${LastExitCode} -ne 0) { 10 | throw "Failed to Pass Tests" 11 | } 12 | 13 | Pop-Location -------------------------------------------------------------------------------- /ci/actions/windows/signing.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Continue" 2 | 3 | if (Test-Path env:CSC_LINK) { 4 | $path = Join-Path -Path "$env:TMP" -ChildPath csc.p12 5 | [IO.File]::WriteAllBytes($path, [Convert]::FromBase64String($env:CSC_LINK)) 6 | $arguments = -split 'sign /a /ph /tr http://timestamp.digicert.com /td sha256 /fd sha256' 7 | $arguments += @('/f', $path, '/p', $env:CSC_KEY_PASSWORD, "$env:BUILD_TYPE\*.exe") 8 | . "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe" $arguments 9 | } -------------------------------------------------------------------------------- /ci/build-ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | qt_dir=${1} 5 | build_target=${2:-all} 6 | 7 | OS=$(uname) 8 | 9 | source "$(dirname "$BASH_SOURCE")/impl/code-inspector.sh" 10 | code_inspect "${ROOTPATH:-.}" 11 | 12 | mkdir -p build 13 | pushd build 14 | 15 | if [[ "${RELEASE:-false}" == "true" ]]; then 16 | BUILD_TYPE="RelWithDebInfo" 17 | fi 18 | 19 | if [[ ${ASAN_INT:-0} -eq 1 ]]; then 20 | SANITIZERS="-DNANO_ASAN_INT=ON" 21 | elif [[ ${ASAN:-0} -eq 1 ]]; then 22 | SANITIZERS="-DNANO_ASAN=ON" 23 | elif [[ ${TSAN:-0} -eq 1 ]]; then 24 | SANITIZERS="-DNANO_TSAN=ON" 25 | elif [[ ${LCOV:-0} -eq 1 ]]; then 26 | SANITIZERS="-DCOVERAGE=ON" 27 | fi 28 | 29 | ulimit -S -n 8192 30 | 31 | cmake \ 32 | -G'Unix Makefiles' \ 33 | -DACTIVE_NETWORK=nano_dev_network \ 34 | -DNANO_TEST=ON \ 35 | -DNANO_GUI=ON \ 36 | -DPORTABLE=1 \ 37 | -DNANO_WARN_TO_ERR=ON \ 38 | -DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Debug} \ 39 | -DQt5_DIR=${qt_dir} \ 40 | ${SANITIZERS:-} \ 41 | .. 42 | 43 | if [[ "$OS" == 'Linux' ]]; then 44 | if [[ ${LCOV:-0} == 1 ]]; then 45 | cmake --build ${PWD} --target generate_coverage -- -j2 46 | else 47 | cmake --build ${PWD} --target ${build_target} -- -j2 48 | fi 49 | else 50 | sudo cmake --build ${PWD} --target ${build_target} -- -j2 51 | fi 52 | 53 | popd 54 | -------------------------------------------------------------------------------- /ci/build-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | qt_dir=${1} 4 | ci_version_pre_release="OFF" 5 | if [[ -n "${CI_VERSION_PRE_RELEASE}" ]]; then 6 | ci_version_pre_release="$CI_VERSION_PRE_RELEASE" 7 | fi 8 | 9 | set -o errexit 10 | set -o nounset 11 | set -o xtrace 12 | OS=$(uname) 13 | 14 | mkdir build 15 | pushd build 16 | CONFIGURATION="Release" 17 | 18 | case "${NETWORK}" in 19 | "BETA") 20 | NETWORK_CFG="beta" 21 | CONFIGURATION="RelWithDebInfo" 22 | ;; 23 | "TEST") 24 | NETWORK_CFG="test" 25 | ;; 26 | *) 27 | NETWORK_CFG="live" 28 | ;; 29 | esac 30 | 31 | cmake \ 32 | -G'Unix Makefiles' \ 33 | -DACTIVE_NETWORK=nano_${NETWORK_CFG}_network \ 34 | -DNANO_GUI=ON \ 35 | -DPORTABLE=1 \ 36 | -DCMAKE_BUILD_TYPE=${CONFIGURATION} \ 37 | -DCMAKE_VERBOSE_MAKEFILE=ON \ 38 | -DQt5_DIR=${qt_dir} \ 39 | -DCI_BUILD=true \ 40 | -DCI_VERSION_PRE_RELEASE="${ci_version_pre_release}" \ 41 | .. 42 | 43 | if [[ "$OS" == 'Linux' ]]; then 44 | cmake --build ${PWD} --target package --config ${CONFIGURATION} -- -j$(nproc) 45 | else 46 | sudo cmake --build ${PWD} --target package --config ${CONFIGURATION} -- -j2 47 | fi 48 | 49 | popd 50 | -------------------------------------------------------------------------------- /ci/build-docker-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -u -x 3 | 4 | if [ "$#" -lt 2 ]; then 5 | echo 'Usage: build-docker-image.sh [...]' >&2 6 | exit 1 7 | fi 8 | 9 | dockerFile="$1" 10 | dockerTag="$2" 11 | githubTag="ghcr.io/${GITHUB_REPOSITORY}/${dockerTag#*/}" 12 | shift 13 | shift 14 | 15 | echo "ci/build-docker-image.sh dockerFile=\"$dockerFile\" dockerTag=\"$dockerTag\" githubTag=\"$githubTag\"" 16 | 17 | scripts="$(dirname "$0")" 18 | 19 | echo "Pulling $githubTag" 20 | "$scripts"/custom-timeout.sh 20 docker pull "${githubTag}" || true 21 | 22 | echo "Building $githubTag" 23 | "$scripts"/custom-timeout.sh 60 docker build "$@" --build-arg REPOSITORY=${GITHUB_REPOSITORY} -f "${dockerFile}" -t "${githubTag}" --cache-from "${githubTag}" . 24 | 25 | echo "Tagging ${dockerTag} from ${githubTag}" 26 | docker tag $githubTag $dockerTag 27 | -------------------------------------------------------------------------------- /ci/build-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | $(dirname "$BASH_SOURCE")/build.sh executables -------------------------------------------------------------------------------- /ci/build-rhel.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | TAG=$(echo $TAG) 3 | VERSION=$(echo "${TAG}" | sed 's/V//' | sed 's/-/_/g') 4 | RPM_RELEASE=$(echo $RPM_RELEASE) 5 | REPO_TO_BUILD=$(echo $REPO_TO_BUILD) 6 | 7 | run_source() { 8 | ./util/makesrc $TAG $REPO_TO_BUILD 9 | } 10 | 11 | run_build() { 12 | mkdir -p ~/rpmbuild/SOURCES/ 13 | mv -f ~/nano-${VERSION}.tar.gz ~/rpmbuild/SOURCES/. 14 | case "${NETWORK}" in 15 | "LIVE") 16 | scl enable gcc-toolset-12 'rpmbuild --nodebuginfo -ba nanocurrency.spec' 17 | ;; 18 | "BETA") 19 | scl enable gcc-toolset-12 'rpmbuild -ba nanocurrency-beta.spec' 20 | ;; 21 | *) 22 | echo "Error: the node network was not defined." 23 | exit 1 24 | ;; 25 | esac 26 | } 27 | 28 | run_update() { 29 | for file in ./nanocurrency*.in; do 30 | outfile="${file//.in/}" 31 | 32 | echo "Updating \"${outfile}\"..." 33 | 34 | rm -f "${file}.new" 35 | awk -v srch="@VERSION@" -v repl="$VERSION" -v srch2="@RELEASE@" -v repl2="$RPM_RELEASE" '{ sub(srch,repl,$0); sub(srch2,repl2, $0); print $0}' <${file} >${file}.new 36 | rm -fr "${outfile}" 37 | cat "${file}.new" >"${outfile}" 38 | rm -f "${file}.new" 39 | chmod 755 "${outfile}" 40 | done 41 | } 42 | 43 | set -x 44 | 45 | run_update 46 | run_source 47 | run_build 48 | -------------------------------------------------------------------------------- /ci/build-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | NANO_TEST=ON \ 5 | NANO_NETWORK=dev \ 6 | NANO_GUI=ON \ 7 | $(dirname "$BASH_SOURCE")/build.sh all_tests -------------------------------------------------------------------------------- /ci/clang-format-check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | source "$(dirname "$BASH_SOURCE")/impl/common.sh" 6 | source "$(dirname "$BASH_SOURCE")/impl/clang-format.sh" 7 | 8 | ################################################################################################### 9 | 10 | does_clang_format_exist 11 | if [[ $? == 0 ]]; then 12 | clang_format_check 13 | result=$? 14 | 15 | if [[ $result == 2 ]]; then 16 | exit $result 17 | fi 18 | 19 | if [[ $result == 1 ]]; then 20 | echo "Source code formatting differs from expected - please run ci/clang-format-do.sh" 21 | exit 1 22 | fi 23 | 24 | echo "clang-format check passed" 25 | fi 26 | 27 | ################################################################################################### 28 | -------------------------------------------------------------------------------- /ci/clang-format-do.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | source "$(dirname "$BASH_SOURCE")/impl/common.sh" 6 | source "$(dirname "$BASH_SOURCE")/impl/clang-format.sh" 7 | 8 | ################################################################################################### 9 | 10 | does_clang_format_exist 11 | if [[ $? == 0 ]]; then 12 | clang_format_do 13 | fi 14 | 15 | ################################################################################################### 16 | -------------------------------------------------------------------------------- /ci/cmake-format-check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | source "$(dirname "$BASH_SOURCE")/impl/common.sh" 6 | source "$(dirname "$BASH_SOURCE")/impl/cmake-format.sh" 7 | 8 | ################################################################################################### 9 | 10 | does_cmake_format_exist 11 | if [[ $? == 0 ]]; then 12 | cmake_format_check 13 | result=$? 14 | 15 | if [[ $result == 2 ]]; then 16 | exit $result 17 | fi 18 | 19 | if [[ $result == 1 ]]; then 20 | echo "CMake formatting differs from expected - please run ci/cmake-format-do.sh" 21 | exit 1 22 | fi 23 | 24 | echo "cmake-format check passed" 25 | fi 26 | 27 | ################################################################################################### 28 | -------------------------------------------------------------------------------- /ci/cmake-format-do.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | source "$(dirname "$BASH_SOURCE")/impl/common.sh" 6 | source "$(dirname "$BASH_SOURCE")/impl/cmake-format.sh" 7 | 8 | ################################################################################################### 9 | 10 | does_cmake_format_exist 11 | if [[ $? == 0 ]]; then 12 | cmake_format_do 13 | fi 14 | 15 | ################################################################################################### 16 | -------------------------------------------------------------------------------- /ci/code-inspector-check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | source "$(dirname "$BASH_SOURCE")/impl/common.sh" 6 | source "$(dirname "$BASH_SOURCE")/impl/code-inspector.sh" 7 | 8 | ################################################################################################### 9 | 10 | set -o errexit 11 | set -o nounset 12 | 13 | code_inspect "${ROOTPATH:-.}" 14 | 15 | echo "code-inspector check passed" 16 | 17 | ################################################################################################### 18 | -------------------------------------------------------------------------------- /ci/custom-timeout.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | delay="$1" 3 | shift 4 | while true; do 5 | printf ".\b" 6 | sleep 120 7 | done & 8 | timeout -k 5 "$((delay * 60))" "$@" 9 | exit "$?" 10 | -------------------------------------------------------------------------------- /ci/impl/code-inspector.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | code_inspect() 6 | { 7 | local SOURCE_ROOT_PATH=$1 8 | if [[ $SOURCE_ROOT_PATH == "" ]]; then 9 | echo "Missing the source code path" >&2 10 | return 1 11 | fi 12 | 13 | # This is to prevent out of scope access in async_write from asio which is not picked up by static analysers 14 | if [[ $(grep -rl --exclude="*asio.hpp" "asio::async_write" $SOURCE_ROOT_PATH/nano) ]]; then 15 | echo "Using boost::asio::async_write directly is not permitted (except in nano/lib/asio.hpp). Use nano::async_write instead" >&2 16 | return 1 17 | fi 18 | 19 | if [[ $(grep -rlP "^\s*assert \(" $SOURCE_ROOT_PATH/nano) ]]; then 20 | echo "Using assert is not permitted. Use debug_assert instead." >&2 21 | return 1 22 | fi 23 | 24 | return 0 25 | } 26 | 27 | ################################################################################################### 28 | -------------------------------------------------------------------------------- /ci/impl/common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################################### 4 | 5 | ROOTPATH="$(git rev-parse --show-toplevel)" 6 | 7 | ################################################################################################### 8 | -------------------------------------------------------------------------------- /ci/prepare/linux/prepare-clang.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | # Clang installer dependencies 5 | DEBIAN_FRONTEND=noninteractive apt-get install -yqq lsb-release software-properties-common gnupg 6 | 7 | CLANG_VERSION=16 8 | 9 | # TODO: Verify integrity (at this time, the clang build is not used for any production artifacts) 10 | curl -O https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh $CLANG_VERSION 11 | 12 | update-alternatives --install /usr/bin/cc cc /usr/bin/clang-$CLANG_VERSION 100 13 | update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-$CLANG_VERSION 100 14 | update-alternatives --install /usr/bin/lldb lldb /usr/bin/lldb-$CLANG_VERSION 100 15 | 16 | # Workaround to get a path that can be easily passed into cmake for BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE 17 | # See https://www.boost.org/doc/libs/1_70_0/doc/html/stacktrace/configuration_and_build.html#stacktrace.configuration_and_build.f3 18 | backtrace_file=$(find /usr/lib/gcc/ -name 'backtrace.h' | head -n 1) && test -f $backtrace_file && ln -s $backtrace_file /usr/local/include/backtrace.h -------------------------------------------------------------------------------- /ci/prepare/linux/prepare-gcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail -------------------------------------------------------------------------------- /ci/prepare/linux/prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | COMPILER=${COMPILER:-gcc} 5 | 6 | echo "Compiler: '${COMPILER}'" 7 | 8 | # Common dependencies needed for building & testing 9 | DEBIAN_FRONTEND=noninteractive apt-get update -qq 10 | 11 | DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ 12 | build-essential \ 13 | g++ \ 14 | curl \ 15 | wget \ 16 | python3 \ 17 | zlib1g-dev \ 18 | cmake \ 19 | git \ 20 | qtbase5-dev \ 21 | qtchooser \ 22 | qt5-qmake \ 23 | qtbase5-dev-tools \ 24 | valgrind \ 25 | xorg xvfb xauth xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic 26 | 27 | # Compiler specific setup 28 | $(dirname "$BASH_SOURCE")/prepare-${COMPILER}.sh -------------------------------------------------------------------------------- /ci/prepare/macos/prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euox pipefail 3 | 4 | # Homebrew randomly fails to update. Retry 5 times with 15s interval 5 | for i in {1..5}; do brew update && break || { echo "Update failed, retrying..."; sleep 15; }; done 6 | 7 | brew install coreutils 8 | 9 | brew install qt@5 10 | brew link qt@5 11 | 12 | # Workaround: https://github.com/Homebrew/homebrew-core/issues/8392 13 | echo "$(brew --prefix qt@5)/bin" >> $GITHUB_PATH -------------------------------------------------------------------------------- /ci/prepare/windows/disable-defender.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Continue" 2 | 3 | Set-MpPreference -DisableArchiveScanning $true 4 | Set-MpPreference -DisableRealtimeMonitoring $true 5 | Set-MpPreference -DisableBehaviorMonitoring $true -------------------------------------------------------------------------------- /ci/prepare/windows/prepare.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = "Stop" 2 | 3 | & "$PSScriptRoot\disable-defender.ps1" 4 | & "$PSScriptRoot\install-qt.ps1" -------------------------------------------------------------------------------- /ci/tests/common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | get_exec_extension() { 4 | case "$(uname -s)" in 5 | Linux*|Darwin*) 6 | echo "" 7 | ;; 8 | CYGWIN*|MINGW32*|MSYS*|MINGW*) 9 | echo ".exe" 10 | ;; 11 | *) 12 | echo "Unknown OS" 13 | exit 1 14 | ;; 15 | esac 16 | } -------------------------------------------------------------------------------- /ci/tests/run-core-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | $(dirname "$BASH_SOURCE")/run-tests.sh core_test -------------------------------------------------------------------------------- /ci/tests/run-flamegraph-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | # Ensure that an argument is provided 5 | if [ "$#" -ne 1 ]; then 6 | echo "Usage: $0 " 7 | exit 1 8 | fi 9 | 10 | # Capture the argument 11 | ARGUMENT="$1" 12 | 13 | # Run the command with the argument 14 | $(dirname "$BASH_SOURCE")/run-tests.sh slow_test --gtest_filter=flamegraph.${ARGUMENT} 15 | -------------------------------------------------------------------------------- /ci/tests/run-qt-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | # Alpine doesn't offer an xvfb 5 | xvfb_run_() 6 | { 7 | INIT_DELAY_SEC=3 8 | 9 | Xvfb :2 -screen 0 1024x768x24 & 10 | xvfb_pid=$! 11 | sleep ${INIT_DELAY_SEC} 12 | DISPLAY=:2 $@ 13 | res=${?} 14 | kill ${xvfb_pid} 15 | 16 | return ${res} 17 | } 18 | 19 | xvfb_run_ $(dirname "$BASH_SOURCE")/run-tests.sh qt_test -------------------------------------------------------------------------------- /ci/tests/run-rpc-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | $(dirname "$BASH_SOURCE")/run-tests.sh rpc_test -------------------------------------------------------------------------------- /ci/tests/show-sanitizer-reports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -uo pipefail 3 | 4 | issue_reported=false 5 | 6 | # Check for sanitizer reports using glob 7 | shopt -s nullglob 8 | reports=(./sanitizer_report*) 9 | 10 | if [[ ${#reports[@]} -gt 0 ]]; then 11 | for report in "${reports[@]}"; do 12 | report_name=$(basename "${report}") 13 | echo "::group::Report: $report_name" 14 | 15 | cat "${report}" 16 | 17 | echo "::endgroup::" 18 | 19 | issue_reported=true 20 | done 21 | else 22 | echo "No report has been generated." 23 | fi 24 | 25 | echo "issue_reported=${issue_reported}" >> $GITHUB_OUTPUT 26 | 27 | if $issue_reported; then 28 | echo "::error::Issues were reported in the sanitizer report." 29 | exit 1 30 | else 31 | echo "No issues found in the sanitizer reports." 32 | exit 0 33 | fi -------------------------------------------------------------------------------- /cmake/Modules/CoverageTest.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") 2 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage -lgcov") 3 | find_program(LCOV_PATH lcov) 4 | message("lcov found: ${LCOV_PATH}") 5 | find_program(GENHTML_PATH genhtml) 6 | message("genhtml found: ${GENHTML_PATH}") 7 | if(NOT CMAKE_COMPILER_IS_GNUCXX) 8 | # Clang version 3.0.0 and greater now supports gcov as well. 9 | message( 10 | WARNING 11 | "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't." 12 | ) 13 | if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 14 | message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") 15 | endif() 16 | endif() 17 | if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL 18 | "Coverage")) 19 | message( 20 | WARNING 21 | "Code coverage results with an optimized (non-Debug) build may be misleading" 22 | ) 23 | endif() -------------------------------------------------------------------------------- /crypto/blake2/README.md: -------------------------------------------------------------------------------- 1 | # BLAKE2 2 | 3 | This is the reference source code package of BLAKE2, which includes 4 | 5 | * `ref/`: C implementations of BLAKE2b, BLAKE2bp, BLAKE2s, BLAKE2sp, 6 | aimed at portability and simplicity. 7 | 8 | * `sse/`: C implementations of BLAKE2b, BLAKE2bp, BLAKE2s, BLAKE2sp, 9 | optimized for speed on CPUs supporting SSE2, SSSE3, SSE4.1, AVX, or 10 | XOP. 11 | 12 | * `csharp/`: C# implementation of BLAKE2b. 13 | 14 | * `b2sum/`: Command line utility to hash files, based on the `sse/` 15 | implementations. 16 | 17 | * `bench/`: Benchmark tool to measure cycles-per-byte speeds and produce 18 | graphs copyright. 19 | 20 | All code is triple-licensed under the [CC0](http://creativecommons.org/publicdomain/zero/1.0), the [OpenSSL Licence](https://www.openssl.org/source/license.html), or the [Apache Public License 2.0](http://www.apache.org/licenses/LICENSE-2.0), 21 | at your choosing. 22 | 23 | More: [https://blake2.net](https://blake2.net). 24 | 25 | Contact: contact@blake2.net 26 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library (ed25519 2 | ed25519-donna-portable.h 3 | ed25519-hash-custom.h 4 | ed25519-randombytes-custom.h 5 | ed25519.h 6 | ed25519.c) 7 | 8 | target_compile_definitions(ed25519 PUBLIC 9 | -DED25519_CUSTOMHASH 10 | -DED25519_CUSTOMRNG) 11 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/ed25519-hash-custom.h: -------------------------------------------------------------------------------- 1 | /* 2 | a custom hash must have a 512bit digest and implement: 3 | 4 | struct ed25519_hash_context; 5 | 6 | void ed25519_hash_init(ed25519_hash_context *ctx); 7 | void ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen); 8 | void ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash); 9 | void ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen); 10 | */ 11 | 12 | #include 13 | 14 | typedef blake2b_state ed25519_hash_context; 15 | 16 | void ed25519_hash_init (ed25519_hash_context * ctx); 17 | 18 | void ed25519_hash_update (ed25519_hash_context * ctx, uint8_t const * in, size_t inlen); 19 | 20 | void ed25519_hash_final (ed25519_hash_context * ctx, uint8_t * out); 21 | 22 | void ed25519_hash (uint8_t * out, uint8_t const * in, size_t inlen); 23 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/ed25519-randombytes-custom.h: -------------------------------------------------------------------------------- 1 | /* 2 | a custom randombytes must implement: 3 | 4 | void ED25519_FN(ed25519_randombytes_unsafe) (void *p, size_t len); 5 | 6 | ed25519_randombytes_unsafe is used by the batch verification function 7 | to create random scalars 8 | */ 9 | 10 | void ed25519_randombytes_unsafe (void * out, size_t outlen); -------------------------------------------------------------------------------- /crypto/ed25519-donna/ed25519.h: -------------------------------------------------------------------------------- 1 | #ifndef ED25519_H 2 | #define ED25519_H 3 | 4 | #include 5 | 6 | #if defined(__cplusplus) 7 | extern "C" { 8 | #endif 9 | 10 | typedef unsigned char ed25519_signature[64]; 11 | typedef unsigned char ed25519_public_key[32]; 12 | typedef unsigned char ed25519_secret_key[32]; 13 | 14 | typedef unsigned char curved25519_key[32]; 15 | 16 | void ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk); 17 | int ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS); 18 | void ed25519_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS); 19 | 20 | int ed25519_sign_open_batch(const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid); 21 | 22 | void ed25519_randombytes_unsafe(void *out, size_t count); 23 | 24 | void curved25519_scalarmult_basepoint(curved25519_key pk, const curved25519_key e); 25 | 26 | #if defined(__cplusplus) 27 | } 28 | #endif 29 | 30 | #endif // ED25519_H 31 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/fuzz/curve25519-ref10.h: -------------------------------------------------------------------------------- 1 | #ifndef CURVE25519_REF10_H 2 | #define CURVE25519_REF10_H 3 | 4 | int crypto_scalarmult_base_ref10(unsigned char *q,const unsigned char *n); 5 | int crypto_scalarmult_ref10(unsigned char *q, const unsigned char *n, const unsigned char *p); 6 | 7 | #endif /* CURVE25519_REF10_H */ 8 | 9 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/fuzz/ed25519-donna-sse2.c: -------------------------------------------------------------------------------- 1 | #define ED25519_SUFFIX _sse2 2 | #define ED25519_SSE2 3 | #include "../ed25519.c" 4 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/fuzz/ed25519-donna.c: -------------------------------------------------------------------------------- 1 | #include "../ed25519.c" 2 | -------------------------------------------------------------------------------- /crypto/ed25519-donna/fuzz/ed25519-ref10.h: -------------------------------------------------------------------------------- 1 | #ifndef ED25519_REF10_H 2 | #define ED25519_REF10_H 3 | 4 | int crypto_sign_pk_ref10(unsigned char *pk,unsigned char *sk); 5 | int crypto_sign_ref10(unsigned char *sm,unsigned long long *smlen,const unsigned char *m,unsigned long long mlen,const unsigned char *sk); 6 | int crypto_sign_open_ref10(unsigned char *m,unsigned long long *mlen,const unsigned char *sm,unsigned long long smlen,const unsigned char *pk); 7 | 8 | #endif /* ED25519_REF10_H */ 9 | 10 | -------------------------------------------------------------------------------- /debian-control/postinst.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set +e 4 | 5 | useradd -r nanocurrency 6 | groupadd -r nanocurrency 7 | 8 | mkdir -p /var/nanocurrency/Nano 9 | mkdir -p /var/nanocurrency/NanoBeta 10 | mkdir -p /var/nanocurrency/NanoTest 11 | chown -R nanocurrency: /var/nanocurrency 12 | 13 | systemctl stop ${NANO_SERVICE} 2>/dev/null 14 | systemctl disable ${NANO_SERVICE} 2>/dev/null 15 | cp ${CMAKE_INSTALL_PREFIX}/extras/systemd/${NANO_SERVICE} /etc/systemd/system/${NANO_SERVICE} 16 | systemctl daemon-reload 17 | systemctl enable ${NANO_SERVICE} 18 | systemctl start ${NANO_SERVICE} 19 | sleep 1 20 | systemctl --no-pager status ${NANO_SERVICE} 21 | 22 | set -e 23 | -------------------------------------------------------------------------------- /debian-control/postrm.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set +e 4 | 5 | systemctl stop ${NANO_SERVICE} 2>/dev/null 6 | systemctl disable ${NANO_SERVICE} 2>/dev/null 7 | rm -rf /etc/systemd/system/${NANO_SERVICE} 8 | systemctl daemon-reload 9 | 10 | set -e 11 | -------------------------------------------------------------------------------- /doc/diagram/.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/doc/diagram/.empty -------------------------------------------------------------------------------- /docker/ci/Dockerfile-base: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | RUN apt-get update -qq && apt-get install -yqq \ 6 | build-essential \ 7 | g++ \ 8 | wget \ 9 | python3 \ 10 | zlib1g-dev \ 11 | cmake \ 12 | git 13 | 14 | RUN apt-get update -qq && apt-get install -yqq \ 15 | qtbase5-dev \ 16 | qtchooser \ 17 | qt5-qmake \ 18 | qtbase5-dev-tools \ 19 | valgrind \ 20 | xorg xvfb xauth xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic 21 | 22 | ARG REPOSITORY=nanocurrency/nano-node 23 | LABEL org.opencontainers.image.source https://github.com/$REPOSITORY 24 | -------------------------------------------------------------------------------- /docker/ci/Dockerfile-clang: -------------------------------------------------------------------------------- 1 | ARG ENV_REPOSITORY=nanocurrency/nano-env 2 | FROM ${ENV_REPOSITORY}:base 3 | 4 | RUN apt-get update -qq && apt-get install -yqq \ 5 | clang \ 6 | lldb 7 | 8 | ENV CXX=/usr/bin/clang++ 9 | ENV CC=/usr/bin/clang 10 | RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 11 | RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 12 | 13 | # workaround to get a path that can be easily passed into cmake for 14 | # BOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE 15 | # see https://www.boost.org/doc/libs/1_70_0/doc/html/stacktrace/configuration_and_build.html#stacktrace.configuration_and_build.f3 16 | 17 | RUN backtrace_file=$(find /usr/lib/gcc/ -name 'backtrace.h' | head -n 1) && test -f $backtrace_file && ln -s $backtrace_file /tmp/backtrace.h 18 | 19 | ARG REPOSITORY=nanocurrency/nano-node 20 | LABEL org.opencontainers.image.source https://github.com/$REPOSITORY 21 | -------------------------------------------------------------------------------- /docker/ci/Dockerfile-gcc: -------------------------------------------------------------------------------- 1 | ARG ENV_REPOSITORY=nanocurrency/nano-env 2 | FROM ${ENV_REPOSITORY}:base 3 | 4 | ARG REPOSITORY=nanocurrency/nano-node 5 | LABEL org.opencontainers.image.source https://github.com/$REPOSITORY 6 | -------------------------------------------------------------------------------- /docker/ci/Dockerfile-rhel: -------------------------------------------------------------------------------- 1 | FROM rockylinux:8 2 | 3 | WORKDIR /workspace 4 | 5 | RUN yum update -y 6 | RUN yum install -y git wget openssl bzip2 7 | RUN yum install -y rpm-build 8 | RUN yum install -y glibc-devel glibc-headers make which 9 | RUN yum install -y cmake gcc-toolset-12 10 | RUN yum install -y python38 11 | -------------------------------------------------------------------------------- /docker/ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REPO_ROOT=`git rev-parse --show-toplevel` 3 | pushd $REPO_ROOT 4 | docker build -f docker/ci/Dockerfile -t nano-ci:latest . 5 | popd 6 | -------------------------------------------------------------------------------- /docker/node/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | network='live' 4 | 5 | print_usage() { 6 | echo 'build.sh [-h] [-n {live|beta|dev}]' 7 | } 8 | 9 | while getopts 'hn:' OPT; do 10 | case "${OPT}" in 11 | h) 12 | print_usage 13 | exit 0 14 | ;; 15 | n) 16 | network="${OPTARG}" 17 | ;; 18 | *) 19 | print_usage >&2 20 | exit 1 21 | ;; 22 | esac 23 | done 24 | 25 | case "${network}" in 26 | live) 27 | network_tag='' 28 | ;; 29 | dev | beta) 30 | network_tag="-${network}" 31 | ;; 32 | *) 33 | echo "Invalid network: ${network}" >&2 34 | exit 1 35 | ;; 36 | esac 37 | 38 | REPO_ROOT=$(git rev-parse --show-toplevel) 39 | COMMIT_SHA=$(git rev-parse --short HEAD) 40 | pushd $REPO_ROOT 41 | docker build --build-arg NETWORK="${network}" -f docker/node/Dockerfile -t nano-node${network_tag}:latest . 42 | popd 43 | -------------------------------------------------------------------------------- /docker/node/config/config-node.toml: -------------------------------------------------------------------------------- 1 | 2 | [node.websocket] 3 | 4 | # WebSocket server bind address. 5 | # type:string,ip 6 | address = "::ffff:0.0.0.0" 7 | # Enable or disable WebSocket server. 8 | # type:bool 9 | enable = true 10 | 11 | [rpc] 12 | 13 | # Enable or disable RPC. 14 | # type:bool 15 | enable = true 16 | -------------------------------------------------------------------------------- /docker/node/config/config-rpc.toml: -------------------------------------------------------------------------------- 1 | 2 | # Bind address for the RPC server 3 | # type:string,ip 4 | address = "::ffff:0.0.0.0" 5 | 6 | # Enable or disable control-level requests 7 | # type:bool 8 | enable_control = false 9 | -------------------------------------------------------------------------------- /docker/sign/Dockerfile-signer: -------------------------------------------------------------------------------- 1 | FROM python:3.9-buster 2 | 3 | 4 | ENV DEBIAN_FRONTEND="noninteractive" 5 | ENV TZ="America/Los_Angeles" 6 | ENV GPG_TTY=/dev/console 7 | 8 | ARG GPG_PRIVATE_KEY 9 | ARG GPG_SIGNER 10 | 11 | ## Install required for rpm signing 12 | RUN apt-get update -yqq && \ 13 | apt-get install -y librpmsign8 gnupg2 wget rpm 14 | 15 | ## Additional for mkrepo support 16 | RUN python3 -m pip install mkrepo boto3 17 | 18 | #WORKDIR /signing 19 | #RUN python3 -m venv && .venv/bin/pip install mkrepo 20 | 21 | ## Control Entrypoint 22 | ADD docker/sign/entry.sh /usr/local/bin/entry.sh 23 | 24 | ENTRYPOINT [ "entry.sh" ] 25 | -------------------------------------------------------------------------------- /docker/sign/README.MD: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ### Build 4 | 5 | `docker build . -f docker/sign/Dockerfile-signer -t ` 6 | 7 | ### Required Variables 8 | * GPG_PRIVATE_KEY -> base64 encoded GPG private signing key 9 | * GPG_SIGNER -> key id to sign with, must match GPG_PRIVATE_KEY 10 | * S3_ACCESS_KEY_ID -> S3 Key with access to rpm/repo 11 | * S3_SECRET_ACCES_KEY -> S3 Secret for S3_ACCESS_KEY_ID 12 | 13 | ### Sign RPM artifacts 14 | `docker run --rm -it -e GPG_PRIVATE_KEY -e GPG_SIGNER -v :/tmp rpm-sign /tmp` 15 | 16 | ### Upload RPM artifacts 17 | Upload artifacts to appropriate location 18 | 19 | ### Update Repo Metadata Files 20 | 21 | `docker run --rm -it -e GPG_PRIVATE_KEY -e GPG_SIGNER -e S3_ACCESS_KEY_ID -e S3_SECRET_ACCESS_KEY repo-update ` -------------------------------------------------------------------------------- /doxygen/MAIN_PAGE.md: -------------------------------------------------------------------------------- 1 | This provides a basic source-code generated documentation for the core classes of the nano-node. 2 | Doxygen docs may look a bit overwhelming as it tries to document all the smaller pieces of code. For 3 | this reason only the files from `nano` directory were added to this. Some other 4 | files were also excluded as the `EXCLUDE_PATTERN` configuration stated below. 5 | 6 | EXCLUDE_PATTERNS = */nano/*_test/* \ 7 | */nano/test_common/* \ 8 | */nano/boost/* \ 9 | */nano/qt/* \ 10 | */nano/nano_wallet/* 11 | 12 | -------------------------------------------------------------------------------- /etc/gpg/clemahieu.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | 3 | mDMEXZTdLxYJKwYBBAHaRw8BAQdAPXgGtAVcgz+RNJRvSgk1YrV5bzEYxG1QY8g6 4 | g1J/Hbu0JENvbGluIExlTWFoaWV1IDxjbGVtYWhpZXVAZ21haWwuY29tPoiQBBMW 5 | CAA4FiEEOp9RXuwHACGmDlkdQ3CFIMjfuTgFAl2U3S8CGwMFCwkIBwIGFQoJCAsC 6 | BBYCAwECHgECF4AACgkQQ3CFIMjfuTjO1wD/fD8d8f1Vv7HUiBc/rFDUZWDS4eYq 7 | VvYxoTVows4otP4A/1DDpZs7xfM1uZjhgIZhUP1pMmLpDj5qmnK1w+9GGj4EuDgE 8 | XZTdLxIKKwYBBAGXVQEFAQEHQM+vDx1fYPjMlF8aMTdJF7iTe+17VQWsQeEwDOG5 9 | qCISAwEIB4h4BBgWCAAgFiEEOp9RXuwHACGmDlkdQ3CFIMjfuTgFAl2U3S8CGwwA 10 | CgkQQ3CFIMjfuTgi+QEA/Nnz32RFBCzErI7WwvsEVL6NJCihqEiRiKG7FvaDd20A 11 | /R87rAQzAkyuCekif5eCQ7V6HD1uBTSTDCIOKM/QDcoA 12 | =A+a5 13 | -----END PGP PUBLIC KEY BLOCK----- 14 | -------------------------------------------------------------------------------- /etc/systemd/nanocurrency-beta.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Nano Beta Network Daemon 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=nanocurrency 8 | WorkingDirectory=/var/nanocurrency/NanoBeta 9 | ExecStart=/usr/bin/nano_node --daemon --network=beta --data_path=/var/nanocurrency/NanoBeta 10 | Restart=on-failure 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /etc/systemd/nanocurrency-test.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Nano Test Network Daemon 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=nanocurrency 8 | WorkingDirectory=/var/nanocurrency/NanoTest 9 | ExecStart=/usr/bin/nano_node --daemon --network=test --data_path=/var/nanocurrency/NanoTest 10 | Restart=on-failure 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /etc/systemd/nanocurrency.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Nano Live Network Daemon 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=nanocurrency 8 | WorkingDirectory=/var/nanocurrency/Nano 9 | ExecStart=/usr/bin/nano_node --daemon --data_path=/var/nanocurrency/Nano 10 | Restart=on-failure 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /images/attack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/attack.png -------------------------------------------------------------------------------- /images/confirmation - complex.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/confirmation - complex.gif -------------------------------------------------------------------------------- /images/confirmation - easy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/confirmation - easy.gif -------------------------------------------------------------------------------- /images/confirmation - simple.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/confirmation - simple.gif -------------------------------------------------------------------------------- /images/fan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/fan.png -------------------------------------------------------------------------------- /images/fork.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/fork.gif -------------------------------------------------------------------------------- /images/transaction.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/images/transaction.gif -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/logo.png -------------------------------------------------------------------------------- /nano/benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(benchmarks entry.cpp ledger.cpp stats.cpp) 2 | 3 | target_link_libraries(benchmarks test_common benchmark::benchmark) 4 | 5 | include_directories(${CMAKE_SOURCE_DIR}/submodules) 6 | -------------------------------------------------------------------------------- /nano/benchmarks/entry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | // Customized main, based on BENCHMARK_MAIN macro 6 | int main (int argc, char ** argv) 7 | { 8 | nano::logger::initialize_dummy (); 9 | 10 | benchmark::MaybeReenterWithoutASLR (argc, argv); 11 | char arg0_default[] = "benchmark"; 12 | char * args_default = reinterpret_cast (arg0_default); 13 | if (!argv) 14 | { 15 | argc = 1; 16 | argv = &args_default; 17 | } 18 | ::benchmark::Initialize (&argc, argv); 19 | if (::benchmark::ReportUnrecognizedArguments (argc, argv)) 20 | return 1; 21 | ::benchmark::RunSpecifiedBenchmarks (); 22 | ::benchmark::Shutdown (); 23 | return 0; 24 | } 25 | 26 | static void BM_StringCreation (benchmark::State & state) 27 | { 28 | for (auto _ : state) 29 | std::string empty_string; 30 | } 31 | // Register the function as a benchmark 32 | BENCHMARK (BM_StringCreation); 33 | 34 | // Define another benchmark 35 | static void BM_StringCopy (benchmark::State & state) 36 | { 37 | std::string x = "hello"; 38 | for (auto _ : state) 39 | std::string copy (x); 40 | } 41 | BENCHMARK (BM_StringCopy); -------------------------------------------------------------------------------- /nano/boost/asio/basic_stream_socket.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/bind_executor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/connect.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/deadline_timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/dispatch.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/executor_work_guard.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/io_context.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/ip/address.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/ip/address_v6.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/ip/network_v6.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/ip/tcp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/local/stream_protocol.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/post.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/read.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/spawn.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/steady_timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/strand.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/thread_pool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/asio/write.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_ASIO_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/core.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/core/flat_buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/http.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/http/message.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/http/string_body.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/beast/websocket.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/private/macro_warnings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #define DISABLE_ASIO_WARNINGS \ 5 | __pragma (warning (push)) \ 6 | __pragma (warning (disable : 4191)) \ 7 | __pragma (warning (disable : 4242)) 8 | 9 | #else 10 | #define DISABLE_ASIO_WARNINGS 11 | #endif 12 | 13 | #ifdef _WIN32 14 | #define REENABLE_WARNINGS \ 15 | __pragma (warning (pop)) 16 | #else 17 | #define REENABLE_WARNINGS 18 | #endif 19 | 20 | #define DISABLE_BEAST_WARNINGS DISABLE_ASIO_WARNINGS 21 | 22 | #ifdef _WIN32 23 | #define DISABLE_PROCESS_WARNINGS \ 24 | __pragma (warning (push)) \ 25 | __pragma (warning (disable : 4191)) \ 26 | __pragma (warning (disable : 4242)) \ 27 | __pragma (warning (disable : 4244)) 28 | #else 29 | #define DISABLE_PROCESS_WARNINGS 30 | #endif 31 | -------------------------------------------------------------------------------- /nano/boost/process/child.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | DISABLE_BEAST_WARNINGS 6 | #include 7 | REENABLE_WARNINGS 8 | -------------------------------------------------------------------------------- /nano/boost/readme.txt: -------------------------------------------------------------------------------- 1 | These are files which wrap other boost files and suppress compiler warnings associated with them. -------------------------------------------------------------------------------- /nano/core_test/assert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST (assert_DeathTest, debug_assert) 6 | { 7 | debug_assert (true); 8 | ASSERT_DEATH (debug_assert (false, "test"), ".*Assertion `false` failed: test.*"); 9 | } 10 | 11 | TEST (assert_DeathTest, release_assert) 12 | { 13 | release_assert (true); 14 | ASSERT_DEATH (release_assert (false, "test"), ".*Assertion `false` failed: test.*"); 15 | } -------------------------------------------------------------------------------- /nano/core_test/entry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace nano 11 | { 12 | namespace test 13 | { 14 | void cleanup_dev_directories_on_exit (); 15 | } 16 | void force_nano_dev_network (); 17 | } 18 | 19 | GTEST_API_ int main (int argc, char ** argv) 20 | { 21 | nano::initialize_file_descriptor_limit (); 22 | nano::logger::initialize_for_tests (nano::log_config::tests_default ()); 23 | nano::force_nano_dev_network (); 24 | nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; 25 | testing::InitGoogleTest (&argc, argv); 26 | auto res = RUN_ALL_TESTS (); 27 | nano::test::cleanup_dev_directories_on_exit (); 28 | return res; 29 | } 30 | -------------------------------------------------------------------------------- /nano/core_test/random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /nano/core_test/random_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | 8 | TEST (random_pool, multithreading) 9 | { 10 | std::vector threads; 11 | for (auto i = 0; i < 100; ++i) 12 | { 13 | threads.emplace_back ([] () { 14 | nano::uint256_union number; 15 | nano::random_pool::generate_block (number.bytes.data (), number.bytes.size ()); 16 | }); 17 | } 18 | for (auto & i : threads) 19 | { 20 | i.join (); 21 | } 22 | } 23 | 24 | // Test that random 64bit numbers are within the given range 25 | TEST (random_pool, generate_word64) 26 | { 27 | int occurrences[10] = { 0 }; 28 | for (auto i = 0; i < 1000; ++i) 29 | { 30 | auto random = nano::random_pool::generate_word64 (1, 9); 31 | ASSERT_TRUE (random >= 1 && random <= 9); 32 | occurrences[random] += 1; 33 | } 34 | 35 | for (auto i = 1; i < 10; ++i) 36 | { 37 | ASSERT_GT (occurrences[i], 0); 38 | } 39 | } 40 | 41 | // Test random numbers > uint32 max 42 | TEST (random_pool, generate_word64_big_number) 43 | { 44 | uint64_t min = static_cast (std::numeric_limits::max ()) + 1; 45 | uint64_t max = std::numeric_limits::max (); 46 | auto big_random = nano::random_pool::generate_word64 (min, max); 47 | ASSERT_GE (big_random, min); 48 | } 49 | -------------------------------------------------------------------------------- /nano/core_test/stacktrace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | // Check that the stacktrace contains the current function name 6 | // This depends on the way testcase names are compiled by gtest 7 | // Current name: "stacktrace_human_readable_Test::TestBody()" 8 | TEST (stacktrace, human_readable) 9 | { 10 | auto stacktrace = nano::generate_stacktrace (); 11 | std::cout << stacktrace << std::endl; 12 | ASSERT_FALSE (stacktrace.empty ()); 13 | ASSERT_TRUE (stacktrace.find ("stacktrace_human_readable_Test") != std::string::npos); 14 | } -------------------------------------------------------------------------------- /nano/core_test/throttle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST (throttle, construction) 6 | { 7 | nano::bootstrap::throttle throttle{ 2 }; 8 | ASSERT_FALSE (throttle.throttled ()); 9 | } 10 | 11 | TEST (throttle, throttled) 12 | { 13 | nano::bootstrap::throttle throttle{ 2 }; 14 | throttle.add (false); 15 | ASSERT_FALSE (throttle.throttled ()); 16 | throttle.add (false); 17 | ASSERT_TRUE (throttle.throttled ()); 18 | } 19 | 20 | TEST (throttle, resize_up) 21 | { 22 | nano::bootstrap::throttle throttle{ 2 }; 23 | throttle.add (false); 24 | throttle.resize (4); 25 | ASSERT_FALSE (throttle.throttled ()); 26 | throttle.add (false); 27 | ASSERT_TRUE (throttle.throttled ()); 28 | } 29 | 30 | TEST (throttle, resize_down) 31 | { 32 | nano::bootstrap::throttle throttle{ 4 }; 33 | throttle.add (false); 34 | ASSERT_FALSE (throttle.throttled ()); 35 | throttle.resize (2); 36 | ASSERT_FALSE (throttle.throttled ()); 37 | throttle.add (false); 38 | ASSERT_TRUE (throttle.throttled ()); 39 | } 40 | -------------------------------------------------------------------------------- /nano/crypto/blake2/blake2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #pragma warning(push) 5 | #pragma warning(disable : 4804) 6 | #endif 7 | 8 | #include 9 | 10 | #ifdef _WIN32 11 | #pragma warning(pop) 12 | #endif 13 | -------------------------------------------------------------------------------- /nano/crypto/readme.txt: -------------------------------------------------------------------------------- 1 | These are files which wrap other crypto/ third party files and suppress compiler warnings associated with them. -------------------------------------------------------------------------------- /nano/crypto_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(nano_ed25519 interface.cpp) 2 | 3 | target_link_libraries(ed25519 nano_ed25519) 4 | 5 | add_library(crypto_lib random_pool.hpp random_pool.cpp random_pool_shuffle.hpp 6 | secure_memory.hpp secure_memory.cpp) 7 | 8 | target_link_libraries(crypto_lib blake2 ed25519 ${CRYPTOPP_LIBRARY}) 9 | -------------------------------------------------------------------------------- /nano/crypto_lib/interface.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" { 5 | #include 6 | void ed25519_randombytes_unsafe (void * out, size_t outlen) 7 | { 8 | nano::random_pool::generate_block (reinterpret_cast (out), outlen); 9 | } 10 | void ed25519_hash_init (ed25519_hash_context * ctx) 11 | { 12 | blake2b_init (ctx, 64); 13 | } 14 | 15 | void ed25519_hash_update (ed25519_hash_context * ctx, uint8_t const * in, size_t inlen) 16 | { 17 | blake2b_update (ctx, in, inlen); 18 | } 19 | 20 | void ed25519_hash_final (ed25519_hash_context * ctx, uint8_t * out) 21 | { 22 | blake2b_final (ctx, out, 64); 23 | } 24 | 25 | void ed25519_hash (uint8_t * out, uint8_t const * in, size_t inlen) 26 | { 27 | ed25519_hash_context ctx; 28 | ed25519_hash_init (&ctx); 29 | ed25519_hash_update (&ctx, in, inlen); 30 | ed25519_hash_final (&ctx, out); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /nano/crypto_lib/random_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | void nano::random_pool::generate_block (unsigned char * output, size_t size) 7 | { 8 | auto & pool = get_pool (); 9 | pool.GenerateBlock (output, size); 10 | } 11 | 12 | unsigned nano::random_pool::generate_word32 (unsigned min, unsigned max) 13 | { 14 | auto & pool = get_pool (); 15 | return pool.GenerateWord32 (min, max); 16 | } 17 | 18 | uint64_t nano::random_pool::generate_word64 (uint64_t min, uint64_t max) 19 | { 20 | auto & pool = get_pool (); 21 | 22 | const auto range = max - min; 23 | const auto max_bits = CryptoPP::BitPrecision (range); 24 | 25 | uint64_t value; 26 | 27 | do 28 | { 29 | pool.GenerateBlock ((unsigned char *)&value, sizeof (value)); 30 | value = CryptoPP::Crop (value, max_bits); 31 | } while (value > range); 32 | 33 | return value + min; 34 | } 35 | 36 | unsigned char nano::random_pool::generate_byte () 37 | { 38 | auto & pool = get_pool (); 39 | return pool.GenerateByte (); 40 | } 41 | 42 | CryptoPP::AutoSeededRandomPool & nano::random_pool::get_pool () 43 | { 44 | static thread_local CryptoPP::AutoSeededRandomPool pool; 45 | return pool; 46 | } 47 | -------------------------------------------------------------------------------- /nano/crypto_lib/random_pool_shuffle.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | template 10 | void random_pool_shuffle (Iter begin, Iter end) 11 | { 12 | random_pool::get_pool ().Shuffle (begin, end); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /nano/crypto_lib/secure_memory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef _MSC_VER 4 | #include 5 | #endif 6 | #if defined __STDC_LIB_EXT1__ 7 | #define __STDC_WANT_LIB_EXT1__ 1 8 | #endif 9 | 10 | /* for explicit_bzero() on glibc */ 11 | #ifndef _DEFAULT_SOURCE 12 | #define _DEFAULT_SOURCE 13 | #endif 14 | 15 | #include 16 | 17 | #if defined(__clang__) 18 | #if __has_attribute(optnone) 19 | #define NOT_OPTIMIZED __attribute__ ((optnone)) 20 | #endif 21 | #elif defined(__GNUC__) 22 | #define NOT_OPTIMIZED __attribute__ ((optimize ("O0"))) 23 | #endif 24 | #ifndef NOT_OPTIMIZED 25 | #define NOT_OPTIMIZED 26 | #endif 27 | 28 | #if defined(__OpenBSD__) 29 | #define HAVE_EXPLICIT_BZERO 1 30 | #elif defined(__GLIBC__) && defined(__GLIBC_PREREQ) 31 | #if __GLIBC_PREREQ(2, 25) 32 | #define HAVE_EXPLICIT_BZERO 1 33 | #endif 34 | #endif 35 | 36 | void NOT_OPTIMIZED nano::secure_wipe_memory (void * v, size_t n) 37 | { 38 | #if defined(_MSC_VER) 39 | SecureZeroMemory (v, n); 40 | #elif defined memset_s 41 | memset_s (v, n, 0, n); 42 | #elif defined(HAVE_EXPLICIT_BZERO) 43 | explicit_bzero (v, n); 44 | #else 45 | memset (v, 0, n); 46 | #endif 47 | } 48 | -------------------------------------------------------------------------------- /nano/crypto_lib/secure_memory.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(__clang__) 4 | #if __has_attribute(optnone) 5 | #define NOT_OPTIMIZED __attribute__ ((optnone)) 6 | #endif 7 | #elif defined(__GNUC__) 8 | #define NOT_OPTIMIZED __attribute__ ((optimize ("O0"))) 9 | #endif 10 | #ifndef NOT_OPTIMIZED 11 | #define NOT_OPTIMIZED 12 | #endif 13 | 14 | namespace nano 15 | { 16 | void NOT_OPTIMIZED secure_wipe_memory (void * v, size_t n); 17 | } -------------------------------------------------------------------------------- /nano/fuzzer_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(fuzz_buffer fuzz_buffer.cpp) 2 | target_compile_options(fuzz_buffer PUBLIC -fsanitize=fuzzer) 3 | target_link_libraries(fuzz_buffer PRIVATE -fsanitize=fuzzer node gtest) 4 | 5 | add_executable(fuzz_bignum fuzz_bignum.cpp) 6 | target_compile_options(fuzz_bignum PUBLIC -fsanitize=fuzzer) 7 | target_link_libraries(fuzz_bignum PRIVATE -fsanitize=fuzzer node gtest) 8 | 9 | add_executable(fuzz_endpoint_parsing fuzz_endpoint_parsing.cpp) 10 | target_compile_options(fuzz_endpoint_parsing PUBLIC -fsanitize=fuzzer) 11 | target_link_libraries(fuzz_endpoint_parsing PRIVATE -fsanitize=fuzzer node 12 | gtest) 13 | -------------------------------------------------------------------------------- /nano/fuzzer_test/fuzz_bignum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** Fuzz decimal, hex and account parsing */ 4 | void fuzz_bignum_parsers (uint8_t const * Data, size_t Size) 5 | { 6 | try 7 | { 8 | auto data (std::string (reinterpret_cast (const_cast (Data)), Size)); 9 | nano::uint128_union u128; 10 | u128.decode_dec (data); 11 | u128.decode_hex (data); 12 | 13 | nano::uint256_union u256; 14 | u256.decode_dec (data); 15 | u256.decode_hex (data); 16 | 17 | nano::uint512_union u512; 18 | u512.decode_hex (data); 19 | 20 | nano::public_key pkey; 21 | pkey.decode_account (data); 22 | 23 | uint64_t out; 24 | nano::from_string_hex (data, out); 25 | } 26 | catch (std::out_of_range const &) 27 | { 28 | } 29 | } 30 | 31 | /** Fuzzer entry point */ 32 | extern "C" int LLVMFuzzerTestOneInput (uint8_t const * Data, size_t Size) 33 | { 34 | fuzz_bignum_parsers (Data, Size); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /nano/fuzzer_test/fuzz_endpoint_parsing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** Fuzz endpoint parsing */ 4 | void fuzz_endpoint_parsing (uint8_t const * Data, size_t Size) 5 | { 6 | auto data (std::string (reinterpret_cast (const_cast (Data)), Size)); 7 | nano::endpoint endpoint; 8 | nano::parse_endpoint (data, endpoint); 9 | nano::tcp_endpoint tcp_endpoint; 10 | nano::parse_tcp_endpoint (data, tcp_endpoint); 11 | } 12 | 13 | /** Fuzzer entry point */ 14 | extern "C" int LLVMFuzzerTestOneInput (uint8_t const * Data, size_t Size) 15 | { 16 | fuzz_endpoint_parsing (Data, Size); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /nano/ipc_flatbuffers_lib/flatbuffer_producer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | nano::ipc::flatbuffer_producer::flatbuffer_producer () 4 | { 5 | fbb = std::make_shared (); 6 | } 7 | 8 | nano::ipc::flatbuffer_producer::flatbuffer_producer (std::shared_ptr const & builder_a) : 9 | fbb (builder_a) 10 | { 11 | } 12 | 13 | void nano::ipc::flatbuffer_producer::make_error (int code, std::string const & message) 14 | { 15 | auto msg = fbb->CreateString (message); 16 | nanoapi::ErrorBuilder builder (*fbb); 17 | builder.add_code (code); 18 | builder.add_message (msg); 19 | create_builder_response (builder); 20 | } 21 | 22 | void nano::ipc::flatbuffer_producer::set_correlation_id (std::string const & correlation_id_a) 23 | { 24 | correlation_id = correlation_id_a; 25 | } 26 | 27 | void nano::ipc::flatbuffer_producer::set_credentials (std::string const & credentials_a) 28 | { 29 | credentials = credentials_a; 30 | } 31 | 32 | std::shared_ptr nano::ipc::flatbuffer_producer::get_shared_flatbuffer () const 33 | { 34 | return fbb; 35 | } 36 | -------------------------------------------------------------------------------- /nano/ipc_flatbuffers_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(ipc_flatbuffers_test_client entry.cpp) 2 | 3 | target_link_libraries(ipc_flatbuffers_test_client node) 4 | -------------------------------------------------------------------------------- /nano/lib/block_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | std::string_view nano::to_string (nano::block_type type) 5 | { 6 | return nano::enum_util::name (type); 7 | } 8 | -------------------------------------------------------------------------------- /nano/lib/block_type.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | enum class block_type : uint8_t 9 | { 10 | invalid = 0, 11 | not_a_block = 1, 12 | send = 2, 13 | receive = 3, 14 | open = 4, 15 | change = 5, 16 | state = 6 17 | }; 18 | 19 | std::string_view to_string (block_type); 20 | } // namespace nano 21 | -------------------------------------------------------------------------------- /nano/lib/block_uniquer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace nano 8 | { 9 | class block; 10 | using block_uniquer = nano::uniquer; 11 | } 12 | -------------------------------------------------------------------------------- /nano/lib/cli.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace nano 8 | { 9 | class config_key_value_pair 10 | { 11 | public: 12 | std::string key; 13 | std::string value; 14 | }; 15 | 16 | std::vector config_overrides (std::vector const & key_value_pairs_a); 17 | 18 | std::istream & operator>> (std::istream & is, nano::config_key_value_pair & into); 19 | } 20 | -------------------------------------------------------------------------------- /nano/lib/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace boost::asio::ip 4 | { 5 | class address; 6 | class tcp; 7 | template 8 | class basic_endpoint; 9 | } 10 | 11 | namespace nano 12 | { 13 | using ip_address = boost::asio::ip::address; 14 | using endpoint = boost::asio::ip::basic_endpoint; 15 | using tcp_endpoint = endpoint; 16 | } 17 | -------------------------------------------------------------------------------- /nano/lib/container_info.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | nano::container_info_composite::container_info_composite (std::string name) : 4 | name (std::move (name)) 5 | { 6 | } 7 | 8 | bool nano::container_info_composite::is_composite () const 9 | { 10 | return true; 11 | } 12 | 13 | void nano::container_info_composite::add_component (std::unique_ptr child) 14 | { 15 | children.push_back (std::move (child)); 16 | } 17 | 18 | std::vector> const & nano::container_info_composite::get_children () const 19 | { 20 | return children; 21 | } 22 | 23 | std::string const & nano::container_info_composite::get_name () const 24 | { 25 | return name; 26 | } 27 | 28 | nano::container_info_leaf::container_info_leaf (container_info_entry info) : 29 | info (std::move (info)) 30 | { 31 | } 32 | 33 | bool nano::container_info_leaf::is_composite () const 34 | { 35 | return false; 36 | } 37 | 38 | nano::container_info_entry const & nano::container_info_leaf::get_info () const 39 | { 40 | return info; 41 | } -------------------------------------------------------------------------------- /nano/lib/diagnosticsconfig.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | class jsonconfig; 10 | class tomlconfig; 11 | class txn_tracking_config final 12 | { 13 | public: 14 | /** If true, enable tracking for transaction read/writes held open longer than the min time variables */ 15 | bool enable{ false }; 16 | std::chrono::milliseconds min_read_txn_time{ 5000 }; 17 | std::chrono::milliseconds min_write_txn_time{ 500 }; 18 | bool ignore_writes_below_block_processor_max_time{ true }; 19 | }; 20 | 21 | /** Configuration options for diagnostics information */ 22 | class diagnostics_config final 23 | { 24 | public: 25 | nano::error serialize_toml (nano::tomlconfig &) const; 26 | nano::error deserialize_toml (nano::tomlconfig &); 27 | 28 | txn_tracking_config txn_tracking; 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /nano/lib/env.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | std::optional nano::env::get (std::string_view name) 8 | { 9 | std::string name_str{ name }; 10 | if (auto value = std::getenv (name_str.c_str ())) 11 | { 12 | return std::string{ value }; 13 | } 14 | return std::nullopt; 15 | } 16 | 17 | template <> 18 | std::optional nano::env::get (std::string_view name) 19 | { 20 | std::vector const on_values{ "1", "true", "on" }; 21 | std::vector const off_values{ "0", "false", "off" }; 22 | 23 | if (auto value = get (name)) 24 | { 25 | // Using case-insensitive comparison 26 | if (std::any_of (on_values.begin (), on_values.end (), [&value] (auto const & on) { return boost::iequals (*value, on); })) 27 | { 28 | return true; 29 | } 30 | if (std::any_of (off_values.begin (), off_values.end (), [&value] (auto const & off) { return boost::iequals (*value, off); })) 31 | { 32 | return false; 33 | } 34 | 35 | throw std::invalid_argument ("Invalid environment boolean value: " + *value); 36 | } 37 | return std::nullopt; 38 | } -------------------------------------------------------------------------------- /nano/lib/env.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace nano::env 9 | { 10 | /** 11 | * Get environment variable as a specific type or none if variable is not present. 12 | */ 13 | std::optional get (std::string_view name); 14 | 15 | /** 16 | * Get environment variable as a specific type or none if variable is not present. 17 | * @throws std::invalid_argument if the value cannot be converted 18 | */ 19 | template 20 | std::optional get (std::string_view name) 21 | { 22 | if (auto value = get (name)) 23 | { 24 | try 25 | { 26 | return boost::lexical_cast (*value); 27 | } 28 | catch (boost::bad_lexical_cast const &) 29 | { 30 | throw std::invalid_argument ("Invalid environment value: " + *value); 31 | } 32 | } 33 | return std::nullopt; 34 | } 35 | 36 | /** 37 | * Specialization for boolean values. 38 | * @throws std::invalid_argument if the value is not a valid boolean 39 | */ 40 | template <> 41 | std::optional get (std::string_view name); 42 | } -------------------------------------------------------------------------------- /nano/lib/epoch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | std::underlying_type_t nano::normalized_epoch (nano::epoch epoch_a) 5 | { 6 | // Currently assumes that the epoch versions in the enum are sequential. 7 | auto start = std::underlying_type_t (nano::epoch::epoch_0); 8 | auto end = std::underlying_type_t (epoch_a); 9 | debug_assert (end >= start); 10 | return end - start; 11 | } 12 | -------------------------------------------------------------------------------- /nano/lib/epoch.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace nano 8 | { 9 | /** 10 | * Tag for which epoch an entry belongs to 11 | */ 12 | enum class epoch : uint8_t 13 | { 14 | invalid = 0, 15 | unspecified = 1, 16 | epoch_begin = 2, 17 | epoch_0 = 2, 18 | epoch_1 = 3, 19 | epoch_2 = 4, 20 | max = epoch_2 21 | }; 22 | 23 | /* This turns epoch_0 into 0 for instance */ 24 | std::underlying_type_t normalized_epoch (nano::epoch epoch_a); 25 | } 26 | namespace std 27 | { 28 | template <> 29 | struct hash<::nano::epoch> 30 | { 31 | std::size_t operator() (::nano::epoch const & epoch_a) const 32 | { 33 | return std::underlying_type_t<::nano::epoch> (epoch_a); 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /nano/lib/formatting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /nano/lib/function.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace nano 8 | { 9 | // TODO: Replace with std::move_only_function in C++23 10 | template 11 | auto wrap_move_only (F && f) 12 | { 13 | using fn_type = decltype (std::function{ std::declval () }); 14 | auto ptr = std::make_shared> (std::forward (f)); 15 | return fn_type ([ptr] (auto &&... args) { 16 | return (*ptr) (std::forward (args)...); 17 | }); 18 | } 19 | } -------------------------------------------------------------------------------- /nano/lib/fwd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct uint8_char_traits; 7 | 8 | namespace nano 9 | { 10 | class block; 11 | class block_details; 12 | class block_visitor; 13 | class container_info; 14 | class jsonconfig; 15 | class logger; 16 | class mutable_block_visitor; 17 | class network_constants; 18 | class object_stream; 19 | class root; 20 | class stats; 21 | class thread_pool; 22 | class thread_runner; 23 | class tomlconfig; 24 | template 25 | class uniquer; 26 | 27 | enum class block_type : uint8_t; 28 | enum class epoch : uint8_t; 29 | enum class work_version; 30 | 31 | using stream = std::basic_streambuf; 32 | } 33 | 34 | namespace nano::stat 35 | { 36 | enum class type; 37 | enum class detail; 38 | enum class dir; 39 | } 40 | -------------------------------------------------------------------------------- /nano/lib/interval.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | class interval 9 | { 10 | public: 11 | bool elapse (auto target) 12 | { 13 | auto const now = std::chrono::steady_clock::now (); 14 | if (now - last >= target) 15 | { 16 | last = now; 17 | return true; 18 | } 19 | return false; 20 | } 21 | 22 | private: 23 | std::chrono::steady_clock::time_point last{}; 24 | }; 25 | 26 | class interval_mt 27 | { 28 | public: 29 | bool elapse (auto target) 30 | { 31 | std::lock_guard guard{ mutex }; 32 | auto const now = std::chrono::steady_clock::now (); 33 | if (now - last >= target) 34 | { 35 | last = now; 36 | return true; 37 | } 38 | return false; 39 | } 40 | 41 | private: 42 | std::mutex mutex; 43 | std::chrono::steady_clock::time_point last{}; 44 | }; 45 | } -------------------------------------------------------------------------------- /nano/lib/ipc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | nano::ipc::socket_base::socket_base (boost::asio::io_context & io_ctx_a) : 5 | io_timer (io_ctx_a) 6 | { 7 | } 8 | 9 | void nano::ipc::socket_base::timer_start (std::chrono::seconds timeout_a) 10 | { 11 | if (timeout_a < std::chrono::seconds::max ()) 12 | { 13 | io_timer.expires_from_now (boost::posix_time::seconds (static_cast (timeout_a.count ()))); 14 | io_timer.async_wait ([this] (boost::system::error_code const & ec) { 15 | if (!ec) 16 | { 17 | this->timer_expired (); 18 | } 19 | }); 20 | } 21 | } 22 | 23 | void nano::ipc::socket_base::timer_expired () 24 | { 25 | close (); 26 | } 27 | 28 | void nano::ipc::socket_base::timer_cancel () 29 | { 30 | boost::system::error_code ec; 31 | io_timer.cancel (ec); 32 | debug_assert (!ec); 33 | } 34 | 35 | nano::ipc::dsock_file_remover::dsock_file_remover (std::string const & file_a) : 36 | filename (file_a) 37 | { 38 | std::remove (filename.c_str ()); 39 | } 40 | 41 | nano::ipc::dsock_file_remover::~dsock_file_remover () 42 | { 43 | std::remove (filename.c_str ()); 44 | } 45 | -------------------------------------------------------------------------------- /nano/lib/json_error_response.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | inline void json_error_response (std::function response_a, std::string const & message_a) 9 | { 10 | boost::property_tree::ptree response_l; 11 | response_l.put ("error", message_a); 12 | std::stringstream ostream; 13 | boost::property_tree::write_json (ostream, response_l); 14 | response_a (ostream.str ()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nano/lib/memory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace 4 | { 5 | #ifdef MEMORY_POOL_DISABLED 6 | /** TSAN on mac is generating some warnings. They need further investigating before memory pools can be used, so disable them for now */ 7 | bool use_memory_pools{ false }; 8 | #else 9 | bool use_memory_pools{ true }; 10 | #endif 11 | } 12 | 13 | bool nano::get_use_memory_pools () 14 | { 15 | return use_memory_pools; 16 | } 17 | 18 | /** This has no effect on Mac */ 19 | void nano::set_use_memory_pools (bool use_memory_pools_a) 20 | { 21 | #ifndef MEMORY_POOL_DISABLED 22 | use_memory_pools = use_memory_pools_a; 23 | #endif 24 | } 25 | 26 | nano::cleanup_guard::cleanup_guard (std::vector> const & cleanup_funcs_a) : 27 | cleanup_funcs (cleanup_funcs_a) 28 | { 29 | } 30 | 31 | nano::cleanup_guard::~cleanup_guard () 32 | { 33 | for (auto & func : cleanup_funcs) 34 | { 35 | func (); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /nano/lib/object_stream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | nano::object_stream_config const & nano::object_stream_config::default_config () 4 | { 5 | static object_stream_config const config{}; 6 | return config; 7 | } 8 | 9 | nano::object_stream_config const & nano::object_stream_config::json_config () 10 | { 11 | static object_stream_config const config{ 12 | .field_name_begin = "\"", 13 | .field_name_end = "\"", 14 | .field_assignment = ":", 15 | .field_separator = ",", 16 | .object_begin = "{", 17 | .object_end = "}", 18 | .array_begin = "[", 19 | .array_end = "]", 20 | .array_element_begin = "", 21 | .array_element_end = "", 22 | .array_element_separator = ",", 23 | .indent = "", 24 | .newline = "", 25 | .precision = 4, 26 | }; 27 | return config; 28 | } -------------------------------------------------------------------------------- /nano/lib/plat/darwin/thread_role.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | void nano::thread_role::set_os_name (std::string const & thread_name) 6 | { 7 | pthread_setname_np (thread_name.c_str ()); 8 | } 9 | -------------------------------------------------------------------------------- /nano/lib/plat/default/debugging.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void nano::create_load_memory_address_files () 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /nano/lib/plat/default/priority.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void nano::work_thread_reprioritize () 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /nano/lib/plat/freebsd/thread_role.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | void nano::thread_role::set_os_name (std::string const & thread_name) 7 | { 8 | pthread_set_name_np (pthread_self (), thread_name.c_str ()); 9 | } 10 | -------------------------------------------------------------------------------- /nano/lib/plat/linux/priority.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | void nano::work_thread_reprioritize () 6 | { 7 | auto handle (pthread_self ()); 8 | int policy; 9 | struct sched_param sched; 10 | if (pthread_getschedparam (handle, &policy, &sched) == 0) 11 | { 12 | policy = SCHED_BATCH; 13 | auto result (pthread_setschedparam (handle, policy, &sched)); 14 | (void)result; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nano/lib/plat/linux/thread_role.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | void nano::thread_role::set_os_name (std::string const & thread_name) 6 | { 7 | pthread_setname_np (pthread_self (), thread_name.c_str ()); 8 | } 9 | -------------------------------------------------------------------------------- /nano/lib/plat/posix/perms.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | void nano::set_umask () 8 | { 9 | umask (077); 10 | } 11 | 12 | void nano::set_secure_perm_directory (std::filesystem::path const & path) 13 | { 14 | std::filesystem::permissions (path, std::filesystem::perms::owner_all); 15 | } 16 | 17 | void nano::set_secure_perm_directory (std::filesystem::path const & path, std::error_code & ec) 18 | { 19 | std::filesystem::permissions (path, std::filesystem::perms::owner_all, ec); 20 | } 21 | 22 | void nano::set_secure_perm_file (std::filesystem::path const & path) 23 | { 24 | std::filesystem::permissions (path, std::filesystem::perms::owner_read | std::filesystem::perms::owner_write); 25 | } 26 | 27 | void nano::set_secure_perm_file (std::filesystem::path const & path, std::error_code & ec) 28 | { 29 | std::filesystem::permissions (path, std::filesystem::perms::owner_read | std::filesystem::perms::owner_write, ec); 30 | } 31 | -------------------------------------------------------------------------------- /nano/lib/plat/windows/priority.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace nano 4 | { 5 | void work_thread_reprioritize () 6 | { 7 | SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nano/lib/plat/windows/registry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace nano 4 | { 5 | bool event_log_reg_entry_exists () 6 | { 7 | HKEY h_key; 8 | auto res = RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Nano\\Nano", 0, KEY_READ, &h_key); 9 | auto found_key = (res == ERROR_SUCCESS); 10 | if (found_key) 11 | { 12 | RegCloseKey (h_key); 13 | } 14 | return found_key; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nano/lib/plat/windows/thread_role.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | void nano::thread_role::set_os_name (std::string const & thread_name) 6 | { 7 | using SetThreadDescription_t = HRESULT (*) (HANDLE, PCWSTR); 8 | SetThreadDescription_t SetThreadDescription_local = (SetThreadDescription_t)GetProcAddress (GetModuleHandle (TEXT ("kernel32.dll")), "SetThreadDescription"); 9 | if (SetThreadDescription_local) 10 | { 11 | std::wstring thread_name_wide (thread_name.begin (), thread_name.end ()); 12 | SetThreadDescription_local (GetCurrentThread (), thread_name_wide.c_str ()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /nano/lib/rocksdbconfig.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class tomlconfig; 11 | 12 | /** Configuration options for RocksDB */ 13 | class rocksdb_config final 14 | { 15 | public: 16 | rocksdb_config () : 17 | enable{ using_rocksdb_in_tests () } 18 | { 19 | } 20 | 21 | nano::error serialize_toml (nano::tomlconfig &) const; 22 | nano::error deserialize_toml (nano::tomlconfig &); 23 | 24 | /** To use RocksDB in tests make sure the environment variable TEST_USE_ROCKSDB=1 is set */ 25 | static bool using_rocksdb_in_tests (); 26 | 27 | bool enable{ false }; 28 | unsigned io_threads{ std::max (nano::hardware_concurrency () / 2, 1u) }; 29 | long read_cache{ 32 }; 30 | long write_cache{ 64 }; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /nano/lib/stacktrace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | void nano::dump_crash_stacktrace () 8 | { 9 | boost::stacktrace::safe_dump_to ("nano_node_backtrace.dump"); 10 | } 11 | 12 | std::string nano::generate_stacktrace () 13 | { 14 | auto stacktrace = boost::stacktrace::stacktrace (); 15 | std::stringstream ss; 16 | ss << stacktrace; 17 | return ss.str (); 18 | } 19 | -------------------------------------------------------------------------------- /nano/lib/stacktrace.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | /** 8 | * Dumps a stacktrace file which can be read using the --debug_output_last_backtrace_dump CLI command 9 | */ 10 | void dump_crash_stacktrace (); 11 | 12 | /** 13 | * Generates the current stacktrace 14 | */ 15 | std::string generate_stacktrace (); 16 | } -------------------------------------------------------------------------------- /nano/lib/stats_enums.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | std::string_view nano::to_string (nano::stat::type type) 5 | { 6 | return nano::enum_util::name (type); 7 | } 8 | 9 | std::string_view nano::to_string (nano::stat::detail detail) 10 | { 11 | return nano::enum_util::name (detail); 12 | } 13 | 14 | std::string_view nano::to_string (nano::stat::dir dir) 15 | { 16 | return nano::enum_util::name (dir); 17 | } 18 | 19 | std::string_view nano::to_string (nano::stat::sample sample) 20 | { 21 | return nano::enum_util::name (sample); 22 | } -------------------------------------------------------------------------------- /nano/lib/threading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | /* 9 | * thread_attributes 10 | */ 11 | 12 | boost::thread::attributes nano::thread_attributes::get_default () 13 | { 14 | boost::thread::attributes attrs; 15 | attrs.set_stack_size (8000000); // 8MB 16 | return attrs; 17 | } 18 | 19 | unsigned nano::hardware_concurrency () 20 | { 21 | static auto const concurrency = [] () { 22 | if (auto value = nano::env::get ("NANO_HARDWARE_CONCURRENCY")) 23 | { 24 | std::cerr << "Hardware concurrency overridden by NANO_HARDWARE_CONCURRENCY environment variable: " << *value << std::endl; 25 | return *value; 26 | } 27 | return std::thread::hardware_concurrency (); 28 | }(); 29 | release_assert (concurrency > 0, "configured hardware concurrency must be non zero"); 30 | return concurrency; 31 | } 32 | 33 | bool nano::join_or_pass (std::thread & thread) 34 | { 35 | if (thread.joinable ()) 36 | { 37 | thread.join (); 38 | return true; 39 | } 40 | else 41 | { 42 | return false; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /nano/lib/threading.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace nano 10 | { 11 | namespace thread_attributes 12 | { 13 | boost::thread::attributes get_default (); 14 | } // namespace thread_attributes 15 | 16 | /** 17 | * Number of available logical processor cores. Might be overridden by setting `NANO_HARDWARE_CONCURRENCY` environment variable 18 | */ 19 | unsigned hardware_concurrency (); 20 | 21 | /** 22 | * If thread is joinable joins it, otherwise does nothing 23 | * Returns thread.joinable() 24 | */ 25 | bool join_or_pass (std::thread &); 26 | } // namespace nano 27 | -------------------------------------------------------------------------------- /nano/lib/utility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | // Issue #3748 6 | void nano::sort_options_description (const boost::program_options::options_description & source, boost::program_options::options_description & target) 7 | { 8 | // Grab all of the options, get the option display name, stick it in a map using the display name as 9 | // the key (the map will sort) and the value as the option itself. 10 | const auto & options = source.options (); 11 | std::map> sorted_options; 12 | for (const auto & option : options) 13 | { 14 | auto pair = std::make_pair (option->canonical_display_name (2), option); 15 | sorted_options.insert (pair); 16 | } 17 | 18 | // Rebuild for display purposes only. 19 | for (const auto & option_pair : sorted_options) 20 | { 21 | target.add (option_pair.second); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /nano/lib/walletconfig.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class tomlconfig; 11 | 12 | /** Configuration options for the Qt wallet */ 13 | class wallet_config final 14 | { 15 | public: 16 | wallet_config (); 17 | /** Update this instance by parsing the given wallet and account */ 18 | nano::error parse (std::string const & wallet_a, std::string const & account_a); 19 | nano::error serialize_toml (nano::tomlconfig & toml_a) const; 20 | nano::error deserialize_toml (nano::tomlconfig & toml_a); 21 | nano::wallet_id wallet; 22 | nano::account account{}; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /nano/lib/work_version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nano 4 | { 5 | enum class work_version 6 | { 7 | unspecified, 8 | work_1 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /nano/load_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(load_test entry.cpp) 2 | 3 | target_link_libraries(load_test test_common Boost::process) 4 | 5 | include_directories(${CMAKE_SOURCE_DIR}/submodules) 6 | include_directories(${CMAKE_SOURCE_DIR}/submodules/gtest/googletest/include) 7 | -------------------------------------------------------------------------------- /nano/nano_node/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(nano_node daemon.cpp daemon.hpp entry.cpp) 2 | 3 | target_link_libraries(nano_node node Boost::process ${PLATFORM_LIBS}) 4 | 5 | include_directories(${CMAKE_SOURCE_DIR}/submodules) 6 | 7 | target_compile_definitions( 8 | nano_node PRIVATE -DTAG_VERSION_STRING=${TAG_VERSION_STRING} 9 | -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) 10 | 11 | set_target_properties( 12 | nano_node PROPERTIES COMPILE_FLAGS 13 | "-DQT_NO_KEYWORDS -DBOOST_ASIO_HAS_STD_ARRAY=1") 14 | 15 | add_custom_command( 16 | TARGET nano_node 17 | POST_BUILD 18 | COMMAND nano_node --generate_config node > 19 | ${PROJECT_BINARY_DIR}/config-node.toml.sample 20 | COMMAND nano_node --generate_config rpc > 21 | ${PROJECT_BINARY_DIR}/config-rpc.toml.sample 22 | COMMAND nano_node --generate_config log > 23 | ${PROJECT_BINARY_DIR}/config-log.toml.sample) 24 | 25 | if((NANO_GUI OR RAIBLOCKS_GUI) AND NOT APPLE) 26 | if(WIN32) 27 | install(TARGETS nano_node RUNTIME DESTINATION .) 28 | else() 29 | install(TARGETS nano_node RUNTIME DESTINATION ./bin) 30 | endif() 31 | endif() 32 | -------------------------------------------------------------------------------- /nano/nano_node/daemon.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace nano 4 | { 5 | class node_flags; 6 | 7 | class daemon 8 | { 9 | nano::logger logger{ "daemon" }; 10 | 11 | public: 12 | void run (std::filesystem::path const &, nano::node_flags const & flags); 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /nano/nano_rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(nano_rpc entry.cpp) 2 | 3 | target_link_libraries(nano_rpc node) 4 | 5 | target_compile_definitions( 6 | nano_rpc 7 | PUBLIC -DACTIVE_NETWORK=${ACTIVE_NETWORK} 8 | PRIVATE -DTAG_VERSION_STRING=${TAG_VERSION_STRING} 9 | -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) 10 | 11 | if((NANO_GUI OR RAIBLOCKS_GUI) AND NOT APPLE) 12 | if(WIN32) 13 | install(TARGETS nano_rpc RUNTIME DESTINATION .) 14 | else() 15 | install(TARGETS nano_rpc RUNTIME DESTINATION ./bin) 16 | endif() 17 | endif() 18 | -------------------------------------------------------------------------------- /nano/nano_wallet/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/nano/nano_wallet/.DS_Store -------------------------------------------------------------------------------- /nano/nano_wallet/icon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class QApplication; 4 | namespace nano 5 | { 6 | void set_application_icon (QApplication &); 7 | } 8 | -------------------------------------------------------------------------------- /nano/nano_wallet/plat/default/icon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void nano::set_application_icon (QApplication &) 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /nano/nano_wallet/plat/windows/icon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void nano::set_application_icon (QApplication & application_a) 8 | { 9 | HICON hIcon = static_cast (LoadImage (GetModuleHandle (nullptr), MAKEINTRESOURCE (1), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT)); 10 | application_a.setWindowIcon (QIcon (QtWin::fromHICON (hIcon))); 11 | DestroyIcon (hIcon); 12 | } 13 | -------------------------------------------------------------------------------- /nano/node/block_context.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class block_context 11 | { 12 | public: 13 | using result_t = nano::block_status; 14 | using callback_t = std::function; 15 | 16 | public: // Keep fields public for simplicity 17 | std::shared_ptr block; 18 | nano::block_source source; 19 | callback_t callback; 20 | std::chrono::steady_clock::time_point arrival{ std::chrono::steady_clock::now () }; 21 | 22 | public: 23 | block_context (std::shared_ptr block, nano::block_source source, callback_t callback = nullptr) : 24 | block{ std::move (block) }, 25 | source{ source }, 26 | callback{ std::move (callback) } 27 | { 28 | debug_assert (source != nano::block_source::unknown); 29 | } 30 | 31 | std::future get_future () 32 | { 33 | return promise.get_future (); 34 | } 35 | 36 | void set_result (result_t result) 37 | { 38 | promise.set_value (result); 39 | } 40 | 41 | private: 42 | std::promise promise; 43 | }; 44 | } -------------------------------------------------------------------------------- /nano/node/block_source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | std::string_view nano::to_string (nano::block_source source) 6 | { 7 | return nano::enum_util::name (source); 8 | } 9 | 10 | nano::stat::detail nano::to_stat_detail (nano::block_source type) 11 | { 12 | return nano::enum_util::cast (type); 13 | } -------------------------------------------------------------------------------- /nano/node/block_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | enum class block_source 10 | { 11 | unknown = 0, 12 | live, 13 | live_originator, 14 | bootstrap, 15 | bootstrap_legacy, 16 | unchecked, 17 | local, 18 | forced, 19 | election, 20 | }; 21 | 22 | std::string_view to_string (block_source); 23 | nano::stat::detail to_stat_detail (block_source); 24 | } -------------------------------------------------------------------------------- /nano/node/bootstrap/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::bootstrap 6 | { 7 | using id_t = uint64_t; 8 | static nano::bootstrap::id_t generate_id () 9 | { 10 | nano::bootstrap::id_t id; 11 | nano::random_pool::generate_block (reinterpret_cast (&id), sizeof (id)); 12 | return id; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /nano/node/bootstrap/throttle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | nano::bootstrap::throttle::throttle (std::size_t size) : 5 | successes_m{ size } 6 | { 7 | samples.insert (samples.end (), size, true); 8 | debug_assert (size > 0); 9 | } 10 | 11 | void nano::bootstrap::throttle::reset () 12 | { 13 | successes_m = samples.size (); 14 | std::fill (samples.begin (), samples.end (), true); 15 | } 16 | 17 | bool nano::bootstrap::throttle::throttled () const 18 | { 19 | return successes_m == 0; 20 | } 21 | 22 | void nano::bootstrap::throttle::add (bool sample) 23 | { 24 | debug_assert (!samples.empty ()); 25 | pop (); 26 | samples.push_back (sample); 27 | if (sample) 28 | { 29 | ++successes_m; 30 | } 31 | } 32 | 33 | void nano::bootstrap::throttle::resize (std::size_t size) 34 | { 35 | debug_assert (size > 0); 36 | while (size < samples.size ()) 37 | { 38 | pop (); 39 | } 40 | while (size > samples.size ()) 41 | { 42 | samples.push_back (false); 43 | } 44 | } 45 | 46 | std::size_t nano::bootstrap::throttle::size () const 47 | { 48 | return samples.size (); 49 | } 50 | 51 | std::size_t nano::bootstrap::throttle::successes () const 52 | { 53 | return successes_m; 54 | } 55 | 56 | void nano::bootstrap::throttle::pop () 57 | { 58 | if (samples.front ()) 59 | { 60 | --successes_m; 61 | } 62 | samples.pop_front (); 63 | } 64 | -------------------------------------------------------------------------------- /nano/node/bootstrap/throttle.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::bootstrap 6 | { 7 | // Class used to throttle the ascending bootstrapper once it reaches a steady state 8 | // Tracks verify_result samples and signals throttling if no tracked samples have gotten results 9 | class throttle 10 | { 11 | public: 12 | // Initialized with all true samples 13 | explicit throttle (std::size_t size); 14 | 15 | [[nodiscard]] bool throttled () const; 16 | void add (bool success); 17 | 18 | // Resizes the number of samples tracked 19 | // Drops the oldest samples if the size decreases 20 | // Adds false samples if the size increases 21 | void resize (std::size_t size); 22 | 23 | [[nodiscard]] std::size_t size () const; 24 | [[nodiscard]] std::size_t successes () const; 25 | 26 | void reset (); 27 | 28 | private: 29 | void pop (); 30 | 31 | // Bit set that tracks sample results. True when something was retrieved, false otherwise 32 | std::deque samples; 33 | std::size_t successes_m; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /nano/node/bucketing.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | class bucketing 9 | { 10 | public: 11 | bucketing (); 12 | 13 | nano::bucket_index bucket_index (nano::amount balance) const; 14 | std::vector const & bucket_indices () const; 15 | size_t size () const; 16 | 17 | private: 18 | std::vector minimums; 19 | std::vector indices; 20 | }; 21 | } -------------------------------------------------------------------------------- /nano/node/cli.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | /** Command line related error codes */ 11 | enum class error_cli 12 | { 13 | generic = 1, 14 | parse_error = 2, 15 | invalid_arguments = 3, 16 | unknown_command = 4, 17 | database_write_error = 5, 18 | reading_config = 6, 19 | ambiguous_pruning_voting_options = 7 20 | }; 21 | 22 | void add_node_options (boost::program_options::options_description &); 23 | void add_node_flag_options (boost::program_options::options_description &); 24 | std::error_code update_flags (nano::node_flags &, boost::program_options::variables_map const &); 25 | std::error_code flags_config_conflicts (nano::node_flags const &, nano::node_config const &); 26 | std::error_code handle_node_options (boost::program_options::variables_map const &); 27 | } 28 | 29 | REGISTER_ERROR_CODES (nano, error_cli) 30 | -------------------------------------------------------------------------------- /nano/node/daemonconfig.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace nano 11 | { 12 | class tomlconfig; 13 | class daemon_config 14 | { 15 | public: 16 | daemon_config () = default; 17 | daemon_config (std::filesystem::path const & data_path, nano::network_params & network_params); 18 | nano::error deserialize_toml (nano::tomlconfig &); 19 | nano::error serialize_toml (nano::tomlconfig &); 20 | bool rpc_enable{ false }; 21 | nano::node_rpc_config rpc; 22 | nano::node_config node; 23 | bool opencl_enable{ false }; 24 | nano::opencl_config opencl; 25 | std::filesystem::path data_path; 26 | }; 27 | 28 | nano::error read_node_config_toml (std::filesystem::path const &, nano::daemon_config & config_a, std::vector const & config_overrides = std::vector ()); 29 | } 30 | -------------------------------------------------------------------------------- /nano/node/distributed_work_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace nano 13 | { 14 | class container_info_component; 15 | class distributed_work; 16 | class node; 17 | class root; 18 | struct work_request; 19 | 20 | class distributed_work_factory final 21 | { 22 | public: 23 | distributed_work_factory (nano::node &); 24 | ~distributed_work_factory (); 25 | bool make (nano::work_version const, nano::root const &, std::vector> const &, uint64_t, std::function)> const &, std::optional const & = std::nullopt); 26 | bool make (std::chrono::seconds const &, nano::work_request const &); 27 | void cancel (nano::root const &); 28 | void cleanup_finished (); 29 | void stop (); 30 | std::size_t size () const; 31 | nano::container_info container_info () const; 32 | 33 | private: 34 | std::unordered_multimap> items; 35 | 36 | nano::node & node; 37 | mutable nano::mutex mutex; 38 | std::atomic stopped{ false }; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /nano/node/election_behavior.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | enum class election_behavior 10 | { 11 | manual, 12 | priority, 13 | /** 14 | * Hinted elections: 15 | * - shorter timespan 16 | * - limited space inside AEC 17 | */ 18 | hinted, 19 | /** 20 | * Optimistic elections: 21 | * - shorter timespan 22 | * - limited space inside AEC 23 | * - more frequent confirmation requests 24 | */ 25 | optimistic, 26 | }; 27 | 28 | std::string_view to_string (election_behavior); 29 | nano::stat::detail to_stat_detail (election_behavior); 30 | } 31 | -------------------------------------------------------------------------------- /nano/node/election_insertion_result.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | class election; 8 | class election_insertion_result final 9 | { 10 | public: 11 | std::shared_ptr election; 12 | bool inserted{ false }; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /nano/node/endpoint_templ.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace std 7 | { 8 | template <> 9 | struct hash<::nano::endpoint> 10 | { 11 | std::size_t operator() (::nano::endpoint const & endpoint_a) const 12 | { 13 | endpoint_hash ehash; 14 | return ehash (endpoint_a); 15 | } 16 | }; 17 | 18 | #ifndef BOOST_ASIO_HAS_STD_HASH 19 | template <> 20 | struct hash 21 | { 22 | std::size_t operator() (boost::asio::ip::address const & ip_a) const 23 | { 24 | ip_address_hash ihash; 25 | return ihash (ip_a); 26 | } 27 | }; 28 | #endif 29 | } 30 | 31 | namespace boost 32 | { 33 | template <> 34 | struct hash<::nano::endpoint> 35 | { 36 | std::size_t operator() (::nano::endpoint const & endpoint_a) const 37 | { 38 | std::hash<::nano::endpoint> hash; 39 | return hash (endpoint_a); 40 | } 41 | }; 42 | 43 | template <> 44 | struct hash 45 | { 46 | std::size_t operator() (boost::asio::ip::address const & ip_a) const 47 | { 48 | std::hash hash; 49 | return hash (ip_a); 50 | } 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /nano/node/epoch_upgrader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace nano 15 | { 16 | class epoch_upgrader final 17 | { 18 | public: 19 | epoch_upgrader (nano::node &, nano::ledger &, nano::store::component &, nano::network_params &, nano::logger &); 20 | 21 | bool start (nano::raw_key const & prv, nano::epoch epoch, uint64_t count_limit, uint64_t threads); 22 | void stop (); 23 | 24 | private: // Dependencies 25 | nano::node & node; 26 | nano::ledger & ledger; 27 | nano::store::component & store; 28 | nano::network_params & network_params; 29 | nano::logger & logger; 30 | 31 | private: 32 | void upgrade_impl (nano::raw_key const & prv, nano::epoch epoch, uint64_t count_limit, uint64_t threads); 33 | 34 | std::atomic stopped{ false }; 35 | nano::locked> epoch_upgrading; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /nano/node/inactive_node.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | nano::inactive_node::inactive_node (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) : 6 | node_wrapper (path_a, config_path_a, node_flags_a), 7 | node (node_wrapper.node) 8 | { 9 | node_wrapper.node->active.stop (); 10 | } 11 | 12 | nano::inactive_node::inactive_node (std::filesystem::path const & path_a, nano::node_flags const & node_flags_a) : 13 | inactive_node (path_a, path_a, node_flags_a) 14 | { 15 | } 16 | 17 | nano::node_flags const & nano::inactive_node_flag_defaults () 18 | { 19 | static nano::node_flags node_flags; 20 | node_flags.inactive_node = true; 21 | node_flags.read_only = true; 22 | node_flags.generate_cache.reps = false; 23 | node_flags.generate_cache.cemented_count = false; 24 | node_flags.generate_cache.unchecked_count = false; 25 | node_flags.generate_cache.account_count = false; 26 | node_flags.disable_bootstrap_listener = true; 27 | node_flags.disable_tcp_realtime = true; 28 | return node_flags; 29 | } 30 | -------------------------------------------------------------------------------- /nano/node/inactive_node.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace nano 10 | { 11 | 12 | class node; 13 | class node_flags; 14 | 15 | class inactive_node final 16 | { 17 | public: 18 | inactive_node (std::filesystem::path const & path_a, nano::node_flags const & node_flags_a); 19 | inactive_node (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a); 20 | 21 | nano::node_wrapper node_wrapper; 22 | std::shared_ptr node; 23 | }; 24 | 25 | std::unique_ptr default_inactive_node (std::filesystem::path const &, boost::program_options::variables_map const &); 26 | 27 | } // namespace nano -------------------------------------------------------------------------------- /nano/node/ipc/flatbuffers_util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | class amount; 10 | class block; 11 | class send_block; 12 | class receive_block; 13 | class change_block; 14 | class open_block; 15 | class state_block; 16 | namespace ipc 17 | { 18 | /** 19 | * Utilities to convert between blocks and Flatbuffers equivalents 20 | */ 21 | class flatbuffers_builder 22 | { 23 | public: 24 | static nanoapi::BlockUnion block_to_union (nano::block const & block_a, nano::amount const & amount_a, bool is_state_send_a = false, bool is_state_epoch_a = false); 25 | static std::unique_ptr from (nano::state_block const & block_a, nano::amount const & amount_a, bool is_state_send_a, bool is_state_epoch_a); 26 | static std::unique_ptr from (nano::send_block const & block_a); 27 | static std::unique_ptr from (nano::receive_block const & block_a); 28 | static std::unique_ptr from (nano::open_block const & block_a); 29 | static std::unique_ptr from (nano::change_block const & block_a); 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /nano/node/make_store.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace nano 12 | { 13 | class ledger_constants; 14 | class lmdb_config; 15 | class rocksdb_config; 16 | class txn_tracking_config; 17 | } 18 | 19 | namespace nano::store 20 | { 21 | class component; 22 | } 23 | 24 | namespace nano 25 | { 26 | std::unique_ptr make_store (nano::logger &, std::filesystem::path const & path, nano::ledger_constants & constants, bool read_only = false, bool add_db_postfix = true, nano::node_config node_config = nano::node_config{}); 27 | } 28 | -------------------------------------------------------------------------------- /nano/node/monitor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace std::chrono_literals; 10 | 11 | namespace nano 12 | { 13 | class monitor_config final 14 | { 15 | public: 16 | nano::error deserialize (nano::tomlconfig &); 17 | nano::error serialize (nano::tomlconfig &) const; 18 | 19 | public: 20 | bool enable{ true }; 21 | std::chrono::seconds interval{ 60s }; 22 | }; 23 | 24 | class monitor final 25 | { 26 | public: 27 | monitor (monitor_config const &, nano::node &); 28 | ~monitor (); 29 | 30 | void start (); 31 | void stop (); 32 | 33 | private: // Dependencies 34 | monitor_config const & config; 35 | nano::node & node; 36 | nano::logger & logger; 37 | 38 | private: 39 | void run (); 40 | void run_one (); 41 | 42 | std::chrono::steady_clock::time_point last_time{}; 43 | 44 | size_t last_blocks_cemented{ 0 }; 45 | size_t last_blocks_total{ 0 }; 46 | 47 | bool stopped{ false }; 48 | nano::condition_variable condition; 49 | mutable nano::mutex mutex; 50 | std::thread thread; 51 | }; 52 | } -------------------------------------------------------------------------------- /nano/node/node_observers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | nano::container_info nano::node_observers::container_info () const 4 | { 5 | nano::container_info info; 6 | info.put ("blocks", blocks.size ()); 7 | info.put ("wallet", wallet.size ()); 8 | info.put ("vote", vote.size ()); 9 | info.put ("active_started", active_started.size ()); 10 | info.put ("active_stopped", active_stopped.size ()); 11 | info.put ("account_balance", account_balance.size ()); 12 | info.put ("disconnect", disconnect.size ()); 13 | info.put ("work_cancel", work_cancel.size ()); 14 | info.put ("telemetry", telemetry.size ()); 15 | info.put ("socket_connected", socket_connected.size ()); 16 | info.put ("channel_connected", channel_connected.size ()); 17 | return info; 18 | } 19 | -------------------------------------------------------------------------------- /nano/node/node_rpc_config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace nano 10 | { 11 | class tomlconfig; 12 | class rpc_child_process_config final 13 | { 14 | public: 15 | bool enable{ false }; 16 | std::string rpc_path{ get_default_rpc_filepath () }; 17 | }; 18 | 19 | class node_rpc_config final 20 | { 21 | public: 22 | nano::error serialize_toml (nano::tomlconfig & toml) const; 23 | nano::error deserialize_toml (nano::tomlconfig & toml); 24 | 25 | bool enable_sign_hash{ false }; 26 | nano::rpc_child_process_config child_process; 27 | 28 | // Used in tests to ensure requests are modified in specific cases 29 | void set_request_callback (std::function); 30 | std::function request_callback; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /nano/node/node_wrapper.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace nano 11 | { 12 | 13 | class node; 14 | class node_flags; 15 | 16 | class node_wrapper final 17 | { 18 | public: 19 | node_wrapper (std::filesystem::path const & path_a, std::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a); 20 | ~node_wrapper (); 21 | 22 | nano::network_params network_params; 23 | std::shared_ptr io_context; 24 | nano::work_pool work; 25 | std::shared_ptr node; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /nano/node/openclconfig.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | nano::opencl_config::opencl_config (unsigned platform_a, unsigned device_a, unsigned threads_a) : 6 | platform (platform_a), 7 | device (device_a), 8 | threads (threads_a) 9 | { 10 | } 11 | 12 | nano::error nano::opencl_config::serialize_toml (nano::tomlconfig & toml) const 13 | { 14 | toml.put ("platform", platform); 15 | toml.put ("device", device); 16 | toml.put ("threads", threads); 17 | 18 | // Add documentation 19 | toml.doc ("platform", "OpenCL platform identifier"); 20 | toml.doc ("device", "OpenCL device identifier"); 21 | toml.doc ("threads", "OpenCL thread count"); 22 | 23 | return toml.get_error (); 24 | } 25 | 26 | nano::error nano::opencl_config::deserialize_toml (nano::tomlconfig & toml) 27 | { 28 | toml.get_optional ("platform", platform); 29 | toml.get_optional ("device", device); 30 | toml.get_optional ("threads", threads); 31 | return toml.get_error (); 32 | } 33 | -------------------------------------------------------------------------------- /nano/node/openclconfig.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | class tomlconfig; 8 | class opencl_config 9 | { 10 | public: 11 | opencl_config () = default; 12 | opencl_config (unsigned, unsigned, unsigned); 13 | nano::error serialize_toml (nano::tomlconfig &) const; 14 | nano::error deserialize_toml (nano::tomlconfig &); 15 | unsigned platform{ 0 }; 16 | unsigned device{ 0 }; 17 | unsigned threads{ 1024 * 1024 }; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /nano/node/pruning.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace nano 10 | { 11 | class pruning final 12 | { 13 | public: 14 | pruning (nano::node_config const &, nano::node_flags const &, nano::ledger &, nano::stats &, nano::logger &); 15 | ~pruning (); 16 | 17 | void start (); 18 | void stop (); 19 | 20 | nano::container_info container_info () const; 21 | 22 | void ongoing_ledger_pruning (); 23 | void ledger_pruning (uint64_t batch_size, bool bootstrap_weight_reached); 24 | bool collect_ledger_pruning_targets (std::deque & pruning_targets_out, nano::account & last_account_out, uint64_t batch_read_size, uint64_t max_depth, uint64_t cutoff_time); 25 | 26 | private: // Dependencies 27 | nano::node_config const & config; 28 | nano::node_flags const & flags; 29 | nano::ledger & ledger; 30 | nano::stats & stats; 31 | nano::logger & logger; 32 | 33 | private: 34 | void run (); 35 | 36 | std::atomic stopped{ false }; 37 | nano::thread_pool workers; 38 | }; 39 | } -------------------------------------------------------------------------------- /nano/node/recently_cemented_cache.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | * class recently_cemented 6 | */ 7 | 8 | nano::recently_cemented_cache::recently_cemented_cache (std::size_t max_size_a) : 9 | max_size{ max_size_a } 10 | { 11 | } 12 | 13 | void nano::recently_cemented_cache::put (const nano::election_status & status) 14 | { 15 | nano::lock_guard guard{ mutex }; 16 | cemented.push_back (status); 17 | if (cemented.size () > max_size) 18 | { 19 | cemented.pop_front (); 20 | } 21 | } 22 | 23 | nano::recently_cemented_cache::queue_t nano::recently_cemented_cache::list () const 24 | { 25 | nano::lock_guard guard{ mutex }; 26 | return cemented; 27 | } 28 | 29 | std::size_t nano::recently_cemented_cache::size () const 30 | { 31 | nano::lock_guard guard{ mutex }; 32 | return cemented.size (); 33 | } 34 | 35 | nano::container_info nano::recently_cemented_cache::container_info () const 36 | { 37 | nano::lock_guard guard{ mutex }; 38 | 39 | nano::container_info info; 40 | info.put ("cemented", cemented); 41 | return info; 42 | } 43 | -------------------------------------------------------------------------------- /nano/node/recently_cemented_cache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class container_info_component; 11 | } 12 | 13 | namespace nano 14 | { 15 | /* 16 | * Helper container for storing recently cemented elections (a block from election might be confirmed but not yet cemented by confirmation height processor) 17 | */ 18 | class recently_cemented_cache final 19 | { 20 | public: 21 | using queue_t = std::deque; 22 | 23 | explicit recently_cemented_cache (std::size_t max_size); 24 | 25 | void put (nano::election_status const &); 26 | queue_t list () const; 27 | std::size_t size () const; 28 | 29 | nano::container_info container_info () const; 30 | 31 | private: 32 | queue_t cemented; 33 | std::size_t const max_size; 34 | 35 | mutable nano::mutex mutex; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /nano/node/rpc_callbacks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | class http_callbacks 9 | { 10 | public: 11 | explicit http_callbacks (nano::node &); 12 | 13 | void start (); 14 | void stop (); 15 | 16 | nano::container_info container_info () const; 17 | 18 | private: // Dependencies 19 | nano::node_config const & config; 20 | nano::node & node; 21 | nano::node_observers & observers; 22 | nano::ledger & ledger; 23 | nano::logger & logger; 24 | nano::stats & stats; 25 | 26 | private: 27 | void setup_callbacks (); 28 | 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 &); 29 | 30 | nano::thread_pool workers; 31 | nano::interval_mt warning_interval; 32 | }; 33 | } -------------------------------------------------------------------------------- /nano/node/scheduler/component.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace nano::scheduler 9 | { 10 | class component final 11 | { 12 | public: 13 | component (nano::node_config &, nano::node &, nano::ledger &, nano::ledger_notifications &, nano::bucketing &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::cementing_set &, nano::stats &, nano::logger &); 14 | ~component (); 15 | 16 | void start (); 17 | void stop (); 18 | 19 | /// Does the block exist in any of the schedulers 20 | bool contains (nano::block_hash const & hash) const; 21 | 22 | nano::container_info container_info () const; 23 | 24 | private: 25 | std::unique_ptr hinted_impl; 26 | std::unique_ptr manual_impl; 27 | std::unique_ptr optimistic_impl; 28 | std::unique_ptr priority_impl; 29 | 30 | public: // Schedulers 31 | nano::scheduler::hinted & hinted; 32 | nano::scheduler::manual & manual; 33 | nano::scheduler::optimistic & optimistic; 34 | nano::scheduler::priority & priority; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /nano/node/scheduler/manual.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace nano::scheduler 14 | { 15 | class buckets; 16 | 17 | class manual final 18 | { 19 | std::deque, boost::optional, nano::election_behavior>> queue; 20 | nano::node & node; 21 | mutable nano::mutex mutex; 22 | nano::condition_variable condition; 23 | bool stopped{ false }; 24 | std::thread thread; 25 | void notify (); 26 | bool predicate () const; 27 | void run (); 28 | 29 | public: 30 | explicit manual (nano::node & node); 31 | ~manual (); 32 | 33 | void start (); 34 | void stop (); 35 | 36 | // Manually start an election for a block 37 | // Call action with confirmed block, may be different than what we started with 38 | void push (std::shared_ptr const &, boost::optional const & = boost::none); 39 | 40 | bool contains (nano::block_hash const &) const; 41 | 42 | nano::container_info container_info () const; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /nano/node/transport/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::transport 6 | { 7 | /** Policy to affect at which stage a buffer can be dropped */ 8 | enum class buffer_drop_policy 9 | { 10 | /** Can be dropped by bandwidth limiter (default) */ 11 | limiter, 12 | /** Should not be dropped by bandwidth limiter */ 13 | no_limiter_drop, 14 | /** Should not be dropped by bandwidth limiter or socket write queue limiter */ 15 | no_socket_drop 16 | }; 17 | 18 | enum class socket_type 19 | { 20 | undefined, 21 | bootstrap, 22 | realtime, 23 | realtime_response_server // special type for tcp channel response server 24 | }; 25 | 26 | std::string_view to_string (socket_type); 27 | 28 | enum class socket_endpoint 29 | { 30 | server, // Socket was created by accepting an incoming connection 31 | client, // Socket was created by initiating an outgoing connection 32 | }; 33 | 34 | std::string_view to_string (socket_endpoint); 35 | } -------------------------------------------------------------------------------- /nano/node/transport/fake.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | nano::transport::fake::channel::channel (nano::node & node) : 7 | transport::channel{ node }, 8 | endpoint{ node.network.endpoint () } 9 | { 10 | set_node_id (node.node_id.pub); 11 | set_network_version (node.network_params.network.protocol_version); 12 | } 13 | 14 | /** 15 | * The send function behaves like a null device, it throws the data away and returns success. 16 | */ 17 | bool nano::transport::fake::channel::send_impl (nano::message const & message, nano::transport::traffic_type traffic_type, nano::transport::channel::callback_t callback) 18 | { 19 | auto buffer = message.to_shared_const_buffer (); 20 | auto size = buffer.size (); 21 | if (callback) 22 | { 23 | node.io_ctx.post ([callback, size] () { 24 | callback (boost::system::errc::make_error_code (boost::system::errc::success), size); 25 | }); 26 | } 27 | return true; 28 | } 29 | 30 | std::string nano::transport::fake::channel::to_string () const 31 | { 32 | return boost::str (boost::format ("%1%") % endpoint); 33 | } -------------------------------------------------------------------------------- /nano/node/transport/fwd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nano::transport 4 | { 5 | class channel; 6 | class loopback_channel; 7 | class tcp_channel; 8 | class tcp_channels; 9 | class tcp_server; 10 | class tcp_socket; 11 | } 12 | 13 | namespace nano::transport::fake 14 | { 15 | class channel; 16 | } 17 | 18 | namespace nano::transport::inproc 19 | { 20 | class channel; 21 | } 22 | -------------------------------------------------------------------------------- /nano/node/transport/inproc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | namespace transport 9 | { 10 | /** 11 | * In-process transport channel. Mostly useful for unit tests 12 | **/ 13 | namespace inproc 14 | { 15 | class channel final : public nano::transport::channel 16 | { 17 | public: 18 | explicit channel (nano::node & node, nano::node & destination); 19 | 20 | std::string to_string () const override; 21 | 22 | nano::endpoint get_remote_endpoint () const override 23 | { 24 | return endpoint; 25 | } 26 | 27 | nano::endpoint get_local_endpoint () const override 28 | { 29 | return endpoint; 30 | } 31 | 32 | nano::transport::transport_type get_type () const override 33 | { 34 | return nano::transport::transport_type::loopback; 35 | } 36 | 37 | void close () override 38 | { 39 | // Can't be closed 40 | } 41 | 42 | protected: 43 | bool send_impl (nano::message const &, nano::transport::traffic_type, nano::transport::channel::callback_t) override; 44 | 45 | private: 46 | nano::node & destination; 47 | nano::endpoint const endpoint; 48 | }; 49 | } // namespace inproc 50 | } // namespace transport 51 | } // namespace nano 52 | -------------------------------------------------------------------------------- /nano/node/transport/loopback.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | nano::transport::loopback_channel::loopback_channel (nano::node & node) : 9 | transport::channel{ node }, 10 | endpoint{ node.network.endpoint () } 11 | { 12 | set_node_id (node.node_id.pub); 13 | set_network_version (node.network_params.network.protocol_version); 14 | } 15 | 16 | bool nano::transport::loopback_channel::send_impl (nano::message const & message, nano::transport::traffic_type traffic_type, nano::transport::channel::callback_t callback) 17 | { 18 | node.stats.inc (nano::stat::type::message_loopback, to_stat_detail (message.type ()), nano::stat::dir::in); 19 | 20 | node.inbound (message, shared_from_this ()); 21 | 22 | if (callback) 23 | { 24 | node.io_ctx.post ([callback_l = std::move (callback)] () { 25 | callback_l (boost::system::errc::make_error_code (boost::system::errc::success), 0); 26 | }); 27 | } 28 | 29 | return true; 30 | } 31 | 32 | std::string nano::transport::loopback_channel::to_string () const 33 | { 34 | return boost::str (boost::format ("%1%") % endpoint); 35 | } 36 | -------------------------------------------------------------------------------- /nano/node/transport/loopback.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano::transport 7 | { 8 | class loopback_channel final : public nano::transport::channel, public std::enable_shared_from_this 9 | { 10 | public: 11 | explicit loopback_channel (nano::node & node); 12 | 13 | std::string to_string () const override; 14 | 15 | nano::endpoint get_remote_endpoint () const override 16 | { 17 | return endpoint; 18 | } 19 | 20 | nano::endpoint get_local_endpoint () const override 21 | { 22 | return endpoint; 23 | } 24 | 25 | nano::transport::transport_type get_type () const override 26 | { 27 | return nano::transport::transport_type::loopback; 28 | } 29 | 30 | void close () override 31 | { 32 | // Can't be closed 33 | } 34 | 35 | protected: 36 | bool send_impl (nano::message const &, nano::transport::traffic_type, nano::transport::channel::callback_t) override; 37 | 38 | private: 39 | nano::endpoint const endpoint; 40 | }; 41 | } -------------------------------------------------------------------------------- /nano/node/transport/tcp_config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano::transport 9 | { 10 | class tcp_config 11 | { 12 | public: 13 | explicit tcp_config (nano::network_constants const & network) 14 | { 15 | if (network.is_dev_network ()) 16 | { 17 | max_inbound_connections = 128; 18 | max_outbound_connections = 128; 19 | max_attempts = 128; 20 | max_attempts_per_ip = 128; 21 | connect_timeout = std::chrono::seconds{ 5 }; 22 | } 23 | } 24 | 25 | public: 26 | nano::error deserialize (nano::tomlconfig &); 27 | nano::error serialize (nano::tomlconfig &) const; 28 | 29 | public: 30 | size_t max_inbound_connections{ 2048 }; 31 | size_t max_outbound_connections{ 2048 }; 32 | size_t max_attempts{ 60 }; 33 | size_t max_attempts_per_ip{ 1 }; 34 | std::chrono::seconds connect_timeout{ 60 }; 35 | std::chrono::seconds handshake_timeout{ 30 }; 36 | std::chrono::seconds io_timeout{ 30 }; 37 | }; 38 | } -------------------------------------------------------------------------------- /nano/node/transport/test_channel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | nano::transport::test_channel::test_channel (nano::node & node_a) : 5 | channel (node_a) 6 | { 7 | } 8 | 9 | bool nano::transport::test_channel::send_impl (nano::message const & message, nano::transport::traffic_type traffic_type, callback_t callback) 10 | { 11 | observers.notify (message, traffic_type); 12 | 13 | if (callback) 14 | { 15 | callback (boost::system::errc::make_error_code (boost::system::errc::success), message.to_shared_const_buffer ().size ()); 16 | } 17 | 18 | return true; 19 | } -------------------------------------------------------------------------------- /nano/node/transport/test_channel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace nano::transport 8 | { 9 | class test_channel final : public nano::transport::channel 10 | { 11 | public: 12 | nano::observer_set observers; // Called for each queued message 13 | 14 | public: 15 | explicit test_channel (nano::node &); 16 | 17 | nano::endpoint get_remote_endpoint () const override 18 | { 19 | return {}; 20 | } 21 | 22 | nano::endpoint get_local_endpoint () const override 23 | { 24 | return {}; 25 | } 26 | 27 | nano::transport::transport_type get_type () const override 28 | { 29 | return nano::transport::transport_type::loopback; 30 | } 31 | 32 | void close () override 33 | { 34 | // Can't be closed 35 | } 36 | 37 | std::string to_string () const override 38 | { 39 | return "test_channel"; 40 | } 41 | 42 | protected: 43 | bool send_impl (nano::message const &, nano::transport::traffic_type, callback_t) override; 44 | }; 45 | } -------------------------------------------------------------------------------- /nano/node/transport/traffic_type.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | std::string_view nano::transport::to_string (nano::transport::traffic_type type) 8 | { 9 | return nano::enum_util::name (type); 10 | } 11 | 12 | std::vector nano::transport::all_traffic_types () 13 | { 14 | return nano::enum_util::values (); 15 | } 16 | 17 | nano::stat::detail nano::transport::to_stat_detail (nano::transport::traffic_type type) 18 | { 19 | return nano::enum_util::cast (type); 20 | } -------------------------------------------------------------------------------- /nano/node/transport/traffic_type.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace nano::transport 9 | { 10 | enum class traffic_type 11 | { 12 | generic, 13 | bootstrap_server, 14 | bootstrap_requests, 15 | block_broadcast, 16 | block_broadcast_initial, 17 | block_broadcast_rpc, 18 | confirmation_requests, 19 | keepalive, 20 | vote, 21 | vote_rebroadcast, 22 | vote_reply, 23 | rep_crawler, 24 | telemetry, 25 | test, 26 | }; 27 | 28 | std::string_view to_string (traffic_type); 29 | std::vector all_traffic_types (); 30 | nano::stat::detail to_stat_detail (traffic_type); 31 | } -------------------------------------------------------------------------------- /nano/node/vote_spacing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void nano::vote_spacing::trim () 4 | { 5 | recent.get ().erase (recent.get ().begin (), recent.get ().upper_bound (std::chrono::steady_clock::now () - delay)); 6 | } 7 | 8 | bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const 9 | { 10 | bool result = true; 11 | for (auto range = recent.get ().equal_range (root_a); result && range.first != range.second; ++range.first) 12 | { 13 | auto & item = *range.first; 14 | result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay; 15 | } 16 | return result; 17 | } 18 | 19 | void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) 20 | { 21 | trim (); 22 | auto now = std::chrono::steady_clock::now (); 23 | auto existing = recent.get ().find (root_a); 24 | if (existing != recent.end ()) 25 | { 26 | recent.get ().modify (existing, [now] (entry & entry) { 27 | entry.time = now; 28 | }); 29 | } 30 | else 31 | { 32 | recent.insert ({ root_a, now, hash_a }); 33 | } 34 | } 35 | 36 | std::size_t nano::vote_spacing::size () const 37 | { 38 | return recent.size (); 39 | } 40 | -------------------------------------------------------------------------------- /nano/node/vote_spacing.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace mi = boost::multi_index; 14 | 15 | namespace nano 16 | { 17 | class vote_spacing final 18 | { 19 | class entry 20 | { 21 | public: 22 | nano::root root; 23 | std::chrono::steady_clock::time_point time; 24 | nano::block_hash hash; 25 | }; 26 | 27 | boost::multi_index_container, 30 | mi::member>, 31 | mi::ordered_non_unique, 32 | mi::member>>> 33 | recent; 34 | std::chrono::milliseconds const delay; 35 | void trim (); 36 | 37 | public: 38 | vote_spacing (std::chrono::milliseconds const & delay) : 39 | delay{ delay } 40 | { 41 | } 42 | bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const; 43 | void flag (nano::root const & root_a, nano::block_hash const & hash_a); 44 | std::size_t size () const; 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /nano/node/vote_with_weight_info.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | class vote_with_weight_info final 10 | { 11 | public: 12 | nano::account representative; 13 | std::chrono::steady_clock::time_point time; 14 | uint64_t timestamp; 15 | nano::block_hash hash; 16 | nano::uint128_t weight; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /nano/node/websocketconfig.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | nano::websocket::config::config (nano::network_constants & network_constants) : 6 | network_constants{ network_constants }, 7 | port{ network_constants.default_websocket_port }, 8 | address{ boost::asio::ip::address_v6::loopback ().to_string () } 9 | { 10 | } 11 | 12 | nano::error nano::websocket::config::serialize_toml (nano::tomlconfig & toml) const 13 | { 14 | toml.put ("enable", enabled, "Enable or disable WebSocket server.\ntype:bool"); 15 | toml.put ("address", address, "WebSocket server bind address.\ntype:string,ip"); 16 | toml.put ("port", port, "WebSocket server listening port.\ntype:uint16"); 17 | return toml.get_error (); 18 | } 19 | 20 | nano::error nano::websocket::config::deserialize_toml (nano::tomlconfig & toml) 21 | { 22 | toml.get ("enable", enabled); 23 | boost::asio::ip::address_v6 address_l; 24 | toml.get_optional ("address", address_l, boost::asio::ip::address_v6::loopback ()); 25 | address = address_l.to_string (); 26 | toml.get ("port", port); 27 | return toml.get_error (); 28 | } 29 | -------------------------------------------------------------------------------- /nano/node/websocketconfig.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class tomlconfig; 11 | namespace websocket 12 | { 13 | /** websocket configuration */ 14 | class config final 15 | { 16 | public: 17 | config (nano::network_constants & network_constants); 18 | nano::error deserialize_toml (nano::tomlconfig & toml_a); 19 | nano::error serialize_toml (nano::tomlconfig & toml) const; 20 | nano::network_constants & network_constants; 21 | bool enabled{ false }; 22 | uint16_t port; 23 | std::string address; 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nano/node/xorshift.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace nano 5 | { 6 | class xorshift1024star final 7 | { 8 | public: 9 | std::array s; 10 | unsigned p{ 0 }; 11 | uint64_t next () 12 | { 13 | auto p_l (p); 14 | auto pn ((p_l + 1) & 15); 15 | p = pn; 16 | uint64_t s0 = s[p_l]; 17 | uint64_t s1 = s[pn]; 18 | s1 ^= s1 << 31; // a 19 | s1 ^= s1 >> 11; // b 20 | s0 ^= s0 >> 30; // c 21 | return (s[pn] = s0 ^ s1) * 1181783497276652981LL; 22 | } 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /nano/qt_test/QTest: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #pragma warning (push) 5 | #pragma warning (disable : 4242) // warning C4242: 'argument': conversion from 'int' to 'ushort', possible loss of data 6 | #endif 7 | 8 | #include 9 | 10 | #ifdef _WIN32 11 | #pragma warning (pop) 12 | #endif 13 | -------------------------------------------------------------------------------- /nano/qt_test/entry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | QApplication * test_application = nullptr; 10 | namespace nano 11 | { 12 | namespace test 13 | { 14 | void cleanup_dev_directories_on_exit (); 15 | } 16 | void force_nano_dev_network (); 17 | } 18 | 19 | int main (int argc, char ** argv) 20 | { 21 | nano::initialize_file_descriptor_limit (); 22 | nano::logger::initialize_for_tests (nano::log_config::tests_default ()); 23 | nano::force_nano_dev_network (); 24 | nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; 25 | QApplication application (argc, argv); 26 | test_application = &application; 27 | testing::InitGoogleTest (&argc, argv); 28 | auto res = RUN_ALL_TESTS (); 29 | nano::test::cleanup_dev_directories_on_exit (); 30 | return res; 31 | } 32 | -------------------------------------------------------------------------------- /nano/rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( 2 | rpc 3 | rpc.hpp 4 | rpc.cpp 5 | rpc_connection.hpp 6 | rpc_connection.cpp 7 | rpc_handler.hpp 8 | rpc_handler.cpp 9 | rpc_request_processor.hpp 10 | rpc_request_processor.cpp) 11 | 12 | target_link_libraries(rpc nano_lib Boost::beast) 13 | -------------------------------------------------------------------------------- /nano/rpc/rpc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace boost 9 | { 10 | namespace asio 11 | { 12 | class io_context; 13 | } 14 | } 15 | 16 | namespace nano 17 | { 18 | class rpc_handler_interface; 19 | 20 | class rpc : public std::enable_shared_from_this 21 | { 22 | public: 23 | rpc (std::shared_ptr, nano::rpc_config config_a, nano::rpc_handler_interface & rpc_handler_interface_a); 24 | virtual ~rpc (); 25 | 26 | void start (); 27 | void stop (); 28 | 29 | virtual void accept (); 30 | 31 | std::uint16_t listening_port () const 32 | { 33 | return acceptor.local_endpoint ().port (); 34 | } 35 | 36 | public: 37 | nano::logger logger{ "rpc" }; 38 | nano::rpc_config config; 39 | std::shared_ptr io_ctx_shared; 40 | boost::asio::io_context & io_ctx; 41 | boost::asio::ip::tcp::acceptor acceptor; 42 | nano::rpc_handler_interface & rpc_handler_interface; 43 | bool stopped{ false }; 44 | }; 45 | 46 | /** Returns the correct RPC implementation based on TLS configuration */ 47 | std::shared_ptr get_rpc (std::shared_ptr, nano::rpc_config const & config_a, nano::rpc_handler_interface & rpc_handler_interface_a); 48 | } 49 | -------------------------------------------------------------------------------- /nano/rpc/rpc_handler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace nano 11 | { 12 | class rpc_config; 13 | class rpc_handler_interface; 14 | class rpc_handler_request_params; 15 | 16 | class rpc_handler : public std::enable_shared_from_this 17 | { 18 | public: 19 | rpc_handler (nano::rpc_config const & rpc_config, std::string const & body_a, std::string const & request_id_a, std::function const & response_a, nano::rpc_handler_interface & rpc_handler_interface_a, nano::logger &); 20 | void process_request (nano::rpc_handler_request_params const & request_params); 21 | 22 | private: 23 | std::string body; 24 | std::string request_id; 25 | boost::property_tree::ptree request; 26 | std::function response; 27 | nano::rpc_config const & rpc_config; 28 | nano::rpc_handler_interface & rpc_handler_interface; 29 | nano::logger & logger; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /nano/rpc_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 2 | rpc_test 3 | common.hpp 4 | rpc_context.hpp 5 | test_response.hpp 6 | rpc_context.cpp 7 | test_response.cpp 8 | common.cpp 9 | entry.cpp 10 | receivable.cpp 11 | rpc.cpp) 12 | 13 | target_link_libraries(rpc_test test_common) 14 | 15 | target_compile_definitions( 16 | rpc_test 17 | PUBLIC -DACTIVE_NETWORK=${ACTIVE_NETWORK} 18 | PRIVATE -DTAG_VERSION_STRING=${TAG_VERSION_STRING} 19 | -DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}) 20 | 21 | include_directories(${CMAKE_SOURCE_DIR}/submodules) 22 | include_directories(${CMAKE_SOURCE_DIR}/submodules/gtest/googletest/include) 23 | -------------------------------------------------------------------------------- /nano/rpc_test/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | std::shared_ptr nano::test::add_ipc_enabled_node (nano::test::system & system, nano::node_config & node_config, nano::node_flags const & node_flags) 6 | { 7 | node_config.ipc_config.transport_tcp.enabled = true; 8 | node_config.ipc_config.transport_tcp.port = system.get_available_port (); 9 | return system.add_node (node_config, node_flags); 10 | } 11 | 12 | std::shared_ptr nano::test::add_ipc_enabled_node (nano::test::system & system, nano::node_config & node_config) 13 | { 14 | return add_ipc_enabled_node (system, node_config, nano::node_flags ()); 15 | } 16 | 17 | std::shared_ptr nano::test::add_ipc_enabled_node (nano::test::system & system) 18 | { 19 | nano::node_config node_config = system.default_config (); 20 | return add_ipc_enabled_node (system, node_config); 21 | } 22 | 23 | void nano::test::reset_confirmation_height (nano::store::component & store, nano::account const & account) 24 | { 25 | auto transaction = store.tx_begin_write (); 26 | nano::confirmation_height_info confirmation_height_info; 27 | if (!store.confirmation_height.get (transaction, account, confirmation_height_info)) 28 | { 29 | store.confirmation_height.clear (transaction, account); 30 | } 31 | } -------------------------------------------------------------------------------- /nano/rpc_test/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | class node; 8 | class node_config; 9 | class node_flags; 10 | class public_key; 11 | using account = public_key; 12 | 13 | namespace store 14 | { 15 | class component; 16 | } 17 | 18 | namespace test 19 | { 20 | class system; 21 | std::shared_ptr add_ipc_enabled_node (nano::test::system & system, nano::node_config & node_config, nano::node_flags const & node_flags); 22 | std::shared_ptr add_ipc_enabled_node (nano::test::system & system, nano::node_config & node_config); 23 | std::shared_ptr add_ipc_enabled_node (nano::test::system & system); 24 | void reset_confirmation_height (nano::store::component & store, nano::account const & account); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nano/rpc_test/entry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | namespace test 11 | { 12 | void cleanup_dev_directories_on_exit (); 13 | } 14 | void force_nano_dev_network (); 15 | } 16 | 17 | int main (int argc, char ** argv) 18 | { 19 | nano::initialize_file_descriptor_limit (); 20 | nano::logger::initialize_for_tests (nano::log_config::tests_default ()); 21 | nano::force_nano_dev_network (); 22 | nano::set_use_memory_pools (false); 23 | nano::node_singleton_memory_pool_purge_guard cleanup_guard; 24 | testing::InitGoogleTest (&argc, argv); 25 | auto res = RUN_ALL_TESTS (); 26 | nano::test::cleanup_dev_directories_on_exit (); 27 | return res; 28 | } 29 | -------------------------------------------------------------------------------- /nano/rpc_test/test_response.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace nano::test 9 | { 10 | class test_response 11 | { 12 | public: 13 | test_response (boost::property_tree::ptree const & request_a, boost::asio::io_context & io_ctx_a); 14 | test_response (boost::property_tree::ptree const & request_a, uint16_t port_a, boost::asio::io_context & io_ctx_a); 15 | void run (uint16_t port_a); 16 | boost::property_tree::ptree const & request; 17 | boost::asio::ip::tcp::socket sock; 18 | boost::property_tree::ptree json; 19 | boost::beast::flat_buffer sb; 20 | boost::beast::http::request req; 21 | boost::beast::http::response resp; 22 | std::atomic status{ 0 }; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /nano/secure/account_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::account_iterator; 5 | -------------------------------------------------------------------------------- /nano/secure/fwd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | class account_info; 8 | class keypair; 9 | class ledger; 10 | class ledger_cache; 11 | class ledger_constants; 12 | class network_params; 13 | class pending_info; 14 | class pending_key; 15 | class vote; 16 | 17 | enum class block_status; 18 | } 19 | 20 | namespace nano::secure 21 | { 22 | class read_transaction; 23 | class transaction; 24 | class write_transaction; 25 | } 26 | -------------------------------------------------------------------------------- /nano/secure/generate_cache_flags.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void nano::generate_cache_flags::enable_all () 4 | { 5 | reps = true; 6 | cemented_count = true; 7 | unchecked_count = true; 8 | account_count = true; 9 | } 10 | -------------------------------------------------------------------------------- /nano/secure/generate_cache_flags.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nano 4 | { 5 | /* Holds flags for various cacheable data. For most CLI operations caching is unnecessary 6 | * (e.g getting the cemented block count) so it can be disabled for performance reasons. */ 7 | class generate_cache_flags 8 | { 9 | public: 10 | bool reps = true; 11 | bool cemented_count = true; 12 | bool unchecked_count = true; 13 | bool account_count = true; 14 | bool block_count = true; 15 | 16 | void enable_all (); 17 | 18 | public: 19 | static generate_cache_flags all_disabled () 20 | { 21 | generate_cache_flags flags; 22 | flags.reps = false; 23 | flags.cemented_count = false; 24 | flags.unchecked_count = false; 25 | flags.account_count = false; 26 | flags.block_count = false; 27 | return flags; 28 | } 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /nano/secure/ledger_cache.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | nano::ledger_cache::ledger_cache (nano::store::rep_weight & rep_weight_store_a, nano::uint128_t min_rep_weight_a) : 4 | rep_weights{ rep_weight_store_a, min_rep_weight_a } 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /nano/secure/ledger_cache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace nano 10 | { 11 | class ledger; 12 | } 13 | namespace nano::store 14 | { 15 | class component; 16 | } 17 | 18 | namespace nano 19 | { 20 | /* Holds an in-memory cache of various counts */ 21 | class ledger_cache 22 | { 23 | friend class store::component; 24 | friend class ledger; 25 | 26 | public: 27 | explicit ledger_cache (nano::store::rep_weight & rep_weight_store_a, nano::uint128_t min_rep_weight_a = 0); 28 | nano::rep_weights rep_weights; 29 | 30 | private: 31 | std::atomic cemented_count{ 0 }; 32 | std::atomic block_count{ 0 }; 33 | std::atomic pruned_count{ 0 }; 34 | std::atomic account_count{ 0 }; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /nano/secure/parallel_traversal.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | template 10 | void parallel_traversal (std::function const & action) 11 | { 12 | // Between 10 and 40 threads, scales well even in low power systems as long as actions are I/O bound 13 | unsigned const thread_count = std::max (10u, std::min (40u, 10 * nano::hardware_concurrency ())); 14 | T const value_max{ std::numeric_limits::max () }; 15 | T const split = value_max / thread_count; 16 | std::vector threads; 17 | threads.reserve (thread_count); 18 | for (unsigned thread (0); thread < thread_count; ++thread) 19 | { 20 | T const start = thread * split; 21 | T const end = (thread + 1) * split; 22 | bool const is_last = thread == thread_count - 1; 23 | 24 | threads.emplace_back ([&action, start, end, is_last] { 25 | nano::thread_role::set (nano::thread_role::name::db_parallel_traversal); 26 | action (start, end, is_last); 27 | }); 28 | } 29 | for (auto & thread : threads) 30 | { 31 | thread.join (); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /nano/secure/plat/osx/working.mm: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | std::filesystem::path app_path_impl () 8 | { 9 | NSString * dir_string = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; 10 | char const * dir_chars = [dir_string UTF8String]; 11 | std::filesystem::path result (dir_chars); 12 | [dir_string release]; 13 | return result; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nano/secure/plat/posix/working.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace nano 8 | { 9 | std::filesystem::path app_path_impl () 10 | { 11 | auto entry (getpwuid (getuid ())); 12 | debug_assert (entry != nullptr); 13 | std::filesystem::path result (entry->pw_dir); 14 | return result; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nano/secure/plat/windows/working.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | std::filesystem::path app_path_impl () 8 | { 9 | std::filesystem::path result; 10 | WCHAR path[MAX_PATH]; 11 | if (SUCCEEDED (SHGetFolderPathW (NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path))) 12 | { 13 | result = std::filesystem::path (path); 14 | } 15 | else 16 | { 17 | debug_assert (false); 18 | } 19 | return result; 20 | } 21 | } -------------------------------------------------------------------------------- /nano/secure/receivable_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | template class nano::receivable_iterator; 6 | template class nano::receivable_iterator; 7 | -------------------------------------------------------------------------------- /nano/secure/utility.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | std::filesystem::path app_path (); 11 | // OS-specific way of finding a path to a home directory. 12 | std::filesystem::path working_path (nano::networks network = nano::network_constants::active_network); 13 | // Construct a random filename 14 | std::filesystem::path random_filename (); 15 | // Get a unique path within the home directory, used for testing. 16 | // Any directories created at this location will be removed when a test finishes. 17 | std::filesystem::path unique_path (nano::networks network = nano::network_constants::active_network); 18 | // Remove all unique tmp directories created by the process 19 | void remove_temporary_directories (); 20 | } 21 | -------------------------------------------------------------------------------- /nano/secure/working.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | std::filesystem::path app_path_impl (); 8 | } 9 | -------------------------------------------------------------------------------- /nano/slow_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( 2 | slow_test 3 | entry.cpp 4 | flamegraph.cpp 5 | node.cpp 6 | vote_cache.cpp 7 | vote_processor.cpp 8 | bootstrap.cpp 9 | ledger.cpp) 10 | 11 | target_link_libraries(slow_test test_common) 12 | 13 | include_directories(${CMAKE_SOURCE_DIR}/submodules) 14 | -------------------------------------------------------------------------------- /nano/slow_test/entry.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | namespace test 10 | { 11 | void cleanup_dev_directories_on_exit (); 12 | } 13 | void force_nano_dev_network (); 14 | } 15 | 16 | int main (int argc, char ** argv) 17 | { 18 | nano::initialize_file_descriptor_limit (); 19 | nano::logger::initialize_for_tests (nano::log_config::tests_default ()); 20 | nano::force_nano_dev_network (); 21 | nano::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard; 22 | testing::InitGoogleTest (&argc, argv); 23 | auto res = RUN_ALL_TESTS (); 24 | nano::test::cleanup_dev_directories_on_exit (); 25 | return res; 26 | } 27 | -------------------------------------------------------------------------------- /nano/store/account.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | template class nano::store::typed_iterator; 6 | template class nano::store::reverse_iterator>; 7 | 8 | std::optional nano::store::account::get (store::transaction const & transaction, nano::account const & account) 9 | { 10 | nano::account_info info; 11 | bool error = get (transaction, account, info); 12 | if (!error) 13 | { 14 | return info; 15 | } 16 | else 17 | { 18 | return std::nullopt; 19 | } 20 | } 21 | 22 | auto nano::store::account::rbegin (store::transaction const & tx) const -> reverse_iterator 23 | { 24 | auto iter = end (tx); 25 | --iter; 26 | return reverse_iterator{ std::move (iter) }; 27 | } 28 | 29 | auto nano::store::account::rend (transaction const & tx) const -> reverse_iterator 30 | { 31 | return reverse_iterator{ end (tx) }; 32 | } 33 | -------------------------------------------------------------------------------- /nano/store/block.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::store::typed_iterator; 5 | -------------------------------------------------------------------------------- /nano/store/block_w_sideband.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano 8 | { 9 | class block; 10 | } 11 | namespace nano::store 12 | { 13 | class block_w_sideband 14 | { 15 | public: 16 | std::shared_ptr block; 17 | nano::block_sideband sideband; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /nano/store/confirmation_height.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::store::typed_iterator; 5 | 6 | std::optional nano::store::confirmation_height::get (store::transaction const & transaction, nano::account const & account) 7 | { 8 | nano::confirmation_height_info info; 9 | bool error = get (transaction, account, info); 10 | if (!error) 11 | { 12 | return info; 13 | } 14 | else 15 | { 16 | return std::nullopt; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nano/store/db_val.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /nano/store/final_vote.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::store::typed_iterator; 5 | -------------------------------------------------------------------------------- /nano/store/fwd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nano 4 | { 5 | enum class tables; 6 | } 7 | namespace nano::store 8 | { 9 | class account; 10 | class block; 11 | class component; 12 | class confirmation_height; 13 | class final_vote; 14 | class online_weight; 15 | class peer; 16 | class pending; 17 | class pruned; 18 | class read_transaction; 19 | class rep_weight; 20 | class transaction; 21 | class version; 22 | class write_transaction; 23 | } 24 | -------------------------------------------------------------------------------- /nano/store/lmdb/db_val.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template <> 4 | void * nano::store::lmdb::db_val::data () const 5 | { 6 | return value.mv_data; 7 | } 8 | 9 | template <> 10 | std::size_t nano::store::lmdb::db_val::size () const 11 | { 12 | return value.mv_size; 13 | } 14 | 15 | template <> 16 | nano::store::lmdb::db_val::db_val (std::size_t size_a, void * data_a) : 17 | value ({ size_a, data_a }) 18 | { 19 | } 20 | 21 | template <> 22 | void nano::store::lmdb::db_val::convert_buffer_to_value () 23 | { 24 | value = { buffer->size (), const_cast (buffer->data ()) }; 25 | } 26 | -------------------------------------------------------------------------------- /nano/store/lmdb/db_val.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store::lmdb 8 | { 9 | using db_val = store::db_val; 10 | } 11 | -------------------------------------------------------------------------------- /nano/store/lmdb/online_weight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store::lmdb 8 | { 9 | class online_weight : public nano::store::online_weight 10 | { 11 | private: 12 | nano::store::lmdb::component & store; 13 | 14 | public: 15 | explicit online_weight (nano::store::lmdb::component & store_a); 16 | void put (store::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; 17 | void del (store::write_transaction const & transaction_a, uint64_t time_a) override; 18 | iterator begin (store::transaction const & transaction_a) const override; 19 | iterator end (store::transaction const & transaction_a) const override; 20 | size_t count (store::transaction const & transaction_a) const override; 21 | void clear (store::write_transaction const & transaction_a) override; 22 | 23 | /** 24 | * Samples of online vote weight 25 | * uint64_t -> nano::amount 26 | */ 27 | MDB_dbi online_weight_handle{ 0 }; 28 | }; 29 | } // namespace nano::store::lmdb 30 | -------------------------------------------------------------------------------- /nano/store/lmdb/peer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store::lmdb 8 | { 9 | class peer : public nano::store::peer 10 | { 11 | private: 12 | nano::store::lmdb::component & store; 13 | 14 | public: 15 | explicit peer (nano::store::lmdb::component & store_a); 16 | void put (store::write_transaction const &, nano::endpoint_key const & endpoint, nano::millis_t timestamp) override; 17 | nano::millis_t get (store::transaction const &, nano::endpoint_key const & endpoint) const override; 18 | void del (store::write_transaction const &, nano::endpoint_key const & endpoint) override; 19 | bool exists (store::transaction const &, nano::endpoint_key const & endpoint) const override; 20 | size_t count (store::transaction const &) const override; 21 | void clear (store::write_transaction const &) override; 22 | iterator begin (store::transaction const &) const override; 23 | iterator end (store::transaction const & transaction_a) const override; 24 | 25 | /* 26 | * Endpoints for peers 27 | * nano::endpoint_key -> no_value 28 | */ 29 | MDB_dbi peers_handle{ 0 }; 30 | }; 31 | } // namespace nano::store::lmdb 32 | -------------------------------------------------------------------------------- /nano/store/lmdb/rep_weight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store::lmdb 8 | { 9 | class component; 10 | 11 | class rep_weight : public nano::store::rep_weight 12 | { 13 | private: 14 | nano::store::lmdb::component & store; 15 | 16 | public: 17 | explicit rep_weight (nano::store::lmdb::component & store_a); 18 | 19 | uint64_t count (store::transaction const & txn) override; 20 | nano::uint128_t get (store::transaction const & txn_a, nano::account const & representative_a) override; 21 | void put (store::write_transaction const & txn_a, nano::account const & representative_a, nano::uint128_t const & weight_a) override; 22 | void del (store::write_transaction const &, nano::account const & representative_a) override; 23 | iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const override; 24 | iterator begin (store::transaction const & transaction_a) const override; 25 | iterator end (store::transaction const & transaction_a) const override; 26 | void for_each_par (std::function const & action_a) const override; 27 | 28 | /** 29 | * Representative weights 30 | * nano::account -> uint128_t 31 | */ 32 | MDB_dbi rep_weights_handle{ 0 }; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /nano/store/lmdb/version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | nano::store::lmdb::version::version (nano::store::lmdb::component & store_a) : 5 | store{ store_a } {}; 6 | 7 | void nano::store::lmdb::version::put (store::write_transaction const & transaction_a, int version) 8 | { 9 | nano::uint256_union version_key{ 1 }; 10 | nano::uint256_union version_value (version); 11 | auto status = store.put (transaction_a, tables::meta, version_key, version_value); 12 | store.release_assert_success (status); 13 | } 14 | 15 | int nano::store::lmdb::version::get (store::transaction const & transaction_a) const 16 | { 17 | nano::uint256_union version_key{ 1 }; 18 | nano::store::lmdb::db_val data; 19 | auto status = store.get (transaction_a, tables::meta, version_key, data); 20 | int result = store.version_minimum; 21 | if (store.success (status)) 22 | { 23 | nano::uint256_union version_value{ data }; 24 | debug_assert (version_value.qwords[2] == 0 && version_value.qwords[1] == 0 && version_value.qwords[0] == 0); 25 | result = version_value.number ().convert_to (); 26 | } 27 | return result; 28 | } 29 | -------------------------------------------------------------------------------- /nano/store/lmdb/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store::lmdb 8 | { 9 | class version : public nano::store::version 10 | { 11 | protected: 12 | nano::store::lmdb::component & store; 13 | 14 | public: 15 | explicit version (nano::store::lmdb::component & store_a); 16 | void put (store::write_transaction const & transaction_a, int version_a) override; 17 | int get (store::transaction const & transaction_a) const override; 18 | 19 | /** 20 | * Meta information about block store, such as versions. 21 | * nano::uint256_union (arbitrary key) -> blob 22 | */ 23 | MDB_dbi meta_handle{ 0 }; 24 | }; 25 | } // namespace nano::store::lmdb 26 | -------------------------------------------------------------------------------- /nano/store/lmdb/wallet_value.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | nano::wallet_value::wallet_value (nano::store::db_val const & val_a) 4 | { 5 | debug_assert (val_a.size () == sizeof (*this)); 6 | std::copy (reinterpret_cast (val_a.data ()), reinterpret_cast (val_a.data ()) + sizeof (key), key.chars.begin ()); 7 | std::copy (reinterpret_cast (val_a.data ()) + sizeof (key), reinterpret_cast (val_a.data ()) + sizeof (key) + sizeof (work), reinterpret_cast (&work)); 8 | } 9 | 10 | nano::wallet_value::wallet_value (nano::raw_key const & key_a, uint64_t work_a) : 11 | key (key_a), 12 | work (work_a) 13 | { 14 | } 15 | 16 | nano::store::db_val nano::wallet_value::val () const 17 | { 18 | static_assert (sizeof (*this) == sizeof (key) + sizeof (work), "Class not packed"); 19 | return nano::store::db_val (sizeof (*this), const_cast (this)); 20 | } 21 | -------------------------------------------------------------------------------- /nano/store/lmdb/wallet_value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class wallet_value 11 | { 12 | public: 13 | wallet_value () = default; 14 | wallet_value (store::db_val const &); 15 | wallet_value (nano::raw_key const &, uint64_t); 16 | store::db_val val () const; 17 | nano::raw_key key; 18 | uint64_t work; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /nano/store/online_weight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | template class nano::store::typed_iterator; 6 | template class nano::store::reverse_iterator>; 7 | 8 | auto nano::store::online_weight::rbegin (store::transaction const & tx) const -> reverse_iterator 9 | { 10 | auto iter = end (tx); 11 | --iter; 12 | return reverse_iterator{ std::move (iter) }; 13 | } 14 | 15 | auto nano::store::online_weight::rend (transaction const & tx) const -> reverse_iterator 16 | { 17 | return reverse_iterator{ end (tx) }; 18 | } 19 | -------------------------------------------------------------------------------- /nano/store/online_weight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace nano 11 | { 12 | class block_hash; 13 | } 14 | namespace nano::store 15 | { 16 | /** 17 | * Manages online weight storage and iteration 18 | */ 19 | class online_weight 20 | { 21 | public: 22 | using iterator = typed_iterator; 23 | using reverse_iterator = store::reverse_iterator; 24 | 25 | public: 26 | virtual void put (store::write_transaction const &, uint64_t, nano::amount const &) = 0; 27 | virtual void del (store::write_transaction const &, uint64_t) = 0; 28 | virtual iterator begin (store::transaction const &) const = 0; 29 | reverse_iterator rbegin (store::transaction const &) const; 30 | reverse_iterator rend (store::transaction const &) const; 31 | virtual iterator end (store::transaction const & transaction_a) const = 0; 32 | virtual size_t count (store::transaction const &) const = 0; 33 | virtual void clear (store::write_transaction const &) = 0; 34 | }; 35 | } // namespace nano::store 36 | -------------------------------------------------------------------------------- /nano/store/peer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::store::typed_iterator; 5 | -------------------------------------------------------------------------------- /nano/store/peer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace nano 10 | { 11 | class block_hash; 12 | } 13 | namespace nano::store 14 | { 15 | /** 16 | * Manages peer storage and iteration 17 | */ 18 | class peer 19 | { 20 | public: 21 | using iterator = typed_iterator; 22 | 23 | public: 24 | /// Returns true if the peer was inserted, false if it was already in the container 25 | virtual void put (store::write_transaction const &, nano::endpoint_key const & endpoint, nano::millis_t timestamp) = 0; 26 | virtual nano::millis_t get (store::transaction const &, nano::endpoint_key const & endpoint) const = 0; 27 | virtual void del (store::write_transaction const &, nano::endpoint_key const & endpoint) = 0; 28 | virtual bool exists (store::transaction const &, nano::endpoint_key const & endpoint) const = 0; 29 | virtual size_t count (store::transaction const &) const = 0; 30 | virtual void clear (store::write_transaction const &) = 0; 31 | virtual iterator begin (store::transaction const &) const = 0; 32 | virtual iterator end (store::transaction const & transaction_a) const = 0; 33 | }; 34 | } // namespace nano::store 35 | -------------------------------------------------------------------------------- /nano/store/pending.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | template class nano::store::typed_iterator; 6 | -------------------------------------------------------------------------------- /nano/store/pruned.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::store::typed_iterator; 5 | -------------------------------------------------------------------------------- /nano/store/rep_weight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class nano::store::typed_iterator; 5 | -------------------------------------------------------------------------------- /nano/store/rep_weight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace nano 11 | { 12 | // class account; 13 | } 14 | namespace nano::store 15 | { 16 | /** 17 | * A lookup table of all representatives and their vote weight 18 | */ 19 | class rep_weight 20 | { 21 | public: 22 | using iterator = typed_iterator; 23 | 24 | public: 25 | virtual ~rep_weight (){}; 26 | virtual uint64_t count (store::transaction const & txn_a) = 0; 27 | virtual nano::uint128_t get (store::transaction const & txn_a, nano::account const & representative_a) = 0; 28 | virtual void put (store::write_transaction const & txn_a, nano::account const & representative_a, nano::uint128_t const & weight_a) = 0; 29 | virtual void del (store::write_transaction const &, nano::account const & representative_a) = 0; 30 | virtual iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const = 0; 31 | virtual iterator begin (store::transaction const & transaction_a) const = 0; 32 | virtual iterator end (store::transaction const & transaction_a) const = 0; 33 | virtual void for_each_par (std::function const & action_a) const = 0; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /nano/store/rocksdb/account.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class component; 8 | } 9 | namespace nano::store::rocksdb 10 | { 11 | class account : public nano::store::account 12 | { 13 | private: 14 | nano::store::rocksdb::component & store; 15 | 16 | public: 17 | explicit account (nano::store::rocksdb::component & store_a); 18 | void put (store::write_transaction const & transaction, nano::account const & account, nano::account_info const & info) override; 19 | bool get (store::transaction const & transaction_a, nano::account const & account_a, nano::account_info & info_a) override; 20 | void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; 21 | bool exists (store::transaction const & transaction_a, nano::account const & account_a) override; 22 | size_t count (store::transaction const & transaction_a) override; 23 | iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; 24 | iterator begin (store::transaction const & transaction_a) const override; 25 | iterator end (store::transaction const & transaction_a) const override; 26 | void for_each_par (std::function const & action_a) const override; 27 | }; 28 | } // namespace nano::store::rocksdb 29 | -------------------------------------------------------------------------------- /nano/store/rocksdb/db_val.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template <> 4 | void * nano::store::rocksdb::db_val::data () const 5 | { 6 | return (void *)value.data (); 7 | } 8 | 9 | template <> 10 | std::size_t nano::store::rocksdb::db_val::size () const 11 | { 12 | return value.size (); 13 | } 14 | 15 | template <> 16 | nano::store::rocksdb::db_val::db_val (std::size_t size_a, void * data_a) : 17 | value (static_cast (data_a), size_a) 18 | { 19 | } 20 | 21 | template <> 22 | void nano::store::rocksdb::db_val::convert_buffer_to_value () 23 | { 24 | value = ::rocksdb::Slice (reinterpret_cast (buffer->data ()), buffer->size ()); 25 | } 26 | -------------------------------------------------------------------------------- /nano/store/rocksdb/db_val.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store::rocksdb 8 | { 9 | using db_val = store::db_val<::rocksdb::Slice>; 10 | } 11 | -------------------------------------------------------------------------------- /nano/store/rocksdb/final_vote.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class component; 8 | } 9 | namespace nano::store::rocksdb 10 | { 11 | class final_vote : public nano::store::final_vote 12 | { 13 | private: 14 | nano::store::rocksdb::component & store; 15 | 16 | public: 17 | explicit final_vote (nano::store::rocksdb::component & store); 18 | bool put (store::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) override; 19 | std::optional get (store::transaction const & transaction_a, nano::qualified_root const & qualified_root_a) override; 20 | void del (store::write_transaction const & transaction_a, nano::qualified_root const & root_a) override; 21 | size_t count (store::transaction const & transaction_a) const override; 22 | void clear (store::write_transaction const & transaction_a) override; 23 | iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; 24 | iterator begin (store::transaction const & transaction_a) const override; 25 | iterator end (store::transaction const & transaction_a) const override; 26 | void for_each_par (std::function const & action_a) const override; 27 | }; 28 | } // namespace nano::store::rocksdb 29 | -------------------------------------------------------------------------------- /nano/store/rocksdb/online_weight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class component; 8 | } 9 | namespace nano::store::rocksdb 10 | { 11 | class online_weight : public nano::store::online_weight 12 | { 13 | private: 14 | nano::store::rocksdb::component & store; 15 | 16 | public: 17 | explicit online_weight (nano::store::rocksdb::component & store_a); 18 | void put (store::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; 19 | void del (store::write_transaction const & transaction_a, uint64_t time_a) override; 20 | iterator begin (store::transaction const & transaction_a) const override; 21 | iterator end (store::transaction const & transaction_a) const override; 22 | size_t count (store::transaction const & transaction_a) const override; 23 | void clear (store::write_transaction const & transaction_a) override; 24 | }; 25 | } // namespace nano::store::rocksdb 26 | -------------------------------------------------------------------------------- /nano/store/rocksdb/peer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class component; 8 | } 9 | namespace nano::store::rocksdb 10 | { 11 | class peer : public nano::store::peer 12 | { 13 | private: 14 | nano::store::rocksdb::component & store; 15 | 16 | public: 17 | explicit peer (nano::store::rocksdb::component & store_a); 18 | void put (store::write_transaction const &, nano::endpoint_key const & endpoint, nano::millis_t timestamp) override; 19 | nano::millis_t get (store::transaction const &, nano::endpoint_key const & endpoint) const override; 20 | void del (store::write_transaction const &, nano::endpoint_key const & endpoint) override; 21 | bool exists (store::transaction const &, nano::endpoint_key const & endpoint) const override; 22 | size_t count (store::transaction const &) const override; 23 | void clear (store::write_transaction const &) override; 24 | iterator begin (store::transaction const &) const override; 25 | iterator end (store::transaction const & transaction_a) const override; 26 | }; 27 | } // namespace nano::store::rocksdb 28 | -------------------------------------------------------------------------------- /nano/store/rocksdb/pending.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class pending : public nano::store::pending 8 | { 9 | private: 10 | nano::store::rocksdb::component & store; 11 | 12 | public: 13 | explicit pending (nano::store::rocksdb::component & store_a); 14 | void put (store::write_transaction const & transaction_a, nano::pending_key const & key_a, nano::pending_info const & pending_info_a) override; 15 | void del (store::write_transaction const & transaction_a, nano::pending_key const & key_a) override; 16 | std::optional get (store::transaction const & transaction_a, nano::pending_key const & key_a) override; 17 | bool exists (store::transaction const & transaction_a, nano::pending_key const & key_a) override; 18 | bool any (store::transaction const & transaction_a, nano::account const & account_a) override; 19 | iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; 20 | iterator begin (store::transaction const & transaction_a) const override; 21 | iterator end (store::transaction const & transaction_a) const override; 22 | void for_each_par (std::function const & action_a) const override; 23 | }; 24 | } // namespace nano::store::rocksdb 25 | -------------------------------------------------------------------------------- /nano/store/rocksdb/pruned.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class component; 8 | } 9 | namespace nano::store::rocksdb 10 | { 11 | class pruned : public nano::store::pruned 12 | { 13 | private: 14 | nano::store::rocksdb::component & store; 15 | 16 | public: 17 | explicit pruned (nano::store::rocksdb::component & store_a); 18 | void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; 19 | void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; 20 | bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; 21 | nano::block_hash random (store::transaction const & transaction_a) override; 22 | size_t count (store::transaction const & transaction_a) const override; 23 | void clear (store::write_transaction const & transaction_a) override; 24 | iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; 25 | iterator begin (store::transaction const & transaction_a) const override; 26 | iterator end (store::transaction const & transaction_a) const override; 27 | void for_each_par (std::function const & action_a) const override; 28 | }; 29 | } // namespace nano::store::rocksdb 30 | -------------------------------------------------------------------------------- /nano/store/rocksdb/rep_weight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class component; 8 | } 9 | namespace nano::store::rocksdb 10 | { 11 | class rep_weight : public nano::store::rep_weight 12 | { 13 | private: 14 | nano::store::rocksdb::component & store; 15 | 16 | public: 17 | explicit rep_weight (nano::store::rocksdb::component & store_a); 18 | uint64_t count (store::transaction const & txn_a) override; 19 | nano::uint128_t get (store::transaction const & txn_a, nano::account const & representative_a) override; 20 | void put (store::write_transaction const & txn_a, nano::account const & representative_a, nano::uint128_t const & weight_a) override; 21 | void del (store::write_transaction const &, nano::account const & representative_a) override; 22 | iterator begin (store::transaction const & txn_a, nano::account const & representative_a) const override; 23 | iterator begin (store::transaction const & txn_a) const override; 24 | iterator end (store::transaction const & transaction_a) const override; 25 | void for_each_par (std::function const & action_a) const override; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /nano/store/rocksdb/transaction_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace nano::store::rocksdb 11 | { 12 | class read_transaction_impl final : public store::read_transaction_impl 13 | { 14 | public: 15 | read_transaction_impl (::rocksdb::DB * db); 16 | ~read_transaction_impl (); 17 | void reset () override; 18 | void renew () override; 19 | void * get_handle () const override; 20 | 21 | private: 22 | ::rocksdb::DB * db; 23 | ::rocksdb::ReadOptions options; 24 | }; 25 | 26 | class write_transaction_impl final : public store::write_transaction_impl 27 | { 28 | public: 29 | write_transaction_impl (::rocksdb::TransactionDB * db_a); 30 | ~write_transaction_impl (); 31 | void commit () override; 32 | void renew () override; 33 | void * get_handle () const override; 34 | bool contains (nano::tables table_a) const override; 35 | 36 | private: 37 | bool check_no_write_tx () const; 38 | 39 | ::rocksdb::Transaction * txn; 40 | ::rocksdb::TransactionDB * db; 41 | bool active{ true }; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /nano/store/rocksdb/utility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | auto nano::store::rocksdb::tx (store::transaction const & transaction_a) -> std::variant<::rocksdb::Transaction *, ::rocksdb::ReadOptions *> 5 | { 6 | if (dynamic_cast (&transaction_a) != nullptr) 7 | { 8 | return static_cast<::rocksdb::ReadOptions *> (transaction_a.get_handle ()); 9 | } 10 | return static_cast<::rocksdb::Transaction *> (transaction_a.get_handle ()); 11 | } 12 | -------------------------------------------------------------------------------- /nano/store/rocksdb/utility.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace nano::store 8 | { 9 | class transaction; 10 | } 11 | 12 | namespace nano::store::rocksdb 13 | { 14 | auto tx (store::transaction const & transaction_a) -> std::variant<::rocksdb::Transaction *, ::rocksdb::ReadOptions *>; 15 | } 16 | -------------------------------------------------------------------------------- /nano/store/rocksdb/version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | nano::store::rocksdb::version::version (nano::store::rocksdb::component & store_a) : 5 | store{ store_a } {}; 6 | 7 | void nano::store::rocksdb::version::put (store::write_transaction const & transaction_a, int version) 8 | { 9 | nano::uint256_union version_key{ 1 }; 10 | nano::uint256_union version_value (version); 11 | auto status = store.put (transaction_a, tables::meta, version_key, version_value); 12 | store.release_assert_success (status); 13 | } 14 | 15 | int nano::store::rocksdb::version::get (store::transaction const & transaction_a) const 16 | { 17 | nano::uint256_union version_key{ 1 }; 18 | nano::store::rocksdb::db_val data; 19 | auto status = store.get (transaction_a, tables::meta, version_key, data); 20 | int result = store.version_minimum; 21 | if (store.success (status)) 22 | { 23 | nano::uint256_union version_value{ data }; 24 | debug_assert (version_value.qwords[2] == 0 && version_value.qwords[1] == 0 && version_value.qwords[0] == 0); 25 | result = version_value.number ().convert_to (); 26 | } 27 | return result; 28 | } 29 | -------------------------------------------------------------------------------- /nano/store/rocksdb/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store::rocksdb 6 | { 7 | class version : public nano::store::version 8 | { 9 | protected: 10 | nano::store::rocksdb::component & store; 11 | 12 | public: 13 | explicit version (nano::store::rocksdb::component & store_a); 14 | void put (store::write_transaction const & transaction_a, int version_a) override; 15 | int get (store::transaction const & transaction_a) const override; 16 | }; 17 | } // namespace nano::store::rocksdb 18 | -------------------------------------------------------------------------------- /nano/store/tables.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano 6 | { 7 | // Keep this in alphabetical order 8 | enum class tables 9 | { 10 | accounts, 11 | blocks, 12 | confirmation_height, 13 | default_unused, // RocksDB only 14 | final_votes, 15 | meta, 16 | online_weight, 17 | peers, 18 | pending, 19 | pruned, 20 | vote, 21 | rep_weights, 22 | }; 23 | } // namespace nano 24 | 25 | namespace std 26 | { 27 | template <> 28 | struct hash<::nano::tables> 29 | { 30 | size_t operator() (::nano::tables const & table_a) const 31 | { 32 | return static_cast (table_a); 33 | } 34 | }; // struct hash 35 | } // namespace std 36 | -------------------------------------------------------------------------------- /nano/store/typed_iterator.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /nano/store/version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /nano/store/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace nano 9 | { 10 | class block_hash; 11 | } 12 | namespace nano::store 13 | { 14 | /** 15 | * Manages version storage 16 | */ 17 | class version 18 | { 19 | public: 20 | virtual void put (store::write_transaction const &, int) = 0; 21 | virtual int get (store::transaction const &) const = 0; 22 | }; 23 | } // namespace nano::store 24 | -------------------------------------------------------------------------------- /nano/store/versioning.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | -------------------------------------------------------------------------------- /nano/store/versioning.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct MDB_val; 6 | 7 | namespace nano::store 8 | { 9 | // Holds historical verisons of classes used when upgrading database stores. 10 | } // namespace nano::store 11 | -------------------------------------------------------------------------------- /nano/test_common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( 2 | test_common 3 | chains.hpp 4 | chains.cpp 5 | ledger_context.hpp 6 | ledger_context.cpp 7 | make_store.hpp 8 | make_store.cpp 9 | network.hpp 10 | network.cpp 11 | rate_observer.cpp 12 | rate_observer.hpp 13 | system.hpp 14 | system.cpp 15 | telemetry.hpp 16 | telemetry.cpp 17 | testutil.hpp 18 | testutil.cpp) 19 | 20 | target_link_libraries(test_common node gtest) 21 | 22 | include_directories(${CMAKE_SOURCE_DIR}/submodules) 23 | include_directories(${CMAKE_SOURCE_DIR}/submodules/gtest/googletest/include) 24 | include_directories(${CMAKE_SOURCE_DIR}/submodules/lmdb) 25 | -------------------------------------------------------------------------------- /nano/test_common/make_store.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | std::unique_ptr nano::test::make_store () 9 | { 10 | return nano::make_store (nano::default_logger (), nano::unique_path (), nano::dev::constants); 11 | } 12 | -------------------------------------------------------------------------------- /nano/test_common/make_store.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace nano::store 6 | { 7 | class component; 8 | } 9 | 10 | namespace nano::test 11 | { 12 | std::unique_ptr make_store (); 13 | } 14 | -------------------------------------------------------------------------------- /nano/test_common/network.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace nano 7 | { 8 | class node; 9 | 10 | namespace transport 11 | { 12 | class channel; 13 | class tcp_channel; 14 | } 15 | 16 | namespace test 17 | { 18 | class system; 19 | /** Waits until a TCP connection is established and returns the TCP channel on success*/ 20 | std::shared_ptr establish_tcp (nano::test::system &, nano::node &, nano::endpoint const &); 21 | 22 | /** Adds a node to the system without establishing connections */ 23 | std::shared_ptr add_outer_node (nano::test::system & system, nano::node_config const & config_a, nano::node_flags = nano::node_flags ()); 24 | 25 | /** Adds a node to the system without establishing connections */ 26 | std::shared_ptr add_outer_node (nano::test::system & system, nano::node_flags = nano::node_flags ()); 27 | 28 | /** speculatively (it is not guaranteed that the port will remain free) find a free tcp binding port and return it */ 29 | uint16_t speculatively_choose_a_free_tcp_bind_port (); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nano/test_common/telemetry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace nano 4 | { 5 | class node; 6 | class telemetry_data; 7 | } 8 | 9 | namespace nano::test 10 | { 11 | /** 12 | * Compares telemetry data without signatures 13 | * @return true if comparison OK 14 | */ 15 | bool compare_telemetry_data (nano::telemetry_data const &, nano::telemetry_data const &); 16 | 17 | /** 18 | * Compares telemetry data and checks signature matches node_id 19 | * @return true if comparison OK 20 | */ 21 | bool compare_telemetry (nano::telemetry_data const &, nano::node const &); 22 | } -------------------------------------------------------------------------------- /qt.conf: -------------------------------------------------------------------------------- 1 | [Paths] 2 | Plugins = PlugIns 3 | Imports = Resources/qml 4 | Qml2Imports = Resources/qml 5 | -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | logo.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /sanitize_ignorelist: -------------------------------------------------------------------------------- 1 | src:*crypto/ed25519* 2 | src:*crypto/blake2* 3 | 4 | src:*submodules/lmdb* -------------------------------------------------------------------------------- /sanitize_ignorelist_asan: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanocurrency/nano-node/bbed2c1c4d6d1b7d55626b73bbfc157163ff179e/sanitize_ignorelist_asan -------------------------------------------------------------------------------- /sanitize_ignorelist_tsan: -------------------------------------------------------------------------------- 1 | # These are triggering TSAN warnings, but are only used in tests 2 | src:*/fakes/work_peer.hpp 3 | src:*/fakes/websocket_client.hpp -------------------------------------------------------------------------------- /sanitize_ignorelist_ubsan: -------------------------------------------------------------------------------- 1 | # This class has a member variable that is marked alignas(16) which means the object should be aligned an a 16-byte boundary which it isn’t. 2 | # Looking at where it’s instantiated it’s a static local function variable that is also thread_local. 3 | # This could be some sort of bug in the thread_local alignment, maybe in combination with being a static local function variable. 4 | # This issue is only reproducible on the GitHub MacOS UBSAN runners. 5 | # /Users/runner/work/nano-node/nano-node/submodules/boost/libs/beast/include/boost/beast/core/detail/chacha.hpp:101:5: runtime error: constructor call on misaligned address 0x0001408c3e08 for type 'boost::beast::detail::chacha<20> *', which requires 16 byte alignment 6 | # 0x0001408c3e08: note: pointer points here 7 | # 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 8 | # ^ 9 | # #0 0x1059df490 in boost::beast::detail::chacha<20ul>::chacha(unsigned int const*, unsigned long long) chacha.hpp 10 | # #1 0x1059df21c in boost::beast::websocket::detail::secure_generate() prng.ipp:123 11 | src:*/beast/core/detail/chacha.hpp 12 | src:*/beast/websocket/detail/prng.ipp 13 | -------------------------------------------------------------------------------- /systest/RUNALL: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | failed=0 6 | 7 | for script in *.sh; do 8 | echo Running script: $script 9 | ./$script; 10 | done 11 | 12 | echo All systests passed. 13 | -------------------------------------------------------------------------------- /systest/cli_wallet_create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | 4 | DATADIR=$(mktemp -d) 5 | 6 | SEED=CEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEED 7 | 8 | # initialise data directory 9 | $NANO_NODE_EXE --initialize --data_path $DATADIR 10 | 11 | # create a wallet and store the wallet ID 12 | wallet_id=`$NANO_NODE_EXE --wallet_create --data_path $DATADIR --seed $SEED` 13 | 14 | # decrypt the wallet and check the seed 15 | $NANO_NODE_EXE --wallet_decrypt_unsafe --wallet $wallet_id --data_path $DATADIR | grep -q "Seed: $SEED" 16 | 17 | # list the wallet and check the wallet ID 18 | $NANO_NODE_EXE --wallet_list --data_path $DATADIR | grep -q "Wallet ID: $wallet_id" 19 | 20 | # if it got this far then it is a pass 21 | exit 0 22 | -------------------------------------------------------------------------------- /systest/daemon_interrupt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | 4 | DATADIR=$(mktemp -d) 5 | 6 | # Start the node in daemon mode in the background 7 | $NANO_NODE_EXE --daemon --network dev --data_path $DATADIR & 8 | NODE_PID=$! 9 | 10 | # Allow some time for the node to start up completely 11 | sleep 10 12 | 13 | # Send an interrupt signal to the node process 14 | kill -SIGINT $NODE_PID 15 | 16 | # Check if the process has stopped using a timeout to avoid infinite waiting 17 | if wait $NODE_PID; then 18 | echo "Node stopped successfully" 19 | else 20 | echo "Node did not stop as expected" 21 | exit 1 22 | fi 23 | -------------------------------------------------------------------------------- /systest/node_initialize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | 4 | test_cmd() { 5 | netmatch="$1" 6 | netcmd="$2" 7 | netarg="$3" 8 | genesishash="$4" 9 | 10 | DATADIR=$(mktemp -d) 11 | 12 | # initialise data directory 13 | $NANO_NODE_EXE --initialize --data_path "$DATADIR" "$netcmd" "$netarg" 14 | 15 | # check that it is the live network 16 | grep -q "Active network: $netmatch" "$DATADIR"/log/log_*.log 17 | 18 | # check that the ledger file is created and has one block, the genesis block 19 | $NANO_NODE_EXE --debug_block_count --data_path "$DATADIR" "$netcmd" "$netarg" | grep -q 'Block count: 1' 20 | 21 | # check the genesis block is correct 22 | $NANO_NODE_EXE --debug_block_dump --data_path "$DATADIR" "$netcmd" "$netarg" | head -n 1 | grep -qi "$genesishash" 23 | } 24 | 25 | test_cmd "live" "--network" "live" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948" 26 | test_cmd "beta" "--network" "beta" "E1227CF974C1455A8B630433D94F3DDBF495EEAC9ADD2481A4A1D90A0D00F488" 27 | test_cmd "test" "--network" "test" "B1D60C0B886B57401EF5A1DAA04340E53726AA6F4D706C085706F31BBD100CEE" 28 | 29 | # if it got this far then it is a pass 30 | exit 0 31 | -------------------------------------------------------------------------------- /systest/rpc_stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | 4 | DATADIR=$(mktemp -d) 5 | 6 | # Start the node in daemon mode in the background 7 | $NANO_NODE_EXE --daemon --network dev --data_path $DATADIR --config rpc.enable=true --rpcconfig enable_control=true & 8 | NODE_PID=$! 9 | 10 | # Allow some time for the node to start up completely 11 | sleep 10 12 | 13 | # Send the stop rpc command 14 | curl -g -d '{ "action": "stop" }' '[::1]:45000' 15 | 16 | # Check if the process has stopped using a timeout to avoid infinite waiting 17 | if wait $NODE_PID; then 18 | echo "Node stopped successfully" 19 | else 20 | echo "Node did not stop as expected" 21 | exit 1 22 | fi 23 | -------------------------------------------------------------------------------- /tsan_clang_blacklist: -------------------------------------------------------------------------------- 1 | src:*mdb.c 2 | src:*midl.c -------------------------------------------------------------------------------- /tsan_suppressions: -------------------------------------------------------------------------------- 1 | race:mdb.c 2 | race:rocksdb 3 | race:Rijndael::Base::FillEncTable 4 | race:Rijndael::Base::FillDecTable 5 | race:CryptoPP::Rijndael 6 | race:boost::asio::detail::conditionally_enabled_mutex::scoped_lock::scoped_lock 7 | -------------------------------------------------------------------------------- /util/build_prep/macosx/build_qt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | pushd /tmp 4 | wget -O qtbase-clang-latest.tgz https://s3.us-east-2.amazonaws.com/repo.nano.org/artifacts/qtbase-clang-latest.tgz 5 | tar -zxf qtbase-clang-latest.tgz 6 | mv tmp/* . 7 | rm -fr tmp 8 | popd 9 | -------------------------------------------------------------------------------- /util/build_prep/rhel/prep.sh.in: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # -----BEGIN COMMON.SH----- 4 | # -----END COMMON.SH----- 5 | 6 | yes | yum update -y 7 | yes | yum install -y git wget openssl bzip2 8 | yes | yum install -y rpm-build || exit 1 9 | yes | yum install -y glibc-devel glibc-headers make which || exit 1 10 | yes | yum install -y cmake gcc-toolset-12 || exit 1 11 | yes | yum install -y python38 || exit 1 12 | 13 | exit 0 14 | -------------------------------------------------------------------------------- /valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | Boost_Log_Initialization 3 | Memcheck:Cond 4 | fun:_ZN5boost10filesystem6detail28directory_iterator_incrementERNS0_18directory_iteratorEPNS_6system10error_codeE 5 | } 6 | 7 | { 8 | LMDB_block_exists 9 | Memcheck:Cond 10 | ... 11 | fun:mdb_node_search 12 | } 13 | 14 | { 15 | wallets_entry_get 16 | Memcheck:Cond 17 | ... 18 | fun:_ZN4nano12wallet_store13entry_get_rawERKNS_11transactionERKNS_13uint256_unionE 19 | } 20 | 21 | { 22 | wallets_entry_get_size8 23 | Memcheck:Value8 24 | ... 25 | fun:_ZN4nano12wallet_store13entry_get_rawERKNS_11transactionERKNS_13uint256_unionE 26 | } 27 | --------------------------------------------------------------------------------