├── .codecov.yml ├── .dockerignore ├── .github └── workflows │ ├── SetPageFileSize.ps1 │ ├── deploy.yaml │ └── tests.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── app.go ├── appmessage │ ├── README.md │ ├── base_message.go │ ├── common.go │ ├── common_test.go │ ├── doc.go │ ├── domainconverters.go │ ├── error.go │ ├── fixedIO_test.go │ ├── message.go │ ├── p2p_blockheaders.go │ ├── p2p_msgaddresses.go │ ├── p2p_msgblock.go │ ├── p2p_msgblock_test.go │ ├── p2p_msgblockheader.go │ ├── p2p_msgblockheader_test.go │ ├── p2p_msgblocklocator.go │ ├── p2p_msgblocklocator_test.go │ ├── p2p_msgblockwithtrusteddata.go │ ├── p2p_msgblockwithtrusteddatav4.go │ ├── p2p_msgdoneblockswithmetadata.go │ ├── p2p_msgdoneheaders.go │ ├── p2p_msgdonepruningpointutxosetchunks.go │ ├── p2p_msgdrequestpruningpointanditsanticoneheaders.go │ ├── p2p_msgibdblock.go │ ├── p2p_msgibdblocklocator.go │ ├── p2p_msgibdblocklocatorhighesthash.go │ ├── p2p_msgibdblocklocatorhighesthashnotfound.go │ ├── p2p_msgibdchainblocklocator.go │ ├── p2p_msginvrelayblock.go │ ├── p2p_msginvtransaction.go │ ├── p2p_msgping.go │ ├── p2p_msgping_test.go │ ├── p2p_msgpong.go │ ├── p2p_msgpong_test.go │ ├── p2p_msgpruningpointproof.go │ ├── p2p_msgpruningpoints.go │ ├── p2p_msgpruningpointutxosetchunk.go │ ├── p2p_msgreject.go │ ├── p2p_msgrequestaddresses.go │ ├── p2p_msgrequestaddresses_test.go │ ├── p2p_msgrequestanticone.go │ ├── p2p_msgrequestblocklocator.go │ ├── p2p_msgrequestblocklocator_test.go │ ├── p2p_msgrequestheaders.go │ ├── p2p_msgrequestheaders_test.go │ ├── p2p_msgrequestibdblocks.go │ ├── p2p_msgrequestibdchainblocklocator.go │ ├── p2p_msgrequestnextheaders.go │ ├── p2p_msgrequestnextpruningpointanditsanticoneblocks.go │ ├── p2p_msgrequestnextpruningpointutxosetchunk.go │ ├── p2p_msgrequestpruningpointproof.go │ ├── p2p_msgrequestpruningpointutxosetandblock.go │ ├── p2p_msgrequestrelayblocks.go │ ├── p2p_msgrequesttransactions.go │ ├── p2p_msgtransactionnotfound.go │ ├── p2p_msgtrusteddata.go │ ├── p2p_msgtx.go │ ├── p2p_msgtx_test.go │ ├── p2p_msgverack.go │ ├── p2p_msgverack_test.go │ ├── p2p_msgversion.go │ ├── p2p_msgversion_test.go │ ├── p2p_netaddress.go │ ├── p2p_netaddress_test.go │ ├── p2p_ready.go │ ├── p2p_unexpectedpruningpoint.go │ ├── protocol.go │ ├── protocol_test.go │ ├── rpc_add_peer.go │ ├── rpc_ban.go │ ├── rpc_estimate_network_hashes_per_second.go │ ├── rpc_get_balance_by_address.go │ ├── rpc_get_balances_by_addresses.go │ ├── rpc_get_block.go │ ├── rpc_get_block_count.go │ ├── rpc_get_block_dag_info.go │ ├── rpc_get_block_template.go │ ├── rpc_get_blocks.go │ ├── rpc_get_coin_supply.go │ ├── rpc_get_connected_peer_info.go │ ├── rpc_get_current_network.go │ ├── rpc_get_headers.go │ ├── rpc_get_info.go │ ├── rpc_get_mempool_entries.go │ ├── rpc_get_mempool_entries_by_addresses.go │ ├── rpc_get_mempool_entry.go │ ├── rpc_get_peer_addresses.go │ ├── rpc_get_selected_tip_hash.go │ ├── rpc_get_subnetwork.go │ ├── rpc_get_utxos_by_addresses.go │ ├── rpc_get_virtual_selected_parent_blue_score.go │ ├── rpc_get_virtual_selected_parent_chain_from_block.go │ ├── rpc_notify_block_added.go │ ├── rpc_notify_finality_conflicts.go │ ├── rpc_notify_new_block_template.go │ ├── rpc_notify_pruning_point_utxo_set_override.go │ ├── rpc_notify_utxos_changed.go │ ├── rpc_notify_virtual_daa_score_changed.go │ ├── rpc_notify_virtual_selected_parent_chain_blue_score_changed.go │ ├── rpc_notify_virtual_selected_parent_chain_changed.go │ ├── rpc_resolve_finality_conflict.go │ ├── rpc_shut_down.go │ ├── rpc_stop_notifying_utxos_changed.go │ ├── rpc_submit_block.go │ ├── rpc_submit_transaction.go │ ├── rpc_unban.go │ └── testdata │ │ └── megatx.bin.bz2 ├── component_manager.go ├── db_version.go ├── log.go ├── protocol │ ├── common │ │ └── common.go │ ├── flowcontext │ │ ├── addresses.go │ │ ├── blocks.go │ │ ├── config.go │ │ ├── domain.go │ │ ├── errors.go │ │ ├── flow_context.go │ │ ├── log.go │ │ ├── network.go │ │ ├── orphans.go │ │ ├── shared_requested_blocks.go │ │ ├── shared_requested_transactions.go │ │ └── transactions.go │ ├── flows │ │ ├── handshake │ │ │ ├── handshake.go │ │ │ ├── log.go │ │ │ ├── receiveversion.go │ │ │ └── sendversion.go │ │ ├── ready │ │ │ ├── log.go │ │ │ └── ready.go │ │ └── v5 │ │ │ ├── addressexchange │ │ │ ├── receiveaddresses.go │ │ │ └── sendaddresses.go │ │ │ ├── blockrelay │ │ │ ├── batch_size_test.go │ │ │ ├── block_locator.go │ │ │ ├── handle_ibd_block_locator.go │ │ │ ├── handle_ibd_block_requests.go │ │ │ ├── handle_ibd_request_chain_block_locator.go │ │ │ ├── handle_pruning_point_and_its_anticone_requests.go │ │ │ ├── handle_pruning_point_proof_requests.go │ │ │ ├── handle_relay_block_requests.go │ │ │ ├── handle_relay_invs.go │ │ │ ├── handle_request_anticone.go │ │ │ ├── handle_request_block_locator.go │ │ │ ├── handle_request_headers.go │ │ │ ├── handle_request_pruning_point_utxo_set.go │ │ │ ├── ibd.go │ │ │ ├── ibd_progress_reporter.go │ │ │ ├── ibd_with_headers_proof.go │ │ │ ├── log.go │ │ │ └── send_virtual_selected_parent_inv.go │ │ │ ├── ping │ │ │ ├── receive.go │ │ │ └── send.go │ │ │ ├── register.go │ │ │ ├── rejects │ │ │ └── handle_rejects.go │ │ │ ├── testing │ │ │ ├── common_test.go │ │ │ ├── receiveaddresses_test.go │ │ │ └── testing.go │ │ │ └── transactionrelay │ │ │ ├── handle_relayed_transactions.go │ │ │ ├── handle_relayed_transactions_test.go │ │ │ ├── handle_requested_transactions.go │ │ │ └── handle_requested_transactions_test.go │ ├── log.go │ ├── manager.go │ ├── peer │ │ ├── log.go │ │ └── peer.go │ ├── protocol.go │ └── protocolerrors │ │ └── protocolerrors.go └── rpc │ ├── log.go │ ├── manager.go │ ├── rpc.go │ ├── rpccontext │ ├── chain_changed.go │ ├── context.go │ ├── log.go │ ├── notificationmanager.go │ ├── utxos_by_addresses.go │ └── verbosedata.go │ └── rpchandlers │ ├── add_peer.go │ ├── ban.go │ ├── estimate_network_hashes_per_second.go │ ├── get_balance_by_address.go │ ├── get_balances_by_addresses.go │ ├── get_block.go │ ├── get_block_count.go │ ├── get_block_dag_info.go │ ├── get_block_template.go │ ├── get_blocks.go │ ├── get_blocks_test.go │ ├── get_coin_supply.go │ ├── get_connected_peer_info.go │ ├── get_current_network.go │ ├── get_headers.go │ ├── get_info.go │ ├── get_mempool_entries.go │ ├── get_mempool_entries_by_addresses.go │ ├── get_mempool_entry.go │ ├── get_peer_addresses.go │ ├── get_selected_tip_hash.go │ ├── get_subnetwork.go │ ├── get_utxos_by_addresses.go │ ├── get_virtual_selected_parent_blue_score.go │ ├── get_virtual_selected_parent_chain_from_block.go │ ├── log.go │ ├── notify_block_added.go │ ├── notify_finality_conflicts.go │ ├── notify_new_block_template.go │ ├── notify_pruning_point_utxo_set_overrides.go │ ├── notify_utxos_changed.go │ ├── notify_virtual_daa_score_changed.go │ ├── notify_virtual_selected_parent_blue_score_changed.go │ ├── notify_virtual_selected_parent_chain_changed.go │ ├── resolve_finality_conflict.go │ ├── shut_down.go │ ├── stop_notifying_pruning_point_utxo_set_overrides.go │ ├── stop_notifying_utxos_changed.go │ ├── submit_block.go │ ├── submit_transaction.go │ └── unban.go ├── build_and_test.sh ├── changelog.txt ├── cmd ├── genkeypair │ ├── README.md │ ├── config.go │ └── main.go ├── karlsenctl │ ├── README.md │ ├── command_parser.go │ ├── commands.go │ ├── config.go │ ├── docker │ │ └── Dockerfile │ ├── main.go │ └── reflection_helpers.go ├── karlsenminer │ ├── README.md │ ├── client.go │ ├── config.go │ ├── docker │ │ └── Dockerfile │ ├── log.go │ ├── main.go │ ├── mineloop.go │ └── templatemanager │ │ └── templatemanager.go └── karlsenwallet │ ├── balance.go │ ├── broadcast.go │ ├── common.go │ ├── config.go │ ├── create.go │ ├── create_unsigned_tx.go │ ├── daemon │ ├── client │ │ └── client.go │ ├── pb │ │ ├── generate.go │ │ ├── karlsenwalletd.pb.go │ │ ├── karlsenwalletd.proto │ │ └── karlsenwalletd_grpc.pb.go │ └── server │ │ ├── address.go │ │ ├── balance.go │ │ ├── broadcast.go │ │ ├── common.go │ │ ├── create_unsigned_transaction.go │ │ ├── external_spendable_utxos.go │ │ ├── log.go │ │ ├── rpc.go │ │ ├── send.go │ │ ├── server.go │ │ ├── shutdown.go │ │ ├── sign.go │ │ ├── split_transaction.go │ │ ├── split_transaction_test.go │ │ ├── sync.go │ │ └── version.go │ ├── docker │ └── Dockerfile │ ├── dump_unencrypted_data.go │ ├── get_daemon_version.go │ ├── keys │ ├── create.go │ ├── get_password.go │ └── keys.go │ ├── libkarlsenwallet │ ├── bip32 │ │ ├── base58 │ │ │ ├── alphabet.go │ │ │ ├── base58.go │ │ │ ├── base58_test.go │ │ │ ├── base58bench_test.go │ │ │ ├── base58check.go │ │ │ ├── base58check_test.go │ │ │ ├── cov_report.sh │ │ │ ├── doc.go │ │ │ └── example_test.go │ │ ├── bip32.go │ │ ├── bip32_test.go │ │ ├── child_key_derivation.go │ │ ├── extended_key.go │ │ ├── hash.go │ │ ├── path.go │ │ ├── serialization.go │ │ └── version.go │ ├── bip39.go │ ├── converters.go │ ├── keychains.go │ ├── keypair.go │ ├── serialization │ │ ├── protoserialization │ │ │ ├── generate.go │ │ │ ├── wallet.pb.go │ │ │ └── wallet.proto │ │ └── serialization.go │ ├── sign.go │ ├── transaction.go │ └── transaction_test.go │ ├── main.go │ ├── new_address.go │ ├── parse.go │ ├── send.go │ ├── show_addresses.go │ ├── sign.go │ ├── start_daemon.go │ ├── sweep.go │ ├── transactions_hex_encoding.go │ ├── utils │ ├── format_kls.go │ ├── format_kls_test.go │ └── readline.go │ └── version.go ├── doc.go ├── docker ├── Dockerfile ├── build.sh └── docker-compose.yaml ├── domain ├── consensus │ ├── consensus.go │ ├── consensus_test.go │ ├── constructors.go │ ├── database │ │ ├── binaryserialization │ │ │ ├── common.go │ │ │ └── hash.go │ │ ├── bucket.go │ │ ├── cursor.go │ │ ├── dbmanager.go │ │ ├── errors.go │ │ ├── key.go │ │ ├── serialization │ │ │ ├── README.md │ │ │ ├── acceptancedata.go │ │ │ ├── block.go │ │ │ ├── block_ghostdag_data.go │ │ │ ├── blockheader.go │ │ │ ├── blocklevelparents.go │ │ │ ├── blockrelations.go │ │ │ ├── blockstatus.go │ │ │ ├── blues_anticone_sizes.go │ │ │ ├── blues_anticone_sizes_test.go │ │ │ ├── daa_block.go │ │ │ ├── dbobjects.pb.go │ │ │ ├── dbobjects.proto │ │ │ ├── generate.go │ │ │ ├── hash.go │ │ │ ├── multiset.go │ │ │ ├── outpoint.go │ │ │ ├── reachability_data.go │ │ │ ├── reachablity_interval.go │ │ │ ├── subnetworkid.go │ │ │ ├── tips.go │ │ │ ├── transaction.go │ │ │ ├── transactionid.go │ │ │ ├── utxo_collection.go │ │ │ ├── utxo_diff.go │ │ │ └── utxo_entry.go │ │ └── transaction.go │ ├── datastructures │ │ ├── acceptancedatastore │ │ │ ├── acceptance_data_staging_shard.go │ │ │ └── acceptance_data_store.go │ │ ├── blockheaderstore │ │ │ ├── block_header_staging_shard.go │ │ │ └── block_header_store.go │ │ ├── blockrelationstore │ │ │ ├── block_relation_staging_shard.go │ │ │ └── block_relation_store.go │ │ ├── blockstatusstore │ │ │ ├── block_status_staging_shard.go │ │ │ └── block_status_store.go │ │ ├── blockstore │ │ │ ├── block_staging_shard.go │ │ │ └── block_store.go │ │ ├── blockwindowheapslicestore │ │ │ ├── block_window_heap_slice_staging_shard.go │ │ │ └── block_window_heap_slice_store.go │ │ ├── consensusstatestore │ │ │ ├── consensus_state_staging_shard.go │ │ │ ├── consensus_state_store.go │ │ │ ├── tips.go │ │ │ ├── utxo.go │ │ │ ├── utxo_serialization.go │ │ │ └── virtual_utxo_set.go │ │ ├── daablocksstore │ │ │ ├── daa_blocks_staging_shard.go │ │ │ └── daa_blocks_store.go │ │ ├── daawindowstore │ │ │ ├── daa_window_staging_shard.go │ │ │ └── daa_window_store.go │ │ ├── finalitystore │ │ │ ├── finality_staging_shard.go │ │ │ └── finality_store.go │ │ ├── ghostdagdatastore │ │ │ ├── ghostadag_data_staging_shard.go │ │ │ └── ghostdag_data_store.go │ │ ├── headersselectedchainstore │ │ │ ├── headers_selected_chain_staging_shard.go │ │ │ └── headers_selected_chain_store.go │ │ ├── headersselectedtipstore │ │ │ ├── headers_selected_tip_staging_shard.go │ │ │ └── headers_selected_tips_store.go │ │ ├── mergedepthrootstore │ │ │ ├── merge_depth_root_staging_shard.go │ │ │ └── merge_depth_root_store.go │ │ ├── multisetstore │ │ │ ├── multiset_staging_shard.go │ │ │ └── multiset_store.go │ │ ├── pruningstore │ │ │ ├── imported_pruning_point.go │ │ │ ├── pruning_staging_shard.go │ │ │ └── pruning_store.go │ │ ├── reachabilitydatastore │ │ │ ├── reachability_data_staging_shard.go │ │ │ └── reachability_data_store.go │ │ └── utxodiffstore │ │ │ ├── utxo_diff_staging_shard.go │ │ │ └── utxo_diff_store.go │ ├── factory.go │ ├── factory_test.go │ ├── finality_test.go │ ├── log.go │ ├── model │ │ ├── acceptancedata_equal_clone_test.go │ │ ├── block_heap.go │ │ ├── blockiterator.go │ │ ├── blockrelations.go │ │ ├── blockrelations_equal_clone_test.go │ │ ├── database.go │ │ ├── errors.go │ │ ├── externalapi │ │ │ ├── acceptancedata.go │ │ │ ├── block.go │ │ │ ├── block_equal_clone_test.go │ │ │ ├── block_with_trusted_data.go │ │ │ ├── blockinfo.go │ │ │ ├── blockinfo_clone_test.go │ │ │ ├── blocklevelparents.go │ │ │ ├── blocklocator.go │ │ │ ├── blocklocator_clone_test.go │ │ │ ├── blockstatus.go │ │ │ ├── blockstatus_equal_clone_test.go │ │ │ ├── blocktemplate.go │ │ │ ├── coinbase.go │ │ │ ├── coinbase_clone_test.go │ │ │ ├── consensus.go │ │ │ ├── consensus_events.go │ │ │ ├── ghostdag.go │ │ │ ├── hash.go │ │ │ ├── hash_clone_equal_test.go │ │ │ ├── pruning_point_proof.go │ │ │ ├── readonlyutxoset.go │ │ │ ├── subnetworkid.go │ │ │ ├── subnetworkid_clone_equal_test.go │ │ │ ├── sync.go │ │ │ ├── sync_equal_clone_test.go │ │ │ ├── transaction.go │ │ │ ├── transaction_equal_clone_test.go │ │ │ ├── utxodiff.go │ │ │ ├── utxoentry.go │ │ │ └── virtual.go │ │ ├── interface_datastructures_acceptancedatastore.go │ │ ├── interface_datastructures_blockheaderstore.go │ │ ├── interface_datastructures_blockrelationstore.go │ │ ├── interface_datastructures_blocks_with_trusted_data_daa_window_store.go │ │ ├── interface_datastructures_blockstatusstore.go │ │ ├── interface_datastructures_blockstore.go │ │ ├── interface_datastructures_consensusstatestore.go │ │ ├── interface_datastructures_daablocksstore.go │ │ ├── interface_datastructures_finalitystore.go │ │ ├── interface_datastructures_ghostdagdatastore.go │ │ ├── interface_datastructures_headersselectedchainstore.go │ │ ├── interface_datastructures_headertipsstore.go │ │ ├── interface_datastructures_mergedepthrootstore.go │ │ ├── interface_datastructures_multisetstore.go │ │ ├── interface_datastructures_pruningstore.go │ │ ├── interface_datastructures_reachabilitydatastore.go │ │ ├── interface_datastructures_utxodiffstore.go │ │ ├── interface_datastructures_windowheapstore.go │ │ ├── interface_processes_blockbuilder.go │ │ ├── interface_processes_blockparentbuilder.go │ │ ├── interface_processes_blockprocessor.go │ │ ├── interface_processes_blockvalidator.go │ │ ├── interface_processes_coinbasemanager.go │ │ ├── interface_processes_consensusstatemanager.go │ │ ├── interface_processes_dagtopologymanager.go │ │ ├── interface_processes_dagtraversalmanager.go │ │ ├── interface_processes_difficultymanager.go │ │ ├── interface_processes_finalitymanager.go │ │ ├── interface_processes_ghostdagmanager.go │ │ ├── interface_processes_headertipsmanager.go │ │ ├── interface_processes_mergedepthmanager.go │ │ ├── interface_processes_parentsmanager.go │ │ ├── interface_processes_pastmediantimemanager.go │ │ ├── interface_processes_pruningmanager.go │ │ ├── interface_processes_pruningproofmanager.go │ │ ├── interface_processes_reachabilitytree.go │ │ ├── interface_processes_syncmanager.go │ │ ├── interface_processes_transactionvalidator.go │ │ ├── multiset.go │ │ ├── reachabilitydata.go │ │ ├── staging_area.go │ │ ├── store.go │ │ ├── subdag.go │ │ ├── testapi │ │ │ ├── test_block_builder.go │ │ │ ├── test_consensus.go │ │ │ ├── test_consensus_state_manager.go │ │ │ ├── test_reachability_manager.go │ │ │ └── test_transaction_validator.go │ │ ├── utxo_diff_reversal_data.go │ │ └── virtual.go │ ├── processes │ │ ├── blockbuilder │ │ │ ├── block_builder.go │ │ │ ├── block_builder_test.go │ │ │ ├── log.go │ │ │ └── test_block_builder.go │ │ ├── blockparentbuilder │ │ │ └── blockparentbuilder.go │ │ ├── blockprocessor │ │ │ ├── blocklogger │ │ │ │ ├── blocklogger.go │ │ │ │ └── log.go │ │ │ ├── blockprocessor.go │ │ │ ├── log.go │ │ │ ├── validate_and_insert_block.go │ │ │ ├── validate_and_insert_block_test.go │ │ │ ├── validate_and_insert_block_with_trusted_data.go │ │ │ ├── validate_and_insert_imported_pruning_point.go │ │ │ ├── validate_and_insert_imported_pruning_point_test.go │ │ │ └── validate_block.go │ │ ├── blockvalidator │ │ │ ├── block_body_in_context.go │ │ │ ├── block_body_in_context_test.go │ │ │ ├── block_body_in_isolation.go │ │ │ ├── block_body_in_isolation_test.go │ │ │ ├── block_header_in_context.go │ │ │ ├── block_header_in_context_test.go │ │ │ ├── block_header_in_isolation.go │ │ │ ├── block_header_in_isolation_test.go │ │ │ ├── blockvalidator.go │ │ │ ├── header_pruning_point.go │ │ │ ├── log.go │ │ │ ├── pruning_violation_proof_of_work_and_difficulty.go │ │ │ └── pruning_violation_proof_of_work_and_difficulty_test.go │ │ ├── coinbasemanager │ │ │ ├── coinbasemanager.go │ │ │ ├── coinbasemanager_external_test.go │ │ │ ├── coinbasemanager_test.go │ │ │ └── payload.go │ │ ├── consensusstatemanager │ │ │ ├── add_block_to_virtual.go │ │ │ ├── add_block_to_virtual_test.go │ │ │ ├── calculate_past_utxo.go │ │ │ ├── calculate_past_utxo_test.go │ │ │ ├── check_finality_violation.go │ │ │ ├── consensus_state_manager.go │ │ │ ├── find_selected_parent_chain_changes.go │ │ │ ├── find_selected_parent_chain_changes_test.go │ │ │ ├── import_pruning_utxo_set.go │ │ │ ├── log.go │ │ │ ├── multisets.go │ │ │ ├── pick_virtual_parents.go │ │ │ ├── populate_tx_with_utxo_entries.go │ │ │ ├── resolve.go │ │ │ ├── resolve_block_status.go │ │ │ ├── resolve_block_status_test.go │ │ │ ├── resolve_virtual_test.go │ │ │ ├── reverse_utxo_diffs.go │ │ │ ├── reverse_utxo_diffs_test.go │ │ │ ├── test_consensus_state_manager.go │ │ │ ├── update_virtual.go │ │ │ ├── utxo_diffs.go │ │ │ ├── verify_and_build_utxo.go │ │ │ └── virtual_parents_test.go │ │ ├── dagtopologymanager │ │ │ ├── dagtopologymanager.go │ │ │ └── dagtopologymanager_external_test.go │ │ ├── dagtraversalmanager │ │ │ ├── anticone.go │ │ │ ├── block_heap.go │ │ │ ├── dagtraversalmanager.go │ │ │ ├── dagtraversalmanager_test.go │ │ │ ├── selected_child_iterator.go │ │ │ ├── window.go │ │ │ └── window_test.go │ │ ├── difficultymanager │ │ │ ├── blockwindow.go │ │ │ ├── difficultymanager.go │ │ │ ├── difficultymanager_test.go │ │ │ ├── hashrate.go │ │ │ └── log.go │ │ ├── finalitymanager │ │ │ ├── finality_manager.go │ │ │ └── log.go │ │ ├── ghostdag2 │ │ │ └── ghostdagimpl.go │ │ ├── ghostdagmanager │ │ │ ├── compare.go │ │ │ ├── ghostdag.go │ │ │ ├── ghostdag_test.go │ │ │ ├── ghostdagmanager.go │ │ │ └── mergeset.go │ │ ├── headersselectedtipmanager │ │ │ ├── headersselectedtipmanager.go │ │ │ └── headersselectedtipmanager_test.go │ │ ├── mergedepthmanager │ │ │ ├── log.go │ │ │ └── merge_depth_manager.go │ │ ├── parentsmanager │ │ │ └── parentsmanager.go │ │ ├── pastmediantimemanager │ │ │ ├── pastmediantimemanager.go │ │ │ └── pastmediantimemanager_test.go │ │ ├── pruningmanager │ │ │ ├── log.go │ │ │ ├── pruning_test.go │ │ │ ├── pruningmanager.go │ │ │ └── testdata │ │ │ │ ├── chain-for-test-pruning.json │ │ │ │ └── dag-for-test-pruning.json │ │ ├── pruningproofmanager │ │ │ ├── log.go │ │ │ └── pruningproofmanager.go │ │ ├── reachabilitymanager │ │ │ ├── fetch.go │ │ │ ├── future_covering_set.go │ │ │ ├── interval.go │ │ │ ├── log.go │ │ │ ├── main_test.go │ │ │ ├── ordered_tree_node_set.go │ │ │ ├── reachability.go │ │ │ ├── reachabilityManager_test.go │ │ │ ├── reachability_external_test.go │ │ │ ├── reachability_stretch_test.go │ │ │ ├── reachability_test.go │ │ │ ├── reachabilitymanager.go │ │ │ ├── reindex_context.go │ │ │ ├── stage.go │ │ │ ├── test_reachabilitymanager.go │ │ │ └── tree.go │ │ ├── syncmanager │ │ │ ├── antipast.go │ │ │ ├── blocklocator.go │ │ │ ├── blocklocator_test.go │ │ │ ├── log.go │ │ │ ├── syncinfo.go │ │ │ ├── syncmanager.go │ │ │ └── syncmanager_test.go │ │ └── transactionvalidator │ │ │ ├── mass.go │ │ │ ├── test_transaction_validator.go │ │ │ ├── transaction_in_context.go │ │ │ ├── transaction_in_context_test.go │ │ │ ├── transaction_in_isolation.go │ │ │ ├── transaction_in_isolation_test.go │ │ │ ├── transactionvalidator.go │ │ │ └── transactionvalidator_test.go │ ├── pruning_test.go │ ├── ruleerrors │ │ ├── rule_error.go │ │ └── rule_error_test.go │ ├── test_consensus.go │ ├── test_consensus_getters.go │ ├── test_consensus_render_to_dot.go │ ├── testdata │ │ ├── dags │ │ │ ├── dag0.json │ │ │ ├── dag1.json │ │ │ ├── dag2.json │ │ │ ├── dag3.json │ │ │ ├── dag4.json │ │ │ └── dag5.json │ │ └── reachability │ │ │ ├── attack-dag-blocks--2^12-delay-factor--1-k--18.json.gz │ │ │ ├── attack-dag-blocks--2^13-delay-factor--1-k--18.json.gz │ │ │ ├── attack-dag-blocks--2^14-delay-factor--1-k--18.json.gz │ │ │ ├── noattack-dag-blocks--2^12-delay-factor--1-k--18.json.gz │ │ │ ├── noattack-dag-blocks--2^13-delay-factor--1-k--18.json.gz │ │ │ └── noattack-dag-blocks--2^14-delay-factor--1-k--18.json.gz │ ├── timelock_CLTV_test.go │ └── utils │ │ ├── blockheader │ │ ├── blockheader.go │ │ └── blockheader_test.go │ │ ├── consensushashing │ │ ├── block.go │ │ ├── calculate_signature_hash.go │ │ ├── calculate_signature_hash_test.go │ │ └── transaction.go │ │ ├── constants │ │ └── constants.go │ │ ├── hashes │ │ ├── domains.go │ │ ├── strings.go │ │ ├── writers.go │ │ └── writers_test.go │ │ ├── hashset │ │ └── hash_set.go │ │ ├── lrucache │ │ └── lrucache.go │ │ ├── lrucacheghostdagdata │ │ └── lrucacheghostdagdata.go │ │ ├── lrucachehashandwindowsizetoblockghostdagdatahashpairs │ │ └── lrucachehashandwindowsizetoblockghostdagdatahashpairs.go │ │ ├── lrucachehashpairtoblockghostdagdatahashpair │ │ └── lrucachehashpairtoblockghostdagdatahashpair.go │ │ ├── lrucacheuint64tohash │ │ └── lrucacheuint64tohash.go │ │ ├── merkle │ │ └── merkle.go │ │ ├── mining │ │ └── solve.go │ │ ├── multiset │ │ └── multiset.go │ │ ├── pow │ │ ├── fishhash.go │ │ ├── fishhash_kernel.go │ │ ├── fishhashplus_kernel.go │ │ ├── heavyhash.go │ │ ├── heavyhash_test.go │ │ ├── log.go │ │ ├── pow.go │ │ ├── xoshiro.go │ │ └── xoshiro_test.go │ │ ├── reachabilitydata │ │ ├── reachability_data.go │ │ └── reachabilitydata_equal_clone_test.go │ │ ├── serialization │ │ └── common.go │ │ ├── sorters │ │ └── timesorter.go │ │ ├── subnetworks │ │ ├── compare.go │ │ ├── from_bytes.go │ │ ├── from_string.go │ │ └── subnetworks.go │ │ ├── testutils │ │ ├── create_transaction.go │ │ ├── for_all_nets.go │ │ ├── for_all_paths.go │ │ ├── op_true_script.go │ │ └── test_ghostdag.go │ │ ├── transactionhelper │ │ ├── coinbase.go │ │ └── new.go │ │ ├── transactionid │ │ ├── from_bytes.go │ │ └── from_string.go │ │ ├── txscript │ │ ├── README.md │ │ ├── data │ │ │ ├── LICENSE │ │ │ ├── script_tests.json │ │ │ ├── sighash.json │ │ │ ├── tx_invalid.json │ │ │ └── tx_valid.json │ │ ├── doc.go │ │ ├── engine.go │ │ ├── engine_test.go │ │ ├── error.go │ │ ├── error_test.go │ │ ├── example_test.go │ │ ├── log.go │ │ ├── main_test.go │ │ ├── opcode.go │ │ ├── opcode_test.go │ │ ├── reference_test.go │ │ ├── script.go │ │ ├── script_test.go │ │ ├── scriptbuilder.go │ │ ├── scriptbuilder_test.go │ │ ├── scriptnum.go │ │ ├── scriptnum_test.go │ │ ├── sigcache.go │ │ ├── sigcache_ecdsa.go │ │ ├── sigcache_test.go │ │ ├── sign.go │ │ ├── sign_test.go │ │ ├── stack.go │ │ ├── stack_test.go │ │ ├── standard.go │ │ └── standard_test.go │ │ ├── utxo │ │ ├── diff_algebra.go │ │ ├── diff_algebra_test.go │ │ ├── immutable_utxo_diff.go │ │ ├── mutable_utxo_diff.go │ │ ├── serialization.go │ │ ├── serialization_test.go │ │ ├── utxo_collection.go │ │ ├── utxo_entry.go │ │ ├── utxo_entry_test.go │ │ ├── utxo_iterator.go │ │ └── utxo_iterator_with_diff.go │ │ ├── utxolrucache │ │ └── utxolrucache.go │ │ └── virtual │ │ └── virtual.go ├── consensusreference │ └── consensusreference.go ├── dagconfig │ ├── README.md │ ├── consensus_defaults.go │ ├── doc.go │ ├── genesis.go │ ├── genesis_test.go │ ├── params.go │ ├── params_test.go │ └── register_test.go ├── domain.go ├── domain_test.go ├── log.go ├── migrate.go ├── miningmanager │ ├── blocktemplatebuilder │ │ ├── blocktemplatebuilder.go │ │ ├── log.go │ │ ├── policy.go │ │ └── txselection.go │ ├── factory.go │ ├── mempool │ │ ├── check_transaction_standard.go │ │ ├── check_transaction_standard_test.go │ │ ├── config.go │ │ ├── error.go │ │ ├── fill_inputs_and_get_missing_parents.go │ │ ├── handle_new_block_transactions.go │ │ ├── log.go │ │ ├── mempool.go │ │ ├── mempool_utxo_set.go │ │ ├── model │ │ │ ├── map_types.go │ │ │ ├── mempool_transaction.go │ │ │ ├── ordered_transactions_by_fee_rate.go │ │ │ ├── orphan_transaction.go │ │ │ └── transaction.go │ │ ├── orphan_pool.go │ │ ├── remove_transaction.go │ │ ├── revalidate_high_priority_transactions.go │ │ ├── transactions_pool.go │ │ ├── validate_and_insert_transaction.go │ │ └── validate_transaction.go │ ├── miningmanager.go │ ├── miningmanager_test.go │ └── model │ │ ├── interface_blocktemplatebuilder.go │ │ └── interface_mempool.go ├── prefixmanager │ ├── log.go │ ├── prefix.go │ └── prefix │ │ └── prefix.go └── utxoindex │ ├── log.go │ ├── model.go │ ├── serialization.go │ ├── serialization_test.go │ ├── store.go │ └── utxoindex.go ├── go.mod ├── go.sum ├── infrastructure ├── config │ ├── config.go │ ├── config_test.go │ ├── log.go │ ├── network.go │ └── sample-karlsend.conf ├── db │ └── database │ │ ├── README.md │ │ ├── common_test.go │ │ ├── cursor.go │ │ ├── cursor_test.go │ │ ├── dataaccessor.go │ │ ├── database.go │ │ ├── database_test.go │ │ ├── doc.go │ │ ├── errors.go │ │ ├── keys.go │ │ ├── keys_test.go │ │ ├── ldb │ │ ├── cursor.go │ │ ├── cursor_test.go │ │ ├── leveldb.go │ │ ├── leveldb_test.go │ │ ├── log.go │ │ ├── options.go │ │ ├── transaction.go │ │ └── transaction_test.go │ │ ├── transaction.go │ │ └── transaction_test.go ├── logger │ ├── backend.go │ ├── doc.go │ ├── level.go │ ├── logger.go │ ├── logs.go │ └── utils.go ├── network │ ├── addressmanager │ │ ├── addressmanager.go │ │ ├── addressmanager_test.go │ │ ├── addressrandomize.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── localaddressmanager.go │ │ ├── log.go │ │ ├── network.go │ │ ├── network_test.go │ │ ├── store.go │ │ ├── store_test.go │ │ └── test_utils.go │ ├── connmanager │ │ ├── connection_requests.go │ │ ├── connection_set.go │ │ ├── connmanager.go │ │ ├── incoming_connections.go │ │ ├── log.go │ │ └── outgoing_connections.go │ ├── dnsseed │ │ ├── log.go │ │ ├── pb │ │ │ ├── generate.go │ │ │ ├── peer_service.pb.go │ │ │ ├── peer_service.proto │ │ │ └── peer_service_grpc.pb.go │ │ └── seed.go │ ├── netadapter │ │ ├── id │ │ │ └── id.go │ │ ├── log.go │ │ ├── netadapter.go │ │ ├── netadapter_test.go │ │ ├── netconnection.go │ │ ├── router │ │ │ ├── log.go │ │ │ ├── route.go │ │ │ └── router.go │ │ ├── server │ │ │ ├── grpcserver │ │ │ │ ├── connection_loops.go │ │ │ │ ├── grpc_connection.go │ │ │ │ ├── grpc_server.go │ │ │ │ ├── log.go │ │ │ │ ├── p2pserver.go │ │ │ │ ├── protowire │ │ │ │ │ ├── README.md │ │ │ │ │ ├── common.go │ │ │ │ │ ├── generate.go │ │ │ │ │ ├── messages.pb.go │ │ │ │ │ ├── messages.proto │ │ │ │ │ ├── messages_grpc.pb.go │ │ │ │ │ ├── p2p.pb.go │ │ │ │ │ ├── p2p.proto │ │ │ │ │ ├── p2p_addresses.go │ │ │ │ │ ├── p2p_block.go │ │ │ │ │ ├── p2p_block_headers.go │ │ │ │ │ ├── p2p_block_locator.go │ │ │ │ │ ├── p2p_block_with_trusted_data.go │ │ │ │ │ ├── p2p_block_with_trusted_data_v4.go │ │ │ │ │ ├── p2p_done_blocks_with_trusted_data.go │ │ │ │ │ ├── p2p_done_headers.go │ │ │ │ │ ├── p2p_done_pruning_point_utxo_set_chunks.go │ │ │ │ │ ├── p2p_header.go │ │ │ │ │ ├── p2p_ibd_block.go │ │ │ │ │ ├── p2p_ibd_block_locator.go │ │ │ │ │ ├── p2p_ibd_block_locator_highest_hash.go │ │ │ │ │ ├── p2p_ibd_block_locator_highest_hash_not_found.go │ │ │ │ │ ├── p2p_ibd_chain_block_locator.go │ │ │ │ │ ├── p2p_inv_relay_block.go │ │ │ │ │ ├── p2p_inv_transactions.go │ │ │ │ │ ├── p2p_ping.go │ │ │ │ │ ├── p2p_pong.go │ │ │ │ │ ├── p2p_pruning_point_proof.go │ │ │ │ │ ├── p2p_pruning_point_utxo_set_chunk.go │ │ │ │ │ ├── p2p_pruning_points.go │ │ │ │ │ ├── p2p_ready.go │ │ │ │ │ ├── p2p_reject.go │ │ │ │ │ ├── p2p_request_addresses.go │ │ │ │ │ ├── p2p_request_anticone.go │ │ │ │ │ ├── p2p_request_block_locator.go │ │ │ │ │ ├── p2p_request_headers.go │ │ │ │ │ ├── p2p_request_ibd_blocks.go │ │ │ │ │ ├── p2p_request_ibd_chain_block_locator.go │ │ │ │ │ ├── p2p_request_next_headers.go │ │ │ │ │ ├── p2p_request_next_pruning_point_and_its_anticone_blocks.go │ │ │ │ │ ├── p2p_request_next_pruning_point_utxo_set_chunk.go │ │ │ │ │ ├── p2p_request_pruning_point_and_its_anticone.go │ │ │ │ │ ├── p2p_request_pruning_point_proof.go │ │ │ │ │ ├── p2p_request_pruning_point_utxo_set_and_block.go │ │ │ │ │ ├── p2p_request_relay_blocks.go │ │ │ │ │ ├── p2p_request_transactions.go │ │ │ │ │ ├── p2p_transaction.go │ │ │ │ │ ├── p2p_transaction_not_found.go │ │ │ │ │ ├── p2p_trusted_data.go │ │ │ │ │ ├── p2p_unexpected_pruning_point.go │ │ │ │ │ ├── p2p_verack.go │ │ │ │ │ ├── p2p_version.go │ │ │ │ │ ├── rpc.md │ │ │ │ │ ├── rpc.pb.go │ │ │ │ │ ├── rpc.proto │ │ │ │ │ ├── rpc_add_peer.go │ │ │ │ │ ├── rpc_ban.go │ │ │ │ │ ├── rpc_error.go │ │ │ │ │ ├── rpc_estimate_network_hashes_per_second.go │ │ │ │ │ ├── rpc_get_balance_by_address.go │ │ │ │ │ ├── rpc_get_balances_by_addresses.go │ │ │ │ │ ├── rpc_get_block.go │ │ │ │ │ ├── rpc_get_block_count.go │ │ │ │ │ ├── rpc_get_block_dag_info.go │ │ │ │ │ ├── rpc_get_block_template.go │ │ │ │ │ ├── rpc_get_blocks.go │ │ │ │ │ ├── rpc_get_connected_peer_info.go │ │ │ │ │ ├── rpc_get_current_network.go │ │ │ │ │ ├── rpc_get_headers.go │ │ │ │ │ ├── rpc_get_info.go │ │ │ │ │ ├── rpc_get_mempool_entries.go │ │ │ │ │ ├── rpc_get_mempool_entries_by_addresses.go │ │ │ │ │ ├── rpc_get_mempool_entry.go │ │ │ │ │ ├── rpc_get_peer_addresses.go │ │ │ │ │ ├── rpc_get_selected_tip_hash.go │ │ │ │ │ ├── rpc_get_subnetwork.go │ │ │ │ │ ├── rpc_get_supply.go │ │ │ │ │ ├── rpc_get_utxos_by_addresses.go │ │ │ │ │ ├── rpc_get_virtual_selected_parent_blue_score.go │ │ │ │ │ ├── rpc_get_virtual_selected_parent_chain_from_block.go │ │ │ │ │ ├── rpc_notify_block_added.go │ │ │ │ │ ├── rpc_notify_finality_conflicts.go │ │ │ │ │ ├── rpc_notify_new_block_template.go │ │ │ │ │ ├── rpc_notify_pruning_point_utxo_set_override.go │ │ │ │ │ ├── rpc_notify_utxos_changed.go │ │ │ │ │ ├── rpc_notify_virtual_daa_score_changed.go │ │ │ │ │ ├── rpc_notify_virtual_selected_parent_blue_score_changed.go │ │ │ │ │ ├── rpc_notify_virtual_selected_parent_chain_changed.go │ │ │ │ │ ├── rpc_resolve_finality_conflict.go │ │ │ │ │ ├── rpc_shut_down.go │ │ │ │ │ ├── rpc_stop_notifying_utxos_changed.go │ │ │ │ │ ├── rpc_submit_block.go │ │ │ │ │ ├── rpc_submit_transaction.go │ │ │ │ │ ├── rpc_unban.go │ │ │ │ │ └── wire.go │ │ │ │ └── rpcserver.go │ │ │ └── server.go │ │ └── standalone │ │ │ ├── log.go │ │ │ ├── minimal_net_adapter.go │ │ │ └── routes.go │ └── rpcclient │ │ ├── grpcclient │ │ ├── grpcclient.go │ │ ├── log.go │ │ └── post.go │ │ ├── log.go │ │ ├── rpc_ban.go │ │ ├── rpc_connect_to_peer.go │ │ ├── rpc_estimate_network_hashes_per_second.go │ │ ├── rpc_get_balance_by_address.go │ │ ├── rpc_get_balances_by_addresses.go │ │ ├── rpc_get_block.go │ │ ├── rpc_get_block_count.go │ │ ├── rpc_get_block_dag_info.go │ │ ├── rpc_get_block_template.go │ │ ├── rpc_get_blocks.go │ │ ├── rpc_get_chain_from_block.go │ │ ├── rpc_get_coin_supply.go │ │ ├── rpc_get_connected_peer_info.go │ │ ├── rpc_get_headers.go │ │ ├── rpc_get_info.go │ │ ├── rpc_get_mempool_entries.go │ │ ├── rpc_get_mempool_entries_by_address.go │ │ ├── rpc_get_mempool_entry.go │ │ ├── rpc_get_peer_addresses.go │ │ ├── rpc_get_selected_tip_hash.go │ │ ├── rpc_get_subnetwork.go │ │ ├── rpc_get_utxos_by_addresses.go │ │ ├── rpc_get_virtual_selected_parent_blue_score.go │ │ ├── rpc_on_block_added.go │ │ ├── rpc_on_chain_changed.go │ │ ├── rpc_on_finality_conflicts.go │ │ ├── rpc_on_new_block_template.go │ │ ├── rpc_on_pruning_point_utxo_set_override.go │ │ ├── rpc_on_utxos_changed.go │ │ ├── rpc_on_virtual_daa_score_changed.go │ │ ├── rpc_on_virtual_selected_parent_blue_score_changed.go │ │ ├── rpc_resolve_finality_conflict.go │ │ ├── rpc_send_raw_transaction.go │ │ ├── rpc_submit_block.go │ │ ├── rpc_unban.go │ │ ├── rpcclient.go │ │ └── rpcrouter.go └── os │ ├── execenv │ └── initialize.go │ ├── limits │ ├── desired_limits.go │ ├── limits_plan9.go │ ├── limits_unix.go │ └── limits_windows.go │ ├── signal │ ├── log.go │ ├── signal.go │ └── signalsigterm.go │ └── winservice │ ├── common.go │ ├── log.go │ ├── service_command_windows.go │ ├── service_main_windows.go │ └── service_windows.go ├── main.go ├── stability-tests ├── README.md ├── application-level-garbage │ ├── README.md │ ├── config.go │ ├── log.go │ ├── main.go │ ├── read.go │ ├── run │ │ ├── blocks.dat │ │ └── run.sh │ └── send.go ├── common │ ├── cmd.go │ ├── file_scanner.go │ ├── log-writer.go │ ├── log.go │ ├── mine │ │ ├── db.go │ │ ├── log.go │ │ ├── mine.go │ │ └── read.go │ ├── paths.go │ ├── rpc │ │ ├── log.go │ │ └── rpc.go │ ├── run-karlsend.go │ └── tempdir.go ├── daa │ ├── README.md │ ├── average_duration.go │ ├── daa_test.go │ └── run │ │ └── run.sh ├── docker │ └── Dockerfile ├── infra-level-garbage │ ├── README.md │ ├── config.go │ ├── log.go │ ├── main.go │ ├── run │ │ ├── messages.dat │ │ └── run.sh │ └── send.go ├── install_and_test.sh ├── karlsendsanity │ ├── README.md │ ├── commandloop.go │ ├── config.go │ ├── log.go │ ├── main.go │ ├── read.go │ └── run │ │ ├── commands-list │ │ └── run.sh ├── many-tips │ ├── config.go │ ├── log.go │ ├── main.go │ └── run │ │ └── run.sh ├── mempool-limits │ ├── README.md │ ├── config.go │ ├── log.go │ ├── main_test.go │ ├── run │ │ └── run.sh │ └── transactions.go ├── minejson │ ├── config.go │ ├── example.json │ ├── log.go │ └── main.go ├── netsync │ ├── README.md │ ├── chain_generator │ │ ├── config.go │ │ ├── log.go │ │ └── main.go │ ├── check_resolve_virtual.go │ ├── check_sync_rate.go │ ├── config.go │ ├── dags-fast │ │ ├── 000170-chain.json.gz │ │ ├── 100-chain.json.gz │ │ └── wide-dag-blocks--2^12-delay-factor--1-k--18.json.gz │ ├── dags-slow │ │ ├── 100000-chain.json.gz │ │ ├── 100070-chain.json.gz │ │ ├── many-small-chains-and-one-big-chain.json.gz │ │ ├── wide-dag-blocks--2^16-delay-factor--1-k--18.json.gz │ │ ├── wide-dag-blocks--2^20-delay-factor--1-k--18.json.gz │ │ ├── wide-dag-blocks--2^20-delay-factor--2-k--18.json.gz │ │ ├── wide-dag-blocks--2^20-delay-factor--4-k--18.json.gz │ │ ├── wide-dag-blocks--2^20-delay-factor--6-k--18.json.gz │ │ └── wide-dag-blocks--2^20-delay-factor--8-k--18.json.gz │ ├── fast-pruning-ibd-test │ │ ├── dag-for-fast-pruning-ibd-test.json.gz │ │ ├── fast-pruning-ibd-test-params.json │ │ └── generate_test.go │ ├── log.go │ ├── main.go │ ├── node.go │ └── run │ │ ├── run-fast.sh │ │ ├── run-slow.sh │ │ └── run.sh ├── orphans │ ├── README.md │ ├── check_top_is_tip.go │ ├── config.go │ ├── connect_to_node.go │ ├── log.go │ ├── main.go │ ├── prepare_blocks.go │ ├── run │ │ └── run.sh │ └── send_blocks.go ├── reorg │ ├── config.go │ ├── log.go │ ├── main.go │ ├── reorg.go │ └── run │ │ ├── run-full-finality-window-reorg.sh │ │ └── run.sh ├── rpc-idle-clients │ ├── config.go │ ├── log.go │ ├── main.go │ └── run │ │ └── run.sh ├── rpc-stability │ ├── README.md │ ├── config.go │ ├── log.go │ ├── main.go │ ├── read.go │ ├── run │ │ ├── commands.json │ │ └── run.sh │ └── send.go ├── run │ ├── run-fast.sh │ ├── run-slow.sh │ └── run.sh └── simple-sync │ ├── README.md │ ├── cmd.go │ ├── config.go │ ├── log.go │ ├── main.go │ ├── mineloop.go │ ├── run │ └── run.sh │ └── start-nodes.go ├── testing └── integration │ ├── 16_incoming_connections_test.go │ ├── address_exchange_test.go │ ├── basic_sync_test.go │ ├── config_test.go │ ├── connect_test.go │ ├── ibd_test.go │ ├── integration.go │ ├── log_test.go │ ├── main_test.go │ ├── mining_test.go │ ├── notifications_test.go │ ├── rpc_test.go │ ├── selected_parent_chain_test.go │ ├── setup_test.go │ ├── tx_relay_test.go │ ├── utxo_index_test.go │ └── virtual_selected_parent_blue_score_test.go ├── util ├── README.md ├── address.go ├── address_test.go ├── amount.go ├── amount_test.go ├── appdata.go ├── appdata_test.go ├── bech32 │ ├── README.md │ ├── bech32.go │ ├── bech32_test.go │ ├── doc.go │ ├── example_test.go │ └── internal_test.go ├── binaryserializer │ ├── binaryserializer.go │ └── binaryserializer_test.go ├── blake2b.go ├── difficulty │ ├── difficulty.go │ └── difficulty_test.go ├── doc.go ├── example_test.go ├── internal_test.go ├── locks │ └── log.go ├── math │ ├── min.go │ └── min_test.go ├── mstime │ ├── mstime.go │ └── mstime_test.go ├── network │ ├── network.go │ └── parse_listeners.go ├── panics │ ├── log.go │ └── panics.go ├── profiling │ └── profiling.go ├── random │ ├── random.go │ └── random_test.go ├── staging │ ├── commit_all_changes.go │ └── log.go └── txmass │ └── calculator.go └── version └── version.go /.codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | patch: off 4 | 5 | project: 6 | default: 7 | informational: true 8 | ignore: 9 | - "**/*.pb.go" # Ignore all auto generated protobuf structures. -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | **/docker-compose.yml 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Temp files 2 | *~ 3 | 4 | # Databases 5 | karlsendnd.db 6 | *-shm 7 | *-wal 8 | 9 | # Log files 10 | *.log 11 | 12 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 13 | *.o 14 | *.a 15 | *.so 16 | *.dylib 17 | 18 | # Test binary, built with `go test -c` 19 | *.test 20 | 21 | # Real binaries, build with `go build .` 22 | karlsend 23 | cmd/gencerts/gencerts 24 | cmd/karlsenctl/karlsenctl 25 | cmd/karlsenminer/karlsenminer 26 | *.exe 27 | *.exe~ 28 | 29 | # Output of the go coverage tool 30 | *.out 31 | 32 | # Folders 33 | _obj 34 | _test 35 | vendor 36 | 37 | # Architecture specific extensions/prefixes 38 | *.[568vq] 39 | [568vq].out 40 | 41 | *.cgo1.go 42 | *.cgo2.c 43 | _cgo_defun.c 44 | _cgo_gotypes.go 45 | _cgo_export.* 46 | 47 | _testmain.go 48 | 49 | 50 | # IDE 51 | .idea 52 | .vscode 53 | debug 54 | debug.test 55 | __debug_bin 56 | 57 | # CI 58 | version.txt 59 | coverage.txt 60 | 61 | testdbs/ 62 | coverage.tmp 63 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Karlsend 2 | 3 | Any contribution to Karlsend is very welcome. 4 | 5 | ## Getting started 6 | 7 | If you want to start contributing to Karlsend and don't know where to 8 | start, you can pick an issue from the [list](https://github.com/karlsen-network/karlsend/issues). 9 | 10 | If you want to make a big change it's better to discuss it first by 11 | opening an issue or talk about it in development [Discord](https://discord.gg/FmNHC2aESv) 12 | to avoid duplicate work. 13 | 14 | ## Pull Request process 15 | 16 | Any pull request should be opened against the development branch 17 | `dev`. 18 | 19 | All pull requests should pass the checks written in 20 | `build_and_test.sh`, so it's recommended to run this script before 21 | submitting your PR. 22 | -------------------------------------------------------------------------------- /app/appmessage/base_message.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | import "time" 4 | 5 | type baseMessage struct { 6 | messageNumber uint64 7 | receivedAt time.Time 8 | } 9 | 10 | func (b *baseMessage) MessageNumber() uint64 { 11 | return b.messageNumber 12 | } 13 | 14 | func (b *baseMessage) SetMessageNumber(messageNumber uint64) { 15 | b.messageNumber = messageNumber 16 | } 17 | 18 | func (b *baseMessage) ReceivedAt() time.Time { 19 | return b.receivedAt 20 | } 21 | 22 | func (b *baseMessage) SetReceivedAt(receivedAt time.Time) { 23 | b.receivedAt = receivedAt 24 | } 25 | -------------------------------------------------------------------------------- /app/appmessage/common.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | import ( 8 | "github.com/pkg/errors" 9 | ) 10 | 11 | // MaxInvPerMsg is the maximum number of inventory vectors that can be in any type of karlsen inv message. 12 | const MaxInvPerMsg = 1 << 17 13 | 14 | // errNonCanonicalVarInt is the common format string used for non-canonically 15 | // encoded variable length integer errors. 16 | var errNonCanonicalVarInt = "non-canonical varint %x - discriminant %x must " + 17 | "encode a value greater than %x" 18 | 19 | // errNoEncodingForType signifies that there's no encoding for the given type. 20 | var errNoEncodingForType = errors.New("there's no encoding for this type") 21 | -------------------------------------------------------------------------------- /app/appmessage/p2p_blockheaders.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // BlockHeadersMessage represents a karlsen BlockHeaders message 4 | type BlockHeadersMessage struct { 5 | baseMessage 6 | BlockHeaders []*MsgBlockHeader 7 | } 8 | 9 | // Command returns the protocol command string for the message 10 | func (msg *BlockHeadersMessage) Command() MessageCommand { 11 | return CmdBlockHeaders 12 | } 13 | 14 | // NewBlockHeadersMessage returns a new karlsen BlockHeaders message 15 | func NewBlockHeadersMessage(blockHeaders []*MsgBlockHeader) *BlockHeadersMessage { 16 | return &BlockHeadersMessage{ 17 | BlockHeaders: blockHeaders, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgblockwithtrusteddatav4.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgBlockWithTrustedDataV4 represents a karlsen BlockWithTrustedDataV4 message 4 | type MsgBlockWithTrustedDataV4 struct { 5 | baseMessage 6 | 7 | Block *MsgBlock 8 | DAAWindowIndices []uint64 9 | GHOSTDAGDataIndices []uint64 10 | } 11 | 12 | // Command returns the protocol command string for the message 13 | func (msg *MsgBlockWithTrustedDataV4) Command() MessageCommand { 14 | return CmdBlockWithTrustedDataV4 15 | } 16 | 17 | // NewMsgBlockWithTrustedDataV4 returns a new MsgBlockWithTrustedDataV4. 18 | func NewMsgBlockWithTrustedDataV4() *MsgBlockWithTrustedDataV4 { 19 | return &MsgBlockWithTrustedDataV4{} 20 | } 21 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgdoneblockswithmetadata.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgDoneBlocksWithTrustedData implements the Message interface and represents a karlsen 4 | // DoneBlocksWithTrustedData message 5 | // 6 | // This message has no payload. 7 | type MsgDoneBlocksWithTrustedData struct { 8 | baseMessage 9 | } 10 | 11 | // Command returns the protocol command string for the message. This is part 12 | // of the Message interface implementation. 13 | func (msg *MsgDoneBlocksWithTrustedData) Command() MessageCommand { 14 | return CmdDoneBlocksWithTrustedData 15 | } 16 | 17 | // NewMsgDoneBlocksWithTrustedData returns a new karlsen DoneBlocksWithTrustedData message that conforms to the 18 | // Message interface. 19 | func NewMsgDoneBlocksWithTrustedData() *MsgDoneBlocksWithTrustedData { 20 | return &MsgDoneBlocksWithTrustedData{} 21 | } 22 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgdoneheaders.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgDoneHeaders implements the Message interface and represents a karlsen 4 | // DoneHeaders message. It is used to notify the IBD syncing peer that the 5 | // syncer sent all the requested headers. 6 | // 7 | // This message has no payload. 8 | type MsgDoneHeaders struct { 9 | baseMessage 10 | } 11 | 12 | // Command returns the protocol command string for the message. This is part 13 | // of the Message interface implementation. 14 | func (msg *MsgDoneHeaders) Command() MessageCommand { 15 | return CmdDoneHeaders 16 | } 17 | 18 | // NewMsgDoneHeaders returns a new karlsen DoneIBDBlocks message that conforms to the 19 | // Message interface. 20 | func NewMsgDoneHeaders() *MsgDoneHeaders { 21 | return &MsgDoneHeaders{} 22 | } 23 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgdonepruningpointutxosetchunks.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgDonePruningPointUTXOSetChunks represents a karlsen DonePruningPointUTXOSetChunks message 4 | type MsgDonePruningPointUTXOSetChunks struct { 5 | baseMessage 6 | } 7 | 8 | // Command returns the protocol command string for the message 9 | func (msg *MsgDonePruningPointUTXOSetChunks) Command() MessageCommand { 10 | return CmdDonePruningPointUTXOSetChunks 11 | } 12 | 13 | // NewMsgDonePruningPointUTXOSetChunks returns a new MsgDonePruningPointUTXOSetChunks. 14 | func NewMsgDonePruningPointUTXOSetChunks() *MsgDonePruningPointUTXOSetChunks { 15 | return &MsgDonePruningPointUTXOSetChunks{} 16 | } 17 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgdrequestpruningpointanditsanticoneheaders.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgRequestPruningPointAndItsAnticone represents a karlsen RequestPruningPointAndItsAnticone message 4 | type MsgRequestPruningPointAndItsAnticone struct { 5 | baseMessage 6 | } 7 | 8 | // Command returns the protocol command string for the message 9 | func (msg *MsgRequestPruningPointAndItsAnticone) Command() MessageCommand { 10 | return CmdRequestPruningPointAndItsAnticone 11 | } 12 | 13 | // NewMsgRequestPruningPointAndItsAnticone returns a new MsgRequestPruningPointAndItsAnticone. 14 | func NewMsgRequestPruningPointAndItsAnticone() *MsgRequestPruningPointAndItsAnticone { 15 | return &MsgRequestPruningPointAndItsAnticone{} 16 | } 17 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgibdblocklocator.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // MsgIBDBlockLocator represents a karlsen ibdBlockLocator message 8 | type MsgIBDBlockLocator struct { 9 | baseMessage 10 | TargetHash *externalapi.DomainHash 11 | BlockLocatorHashes []*externalapi.DomainHash 12 | } 13 | 14 | // Command returns the protocol command string for the message 15 | func (msg *MsgIBDBlockLocator) Command() MessageCommand { 16 | return CmdIBDBlockLocator 17 | } 18 | 19 | // NewMsgIBDBlockLocator returns a new karlsen ibdBlockLocator message 20 | func NewMsgIBDBlockLocator(targetHash *externalapi.DomainHash, 21 | blockLocatorHashes []*externalapi.DomainHash) *MsgIBDBlockLocator { 22 | 23 | return &MsgIBDBlockLocator{ 24 | TargetHash: targetHash, 25 | BlockLocatorHashes: blockLocatorHashes, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgibdblocklocatorhighesthash.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // MsgIBDBlockLocatorHighestHash represents a karlsen BlockLocatorHighestHash message 8 | type MsgIBDBlockLocatorHighestHash struct { 9 | baseMessage 10 | HighestHash *externalapi.DomainHash 11 | } 12 | 13 | // Command returns the protocol command string for the message 14 | func (msg *MsgIBDBlockLocatorHighestHash) Command() MessageCommand { 15 | return CmdIBDBlockLocatorHighestHash 16 | } 17 | 18 | // NewMsgIBDBlockLocatorHighestHash returns a new BlockLocatorHighestHash message 19 | func NewMsgIBDBlockLocatorHighestHash(highestHash *externalapi.DomainHash) *MsgIBDBlockLocatorHighestHash { 20 | return &MsgIBDBlockLocatorHighestHash{ 21 | HighestHash: highestHash, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgibdblocklocatorhighesthashnotfound.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgIBDBlockLocatorHighestHashNotFound represents a karlsen BlockLocatorHighestHashNotFound message 4 | type MsgIBDBlockLocatorHighestHashNotFound struct { 5 | baseMessage 6 | } 7 | 8 | // Command returns the protocol command string for the message 9 | func (msg *MsgIBDBlockLocatorHighestHashNotFound) Command() MessageCommand { 10 | return CmdIBDBlockLocatorHighestHashNotFound 11 | } 12 | 13 | // NewMsgIBDBlockLocatorHighestHashNotFound returns a new IBDBlockLocatorHighestHashNotFound message 14 | func NewMsgIBDBlockLocatorHighestHashNotFound() *MsgIBDBlockLocatorHighestHashNotFound { 15 | return &MsgIBDBlockLocatorHighestHashNotFound{} 16 | } 17 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgping_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | // TestPing tests the MsgPing API against the latest protocol version. 12 | func TestPing(t *testing.T) { 13 | // Ensure we get the same nonce back out. 14 | nonce := uint64(0x61c2c5535902862) 15 | msg := NewMsgPing(nonce) 16 | if msg.Nonce != nonce { 17 | t.Errorf("NewMsgPing: wrong nonce - got %v, want %v", 18 | msg.Nonce, nonce) 19 | } 20 | 21 | // Ensure the command is expected value. 22 | wantCmd := MessageCommand(7) 23 | if cmd := msg.Command(); cmd != wantCmd { 24 | t.Errorf("NewMsgPing: wrong command - got %v want %v", 25 | cmd, wantCmd) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgpong_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | // TestPongLatest tests the MsgPong API against the latest protocol version. 12 | func TestPongLatest(t *testing.T) { 13 | nonce := uint64(0x1a05b581a5182c) 14 | msg := NewMsgPong(nonce) 15 | if msg.Nonce != nonce { 16 | t.Errorf("NewMsgPong: wrong nonce - got %v, want %v", 17 | msg.Nonce, nonce) 18 | } 19 | 20 | // Ensure the command is expected value. 21 | wantCmd := MessageCommand(8) 22 | if cmd := msg.Command(); cmd != wantCmd { 23 | t.Errorf("NewMsgPong: wrong command - got %v want %v", 24 | cmd, wantCmd) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgpruningpointproof.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgPruningPointProof represents a karlsen PruningPointProof message 4 | type MsgPruningPointProof struct { 5 | baseMessage 6 | 7 | Headers [][]*MsgBlockHeader 8 | } 9 | 10 | // Command returns the protocol command string for the message 11 | func (msg *MsgPruningPointProof) Command() MessageCommand { 12 | return CmdPruningPointProof 13 | } 14 | 15 | // NewMsgPruningPointProof returns a new MsgPruningPointProof. 16 | func NewMsgPruningPointProof(headers [][]*MsgBlockHeader) *MsgPruningPointProof { 17 | return &MsgPruningPointProof{ 18 | Headers: headers, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgpruningpoints.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgPruningPoints represents a karlsen PruningPoints message 4 | type MsgPruningPoints struct { 5 | baseMessage 6 | 7 | Headers []*MsgBlockHeader 8 | } 9 | 10 | // Command returns the protocol command string for the message 11 | func (msg *MsgPruningPoints) Command() MessageCommand { 12 | return CmdPruningPoints 13 | } 14 | 15 | // NewMsgPruningPoints returns a new MsgPruningPoints. 16 | func NewMsgPruningPoints(headers []*MsgBlockHeader) *MsgPruningPoints { 17 | return &MsgPruningPoints{ 18 | Headers: headers, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgreject.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgReject implements the Message interface and represents a karlsen 4 | // Reject message. It is used to notify peers why they are banned. 5 | type MsgReject struct { 6 | baseMessage 7 | Reason string 8 | } 9 | 10 | // Command returns the protocol command string for the message. This is part 11 | // of the Message interface implementation. 12 | func (msg *MsgReject) Command() MessageCommand { 13 | return CmdReject 14 | } 15 | 16 | // NewMsgReject returns a new karlsen Reject message that conforms to the 17 | // Message interface. 18 | func NewMsgReject(reason string) *MsgReject { 19 | return &MsgReject{ 20 | Reason: reason, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestaddresses_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | // TestRequestAddresses tests the MsgRequestAddresses API. 12 | func TestRequestAddresses(t *testing.T) { 13 | // Ensure the command is expected value. 14 | wantCmd := MessageCommand(2) 15 | msg := NewMsgRequestAddresses(false, nil) 16 | if cmd := msg.Command(); cmd != wantCmd { 17 | t.Errorf("NewMsgRequestAddresses: wrong command - got %v want %v", 18 | cmd, wantCmd) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestblocklocator_test.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 7 | ) 8 | 9 | // TestRequestBlockLocator tests the MsgRequestBlockLocator API. 10 | func TestRequestBlockLocator(t *testing.T) { 11 | hashStr := "000000000002e7ad7b9eef9479e4aabc65cb831269cc20d2632c13684406dee0" 12 | highHash, err := externalapi.NewDomainHashFromString(hashStr) 13 | if err != nil { 14 | t.Errorf("NewHashFromStr: %v", err) 15 | } 16 | 17 | // Ensure the command is expected value. 18 | wantCmd := MessageCommand(9) 19 | msg := NewMsgRequestBlockLocator(highHash, 0) 20 | if cmd := msg.Command(); cmd != wantCmd { 21 | t.Errorf("NewMsgRequestBlockLocator: wrong command - got %v want %v", 22 | cmd, wantCmd) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestibdblocks.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // MsgRequestIBDBlocks implements the Message interface and represents a karlsen 8 | // RequestIBDBlocks message. It is used to request blocks as part of the IBD 9 | // protocol. 10 | type MsgRequestIBDBlocks struct { 11 | baseMessage 12 | Hashes []*externalapi.DomainHash 13 | } 14 | 15 | // Command returns the protocol command string for the message. This is part 16 | // of the Message interface implementation. 17 | func (msg *MsgRequestIBDBlocks) Command() MessageCommand { 18 | return CmdRequestIBDBlocks 19 | } 20 | 21 | // NewMsgRequestIBDBlocks returns a new MsgRequestIBDBlocks. 22 | func NewMsgRequestIBDBlocks(hashes []*externalapi.DomainHash) *MsgRequestIBDBlocks { 23 | return &MsgRequestIBDBlocks{ 24 | Hashes: hashes, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestnextheaders.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgRequestNextHeaders implements the Message interface and represents a karlsen 4 | // RequestNextHeaders message. It is used to notify the IBD syncer peer to send 5 | // more headers. 6 | // 7 | // This message has no payload. 8 | type MsgRequestNextHeaders struct { 9 | baseMessage 10 | } 11 | 12 | // Command returns the protocol command string for the message. This is part 13 | // of the Message interface implementation. 14 | func (msg *MsgRequestNextHeaders) Command() MessageCommand { 15 | return CmdRequestNextHeaders 16 | } 17 | 18 | // NewMsgRequestNextHeaders returns a new karlsen RequestNextHeaders message that conforms to the 19 | // Message interface. 20 | func NewMsgRequestNextHeaders() *MsgRequestNextHeaders { 21 | return &MsgRequestNextHeaders{} 22 | } 23 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestnextpruningpointutxosetchunk.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgRequestNextPruningPointUTXOSetChunk represents a karlsen RequestNextPruningPointUTXOSetChunk message 4 | type MsgRequestNextPruningPointUTXOSetChunk struct { 5 | baseMessage 6 | } 7 | 8 | // Command returns the protocol command string for the message 9 | func (msg *MsgRequestNextPruningPointUTXOSetChunk) Command() MessageCommand { 10 | return CmdRequestNextPruningPointUTXOSetChunk 11 | } 12 | 13 | // NewMsgRequestNextPruningPointUTXOSetChunk returns a new MsgRequestNextPruningPointUTXOSetChunk. 14 | func NewMsgRequestNextPruningPointUTXOSetChunk() *MsgRequestNextPruningPointUTXOSetChunk { 15 | return &MsgRequestNextPruningPointUTXOSetChunk{} 16 | } 17 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestpruningpointproof.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgRequestPruningPointProof represents a karlsen RequestPruningPointProof message 4 | type MsgRequestPruningPointProof struct { 5 | baseMessage 6 | } 7 | 8 | // Command returns the protocol command string for the message 9 | func (msg *MsgRequestPruningPointProof) Command() MessageCommand { 10 | return CmdRequestPruningPointProof 11 | } 12 | 13 | // NewMsgRequestPruningPointProof returns a new MsgRequestPruningPointProof. 14 | func NewMsgRequestPruningPointProof() *MsgRequestPruningPointProof { 15 | return &MsgRequestPruningPointProof{} 16 | } 17 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgrequestpruningpointutxosetandblock.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // MsgRequestPruningPointUTXOSet represents a karlsen RequestPruningPointUTXOSet message 8 | type MsgRequestPruningPointUTXOSet struct { 9 | baseMessage 10 | PruningPointHash *externalapi.DomainHash 11 | } 12 | 13 | // Command returns the protocol command string for the message 14 | func (msg *MsgRequestPruningPointUTXOSet) Command() MessageCommand { 15 | return CmdRequestPruningPointUTXOSet 16 | } 17 | 18 | // NewMsgRequestPruningPointUTXOSet returns a new MsgRequestPruningPointUTXOSet 19 | func NewMsgRequestPruningPointUTXOSet(pruningPointHash *externalapi.DomainHash) *MsgRequestPruningPointUTXOSet { 20 | return &MsgRequestPruningPointUTXOSet{ 21 | PruningPointHash: pruningPointHash, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgtrusteddata.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgTrustedData represents a karlsen TrustedData message 4 | type MsgTrustedData struct { 5 | baseMessage 6 | 7 | DAAWindow []*TrustedDataDAAHeader 8 | GHOSTDAGData []*BlockGHOSTDAGDataHashPair 9 | } 10 | 11 | // Command returns the protocol command string for the message 12 | func (msg *MsgTrustedData) Command() MessageCommand { 13 | return CmdTrustedData 14 | } 15 | 16 | // NewMsgTrustedData returns a new MsgTrustedData. 17 | func NewMsgTrustedData() *MsgTrustedData { 18 | return &MsgTrustedData{} 19 | } 20 | 21 | // TrustedDataDAAHeader is an appmessage representation of externalapi.TrustedDataDataDAAHeader 22 | type TrustedDataDAAHeader struct { 23 | Header *MsgBlockHeader 24 | GHOSTDAGData *BlockGHOSTDAGData 25 | } 26 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgverack.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | // MsgVerAck defines a karlsen verack message which is used for a peer to 8 | // acknowledge a version message (MsgVersion) after it has used the information 9 | // to negotiate parameters. It implements the Message interface. 10 | // 11 | // This message has no payload. 12 | type MsgVerAck struct { 13 | baseMessage 14 | } 15 | 16 | // Command returns the protocol command string for the message. This is part 17 | // of the Message interface implementation. 18 | func (msg *MsgVerAck) Command() MessageCommand { 19 | return CmdVerAck 20 | } 21 | 22 | // NewMsgVerAck returns a new karlsen verack message that conforms to the 23 | // Message interface. 24 | func NewMsgVerAck() *MsgVerAck { 25 | return &MsgVerAck{} 26 | } 27 | -------------------------------------------------------------------------------- /app/appmessage/p2p_msgverack_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | // TestVerAck tests the MsgVerAck API. 12 | func TestVerAck(t *testing.T) { 13 | // Ensure the command is expected value. 14 | wantCmd := MessageCommand(1) 15 | msg := NewMsgVerAck() 16 | if cmd := msg.Command(); cmd != wantCmd { 17 | t.Errorf("NewMsgVerAck: wrong command - got %v want %v", 18 | cmd, wantCmd) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/appmessage/p2p_netaddress_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package appmessage 6 | 7 | import ( 8 | "net" 9 | "testing" 10 | ) 11 | 12 | // TestNetAddress tests the NetAddress API. 13 | func TestNetAddress(t *testing.T) { 14 | ip := net.ParseIP("127.0.0.1") 15 | port := 42111 16 | 17 | // Test NewNetAddress. 18 | na := NewNetAddress(&net.TCPAddr{IP: ip, Port: port}) 19 | 20 | // Ensure we get the same ip, port, and services back out. 21 | if !na.IP.Equal(ip) { 22 | t.Errorf("NetNetAddress: wrong ip - got %v, want %v", na.IP, ip) 23 | } 24 | if na.Port != uint16(port) { 25 | t.Errorf("NetNetAddress: wrong port - got %v, want %v", na.Port, 26 | port) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/appmessage/p2p_ready.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgReady implements the Message interface and represents a karlsen 4 | // Ready message. It is used to notify that the peer is ready to receive 5 | // messages. 6 | // 7 | // This message has no payload. 8 | type MsgReady struct { 9 | baseMessage 10 | } 11 | 12 | // Command returns the protocol command string for the message. This is part 13 | // of the Message interface implementation. 14 | func (msg *MsgReady) Command() MessageCommand { 15 | return CmdReady 16 | } 17 | 18 | // NewMsgReady returns a new karlsen Ready message that conforms to the 19 | // Message interface. 20 | func NewMsgReady() *MsgReady { 21 | return &MsgReady{} 22 | } 23 | -------------------------------------------------------------------------------- /app/appmessage/p2p_unexpectedpruningpoint.go: -------------------------------------------------------------------------------- 1 | package appmessage 2 | 3 | // MsgUnexpectedPruningPoint represents a karlsen UnexpectedPruningPoint message 4 | type MsgUnexpectedPruningPoint struct { 5 | baseMessage 6 | } 7 | 8 | // Command returns the protocol command string for the message 9 | func (msg *MsgUnexpectedPruningPoint) Command() MessageCommand { 10 | return CmdUnexpectedPruningPoint 11 | } 12 | 13 | // NewMsgUnexpectedPruningPoint returns a new karlsen UnexpectedPruningPoint message 14 | func NewMsgUnexpectedPruningPoint() *MsgUnexpectedPruningPoint { 15 | return &MsgUnexpectedPruningPoint{} 16 | } 17 | -------------------------------------------------------------------------------- /app/appmessage/testdata/megatx.bin.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/app/appmessage/testdata/megatx.bin.bz2 -------------------------------------------------------------------------------- /app/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2017 The btcsuite developers 2 | // Copyright (c) 2017 The Decred developers 3 | // Use of this source code is governed by an ISC 4 | // license that can be found in the LICENSE file. 5 | 6 | package app 7 | 8 | import ( 9 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 10 | ) 11 | 12 | var log = logger.RegisterSubSystem("KLSD") 13 | -------------------------------------------------------------------------------- /app/protocol/flowcontext/addresses.go: -------------------------------------------------------------------------------- 1 | package flowcontext 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/addressmanager" 5 | ) 6 | 7 | // AddressManager returns the address manager associated to the flow context. 8 | func (f *FlowContext) AddressManager() *addressmanager.AddressManager { 9 | return f.addressManager 10 | } 11 | -------------------------------------------------------------------------------- /app/protocol/flowcontext/config.go: -------------------------------------------------------------------------------- 1 | package flowcontext 2 | 3 | import "github.com/karlsen-network/karlsend/v2/infrastructure/config" 4 | 5 | // Config returns an instance of *config.Config associated to the flow context. 6 | func (f *FlowContext) Config() *config.Config { 7 | return f.cfg 8 | } 9 | -------------------------------------------------------------------------------- /app/protocol/flowcontext/domain.go: -------------------------------------------------------------------------------- 1 | package flowcontext 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain" 5 | ) 6 | 7 | // Domain returns the Domain object associated to the flow context. 8 | func (f *FlowContext) Domain() domain.Domain { 9 | return f.domain 10 | } 11 | -------------------------------------------------------------------------------- /app/protocol/flowcontext/log.go: -------------------------------------------------------------------------------- 1 | package flowcontext 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("PROT") 8 | -------------------------------------------------------------------------------- /app/protocol/flows/handshake/log.go: -------------------------------------------------------------------------------- 1 | package handshake 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("PROT") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /app/protocol/flows/ready/log.go: -------------------------------------------------------------------------------- 1 | package ready 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("PROT") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /app/protocol/flows/v5/blockrelay/batch_size_test.go: -------------------------------------------------------------------------------- 1 | package blockrelay 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | func TestIBDBatchSizeLessThanRouteCapacity(t *testing.T) { 10 | // The `ibdBatchSize` constant must be equal at both syncer and syncee. Therefore, we do not want 11 | // to set it to `router.DefaultMaxMessages` to avoid confusion and human errors. 12 | // However, nonetheless we must enforce that it does not exceed `router.DefaultMaxMessages` 13 | if ibdBatchSize >= router.DefaultMaxMessages { 14 | t.Fatalf("IBD batch size (%d) must be smaller than router.DefaultMaxMessages (%d)", 15 | ibdBatchSize, router.DefaultMaxMessages) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/protocol/flows/v5/blockrelay/log.go: -------------------------------------------------------------------------------- 1 | package blockrelay 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("PROT") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /app/protocol/flows/v5/testing/common_test.go: -------------------------------------------------------------------------------- 1 | package testing 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | 7 | "github.com/karlsen-network/karlsend/v2/app/protocol/protocolerrors" 8 | "github.com/pkg/errors" 9 | ) 10 | 11 | func checkFlowError(t *testing.T, err error, isProtocolError bool, shouldBan bool, contains string) { 12 | pErr := protocolerrors.ProtocolError{} 13 | if errors.As(err, &pErr) != isProtocolError { 14 | t.Fatalf("Unexepcted error %+v", err) 15 | } 16 | 17 | if pErr.ShouldBan != shouldBan { 18 | t.Fatalf("Exepcted shouldBan %t but got %t", shouldBan, pErr.ShouldBan) 19 | } 20 | 21 | if !strings.Contains(err.Error(), contains) { 22 | t.Fatalf("Unexpected error. Expected error to contain '%s' but got: %+v", contains, err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/protocol/flows/v5/testing/testing.go: -------------------------------------------------------------------------------- 1 | package testing 2 | 3 | // Because of a bug in Go coverage fails if you have packages with test files only. See https://github.com/golang/go/issues/27333 4 | // So this is a dummy non-test go file in the package. 5 | -------------------------------------------------------------------------------- /app/protocol/log.go: -------------------------------------------------------------------------------- 1 | package protocol 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("PROT") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /app/protocol/peer/log.go: -------------------------------------------------------------------------------- 1 | package peer 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("PROT") 8 | -------------------------------------------------------------------------------- /app/rpc/log.go: -------------------------------------------------------------------------------- 1 | package rpc 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("RPCS") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /app/rpc/rpccontext/log.go: -------------------------------------------------------------------------------- 1 | package rpccontext 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("RPCS") 8 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/get_block_count.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleGetBlockCount handles the respectively named RPC command 10 | func HandleGetBlockCount(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | syncInfo, err := context.Domain.Consensus().GetSyncInfo() 12 | if err != nil { 13 | return nil, err 14 | } 15 | response := appmessage.NewGetBlockCountResponseMessage(syncInfo) 16 | return response, nil 17 | } 18 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/get_current_network.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleGetCurrentNetwork handles the respectively named RPC command 10 | func HandleGetCurrentNetwork(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | response := appmessage.NewGetCurrentNetworkResponseMessage(context.Config.ActiveNetParams.Net.String()) 12 | return response, nil 13 | } 14 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/get_headers.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleGetHeaders handles the respectively named RPC command 10 | func HandleGetHeaders(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) { 11 | response := &appmessage.GetHeadersResponseMessage{} 12 | response.Error = appmessage.RPCErrorf("not implemented") 13 | return response, nil 14 | } 15 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/get_selected_tip_hash.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleGetSelectedTipHash handles the respectively named RPC command 10 | func HandleGetSelectedTipHash(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | selectedTip, err := context.Domain.Consensus().GetVirtualSelectedParent() 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | response := appmessage.NewGetSelectedTipHashResponseMessage(selectedTip.String()) 17 | 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/get_subnetwork.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleGetSubnetwork handles the respectively named RPC command 10 | func HandleGetSubnetwork(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) { 11 | response := &appmessage.GetSubnetworkResponseMessage{} 12 | response.Error = appmessage.RPCErrorf("not implemented") 13 | return response, nil 14 | } 15 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/get_virtual_selected_parent_blue_score.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleGetVirtualSelectedParentBlueScore handles the respectively named RPC command 10 | func HandleGetVirtualSelectedParentBlueScore(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | c := context.Domain.Consensus() 12 | selectedParent, err := c.GetVirtualSelectedParent() 13 | if err != nil { 14 | return nil, err 15 | } 16 | blockInfo, err := c.GetBlockInfo(selectedParent) 17 | if err != nil { 18 | return nil, err 19 | } 20 | return appmessage.NewGetVirtualSelectedParentBlueScoreResponseMessage(blockInfo.BlueScore), nil 21 | } 22 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/log.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("RPCS") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/notify_block_added.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleNotifyBlockAdded handles the respectively named RPC command 10 | func HandleNotifyBlockAdded(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.PropagateBlockAddedNotifications() 16 | 17 | response := appmessage.NewNotifyBlockAddedResponseMessage() 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/notify_finality_conflicts.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleNotifyFinalityConflicts handles the respectively named RPC command 10 | func HandleNotifyFinalityConflicts(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.PropagateFinalityConflictNotifications() 16 | listener.PropagateFinalityConflictResolvedNotifications() 17 | 18 | response := appmessage.NewNotifyFinalityConflictsResponseMessage() 19 | return response, nil 20 | } 21 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/notify_new_block_template.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleNotifyNewBlockTemplate handles the respectively named RPC command 10 | func HandleNotifyNewBlockTemplate(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.PropagateNewBlockTemplateNotifications() 16 | 17 | response := appmessage.NewNotifyNewBlockTemplateResponseMessage() 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/notify_pruning_point_utxo_set_overrides.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleNotifyPruningPointUTXOSetOverrideRequest handles the respectively named RPC command 10 | func HandleNotifyPruningPointUTXOSetOverrideRequest(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.PropagatePruningPointUTXOSetOverrideNotifications() 16 | 17 | response := appmessage.NewNotifyPruningPointUTXOSetOverrideResponseMessage() 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/notify_virtual_daa_score_changed.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleNotifyVirtualDaaScoreChanged handles the respectively named RPC command 10 | func HandleNotifyVirtualDaaScoreChanged(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.PropagateVirtualDaaScoreChangedNotifications() 16 | 17 | response := appmessage.NewNotifyVirtualDaaScoreChangedResponseMessage() 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/notify_virtual_selected_parent_blue_score_changed.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleNotifyVirtualSelectedParentBlueScoreChanged handles the respectively named RPC command 10 | func HandleNotifyVirtualSelectedParentBlueScoreChanged(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.PropagateVirtualSelectedParentBlueScoreChangedNotifications() 16 | 17 | response := appmessage.NewNotifyVirtualSelectedParentBlueScoreChangedResponseMessage() 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /app/rpc/rpchandlers/stop_notifying_pruning_point_utxo_set_overrides.go: -------------------------------------------------------------------------------- 1 | package rpchandlers 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/karlsen-network/karlsend/v2/app/rpc/rpccontext" 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/router" 7 | ) 8 | 9 | // HandleStopNotifyingPruningPointUTXOSetOverrideRequest handles the respectively named RPC command 10 | func HandleStopNotifyingPruningPointUTXOSetOverrideRequest(context *rpccontext.Context, router *router.Router, _ appmessage.Message) (appmessage.Message, error) { 11 | listener, err := context.NotificationManager.Listener(router) 12 | if err != nil { 13 | return nil, err 14 | } 15 | listener.StopPropagatingPruningPointUTXOSetOverrideNotifications() 16 | 17 | response := appmessage.NewStopNotifyingPruningPointUTXOSetOverrideResponseMessage() 18 | return response, nil 19 | } 20 | -------------------------------------------------------------------------------- /cmd/genkeypair/README.md: -------------------------------------------------------------------------------- 1 | # genkeypair 2 | 3 | A tool for generating private-key-address pairs. 4 | 5 | Note: This tool prints unencrypted private keys and is not 6 | recommended for day to day use, and is intended mainly for tests. 7 | 8 | In order to manage your funds it's recommended to use 9 | [karlsenwallet](../karlsenwallet) 10 | -------------------------------------------------------------------------------- /cmd/genkeypair/config.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/jessevdk/go-flags" 5 | "github.com/karlsen-network/karlsend/v2/infrastructure/config" 6 | ) 7 | 8 | type configFlags struct { 9 | config.NetworkFlags 10 | } 11 | 12 | func parseConfig() (*configFlags, error) { 13 | cfg := &configFlags{} 14 | parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag) 15 | _, err := parser.Parse() 16 | if err != nil { 17 | return nil, err 18 | } 19 | 20 | err = cfg.ResolveNetwork(parser) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | return cfg, nil 26 | } 27 | -------------------------------------------------------------------------------- /cmd/genkeypair/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/libkarlsenwallet" 7 | "github.com/karlsen-network/karlsend/v2/util" 8 | ) 9 | 10 | func main() { 11 | cfg, err := parseConfig() 12 | if err != nil { 13 | panic(err) 14 | } 15 | 16 | privateKey, publicKey, err := libkarlsenwallet.CreateKeyPair(false) 17 | if err != nil { 18 | panic(err) 19 | } 20 | 21 | addr, err := util.NewAddressPublicKey(publicKey, cfg.NetParams().Prefix) 22 | if err != nil { 23 | panic(err) 24 | } 25 | 26 | fmt.Printf("Private key: %x\n", privateKey) 27 | fmt.Printf("Address: %s\n", addr) 28 | } 29 | -------------------------------------------------------------------------------- /cmd/karlsenctl/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # -- multistage docker build: stage #1: build stage 2 | FROM golang:1.19-alpine AS build 3 | 4 | RUN mkdir -p /go/src/github.com/karlsen-network/karlsend/ 5 | 6 | WORKDIR /go/src/github.com/karlsen-network/karlsend/ 7 | 8 | RUN apk add --no-cache curl git openssh binutils gcc musl-dev 9 | 10 | COPY go.mod . 11 | COPY go.sum . 12 | 13 | RUN go mod download 14 | 15 | COPY . . 16 | 17 | WORKDIR /go/src/github.com/karlsen-network/karlsend/cmd/karlsenctl 18 | 19 | RUN GOOS=linux go build -a -installsuffix cgo -o karlsenctl . 20 | 21 | # --- multistage docker build: stage #2: runtime image 22 | FROM alpine 23 | WORKDIR /app 24 | 25 | RUN apk add --no-cache ca-certificates tini 26 | 27 | COPY --from=build /go/src/github.com/karlsen-network/karlsend/cmd/karlsenctl/karlsenctl /app/ 28 | 29 | USER nobody 30 | ENTRYPOINT [ "/sbin/tini", "--" ] 31 | -------------------------------------------------------------------------------- /cmd/karlsenminer/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # -- multistage docker build: stage #1: build stage 2 | FROM golang:1.19-alpine AS build 3 | 4 | RUN mkdir -p /go/src/github.com/karlsen-network/karlsend/ 5 | 6 | WORKDIR /go/src/github.com/karlsen-network/karlsend/ 7 | 8 | RUN apk add --no-cache curl git openssh binutils gcc musl-dev 9 | 10 | COPY go.mod . 11 | COPY go.sum . 12 | 13 | RUN go mod download 14 | 15 | COPY . . 16 | 17 | WORKDIR /go/src/github.com/karlsen-network/karlsend/cmd/karlsenminer 18 | RUN GOOS=linux go build -a -installsuffix cgo -o karlsenminer . 19 | 20 | # --- multistage docker build: stage #2: runtime image 21 | FROM alpine 22 | WORKDIR /app 23 | 24 | RUN apk add --no-cache ca-certificates tini 25 | 26 | COPY --from=build /go/src/github.com/karlsen-network/karlsend/cmd/karlsenminer/karlsenminer /app/ 27 | 28 | USER nobody 29 | ENTRYPOINT [ "/sbin/tini", "--" ] 30 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/common.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | ) 8 | 9 | const daemonTimeout = 2 * time.Minute 10 | 11 | func printErrorAndExit(err error) { 12 | fmt.Fprintf(os.Stderr, "%s\n", err) 13 | os.Exit(1) 14 | } 15 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/daemon/pb/generate.go: -------------------------------------------------------------------------------- 1 | //go:generate protoc --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative karlsenwalletd.proto 2 | 3 | package pb 4 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/daemon/server/common.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | type walletUTXO struct { 6 | Outpoint *externalapi.DomainOutpoint 7 | UTXOEntry externalapi.UTXOEntry 8 | address *walletAddress 9 | } 10 | 11 | type walletAddress struct { 12 | index uint32 13 | cosignerIndex uint32 14 | keyChain uint8 15 | } 16 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/daemon/server/rpc.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/karlsen-network/karlsend/v2/domain/dagconfig" 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/rpcclient" 8 | ) 9 | 10 | func connectToRPC(params *dagconfig.Params, rpcServer string, timeout uint32) (*rpcclient.RPCClient, error) { 11 | rpcAddress, err := params.NormalizeRPCServerAddress(rpcServer) 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | rpcClient, err := rpcclient.NewRPCClient(rpcAddress) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | if timeout != 0 { 22 | rpcClient.SetTimeout(time.Duration(timeout) * time.Second) 23 | } 24 | 25 | return rpcClient, err 26 | } 27 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/daemon/server/send.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/pb" 7 | ) 8 | 9 | func (s *server) Send(_ context.Context, request *pb.SendRequest) (*pb.SendResponse, error) { 10 | s.lock.Lock() 11 | defer s.lock.Unlock() 12 | 13 | unsignedTransactions, err := s.createUnsignedTransactions(request.ToAddress, request.Amount, request.IsSendAll, 14 | request.From, request.UseExistingChangeAddress) 15 | 16 | if err != nil { 17 | return nil, err 18 | } 19 | 20 | signedTransactions, err := s.signTransactions(unsignedTransactions, request.Password) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | txIDs, err := s.broadcast(signedTransactions, false) 26 | if err != nil { 27 | return nil, err 28 | } 29 | 30 | return &pb.SendResponse{TxIDs: txIDs, SignedTransactions: signedTransactions}, nil 31 | } 32 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/daemon/server/shutdown.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/pb" 7 | ) 8 | 9 | func (s *server) Shutdown(ctx context.Context, request *pb.ShutdownRequest) (*pb.ShutdownResponse, error) { 10 | s.lock.Lock() 11 | defer s.lock.Unlock() 12 | close(s.shutdown) 13 | return &pb.ShutdownResponse{}, nil 14 | } 15 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/daemon/server/version.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/pb" 7 | "github.com/karlsen-network/karlsend/v2/version" 8 | ) 9 | 10 | func (s *server) GetVersion(_ context.Context, _ *pb.GetVersionRequest) (*pb.GetVersionResponse, error) { 11 | s.lock.RLock() 12 | defer s.lock.RUnlock() 13 | 14 | return &pb.GetVersionResponse{ 15 | Version: version.Version(), 16 | }, nil 17 | } 18 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # -- multistage docker build: stage #1: build stage 2 | FROM golang:1.18-alpine AS build 3 | 4 | RUN mkdir -p /go/src/github.com/karlsen-network/karlsend/ 5 | 6 | WORKDIR /go/src/github.com/karlsen-network/karlsend/ 7 | 8 | RUN apk add --no-cache curl git openssh binutils gcc musl-dev 9 | 10 | COPY go.mod . 11 | COPY go.sum . 12 | 13 | RUN go mod download 14 | 15 | COPY . . 16 | 17 | WORKDIR /go/src/github.com/karlsen-network/karlsend/cmd/karlsenwallet 18 | RUN GOOS=linux go build -a -installsuffix cgo -o karlsenwallet . 19 | 20 | # --- multistage docker build: stage #2: runtime image 21 | FROM alpine 22 | WORKDIR /app 23 | 24 | RUN apk add --no-cache ca-certificates tini 25 | 26 | COPY --from=build /go/src/github.com/karlsen-network/karlsend/cmd/karlsenwallet/karlsenwallet /app/ 27 | 28 | USER nobody 29 | ENTRYPOINT [ "/sbin/tini", "--" ] 30 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/get_daemon_version.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/client" 8 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/pb" 9 | ) 10 | 11 | func getDaemonVersion(conf *getDaemonVersionConfig) error { 12 | daemonClient, tearDown, err := client.Connect(conf.DaemonAddress) 13 | if err != nil { 14 | return err 15 | } 16 | defer tearDown() 17 | 18 | ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout) 19 | defer cancel() 20 | response, err := daemonClient.GetVersion(ctx, &pb.GetVersionRequest{}) 21 | if err != nil { 22 | return err 23 | } 24 | fmt.Println(response.Version) 25 | 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/libkarlsenwallet/bip32/base58/base58bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package base58_test 6 | 7 | import ( 8 | "bytes" 9 | "testing" 10 | 11 | "github.com/btcsuite/btcutil/base58" 12 | ) 13 | 14 | func BenchmarkBase58Encode(b *testing.B) { 15 | b.StopTimer() 16 | data := bytes.Repeat([]byte{0xff}, 5000) 17 | b.SetBytes(int64(len(data))) 18 | b.StartTimer() 19 | 20 | for i := 0; i < b.N; i++ { 21 | base58.Encode(data) 22 | } 23 | } 24 | 25 | func BenchmarkBase58Decode(b *testing.B) { 26 | b.StopTimer() 27 | data := bytes.Repeat([]byte{0xff}, 5000) 28 | encoded := base58.Encode(data) 29 | b.SetBytes(int64(len(encoded))) 30 | b.StartTimer() 31 | 32 | for i := 0; i < b.N; i++ { 33 | base58.Decode(encoded) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/libkarlsenwallet/bip32/base58/cov_report.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script uses gocov to generate a test coverage report. 4 | # The gocov tool my be obtained with the following command: 5 | # go get github.com/axw/gocov/gocov 6 | # 7 | # It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. 8 | 9 | # Check for gocov. 10 | type gocov >/dev/null 2>&1 11 | if [ $? -ne 0 ]; then 12 | echo >&2 "This script requires the gocov tool." 13 | echo >&2 "You may obtain it with the following command:" 14 | echo >&2 "go get github.com/axw/gocov/gocov" 15 | exit 1 16 | fi 17 | gocov test | gocov report 18 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/libkarlsenwallet/keychains.go: -------------------------------------------------------------------------------- 1 | package libkarlsenwallet 2 | 3 | const ( 4 | // ExternalKeychain is the key chain that is used to create receive addresses 5 | ExternalKeychain = 0 6 | // InternalKeychain is used to create change addresses 7 | InternalKeychain = 1 8 | ) 9 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/libkarlsenwallet/serialization/protoserialization/generate.go: -------------------------------------------------------------------------------- 1 | //go:generate protoc --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative wallet.proto 2 | 3 | package protoserialization 4 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/new_address.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/client" 8 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/pb" 9 | ) 10 | 11 | func newAddress(conf *newAddressConfig) error { 12 | daemonClient, tearDown, err := client.Connect(conf.DaemonAddress) 13 | if err != nil { 14 | return err 15 | } 16 | defer tearDown() 17 | 18 | ctx, cancel := context.WithTimeout(context.Background(), daemonTimeout) 19 | defer cancel() 20 | 21 | response, err := daemonClient.NewAddress(ctx, &pb.NewAddressRequest{}) 22 | if err != nil { 23 | return err 24 | } 25 | 26 | fmt.Printf("New address:\n%s\n", response.Address) 27 | return nil 28 | } 29 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/start_daemon.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/daemon/server" 4 | 5 | func startDaemon(conf *startDaemonConfig) error { 6 | return server.Start(conf.NetParams(), conf.Listen, conf.RPCServer, conf.KeysFile, conf.Profile, conf.Timeout) 7 | } 8 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/utils/readline.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bufio" 5 | "strings" 6 | 7 | "github.com/pkg/errors" 8 | ) 9 | 10 | // ReadLine reads one line from the given reader with trimmed white space. 11 | func ReadLine(reader *bufio.Reader) (string, error) { 12 | line, err := reader.ReadBytes('\n') 13 | if err != nil { 14 | return "", errors.WithStack(err) 15 | } 16 | 17 | return strings.TrimSpace(string(line)), nil 18 | } 19 | -------------------------------------------------------------------------------- /cmd/karlsenwallet/version.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "strings" 8 | 9 | "github.com/karlsen-network/karlsend/v2/version" 10 | ) 11 | 12 | func showVersion() { 13 | appName := filepath.Base(os.Args[0]) 14 | appName = strings.TrimSuffix(appName, filepath.Ext(appName)) 15 | fmt.Println(appName, "version", version.Version()) 16 | } 17 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # -- multistage docker build: stage #1: build stage 2 | FROM golang:1.19-alpine AS build 3 | 4 | RUN mkdir -p /go/src/github.com/karlsen-network/karlsend/ 5 | 6 | WORKDIR /go/src/github.com/karlsen-network/karlsend/ 7 | 8 | RUN apk add --no-cache curl git openssh binutils gcc musl-dev 9 | 10 | COPY go.mod . 11 | COPY go.sum . 12 | 13 | 14 | # Cache karlsend dependencies 15 | RUN go mod download 16 | 17 | COPY . . 18 | 19 | RUN go build $FLAGS -o karlsend . 20 | 21 | # --- multistage docker build: stage #2: runtime image 22 | FROM alpine 23 | WORKDIR /app 24 | 25 | RUN apk add --no-cache ca-certificates tini 26 | 27 | COPY --from=build /go/src/github.com/karlsen-network/karlsend/karlsend /app/ 28 | COPY --from=build /go/src/github.com/karlsen-network/karlsend/infrastructure/config/sample-karlsend.conf /app/ 29 | 30 | USER root 31 | ENTRYPOINT [ "/sbin/tini", "--" ] 32 | -------------------------------------------------------------------------------- /docker/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PUSH=$1 3 | DOCKER_REPO=karlsennetwork/karlsend 4 | 5 | set -e 6 | 7 | tag=$(git log -n1 --format="%cs.%h") 8 | 9 | cd $(dirname $(cd $(dirname $0); pwd)) 10 | docker build --pull -t $DOCKER_REPO:$tag -f docker/Dockerfile . 11 | docker tag $DOCKER_REPO:$tag $DOCKER_REPO:latest 12 | echo Tagged $DOCKER_REPO:latest 13 | 14 | if [ "$PUSH" = "push" ]; then 15 | docker push $DOCKER_REPO:$tag 16 | docker push $DOCKER_REPO:latest 17 | fi 18 | -------------------------------------------------------------------------------- /docker/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | 5 | karlsend: 6 | container_name: karlsend 7 | image: karlsennetwork/karlsend:latest 8 | restart: unless-stopped 9 | ports: 10 | - "42110:42110/tcp" 11 | - "42111:42111/tcp" 12 | volumes: 13 | - $HOME/.karlsend:/app/data/ 14 | # use managed volumes 15 | # - karlsend:/app/data/ 16 | command: ./karlsend --utxoindex --connect=mainnet-dnsseed-1.karlsencoin.com --appdir=/app/data -------------------------------------------------------------------------------- /domain/consensus/database/binaryserialization/common.go: -------------------------------------------------------------------------------- 1 | package binaryserialization 2 | 3 | import ( 4 | "encoding/binary" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | const uint64Length = 8 9 | 10 | // SerializeUint64 serializes a uint64 11 | func SerializeUint64(value uint64) []byte { 12 | var keyBytes [uint64Length]byte 13 | binary.LittleEndian.PutUint64(keyBytes[:], value) 14 | return keyBytes[:] 15 | } 16 | 17 | // DeserializeUint64 deserializes bytes to uint64 18 | func DeserializeUint64(valueBytes []byte) (uint64, error) { 19 | if len(valueBytes) != uint64Length { 20 | return 0, errors.Errorf("the given value is %d bytes so it cannot be deserialized into uint64", 21 | len(valueBytes)) 22 | } 23 | return binary.LittleEndian.Uint64(valueBytes), nil 24 | } 25 | -------------------------------------------------------------------------------- /domain/consensus/database/errors.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/db/database" 5 | ) 6 | 7 | // ErrNotFound denotes that the requested item was not 8 | // found in the database. 9 | var ErrNotFound = database.ErrNotFound 10 | 11 | // IsNotFoundError checks whether an error is an ErrNotFound. 12 | func IsNotFoundError(err error) bool { 13 | return database.IsNotFoundError(err) 14 | } 15 | -------------------------------------------------------------------------------- /domain/consensus/database/key.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/infrastructure/db/database" 6 | ) 7 | 8 | func dbKeyToDatabaseKey(key model.DBKey) *database.Key { 9 | if key, ok := key.(dbKey); ok { 10 | return key.key 11 | } 12 | if key, ok := key.(*dbKey); ok { 13 | return key.key 14 | } 15 | return dbBucketToDatabaseBucket(key.Bucket()).Key(key.Suffix()) 16 | } 17 | 18 | type dbKey struct { 19 | key *database.Key 20 | } 21 | 22 | func (d dbKey) Bytes() []byte { 23 | return d.key.Bytes() 24 | } 25 | 26 | func (d dbKey) Bucket() model.DBBucket { 27 | return newDBBucket(d.key.Bucket()) 28 | } 29 | 30 | func (d dbKey) Suffix() []byte { 31 | return d.key.Suffix() 32 | } 33 | 34 | func newDBKey(key *database.Key) model.DBKey { 35 | return dbKey{key: key} 36 | } 37 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/README.md: -------------------------------------------------------------------------------- 1 | # Serialization 2 | 3 | 1. Download and place in your PATH: https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip 4 | 2. `go get github.com/golang/protobuf/protoc-gen-go` 5 | 3. `go get google.golang.org/grpc/cmd/protoc-gen-go-grpc` 6 | 4. In the protowire directory: `go generate .` 7 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/blockstatus.go: -------------------------------------------------------------------------------- 1 | package serialization 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // DomainBlockStatusToDbBlockStatus converts model.BlockStatus to DbBlockStatus 8 | func DomainBlockStatusToDbBlockStatus(domainBlockStatus externalapi.BlockStatus) *DbBlockStatus { 9 | return &DbBlockStatus{ 10 | Status: uint32(domainBlockStatus), 11 | } 12 | } 13 | 14 | // DbBlockStatusToDomainBlockStatus converts DbBlockStatus to model.BlockStatus 15 | func DbBlockStatusToDomainBlockStatus(dbBlockStatus *DbBlockStatus) externalapi.BlockStatus { 16 | return externalapi.BlockStatus(dbBlockStatus.Status) 17 | } 18 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/generate.go: -------------------------------------------------------------------------------- 1 | //go:generate protoc --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative dbobjects.proto 2 | 3 | package serialization 4 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/multiset.go: -------------------------------------------------------------------------------- 1 | package serialization 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/utils/multiset" 6 | ) 7 | 8 | // MultisetToDBMultiset converts Multiset to DbMultiset 9 | func MultisetToDBMultiset(multiset model.Multiset) *DbMultiset { 10 | return &DbMultiset{ 11 | Multiset: multiset.Serialize(), 12 | } 13 | } 14 | 15 | // DBMultisetToMultiset converts DbMultiset to Multiset 16 | func DBMultisetToMultiset(dbMultiset *DbMultiset) (model.Multiset, error) { 17 | return multiset.FromBytes(dbMultiset.Multiset) 18 | } 19 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/reachablity_interval.go: -------------------------------------------------------------------------------- 1 | package serialization 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | ) 6 | 7 | func reachablityIntervalToDBReachablityInterval(reachabilityInterval *model.ReachabilityInterval) *DbReachabilityInterval { 8 | return &DbReachabilityInterval{ 9 | Start: reachabilityInterval.Start, 10 | End: reachabilityInterval.End, 11 | } 12 | } 13 | 14 | func dbReachablityIntervalToReachablityInterval(dbReachabilityInterval *DbReachabilityInterval) *model.ReachabilityInterval { 15 | return &model.ReachabilityInterval{ 16 | Start: dbReachabilityInterval.Start, 17 | End: dbReachabilityInterval.End, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/subnetworkid.go: -------------------------------------------------------------------------------- 1 | package serialization 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/utils/subnetworks" 6 | ) 7 | 8 | // DbSubnetworkIDToDomainSubnetworkID converts DbSubnetworkId to DomainSubnetworkID 9 | func DbSubnetworkIDToDomainSubnetworkID(dbSubnetworkID *DbSubnetworkId) (*externalapi.DomainSubnetworkID, error) { 10 | return subnetworks.FromBytes(dbSubnetworkID.SubnetworkId) 11 | } 12 | 13 | // DomainSubnetworkIDToDbSubnetworkID converts DomainSubnetworkID to DbSubnetworkId 14 | func DomainSubnetworkIDToDbSubnetworkID(domainSubnetworkID *externalapi.DomainSubnetworkID) *DbSubnetworkId { 15 | return &DbSubnetworkId{SubnetworkId: domainSubnetworkID[:]} 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/tips.go: -------------------------------------------------------------------------------- 1 | package serialization 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // TipsToDBTips converts a slice of hashes to DbTips 8 | func TipsToDBTips(tips []*externalapi.DomainHash) *DbTips { 9 | return &DbTips{ 10 | Tips: DomainHashesToDbHashes(tips), 11 | } 12 | } 13 | 14 | // DBTipsToTips converts DbTips to a slice of hashes 15 | func DBTipsToTips(dbTips *DbTips) ([]*externalapi.DomainHash, error) { 16 | return DbHashesToDomainHashes(dbTips.Tips) 17 | } 18 | -------------------------------------------------------------------------------- /domain/consensus/database/serialization/transactionid.go: -------------------------------------------------------------------------------- 1 | package serialization 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/utils/transactionid" 6 | ) 7 | 8 | // DbTransactionIDToDomainTransactionID converts DbTransactionId to DomainTransactionID 9 | func DbTransactionIDToDomainTransactionID(dbTransactionID *DbTransactionId) (*externalapi.DomainTransactionID, error) { 10 | return transactionid.FromBytes(dbTransactionID.TransactionId) 11 | } 12 | 13 | // DomainTransactionIDToDbTransactionID converts DomainTransactionID to DbTransactionId 14 | func DomainTransactionIDToDbTransactionID(domainTransactionID *externalapi.DomainTransactionID) *DbTransactionId { 15 | return &DbTransactionId{TransactionId: domainTransactionID.ByteSlice()} 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/log.go: -------------------------------------------------------------------------------- 1 | package consensus 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("BDAG") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /domain/consensus/model/block_heap.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockHeap represents a heap of block hashes, providing a priority-queue functionality 6 | type BlockHeap interface { 7 | Push(blockHash *externalapi.DomainHash) error 8 | PushSlice(blockHash []*externalapi.DomainHash) error 9 | Pop() *externalapi.DomainHash 10 | Len() int 11 | ToSlice() []*externalapi.DomainHash 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/blockiterator.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockIterator is an iterator over blocks according to some order. 6 | type BlockIterator interface { 7 | First() bool 8 | Next() bool 9 | Get() (*externalapi.DomainHash, error) 10 | Close() error 11 | } 12 | -------------------------------------------------------------------------------- /domain/consensus/model/errors.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/pkg/errors" 4 | 5 | // ErrBlockNotInSelectedParentChain is returned from CreateHeadersSelectedChainBlockLocator if one of the parameters 6 | // passed to it are not in the headers selected parent chain 7 | var ErrBlockNotInSelectedParentChain = errors.New("Block is not in selected parent chain") 8 | 9 | // ErrReachedMaxTraversalAllowed is returned from AnticoneFromBlocks if `maxTraversalAllowed` was specified 10 | // and the traversal passed it 11 | var ErrReachedMaxTraversalAllowed = errors.New("Traversal searching for anticone passed the maxTraversalAllowed limit") 12 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/block_with_trusted_data.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // BlockWithTrustedData is a block with pre-filled data 4 | // that is not validated by the consensus. 5 | // This is used when bring the pruning point and its 6 | // anticone on a pruned-headers node. 7 | type BlockWithTrustedData struct { 8 | Block *DomainBlock 9 | DAAWindow []*TrustedDataDataDAAHeader 10 | GHOSTDAGData []*BlockGHOSTDAGDataHashPair 11 | } 12 | 13 | // TrustedDataDataDAAHeader is a block that belongs to BlockWithTrustedData.DAAWindow 14 | type TrustedDataDataDAAHeader struct { 15 | Header BlockHeader 16 | GHOSTDAGData *BlockGHOSTDAGData 17 | } 18 | 19 | // BlockGHOSTDAGDataHashPair is a pair of a block hash and its ghostdag data 20 | type BlockGHOSTDAGDataHashPair struct { 21 | Hash *DomainHash 22 | GHOSTDAGData *BlockGHOSTDAGData 23 | } 24 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/blocktemplate.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // DomainBlockTemplate contains a Block plus metadata related to its generation 4 | type DomainBlockTemplate struct { 5 | Block *DomainBlock 6 | CoinbaseData *DomainCoinbaseData 7 | CoinbaseHasRedReward bool 8 | IsNearlySynced bool 9 | } 10 | 11 | // Clone returns a clone of DomainBlockTemplate 12 | func (bt *DomainBlockTemplate) Clone() *DomainBlockTemplate { 13 | return &DomainBlockTemplate{ 14 | Block: bt.Block.Clone(), 15 | CoinbaseData: bt.CoinbaseData.Clone(), 16 | CoinbaseHasRedReward: bt.CoinbaseHasRedReward, 17 | IsNearlySynced: bt.IsNearlySynced, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/pruning_point_proof.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // PruningPointProof is the data structure holding the pruning point proof 4 | type PruningPointProof struct { 5 | Headers [][]BlockHeader 6 | } 7 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/readonlyutxoset.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // ReadOnlyUTXOSetIterator is an iterator over all entries in a 4 | // ReadOnlyUTXOSet 5 | type ReadOnlyUTXOSetIterator interface { 6 | First() bool 7 | Next() bool 8 | Get() (outpoint *DomainOutpoint, utxoEntry UTXOEntry, err error) 9 | Close() error 10 | } 11 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/sync.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // SyncInfo holds info about the current sync state of the consensus 4 | type SyncInfo struct { 5 | HeaderCount uint64 6 | BlockCount uint64 7 | } 8 | 9 | // Clone returns a clone of SyncInfo 10 | func (si *SyncInfo) Clone() *SyncInfo { 11 | return &SyncInfo{ 12 | HeaderCount: si.HeaderCount, 13 | BlockCount: si.BlockCount, 14 | } 15 | } 16 | 17 | // If this doesn't compile, it means the type definition has been changed, so it's 18 | // an indication to update Equal and Clone accordingly. 19 | var _ = SyncInfo{0, 0} 20 | 21 | // Equal returns whether si equals to other 22 | func (si *SyncInfo) Equal(other *SyncInfo) bool { 23 | if si == nil || other == nil { 24 | return si == other 25 | } 26 | 27 | if si.HeaderCount != other.HeaderCount { 28 | return false 29 | } 30 | 31 | if si.BlockCount != other.BlockCount { 32 | return false 33 | } 34 | 35 | return true 36 | } 37 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/utxoentry.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // UTXOEntry houses details about an individual transaction output in a utxo 4 | // set such as whether or not it was contained in a coinbase tx, the daa 5 | // score of the block that accepts the tx, its public key script, and how 6 | // much it pays. 7 | type UTXOEntry interface { 8 | Amount() uint64 // Utxo amount in Sompis 9 | ScriptPublicKey() *ScriptPublicKey // The public key script for the output. 10 | BlockDAAScore() uint64 // Daa score of the block accepting the tx. 11 | IsCoinbase() bool 12 | Equal(other UTXOEntry) bool 13 | } 14 | 15 | // OutpointAndUTXOEntryPair is an outpoint along with its 16 | // respective UTXO entry 17 | type OutpointAndUTXOEntryPair struct { 18 | Outpoint *DomainOutpoint 19 | UTXOEntry UTXOEntry 20 | } 21 | -------------------------------------------------------------------------------- /domain/consensus/model/externalapi/virtual.go: -------------------------------------------------------------------------------- 1 | package externalapi 2 | 3 | // VirtualInfo represents information about the virtual block needed by external components 4 | type VirtualInfo struct { 5 | ParentHashes []*DomainHash 6 | Bits uint32 7 | PastMedianTime int64 8 | BlueScore uint64 9 | DAAScore uint64 10 | } 11 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_acceptancedatastore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // AcceptanceDataStore represents a store of AcceptanceData 6 | type AcceptanceDataStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, acceptanceData externalapi.AcceptanceData) 9 | IsStaged(stagingArea *StagingArea) bool 10 | Get(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (externalapi.AcceptanceData, error) 11 | Delete(stagingArea *StagingArea, blockHash *externalapi.DomainHash) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_blockheaderstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockHeaderStore represents a store of block headers 6 | type BlockHeaderStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, blockHeader externalapi.BlockHeader) 9 | IsStaged(stagingArea *StagingArea) bool 10 | BlockHeader(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (externalapi.BlockHeader, error) 11 | HasBlockHeader(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (bool, error) 12 | BlockHeaders(dbContext DBReader, stagingArea *StagingArea, blockHashes []*externalapi.DomainHash) ([]externalapi.BlockHeader, error) 13 | Delete(stagingArea *StagingArea, blockHash *externalapi.DomainHash) 14 | Count(stagingArea *StagingArea) uint64 15 | } 16 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_blockrelationstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockRelationStore represents a store of BlockRelations 6 | type BlockRelationStore interface { 7 | Store 8 | StageBlockRelation(stagingArea *StagingArea, blockHash *externalapi.DomainHash, blockRelations *BlockRelations) 9 | IsStaged(stagingArea *StagingArea) bool 10 | BlockRelation(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (*BlockRelations, error) 11 | Has(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (bool, error) 12 | UnstageAll(stagingArea *StagingArea) 13 | } 14 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_blocks_with_trusted_data_daa_window_store.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // BlocksWithTrustedDataDAAWindowStore stores the DAA window of blocks with trusted data 8 | type BlocksWithTrustedDataDAAWindowStore interface { 9 | Store 10 | IsStaged(stagingArea *StagingArea) bool 11 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, index uint64, ghostdagData *externalapi.BlockGHOSTDAGDataHashPair) 12 | DAAWindowBlock(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash, index uint64) (*externalapi.BlockGHOSTDAGDataHashPair, error) 13 | } 14 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_blockstatusstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockStatusStore represents a store of BlockStatuses 6 | type BlockStatusStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, blockStatus externalapi.BlockStatus) 9 | IsStaged(stagingArea *StagingArea) bool 10 | Get(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (externalapi.BlockStatus, error) 11 | Exists(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (bool, error) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_daablocksstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // DAABlocksStore represents a store of ??? 6 | type DAABlocksStore interface { 7 | Store 8 | StageDAAScore(stagingArea *StagingArea, blockHash *externalapi.DomainHash, daaScore uint64) 9 | StageBlockDAAAddedBlocks(stagingArea *StagingArea, blockHash *externalapi.DomainHash, addedBlocks []*externalapi.DomainHash) 10 | IsStaged(stagingArea *StagingArea) bool 11 | DAAAddedBlocks(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) ([]*externalapi.DomainHash, error) 12 | DAAScore(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (uint64, error) 13 | Delete(stagingArea *StagingArea, blockHash *externalapi.DomainHash) 14 | } 15 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_finalitystore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // FinalityStore represents a store for finality data 8 | type FinalityStore interface { 9 | Store 10 | IsStaged(stagingArea *StagingArea) bool 11 | StageFinalityPoint(stagingArea *StagingArea, blockHash *externalapi.DomainHash, finalityPointHash *externalapi.DomainHash) 12 | FinalityPoint(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (*externalapi.DomainHash, error) 13 | } 14 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_ghostdagdatastore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // GHOSTDAGDataStore represents a store of BlockGHOSTDAGData 6 | type GHOSTDAGDataStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, blockGHOSTDAGData *externalapi.BlockGHOSTDAGData, isTrustedData bool) 9 | IsStaged(stagingArea *StagingArea) bool 10 | Get(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash, isTrustedData bool) (*externalapi.BlockGHOSTDAGData, error) 11 | UnstageAll(stagingArea *StagingArea) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_headersselectedchainstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // HeadersSelectedChainStore represents a store of the headers selected chain 6 | type HeadersSelectedChainStore interface { 7 | Store 8 | Stage(dbContext DBReader, stagingArea *StagingArea, chainChanges *externalapi.SelectedChainPath) error 9 | IsStaged(stagingArea *StagingArea) bool 10 | GetIndexByHash(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (uint64, error) 11 | GetHashByIndex(dbContext DBReader, stagingArea *StagingArea, index uint64) (*externalapi.DomainHash, error) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_headertipsstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // HeaderSelectedTipStore represents a store of the headers selected tip 6 | type HeaderSelectedTipStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, selectedTip *externalapi.DomainHash) 9 | IsStaged(stagingArea *StagingArea) bool 10 | HeadersSelectedTip(dbContext DBReader, stagingArea *StagingArea) (*externalapi.DomainHash, error) 11 | Has(dbContext DBReader, stagingArea *StagingArea) (bool, error) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_mergedepthrootstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // MergeDepthRootStore represents a store for merge depth roots 8 | type MergeDepthRootStore interface { 9 | Store 10 | IsStaged(stagingArea *StagingArea) bool 11 | StageMergeDepthRoot(stagingArea *StagingArea, blockHash *externalapi.DomainHash, root *externalapi.DomainHash) 12 | MergeDepthRoot(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (*externalapi.DomainHash, error) 13 | } 14 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_multisetstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // MultisetStore represents a store of Multisets 6 | type MultisetStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, multiset Multiset) 9 | IsStaged(stagingArea *StagingArea) bool 10 | Get(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (Multiset, error) 11 | Delete(stagingArea *StagingArea, blockHash *externalapi.DomainHash) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_utxodiffstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // UTXODiffStore represents a store of UTXODiffs 6 | type UTXODiffStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, utxoDiff externalapi.UTXODiff, utxoDiffChild *externalapi.DomainHash) 9 | IsStaged(stagingArea *StagingArea) bool 10 | UTXODiff(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (externalapi.UTXODiff, error) 11 | UTXODiffChild(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (*externalapi.DomainHash, error) 12 | HasUTXODiffChild(dbContext DBReader, stagingArea *StagingArea, blockHash *externalapi.DomainHash) (bool, error) 13 | Delete(stagingArea *StagingArea, blockHash *externalapi.DomainHash) 14 | } 15 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_datastructures_windowheapstore.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // WindowHeapSliceStore caches the slices that are needed for the heap implementation of DAGTraversalManager.BlockWindow 6 | type WindowHeapSliceStore interface { 7 | Store 8 | Stage(stagingArea *StagingArea, blockHash *externalapi.DomainHash, windowSize int, pairs []*externalapi.BlockGHOSTDAGDataHashPair) 9 | IsStaged(stagingArea *StagingArea) bool 10 | Get(stagingArea *StagingArea, blockHash *externalapi.DomainHash, windowSize int) ([]*externalapi.BlockGHOSTDAGDataHashPair, error) 11 | } 12 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_blockbuilder.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockBuilder is responsible for creating blocks from the current state 6 | type BlockBuilder interface { 7 | BuildBlock(coinbaseData *externalapi.DomainCoinbaseData, 8 | transactions []*externalapi.DomainTransaction) (block *externalapi.DomainBlock, coinbaseHasRedReward bool, err error) 9 | } 10 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_blockparentbuilder.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockParentBuilder exposes a method to build super-block parents for 6 | // a given set of direct parents 7 | type BlockParentBuilder interface { 8 | BuildParents(stagingArea *StagingArea, 9 | daaScore uint64, 10 | directParentHashes []*externalapi.DomainHash) ([]externalapi.BlockLevelParents, error) 11 | } 12 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_blockprocessor.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // BlockProcessor is responsible for processing incoming blocks 6 | type BlockProcessor interface { 7 | ValidateAndInsertBlock(block *externalapi.DomainBlock, shouldValidateAgainstUTXO bool) (*externalapi.VirtualChangeSet, externalapi.BlockStatus, error) 8 | ValidateAndInsertImportedPruningPoint(newPruningPoint *externalapi.DomainHash) error 9 | ValidateAndInsertBlockWithTrustedData(block *externalapi.BlockWithTrustedData, validateUTXO bool) (*externalapi.VirtualChangeSet, externalapi.BlockStatus, error) 10 | } 11 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_blockvalidator.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // BlockValidator exposes a set of validation classes, after which 8 | // it's possible to determine whether a block is valid 9 | type BlockValidator interface { 10 | ValidateHeaderInIsolation(stagingArea *StagingArea, blockHash *externalapi.DomainHash) error 11 | ValidateBodyInIsolation(stagingArea *StagingArea, blockHash *externalapi.DomainHash) error 12 | ValidateHeaderInContext(stagingArea *StagingArea, blockHash *externalapi.DomainHash, isBlockWithTrustedData bool) error 13 | ValidateBodyInContext(stagingArea *StagingArea, blockHash *externalapi.DomainHash, isBlockWithTrustedData bool) error 14 | ValidatePruningPointViolationAndProofOfWorkAndDifficulty(stagingArea *StagingArea, blockHash *externalapi.DomainHash, isBlockWithTrustedData bool) error 15 | } 16 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_coinbasemanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // CoinbaseManager exposes methods for handling blocks' 6 | // coinbase transactions 7 | type CoinbaseManager interface { 8 | ExpectedCoinbaseTransaction(stagingArea *StagingArea, blockHash *externalapi.DomainHash, 9 | coinbaseData *externalapi.DomainCoinbaseData) (expectedTransaction *externalapi.DomainTransaction, hasRedReward bool, err error) 10 | CalcBlockSubsidy(stagingArea *StagingArea, blockHash *externalapi.DomainHash) (uint64, error) 11 | ExtractCoinbaseDataBlueScoreAndSubsidy(coinbaseTx *externalapi.DomainTransaction) (blueScore uint64, coinbaseData *externalapi.DomainCoinbaseData, subsidy uint64, err error) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_difficultymanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // DifficultyManager provides a method to resolve the 8 | // difficulty value of a block 9 | type DifficultyManager interface { 10 | StageDAADataAndReturnRequiredDifficulty(stagingArea *StagingArea, blockHash *externalapi.DomainHash, isBlockWithTrustedData bool) (uint32, error) 11 | RequiredDifficulty(stagingArea *StagingArea, blockHash *externalapi.DomainHash) (uint32, error) 12 | EstimateNetworkHashesPerSecond(startHash *externalapi.DomainHash, windowSize int) (uint64, error) 13 | GenesisDifficulty() uint32 14 | DifficultyAdjustmentWindowSize() int 15 | } 16 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_finalitymanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // FinalityManager provides method to validate that a block does not violate finality 6 | type FinalityManager interface { 7 | VirtualFinalityPoint(stagingArea *StagingArea) (*externalapi.DomainHash, error) 8 | FinalityPoint(stagingArea *StagingArea, blockHash *externalapi.DomainHash, isBlockWithTrustedData bool) (*externalapi.DomainHash, error) 9 | } 10 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_ghostdagmanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // GHOSTDAGManager resolves and manages GHOSTDAG block data 6 | type GHOSTDAGManager interface { 7 | GHOSTDAG(stagingArea *StagingArea, blockHash *externalapi.DomainHash) error 8 | ChooseSelectedParent(stagingArea *StagingArea, blockHashes ...*externalapi.DomainHash) (*externalapi.DomainHash, error) 9 | Less(blockHashA *externalapi.DomainHash, ghostdagDataA *externalapi.BlockGHOSTDAGData, 10 | blockHashB *externalapi.DomainHash, ghostdagDataB *externalapi.BlockGHOSTDAGData) bool 11 | GetSortedMergeSet(stagingArea *StagingArea, current *externalapi.DomainHash) ([]*externalapi.DomainHash, error) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_headertipsmanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // HeadersSelectedTipManager manages the state of the headers selected tip 6 | type HeadersSelectedTipManager interface { 7 | AddHeaderTip(stagingArea *StagingArea, hash *externalapi.DomainHash) error 8 | } 9 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_mergedepthmanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // MergeDepthManager is used to validate mergeDepth for blocks 6 | type MergeDepthManager interface { 7 | CheckBoundedMergeDepth(stagingArea *StagingArea, blockHash *externalapi.DomainHash, isBlockWithTrustedData bool) error 8 | NonBoundedMergeDepthViolatingBlues(stagingArea *StagingArea, blockHash, mergeDepthRoot *externalapi.DomainHash) ([]*externalapi.DomainHash, error) 9 | VirtualMergeDepthRoot(stagingArea *StagingArea) (*externalapi.DomainHash, error) 10 | } 11 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_parentsmanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // ParentsManager lets is a wrapper above header parents that replaces empty parents with genesis when needed. 6 | type ParentsManager interface { 7 | ParentsAtLevel(blockHeader externalapi.BlockHeader, level int) externalapi.BlockLevelParents 8 | Parents(blockHeader externalapi.BlockHeader) []externalapi.BlockLevelParents 9 | } 10 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_pastmediantimemanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // PastMedianTimeManager provides a method to resolve the 6 | // past median time of a block 7 | type PastMedianTimeManager interface { 8 | PastMedianTime(stagingArea *StagingArea, blockHash *externalapi.DomainHash) (int64, error) 9 | InvalidateVirtualPastMedianTimeCache() 10 | } 11 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_pruningproofmanager.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // PruningProofManager builds, validates and applies pruning proofs. 6 | type PruningProofManager interface { 7 | BuildPruningPointProof(stagingArea *StagingArea) (*externalapi.PruningPointProof, error) 8 | ValidatePruningPointProof(pruningPointProof *externalapi.PruningPointProof) error 9 | ApplyPruningPointProof(pruningPointProof *externalapi.PruningPointProof) error 10 | } 11 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_reachabilitytree.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // ReachabilityManager maintains a structure that allows to answer 6 | // reachability queries in sub-linear time 7 | type ReachabilityManager interface { 8 | Init(stagingArea *StagingArea) error 9 | AddBlock(stagingArea *StagingArea, blockHash *externalapi.DomainHash) error 10 | IsReachabilityTreeAncestorOf(stagingArea *StagingArea, blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) 11 | IsDAGAncestorOf(stagingArea *StagingArea, blockHashA *externalapi.DomainHash, blockHashB *externalapi.DomainHash) (bool, error) 12 | UpdateReindexRoot(stagingArea *StagingArea, selectedTip *externalapi.DomainHash) error 13 | FindNextAncestor(stagingArea *StagingArea, descendant, ancestor *externalapi.DomainHash) (*externalapi.DomainHash, error) 14 | } 15 | -------------------------------------------------------------------------------- /domain/consensus/model/interface_processes_transactionvalidator.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // TransactionValidator exposes a set of validation classes, after which 8 | // it's possible to determine whether a transaction is valid 9 | type TransactionValidator interface { 10 | ValidateTransactionInIsolation(transaction *externalapi.DomainTransaction, povDAAScore uint64) error 11 | ValidateTransactionInContextIgnoringUTXO(stagingArea *StagingArea, tx *externalapi.DomainTransaction, 12 | povBlockHash *externalapi.DomainHash, povBlockPastMedianTime int64) error 13 | ValidateTransactionInContextAndPopulateFee(stagingArea *StagingArea, 14 | tx *externalapi.DomainTransaction, povBlockHash *externalapi.DomainHash) error 15 | PopulateMass(transaction *externalapi.DomainTransaction) 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/model/multiset.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // Multiset represents a secp256k1 multiset 6 | type Multiset interface { 7 | Add(data []byte) 8 | Remove(data []byte) 9 | Hash() *externalapi.DomainHash 10 | Serialize() []byte 11 | Clone() Multiset 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/model/store.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | // Store is a common interface for data stores 4 | type Store interface { 5 | } 6 | -------------------------------------------------------------------------------- /domain/consensus/model/subdag.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // SubDAG represents a context-free representation of a partial DAG 6 | type SubDAG struct { 7 | RootHashes []*externalapi.DomainHash 8 | TipHashes []*externalapi.DomainHash 9 | Blocks map[externalapi.DomainHash]*SubDAGBlock 10 | } 11 | 12 | // SubDAGBlock represents a block in a SubDAG 13 | type SubDAGBlock struct { 14 | BlockHash *externalapi.DomainHash 15 | ParentHashes []*externalapi.DomainHash 16 | ChildHashes []*externalapi.DomainHash 17 | } 18 | -------------------------------------------------------------------------------- /domain/consensus/model/testapi/test_consensus_state_manager.go: -------------------------------------------------------------------------------- 1 | package testapi 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 6 | ) 7 | 8 | // TestConsensusStateManager adds to the main ConsensusStateManager methods required by tests 9 | type TestConsensusStateManager interface { 10 | model.ConsensusStateManager 11 | AddUTXOToMultiset(multiset model.Multiset, entry externalapi.UTXOEntry, 12 | outpoint *externalapi.DomainOutpoint) error 13 | ResolveBlockStatus(stagingArea *model.StagingArea, blockHash *externalapi.DomainHash, 14 | useSeparateStagingAreaPerBlock bool) (externalapi.BlockStatus, error) 15 | } 16 | -------------------------------------------------------------------------------- /domain/consensus/model/testapi/test_reachability_manager.go: -------------------------------------------------------------------------------- 1 | package testapi 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 6 | ) 7 | 8 | // TestReachabilityManager adds to the main ReachabilityManager methods required by tests 9 | type TestReachabilityManager interface { 10 | model.ReachabilityManager 11 | SetReachabilityReindexWindow(reindexWindow uint64) 12 | SetReachabilityReindexSlack(reindexSlack uint64) 13 | ReachabilityReindexSlack() uint64 14 | ValidateIntervals(root *externalapi.DomainHash) error 15 | GetAllNodes(root *externalapi.DomainHash) ([]*externalapi.DomainHash, error) 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/model/testapi/test_transaction_validator.go: -------------------------------------------------------------------------------- 1 | package testapi 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/utils/txscript" 6 | ) 7 | 8 | // TestTransactionValidator adds to the main TransactionValidator methods required by tests 9 | type TestTransactionValidator interface { 10 | model.TransactionValidator 11 | SigCache() *txscript.SigCache 12 | SetSigCache(sigCache *txscript.SigCache) 13 | } 14 | -------------------------------------------------------------------------------- /domain/consensus/model/utxo_diff_reversal_data.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // UTXODiffReversalData is used by ConsensusStateManager to reverse the UTXODiffs during a re-org 6 | type UTXODiffReversalData struct { 7 | SelectedParentHash *externalapi.DomainHash 8 | SelectedParentUTXODiff externalapi.UTXODiff 9 | } 10 | -------------------------------------------------------------------------------- /domain/consensus/model/virtual.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // VirtualBlockHash is a marker hash for the virtual block 6 | var VirtualBlockHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{ 7 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 8 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 9 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 10 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 11 | }) 12 | 13 | // VirtualGenesisBlockHash is a marker hash for the virtual genesis block 14 | var VirtualGenesisBlockHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{ 15 | 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 16 | 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 17 | 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 18 | 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 19 | }) 20 | -------------------------------------------------------------------------------- /domain/consensus/processes/blockbuilder/log.go: -------------------------------------------------------------------------------- 1 | package blockbuilder 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("BDAG") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/blockprocessor/blocklogger/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package blocklogger 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("BDAG") 12 | -------------------------------------------------------------------------------- /domain/consensus/processes/blockprocessor/log.go: -------------------------------------------------------------------------------- 1 | package blockprocessor 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("BDAG") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/blockvalidator/log.go: -------------------------------------------------------------------------------- 1 | package blockvalidator 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("BLVA") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/consensusstatemanager/log.go: -------------------------------------------------------------------------------- 1 | package consensusstatemanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("BDAG") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/consensusstatemanager/utxo_diffs.go: -------------------------------------------------------------------------------- 1 | package consensusstatemanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 6 | ) 7 | 8 | func (csm *consensusStateManager) stageDiff(stagingArea *model.StagingArea, blockHash *externalapi.DomainHash, 9 | utxoDiff externalapi.UTXODiff, utxoDiffChild *externalapi.DomainHash) { 10 | 11 | log.Tracef("stageDiff start for block %s", blockHash) 12 | defer log.Tracef("stageDiff end for block %s", blockHash) 13 | 14 | log.Debugf("Staging block %s as the diff child of %s", utxoDiffChild, blockHash) 15 | csm.utxoDiffStore.Stage(stagingArea, blockHash, utxoDiff, utxoDiffChild) 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/processes/difficultymanager/log.go: -------------------------------------------------------------------------------- 1 | package difficultymanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("DAA") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/finalitymanager/log.go: -------------------------------------------------------------------------------- 1 | package finalitymanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("BDAG") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/mergedepthmanager/log.go: -------------------------------------------------------------------------------- 1 | package mergedepthmanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("MDMN") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/pruningmanager/log.go: -------------------------------------------------------------------------------- 1 | package pruningmanager 2 | 3 | import "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 4 | 5 | var log = logger.RegisterSubSystem("PRNM") 6 | -------------------------------------------------------------------------------- /domain/consensus/processes/pruningproofmanager/log.go: -------------------------------------------------------------------------------- 1 | package pruningproofmanager 2 | 3 | import "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 4 | 5 | var log = logger.RegisterSubSystem("PPMN") 6 | -------------------------------------------------------------------------------- /domain/consensus/processes/reachabilitymanager/log.go: -------------------------------------------------------------------------------- 1 | package reachabilitymanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("REAC") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/reachabilitymanager/main_test.go: -------------------------------------------------------------------------------- 1 | package reachabilitymanager_test 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | ) 9 | 10 | const logLevel = logger.LevelWarn 11 | 12 | func TestMain(m *testing.M) { 13 | logger.SetLogLevels(logLevel) 14 | logger.InitLogStdout(logLevel) 15 | os.Exit(m.Run()) 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/processes/syncmanager/log.go: -------------------------------------------------------------------------------- 1 | package syncmanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("SYNC") 8 | -------------------------------------------------------------------------------- /domain/consensus/processes/syncmanager/syncinfo.go: -------------------------------------------------------------------------------- 1 | package syncmanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 6 | ) 7 | 8 | func (sm *syncManager) syncInfo(stagingArea *model.StagingArea) (*externalapi.SyncInfo, error) { 9 | headerCount := sm.getHeaderCount(stagingArea) 10 | blockCount := sm.getBlockCount(stagingArea) 11 | 12 | return &externalapi.SyncInfo{ 13 | HeaderCount: headerCount, 14 | BlockCount: blockCount, 15 | }, nil 16 | } 17 | 18 | func (sm *syncManager) getHeaderCount(stagingArea *model.StagingArea) uint64 { 19 | return sm.blockHeaderStore.Count(stagingArea) 20 | } 21 | 22 | func (sm *syncManager) getBlockCount(stagingArea *model.StagingArea) uint64 { 23 | return sm.blockStore.Count(stagingArea) 24 | } 25 | -------------------------------------------------------------------------------- /domain/consensus/processes/transactionvalidator/mass.go: -------------------------------------------------------------------------------- 1 | package transactionvalidator 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // PopulateMass calculates and populates the mass of the given transaction 8 | func (v *transactionValidator) PopulateMass(transaction *externalapi.DomainTransaction) { 9 | if transaction.Mass != 0 { 10 | return 11 | } 12 | transaction.Mass = v.txMassCalculator.CalculateTransactionMass(transaction) 13 | } 14 | -------------------------------------------------------------------------------- /domain/consensus/testdata/reachability/attack-dag-blocks--2^12-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/domain/consensus/testdata/reachability/attack-dag-blocks--2^12-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /domain/consensus/testdata/reachability/attack-dag-blocks--2^13-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/domain/consensus/testdata/reachability/attack-dag-blocks--2^13-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /domain/consensus/testdata/reachability/attack-dag-blocks--2^14-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/domain/consensus/testdata/reachability/attack-dag-blocks--2^14-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /domain/consensus/testdata/reachability/noattack-dag-blocks--2^12-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/domain/consensus/testdata/reachability/noattack-dag-blocks--2^12-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /domain/consensus/testdata/reachability/noattack-dag-blocks--2^13-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/domain/consensus/testdata/reachability/noattack-dag-blocks--2^13-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /domain/consensus/testdata/reachability/noattack-dag-blocks--2^14-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/domain/consensus/testdata/reachability/noattack-dag-blocks--2^14-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /domain/consensus/utils/hashes/strings.go: -------------------------------------------------------------------------------- 1 | package hashes 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // ToStrings converts a slice of hashes into a slice of the corresponding strings 8 | func ToStrings(hashes []*externalapi.DomainHash) []string { 9 | strings := make([]string, len(hashes)) 10 | for i, hash := range hashes { 11 | strings[i] = hash.String() 12 | } 13 | return strings 14 | } 15 | -------------------------------------------------------------------------------- /domain/consensus/utils/mining/solve.go: -------------------------------------------------------------------------------- 1 | package mining 2 | 3 | import ( 4 | "math" 5 | "math/rand" 6 | 7 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 8 | "github.com/karlsen-network/karlsend/v2/domain/consensus/utils/pow" 9 | "github.com/pkg/errors" 10 | ) 11 | 12 | // SolveBlock increments the given block's nonce until it matches the difficulty requirements in its bits field 13 | func SolveBlock(block *externalapi.DomainBlock, rd *rand.Rand) { 14 | header := block.Header.ToMutable() 15 | state := pow.NewState(header, false) 16 | for state.Nonce = rd.Uint64(); state.Nonce < math.MaxUint64; state.Nonce++ { 17 | if state.CheckProofOfWork() { 18 | header.SetNonce(state.Nonce) 19 | block.Header = header.ToImmutable() 20 | return 21 | } 22 | } 23 | 24 | panic(errors.New("went over all the nonce space and couldn't find a single one that gives a valid block")) 25 | } 26 | -------------------------------------------------------------------------------- /domain/consensus/utils/pow/log.go: -------------------------------------------------------------------------------- 1 | package pow 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("POWK") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /domain/consensus/utils/pow/xoshiro_test.go: -------------------------------------------------------------------------------- 1 | package pow 2 | 3 | import "testing" 4 | 5 | // Test vectors are from here: https://github.com/rust-random/rngs/blob/17aa826cc38d3e8408c9489ac859fa9397acd479/rand_xoshiro/src/xoshiro256plusplus.rs#L121 6 | func TestXoShiRo256PlusPlus_Uint64(t *testing.T) { 7 | state := xoShiRo256PlusPlus{1, 2, 3, 4} 8 | expected := []uint64{41943041, 58720359, 3588806011781223, 3591011842654386, 9 | 9228616714210784205, 9973669472204895162, 14011001112246962877, 10 | 12406186145184390807, 15849039046786891736, 10450023813501588000} 11 | for _, ex := range expected { 12 | val := state.Uint64() 13 | if val != ex { 14 | t.Errorf("expected: %d, found: %d", ex, val) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /domain/consensus/utils/subnetworks/compare.go: -------------------------------------------------------------------------------- 1 | package subnetworks 2 | 3 | import ( 4 | "bytes" 5 | 6 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 7 | ) 8 | 9 | // Less returns true iff id a is less than id b 10 | func Less(a, b externalapi.DomainSubnetworkID) bool { 11 | return bytes.Compare(a[:], b[:]) < 0 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensus/utils/subnetworks/from_bytes.go: -------------------------------------------------------------------------------- 1 | package subnetworks 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | // FromBytes creates a DomainSubnetworkID from the given byte slice 9 | func FromBytes(subnetworkIDBytes []byte) (*externalapi.DomainSubnetworkID, error) { 10 | if len(subnetworkIDBytes) != externalapi.DomainSubnetworkIDSize { 11 | return nil, errors.Errorf("invalid hash size. Want: %d, got: %d", 12 | externalapi.DomainSubnetworkIDSize, len(subnetworkIDBytes)) 13 | } 14 | var domainSubnetworkID externalapi.DomainSubnetworkID 15 | copy(domainSubnetworkID[:], subnetworkIDBytes) 16 | return &domainSubnetworkID, nil 17 | } 18 | -------------------------------------------------------------------------------- /domain/consensus/utils/subnetworks/from_string.go: -------------------------------------------------------------------------------- 1 | package subnetworks 2 | 3 | import ( 4 | "encoding/hex" 5 | 6 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 7 | ) 8 | 9 | // FromString creates a DomainSubnetworkID from the given byte slice 10 | func FromString(str string) (*externalapi.DomainSubnetworkID, error) { 11 | subnetworkIDBytes, err := hex.DecodeString(str) 12 | if err != nil { 13 | return nil, err 14 | } 15 | return FromBytes(subnetworkIDBytes) 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/utils/testutils/for_all_paths.go: -------------------------------------------------------------------------------- 1 | package testutils 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/karlsen-network/karlsend/v2/cmd/karlsenwallet/keys" 8 | ) 9 | 10 | // ForAllPaths runs the passed testFunc with all available derivation paths 11 | func ForAllPaths(t *testing.T, testFunc func(*testing.T, uint32)) { 12 | for i := uint32(1); i <= keys.LastVersion; i++ { 13 | version := fmt.Sprintf("v%d", i) 14 | t.Run(version, func(t *testing.T) { 15 | t.Logf("Running test for wallet version %d", i) 16 | testFunc(t, i) 17 | }) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /domain/consensus/utils/transactionid/from_bytes.go: -------------------------------------------------------------------------------- 1 | package transactionid 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // FromBytes creates a DomainTransactionID from the given byte slice 8 | func FromBytes(transactionIDBytes []byte) (*externalapi.DomainTransactionID, error) { 9 | hash, err := externalapi.NewDomainHashFromByteSlice(transactionIDBytes) 10 | if err != nil { 11 | return nil, err 12 | } 13 | return (*externalapi.DomainTransactionID)(hash), nil 14 | } 15 | -------------------------------------------------------------------------------- /domain/consensus/utils/transactionid/from_string.go: -------------------------------------------------------------------------------- 1 | package transactionid 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // FromString creates a new DomainTransactionID from the given string 8 | func FromString(str string) (*externalapi.DomainTransactionID, error) { 9 | hash, err := externalapi.NewDomainHashFromString(str) 10 | return (*externalapi.DomainTransactionID)(hash), err 11 | } 12 | -------------------------------------------------------------------------------- /domain/consensus/utils/txscript/data/LICENSE: -------------------------------------------------------------------------------- 1 | The json files in this directory originate from the bitcoind project 2 | (https://github.com/bitcoin/bitcoin) and is released under the following 3 | license: 4 | 5 | Copyright (c) 2012-2014 The Bitcoin Core developers 6 | Distributed under the MIT/X11 software license, see the accompanying 7 | file COPYING or http://www.opensource.org/licenses/mit-license.php. 8 | 9 | -------------------------------------------------------------------------------- /domain/consensus/utils/txscript/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2015 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package txscript 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("SCRP") 12 | -------------------------------------------------------------------------------- /domain/consensus/utils/txscript/main_test.go: -------------------------------------------------------------------------------- 1 | package txscript 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | ) 9 | 10 | func TestMain(m *testing.M) { 11 | // set log level to trace, so that logClosures passed to log.Tracef are covered 12 | log.SetLevel(logger.LevelTrace) 13 | logger.InitLogStdout(logger.LevelTrace) 14 | 15 | os.Exit(m.Run()) 16 | } 17 | -------------------------------------------------------------------------------- /domain/consensus/utils/virtual/virtual.go: -------------------------------------------------------------------------------- 1 | package virtual 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 6 | ) 7 | 8 | // ContainsOnlyVirtualGenesis returns whether the given block hashes contain only the virtual 9 | // genesis hash. 10 | func ContainsOnlyVirtualGenesis(blockHashes []*externalapi.DomainHash) bool { 11 | return len(blockHashes) == 1 && blockHashes[0].Equal(model.VirtualGenesisBlockHash) 12 | } 13 | -------------------------------------------------------------------------------- /domain/consensusreference/consensusreference.go: -------------------------------------------------------------------------------- 1 | package consensusreference 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // ConsensusReference holds a reference to a consensus object. 6 | // The consensus object may be swapped with a new one entirely 7 | // during the IBD process. Before an atomic consensus operation, 8 | // callers are expected to call Consensus() once and work against 9 | // that instance throughout. 10 | type ConsensusReference struct { 11 | consensus **externalapi.Consensus 12 | } 13 | 14 | // Consensus returns the underlying consensus 15 | func (ref ConsensusReference) Consensus() externalapi.Consensus { 16 | return **ref.consensus 17 | } 18 | 19 | // NewConsensusReference constructs a new ConsensusReference 20 | func NewConsensusReference(consensus **externalapi.Consensus) ConsensusReference { 21 | return ConsensusReference{consensus: consensus} 22 | } 23 | -------------------------------------------------------------------------------- /domain/log.go: -------------------------------------------------------------------------------- 1 | package domain 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("DOMN") 8 | -------------------------------------------------------------------------------- /domain/miningmanager/blocktemplatebuilder/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package blocktemplatebuilder 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("BLTB") 12 | -------------------------------------------------------------------------------- /domain/miningmanager/blocktemplatebuilder/policy.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package blocktemplatebuilder 6 | 7 | // policy houses the policy (configuration parameters) which is used to control 8 | // the generation of block templates. See the documentation for 9 | // NewBlockTemplate for more details on each of these parameters are used. 10 | type policy struct { 11 | // BlockMaxMass is the maximum block mass to be used when generating a 12 | // block template. 13 | BlockMaxMass uint64 14 | } 15 | -------------------------------------------------------------------------------- /domain/miningmanager/mempool/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package mempool 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("TXMP") 12 | -------------------------------------------------------------------------------- /domain/miningmanager/mempool/model/transaction.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 4 | 5 | // Transaction represents a generic transaction either in the mempool's main TransactionPool or OrphanPool 6 | type Transaction interface { 7 | TransactionID() *externalapi.DomainTransactionID 8 | Transaction() *externalapi.DomainTransaction 9 | } 10 | -------------------------------------------------------------------------------- /domain/miningmanager/model/interface_blocktemplatebuilder.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | consensusexternalapi "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // BlockTemplateBuilder builds block templates for miners to consume 8 | type BlockTemplateBuilder interface { 9 | BuildBlockTemplate(coinbaseData *consensusexternalapi.DomainCoinbaseData) (*consensusexternalapi.DomainBlockTemplate, error) 10 | ModifyBlockTemplate(newCoinbaseData *consensusexternalapi.DomainCoinbaseData, 11 | blockTemplateToModify *consensusexternalapi.DomainBlockTemplate) (*consensusexternalapi.DomainBlockTemplate, error) 12 | } 13 | -------------------------------------------------------------------------------- /domain/prefixmanager/log.go: -------------------------------------------------------------------------------- 1 | package prefixmanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("PRFX") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /domain/utxoindex/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package utxoindex 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("UTIN") 12 | -------------------------------------------------------------------------------- /domain/utxoindex/model.go: -------------------------------------------------------------------------------- 1 | package utxoindex 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | ) 6 | 7 | // ScriptPublicKeyString is a script public key represented as a string 8 | // We use this type rather than just a byte slice because Go maps don't 9 | // support slices as keys. See: UTXOChanges 10 | type ScriptPublicKeyString string 11 | 12 | // UTXOOutpointEntryPairs is a map between UTXO outpoints to UTXO entries 13 | type UTXOOutpointEntryPairs map[externalapi.DomainOutpoint]externalapi.UTXOEntry 14 | 15 | // UTXOOutpoints is a set of UTXO outpoints 16 | type UTXOOutpoints map[externalapi.DomainOutpoint]interface{} 17 | 18 | // UTXOChanges is the set of changes made to the UTXO index after 19 | // a successful update 20 | type UTXOChanges struct { 21 | Added map[ScriptPublicKeyString]UTXOOutpointEntryPairs 22 | Removed map[ScriptPublicKeyString]UTXOOutpointEntryPairs 23 | } 24 | -------------------------------------------------------------------------------- /infrastructure/config/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package config 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("CNFG") 12 | -------------------------------------------------------------------------------- /infrastructure/db/database/dataaccessor.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | // DataAccessor defines the common interface by which data gets 4 | // accessed in a generic karlsend database. 5 | type DataAccessor interface { 6 | // Put sets the value for the given key. It overwrites 7 | // any previous value for that key. 8 | Put(key *Key, value []byte) error 9 | 10 | // Get gets the value for the given key. It returns 11 | // ErrNotFound if the given key does not exist. 12 | Get(key *Key) ([]byte, error) 13 | 14 | // Has returns true if the database does contains the 15 | // given key. 16 | Has(key *Key) (bool, error) 17 | 18 | // Delete deletes the value for the given key. Will not 19 | // return an error if the key doesn't exist. 20 | Delete(key *Key) error 21 | 22 | // Cursor begins a new cursor over the given bucket. 23 | Cursor(bucket *Bucket) (Cursor, error) 24 | } 25 | -------------------------------------------------------------------------------- /infrastructure/db/database/database.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | // Database defines the interface of a database that can begin 4 | // transactions and close itself. 5 | // 6 | // Important: This is not part of the DataAccessor interface 7 | // because the Transaction interface includes it. Were we to 8 | // merge Database with DataAccessor, implementors of the 9 | // Transaction interface would be forced to implement methods 10 | // such as Begin and Close, which is undesirable. 11 | type Database interface { 12 | DataAccessor 13 | 14 | // Begin begins a new database transaction. 15 | Begin() (Transaction, error) 16 | 17 | // Compact compacts the database instance. 18 | Compact() error 19 | 20 | // Close closes the database. 21 | Close() error 22 | } 23 | -------------------------------------------------------------------------------- /infrastructure/db/database/errors.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import "errors" 4 | 5 | // ErrNotFound denotes that the requested item was not 6 | // found in the database. 7 | var ErrNotFound = errors.New("not found") 8 | 9 | // IsNotFoundError checks whether an error is an ErrNotFound. 10 | func IsNotFoundError(err error) bool { 11 | return errors.Is(err, ErrNotFound) 12 | } 13 | -------------------------------------------------------------------------------- /infrastructure/db/database/ldb/log.go: -------------------------------------------------------------------------------- 1 | package ldb 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("KSDB") 8 | -------------------------------------------------------------------------------- /infrastructure/db/database/ldb/options.go: -------------------------------------------------------------------------------- 1 | package ldb 2 | 3 | import "github.com/syndtr/goleveldb/leveldb/opt" 4 | 5 | // Options is a function that returns a leveldb 6 | // opt.Options struct for opening a database. 7 | func Options() opt.Options { 8 | return opt.Options{ 9 | Compression: opt.NoCompression, 10 | DisableSeeksCompaction: true, 11 | NoSync: true, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /infrastructure/network/addressmanager/config.go: -------------------------------------------------------------------------------- 1 | package addressmanager 2 | 3 | import ( 4 | "net" 5 | 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/config" 7 | ) 8 | 9 | // Config is a descriptor which specifies the AddressManager instance configuration. 10 | type Config struct { 11 | AcceptUnroutable bool 12 | DefaultPort string 13 | ExternalIPs []string 14 | Listeners []string 15 | Lookup func(string) ([]net.IP, error) 16 | } 17 | 18 | // NewConfig returns a new address manager Config. 19 | func NewConfig(cfg *config.Config) *Config { 20 | return &Config{ 21 | AcceptUnroutable: cfg.NetParams().AcceptUnroutable, 22 | DefaultPort: cfg.NetParams().DefaultPort, 23 | ExternalIPs: cfg.ExternalIPs, 24 | Listeners: cfg.Listeners, 25 | Lookup: cfg.Lookup, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /infrastructure/network/addressmanager/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package addressmanager 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var log = logger.RegisterSubSystem("ADXR") 12 | -------------------------------------------------------------------------------- /infrastructure/network/connmanager/connection_set.go: -------------------------------------------------------------------------------- 1 | package connmanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter" 5 | ) 6 | 7 | type connectionSet map[string]*netadapter.NetConnection 8 | 9 | func (cs connectionSet) add(connection *netadapter.NetConnection) { 10 | cs[connection.Address()] = connection 11 | } 12 | 13 | func (cs connectionSet) remove(connection *netadapter.NetConnection) { 14 | delete(cs, connection.Address()) 15 | } 16 | 17 | func (cs connectionSet) get(address string) (*netadapter.NetConnection, bool) { 18 | connection, ok := cs[address] 19 | return connection, ok 20 | } 21 | 22 | func convertToSet(connections []*netadapter.NetConnection) connectionSet { 23 | connSet := make(connectionSet, len(connections)) 24 | 25 | for _, connection := range connections { 26 | connSet[connection.Address()] = connection 27 | } 28 | 29 | return connSet 30 | } 31 | -------------------------------------------------------------------------------- /infrastructure/network/connmanager/log.go: -------------------------------------------------------------------------------- 1 | package connmanager 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("CMGR") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /infrastructure/network/dnsseed/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package dnsseed 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var log = logger.RegisterSubSystem("CMGR") 13 | var spawn = panics.GoroutineWrapperFunc(log) 14 | -------------------------------------------------------------------------------- /infrastructure/network/dnsseed/pb/generate.go: -------------------------------------------------------------------------------- 1 | //go:generate protoc --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative peer_service.proto 2 | 3 | package pb 4 | -------------------------------------------------------------------------------- /infrastructure/network/dnsseed/pb/peer_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "github.com/karlsen-network/karlsend/pb"; 4 | 5 | service PeerService { 6 | rpc GetPeersList(GetPeersListRequest) returns (GetPeersListResponse) {} 7 | } 8 | 9 | message GetPeersListRequest { 10 | bytes subnetworkID = 1; 11 | bool includeAllSubnetworks = 2; 12 | } 13 | 14 | message GetPeersListResponse { 15 | repeated NetAddress addresses = 1; 16 | } 17 | 18 | message NetAddress { 19 | int64 timestamp = 1; 20 | bytes IP = 2; 21 | uint32 port = 3; 22 | } -------------------------------------------------------------------------------- /infrastructure/network/netadapter/log.go: -------------------------------------------------------------------------------- 1 | package netadapter 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("NTAR") 8 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/router/log.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("ROUT") 8 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package grpcserver 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var log = logger.RegisterSubSystem("TXMP") 13 | var spawn = panics.GoroutineWrapperFunc(log) 14 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/README.md: -------------------------------------------------------------------------------- 1 | # protowire 2 | 3 | 1. Download and place in your PATH: 4 | https://github.com/protocolbuffers/protobuf/releases/download/v3.12.3/protoc-3.12.3-linux-x86_64.zip 5 | 2. `go install github.com/golang/protobuf/protoc-gen-go` 6 | 3. `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc` 7 | 4. In the protowire directory: `go generate .` 8 | 9 | # Documentation 10 | 11 | To generate `rpc.md`: 12 | 13 | 1. `go install -u github.com/karlsen-network/protoc-gen-doc/cmd/protoc-gen-doc` 14 | 2. In the protowire directory: `protoc --doc_out=. --doc_opt=markdown,rpc.md rpc.proto` 15 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/generate.go: -------------------------------------------------------------------------------- 1 | //go:generate protoc --go_out=. --go-grpc_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative p2p.proto rpc.proto messages.proto 2 | 3 | package protowire 4 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_done_blocks_with_trusted_data.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_DoneBlocksWithTrustedData) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_DoneBlocksWithTrustedData is nil") 11 | } 12 | return &appmessage.MsgDoneBlocksWithTrustedData{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_DoneBlocksWithTrustedData) fromAppMessage(_ *appmessage.MsgDoneBlocksWithTrustedData) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_done_headers.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_DoneHeaders) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_DoneHeaders is nil") 11 | } 12 | return &appmessage.MsgDoneHeaders{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_DoneHeaders) fromAppMessage(_ *appmessage.MsgDoneHeaders) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_done_pruning_point_utxo_set_chunks.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_DonePruningPointUtxoSetChunks) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_DonePruningPointUtxoSetChunks is nil") 11 | } 12 | return &appmessage.MsgDonePruningPointUTXOSetChunks{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_DonePruningPointUtxoSetChunks) fromAppMessage(_ *appmessage.MsgDonePruningPointUTXOSetChunks) error { 16 | x.DonePruningPointUtxoSetChunks = &DonePruningPointUtxoSetChunksMessage{} 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_ibd_block.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_IbdBlock) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_IbdBlock is nil") 11 | } 12 | msgBlock, err := x.IbdBlock.toAppMessage() 13 | if err != nil { 14 | return nil, err 15 | } 16 | return &appmessage.MsgIBDBlock{MsgBlock: msgBlock}, nil 17 | } 18 | 19 | func (x *KarlsendMessage_IbdBlock) fromAppMessage(msgIBDBlock *appmessage.MsgIBDBlock) error { 20 | x.IbdBlock = new(BlockMessage) 21 | return x.IbdBlock.fromAppMessage(msgIBDBlock.MsgBlock) 22 | } 23 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_ibd_block_locator_highest_hash_not_found.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_IbdBlockLocatorHighestHashNotFound) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_IbdBlockLocatorHighestHashNotFound is nil") 11 | } 12 | return &appmessage.MsgIBDBlockLocatorHighestHashNotFound{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_IbdBlockLocatorHighestHashNotFound) fromAppMessage(message *appmessage.MsgIBDBlockLocatorHighestHashNotFound) error { 16 | x.IbdBlockLocatorHighestHashNotFound = &IbdBlockLocatorHighestHashNotFoundMessage{} 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_ping.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_Ping) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_Ping is nil") 11 | } 12 | return x.Ping.toAppMessage() 13 | } 14 | 15 | func (x *PingMessage) toAppMessage() (appmessage.Message, error) { 16 | if x == nil { 17 | return nil, errors.Wrapf(errorNil, "PingMessage is nil") 18 | } 19 | return &appmessage.MsgPing{ 20 | Nonce: x.Nonce, 21 | }, nil 22 | } 23 | 24 | func (x *KarlsendMessage_Ping) fromAppMessage(msgPing *appmessage.MsgPing) error { 25 | x.Ping = &PingMessage{ 26 | Nonce: msgPing.Nonce, 27 | } 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_pong.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_Pong) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_Pong is nil") 11 | } 12 | return x.Pong.toAppMessage() 13 | } 14 | 15 | func (x *PongMessage) toAppMessage() (appmessage.Message, error) { 16 | if x == nil { 17 | return nil, errors.Wrapf(errorNil, "PongMessage is nil") 18 | } 19 | return &appmessage.MsgPong{ 20 | Nonce: x.Nonce, 21 | }, nil 22 | } 23 | 24 | func (x *KarlsendMessage_Pong) fromAppMessage(msgPong *appmessage.MsgPong) error { 25 | x.Pong = &PongMessage{ 26 | Nonce: msgPong.Nonce, 27 | } 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_ready.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_Ready) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_Ready is nil") 11 | } 12 | return &appmessage.MsgReady{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_Ready) fromAppMessage(_ *appmessage.MsgReady) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_reject.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_Reject) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_Reject is nil") 11 | } 12 | return x.Reject.toAppMessage() 13 | } 14 | 15 | func (x *RejectMessage) toAppMessage() (appmessage.Message, error) { 16 | if x == nil { 17 | return nil, errors.Wrapf(errorNil, "RejectMessage is nil") 18 | } 19 | return &appmessage.MsgReject{ 20 | Reason: x.Reason, 21 | }, nil 22 | } 23 | 24 | func (x *KarlsendMessage_Reject) fromAppMessage(msgReject *appmessage.MsgReject) error { 25 | x.Reject = &RejectMessage{ 26 | Reason: msgReject.Reason, 27 | } 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_request_next_headers.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_RequestNextHeaders) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_RequestNextHeaders is nil") 11 | } 12 | return &appmessage.MsgRequestNextHeaders{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_RequestNextHeaders) fromAppMessage(_ *appmessage.MsgRequestNextHeaders) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_request_next_pruning_point_and_its_anticone_blocks.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_RequestNextPruningPointAndItsAnticoneBlocks) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_DonePruningPointAndItsAnticoneBlocks is nil") 11 | } 12 | return &appmessage.MsgRequestNextPruningPointAndItsAnticoneBlocks{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_RequestNextPruningPointAndItsAnticoneBlocks) fromAppMessage(_ *appmessage.MsgRequestNextPruningPointAndItsAnticoneBlocks) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_request_next_pruning_point_utxo_set_chunk.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_RequestNextPruningPointUtxoSetChunk) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_RequestNextPruningPointUtxoSetChunk is nil") 11 | } 12 | return &appmessage.MsgRequestNextPruningPointUTXOSetChunk{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_RequestNextPruningPointUtxoSetChunk) fromAppMessage(_ *appmessage.MsgRequestNextPruningPointUTXOSetChunk) error { 16 | x.RequestNextPruningPointUtxoSetChunk = &RequestNextPruningPointUtxoSetChunkMessage{} 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_request_pruning_point_and_its_anticone.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_RequestPruningPointAndItsAnticone) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_RequestPruningPointAndItsAnticone is nil") 11 | } 12 | return &appmessage.MsgRequestPruningPointAndItsAnticone{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_RequestPruningPointAndItsAnticone) fromAppMessage(_ *appmessage.MsgRequestPruningPointAndItsAnticone) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_request_pruning_point_proof.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_RequestPruningPointProof) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_RequestPruningPointProof is nil") 11 | } 12 | return &appmessage.MsgRequestPruningPointProof{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_RequestPruningPointProof) fromAppMessage(_ *appmessage.MsgRequestPruningPointProof) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_unexpected_pruning_point.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | func (x *KarlsendMessage_UnexpectedPruningPoint) toAppMessage() (appmessage.Message, error) { 6 | return &appmessage.MsgUnexpectedPruningPoint{}, nil 7 | } 8 | 9 | func (x *KarlsendMessage_UnexpectedPruningPoint) fromAppMessage(_ *appmessage.MsgUnexpectedPruningPoint) error { 10 | return nil 11 | } 12 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/p2p_verack.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *KarlsendMessage_Verack) toAppMessage() (appmessage.Message, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "KarlsendMessage_Verack is nil") 11 | } 12 | return &appmessage.MsgVerAck{}, nil 13 | } 14 | 15 | func (x *KarlsendMessage_Verack) fromAppMessage(_ *appmessage.MsgVerAck) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/server/grpcserver/protowire/rpc_error.go: -------------------------------------------------------------------------------- 1 | package protowire 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func (x *RPCError) toAppMessage() (*appmessage.RPCError, error) { 9 | if x == nil { 10 | return nil, errors.Wrapf(errorNil, "RPCError is nil") 11 | } 12 | return &appmessage.RPCError{Message: x.Message}, nil 13 | } 14 | -------------------------------------------------------------------------------- /infrastructure/network/netadapter/standalone/log.go: -------------------------------------------------------------------------------- 1 | package standalone 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("NTAR") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/grpcclient/log.go: -------------------------------------------------------------------------------- 1 | package grpcclient 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("RPCC") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/log.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var log = logger.RegisterSubSystem("RPCC") 9 | var spawn = panics.GoroutineWrapperFunc(log) 10 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_ban.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // Ban sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) Ban(ip string) (*appmessage.BanResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewBanRequestMessage(ip)) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdBanRequestMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | banResponse := response.(*appmessage.BanResponseMessage) 16 | if banResponse.Error != nil { 17 | return nil, c.convertRPCError(banResponse.Error) 18 | } 19 | return banResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_connect_to_peer.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // AddPeer sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) AddPeer(address string, isPermanent bool) error { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewAddPeerRequestMessage(address, isPermanent)) 8 | if err != nil { 9 | return err 10 | } 11 | response, err := c.route(appmessage.CmdAddPeerResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return err 14 | } 15 | getMempoolEntryResponse := response.(*appmessage.AddPeerResponseMessage) 16 | if getMempoolEntryResponse.Error != nil { 17 | return c.convertRPCError(getMempoolEntryResponse.Error) 18 | } 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_block.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetBlock sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetBlock(hash string, includeTransactions bool) ( 7 | *appmessage.GetBlockResponseMessage, error) { 8 | 9 | err := c.rpcRouter.outgoingRoute().Enqueue( 10 | appmessage.NewGetBlockRequestMessage(hash, includeTransactions)) 11 | if err != nil { 12 | return nil, err 13 | } 14 | response, err := c.route(appmessage.CmdGetBlockResponseMessage).DequeueWithTimeout(c.timeout) 15 | if err != nil { 16 | return nil, err 17 | } 18 | GetBlockResponse := response.(*appmessage.GetBlockResponseMessage) 19 | if GetBlockResponse.Error != nil { 20 | return nil, c.convertRPCError(GetBlockResponse.Error) 21 | } 22 | return GetBlockResponse, nil 23 | } 24 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_block_count.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetBlockCount sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetBlockCount() (*appmessage.GetBlockCountResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetBlockCountRequestMessage()) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetBlockCountResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | getBlockCountResponse := response.(*appmessage.GetBlockCountResponseMessage) 16 | if getBlockCountResponse.Error != nil { 17 | return nil, c.convertRPCError(getBlockCountResponse.Error) 18 | } 19 | return getBlockCountResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_block_dag_info.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetBlockDAGInfo sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetBlockDAGInfo() (*appmessage.GetBlockDAGInfoResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetBlockDAGInfoRequestMessage()) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetBlockDAGInfoResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | GetBlockDAGInfoResponse := response.(*appmessage.GetBlockDAGInfoResponseMessage) 16 | if GetBlockDAGInfoResponse.Error != nil { 17 | return nil, c.convertRPCError(GetBlockDAGInfoResponse.Error) 18 | } 19 | return GetBlockDAGInfoResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_coin_supply.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetCoinSupply sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetCoinSupply() (*appmessage.GetCoinSupplyResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetCoinSupplyRequestMessage()) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetCoinSupplyResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | geCoinSupplyResponse := response.(*appmessage.GetCoinSupplyResponseMessage) 16 | if geCoinSupplyResponse.Error != nil { 17 | return nil, c.convertRPCError(geCoinSupplyResponse.Error) 18 | } 19 | return geCoinSupplyResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_headers.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetHeaders sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetHeaders(startHash string, limit uint64, isAscending bool) (*appmessage.GetHeadersResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetHeadersRequestMessage(startHash, limit, isAscending)) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetHeadersResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | getHeadersResponse := response.(*appmessage.GetHeadersResponseMessage) 16 | if getHeadersResponse.Error != nil { 17 | return nil, c.convertRPCError(getHeadersResponse.Error) 18 | } 19 | return getHeadersResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_info.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetInfo sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetInfo() (*appmessage.GetInfoResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetInfoRequestMessage()) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetInfoResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | getInfoResponse := response.(*appmessage.GetInfoResponseMessage) 16 | if getInfoResponse.Error != nil { 17 | return nil, c.convertRPCError(getInfoResponse.Error) 18 | } 19 | return getInfoResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_peer_addresses.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetPeerAddresses sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetPeerAddresses() (*appmessage.GetPeerAddressesResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetPeerAddressesRequestMessage()) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetPeerAddressesResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | getPeerAddressesResponse := response.(*appmessage.GetPeerAddressesResponseMessage) 16 | if getPeerAddressesResponse.Error != nil { 17 | return nil, c.convertRPCError(getPeerAddressesResponse.Error) 18 | } 19 | return getPeerAddressesResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_selected_tip_hash.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetSelectedTipHash sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetSelectedTipHash() (*appmessage.GetSelectedTipHashResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetSelectedTipHashRequestMessage()) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetSelectedTipHashResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | getSelectedTipHashResponse := response.(*appmessage.GetSelectedTipHashResponseMessage) 16 | if getSelectedTipHashResponse.Error != nil { 17 | return nil, c.convertRPCError(getSelectedTipHashResponse.Error) 18 | } 19 | return getSelectedTipHashResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_get_subnetwork.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // GetSubnetwork sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) GetSubnetwork(subnetworkID string) (*appmessage.GetSubnetworkResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewGetSubnetworkRequestMessage(subnetworkID)) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdGetSubnetworkResponseMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | getSubnetworkResponse := response.(*appmessage.GetSubnetworkResponseMessage) 16 | if getSubnetworkResponse.Error != nil { 17 | return nil, c.convertRPCError(getSubnetworkResponse.Error) 18 | } 19 | return getSubnetworkResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/network/rpcclient/rpc_unban.go: -------------------------------------------------------------------------------- 1 | package rpcclient 2 | 3 | import "github.com/karlsen-network/karlsend/v2/app/appmessage" 4 | 5 | // Unban sends an RPC request respective to the function's name and returns the RPC server's response 6 | func (c *RPCClient) Unban(ip string) (*appmessage.UnbanResponseMessage, error) { 7 | err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewUnbanRequestMessage(ip)) 8 | if err != nil { 9 | return nil, err 10 | } 11 | response, err := c.route(appmessage.CmdUnbanRequestMessage).DequeueWithTimeout(c.timeout) 12 | if err != nil { 13 | return nil, err 14 | } 15 | unbanResponse := response.(*appmessage.UnbanResponseMessage) 16 | if unbanResponse.Error != nil { 17 | return nil, c.convertRPCError(unbanResponse.Error) 18 | } 19 | return unbanResponse, nil 20 | } 21 | -------------------------------------------------------------------------------- /infrastructure/os/execenv/initialize.go: -------------------------------------------------------------------------------- 1 | package execenv 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "runtime" 7 | 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/os/limits" 9 | ) 10 | 11 | // Initialize initializes the execution environment required to run karlsend 12 | func Initialize(desiredLimits *limits.DesiredLimits) { 13 | // Use all processor cores. 14 | runtime.GOMAXPROCS(runtime.NumCPU()) 15 | 16 | // Up some limits. 17 | if err := limits.SetLimits(desiredLimits); err != nil { 18 | fmt.Fprintf(os.Stderr, "failed to set limits: %s\n", err) 19 | os.Exit(1) 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /infrastructure/os/limits/desired_limits.go: -------------------------------------------------------------------------------- 1 | package limits 2 | 3 | // DesiredLimits is a structure that specifies the limits desired by a running application 4 | type DesiredLimits struct { 5 | FileLimitWant uint64 6 | FileLimitMin uint64 7 | } 8 | -------------------------------------------------------------------------------- /infrastructure/os/limits/limits_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package limits 6 | 7 | // SetLimits is a no-op on Plan 9 due to the lack of process accounting. 8 | func SetLimits(*DesiredLimits) error { 9 | return nil 10 | } 11 | -------------------------------------------------------------------------------- /infrastructure/os/limits/limits_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package limits 6 | 7 | // SetLimits is a no-op on Windows since it's not required there. 8 | func SetLimits(*DesiredLimits) error { 9 | return nil 10 | } 11 | -------------------------------------------------------------------------------- /infrastructure/os/signal/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package signal 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | ) 10 | 11 | var klsdLog = logger.RegisterSubSystem("KLSD") 12 | -------------------------------------------------------------------------------- /infrastructure/os/signal/signalsigterm.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris 6 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 7 | 8 | package signal 9 | 10 | import ( 11 | "os" 12 | "syscall" 13 | ) 14 | 15 | func init() { 16 | interruptSignals = []os.Signal{os.Interrupt, syscall.SIGTERM} 17 | } 18 | -------------------------------------------------------------------------------- /infrastructure/os/winservice/common.go: -------------------------------------------------------------------------------- 1 | package winservice 2 | 3 | import "github.com/karlsen-network/karlsend/v2/infrastructure/config" 4 | 5 | // ServiceDescription contains information about a service, needed to administer it 6 | type ServiceDescription struct { 7 | Name string 8 | DisplayName string 9 | Description string 10 | } 11 | 12 | // MainFunc specifies the signature of an application's main function to be able to run as a windows service 13 | type MainFunc func(startedChan chan<- struct{}) error 14 | 15 | // WinServiceMain is only invoked on Windows. It detects when karlsend is running 16 | // as a service and reacts accordingly. 17 | var WinServiceMain = func(MainFunc, *ServiceDescription, *config.Config) (bool, error) { return false, nil } 18 | -------------------------------------------------------------------------------- /infrastructure/os/winservice/log.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package winservice 6 | 7 | import ( 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var log = logger.RegisterSubSystem("CNFG") 13 | var spawn = panics.GoroutineWrapperFunc(log) 14 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | _ "net/http/pprof" 9 | "os" 10 | 11 | "github.com/karlsen-network/karlsend/v2/app" 12 | ) 13 | 14 | func main() { 15 | if err := app.StartApp(); err != nil { 16 | os.Exit(1) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /stability-tests/README.md: -------------------------------------------------------------------------------- 1 | # Stability-Test Tools 2 | 3 | This package provides some higher-level tests for karlsend. These are 4 | tests that are beyond the scope of unit-tests, and some of them might 5 | take long time to run. 6 | 7 | # Running 8 | 9 | * To run only the fast running tests call `./install_and_test.sh` 10 | * To include all tests call `SLOW=1 ./install_and_test.sh` (Note this 11 | will take many hours to finish) 12 | * To run a single test cd `[test-name]/run` and call `./run.sh` 13 | -------------------------------------------------------------------------------- /stability-tests/application-level-garbage/README.md: -------------------------------------------------------------------------------- 1 | # Application Level Garbage Generator 2 | 3 | This tool sends invalid blocks to a node, making sure the node 4 | responds with a reject, and does not crash as a result. 5 | 6 | ## Running 7 | 8 | 1. `go install` karlsend and application-level-garbage. 9 | 2. `cd run` 10 | 3. `./run.sh` 11 | -------------------------------------------------------------------------------- /stability-tests/application-level-garbage/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("APLG") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/application-level-garbage/read.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 7 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 8 | "github.com/pkg/errors" 9 | ) 10 | 11 | var blockBuffer []byte 12 | 13 | func readBlocks() (<-chan *externalapi.DomainBlock, error) { 14 | c := make(chan *externalapi.DomainBlock) 15 | 16 | spawn("applicationLevelGarbage-readBlocks", func() { 17 | lineNum := 0 18 | for blockJSON := range common.ScanFile(activeConfig().BlocksFilePath) { 19 | domainBlock := &externalapi.DomainBlock{} 20 | 21 | err := json.Unmarshal(blockJSON, domainBlock) 22 | if err != nil { 23 | panic(errors.Wrapf(err, "error deserializing line No. %d with json %s", lineNum, blockJSON)) 24 | } 25 | 26 | c <- domainBlock 27 | } 28 | close(c) 29 | }) 30 | 31 | return c, nil 32 | } 33 | -------------------------------------------------------------------------------- /stability-tests/application-level-garbage/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf /tmp/karlsend-temp 3 | 4 | karlsend --devnet --appdir=/tmp/karlsend-temp --profile=6061 --loglevel=debug & 5 | KARLSEND_PID=$! 6 | KARLSEND_KILLED=0 7 | function killKarlsendIfNotKilled() { 8 | if [ $KARLSEND_KILLED -eq 0 ]; then 9 | kill $KARLSEND_PID 10 | fi 11 | } 12 | trap "killKarlsendIfNotKilled" EXIT 13 | 14 | sleep 1 15 | 16 | application-level-garbage --devnet -alocalhost:42611 -b blocks.dat --profile=7000 17 | TEST_EXIT_CODE=$? 18 | 19 | kill $KARLSEND_PID 20 | 21 | wait $KARLSEND_PID 22 | KARLSEND_KILLED=1 23 | KARLSEND_EXIT_CODE=$? 24 | 25 | echo "Exit code: $TEST_EXIT_CODE" 26 | echo "Karlsend exit code: $KARLSEND_EXIT_CODE" 27 | 28 | if [ $TEST_EXIT_CODE -eq 0 ] && [ $KARLSEND_EXIT_CODE -eq 0 ]; then 29 | echo "application-level-garbage test: PASSED" 30 | exit 0 31 | fi 32 | echo "application-level-garbage test: FAILED" 33 | exit 1 34 | -------------------------------------------------------------------------------- /stability-tests/common/log-writer.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 7 | ) 8 | 9 | // LogWriter writes to the given log with the given log level and prefix 10 | type LogWriter struct { 11 | log *logger.Logger 12 | level logger.Level 13 | prefix string 14 | } 15 | 16 | func (clw LogWriter) Write(p []byte) (n int, err error) { 17 | logWithoutNewLine := strings.TrimSuffix(string(p), "\n") 18 | clw.log.Writef(clw.level, "%s: %s", clw.prefix, logWithoutNewLine) 19 | return len(p), nil 20 | } 21 | 22 | // NewLogWriter returns a new LogWriter that forwards to `log` all data written to it using at `level` level 23 | func NewLogWriter(log *logger.Logger, level logger.Level, prefix string) LogWriter { 24 | return LogWriter{ 25 | log: log, 26 | level: level, 27 | prefix: prefix, 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /stability-tests/common/paths.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import "github.com/karlsen-network/karlsend/v2/util" 4 | 5 | // DefaultAppDir is the default app directory to be used by all tests 6 | var DefaultAppDir = util.AppDir("stability-tests", false) 7 | -------------------------------------------------------------------------------- /stability-tests/common/tempdir.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import "io/ioutil" 4 | 5 | // TempDir returns a temporary directory with the given pattern, prefixed with STABILITY_TEMP_DIR_ 6 | func TempDir(pattern string) (string, error) { 7 | const prefix = "STABILITY_TEMP_DIR_" 8 | return ioutil.TempDir("", prefix+pattern) 9 | } 10 | -------------------------------------------------------------------------------- /stability-tests/daa/README.md: -------------------------------------------------------------------------------- 1 | # DAA Tool 2 | 3 | This tool simulates various hashrate patterns to stress-test the DAA 4 | algorithm. 5 | 6 | ## Running 7 | 8 | 1. `go install` karlsend and daa. 9 | 2. `cd run` 10 | 3. `./run.sh` 11 | -------------------------------------------------------------------------------- /stability-tests/daa/average_duration.go: -------------------------------------------------------------------------------- 1 | package daa 2 | 3 | import "time" 4 | 5 | type averageDuration struct { 6 | average float64 7 | count uint64 8 | sampleSize uint64 9 | } 10 | 11 | func newAverageDuration(sampleSize uint64) *averageDuration { 12 | return &averageDuration{ 13 | average: 0, 14 | count: 0, 15 | sampleSize: sampleSize, 16 | } 17 | } 18 | 19 | func (ad *averageDuration) add(duration time.Duration) { 20 | durationNanoseconds := float64(duration.Nanoseconds()) 21 | 22 | ad.count++ 23 | if ad.count > ad.sampleSize { 24 | ad.count = ad.sampleSize 25 | } 26 | 27 | if ad.count == 1 { 28 | ad.average = durationNanoseconds 29 | return 30 | } 31 | 32 | ad.average = ad.average + ((durationNanoseconds - ad.average) / float64(ad.count)) 33 | } 34 | 35 | func (ad *averageDuration) toDuration() time.Duration { 36 | return time.Duration(ad.average) 37 | } 38 | -------------------------------------------------------------------------------- /stability-tests/daa/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RUN_STABILITY_TESTS=true go test ../ -v -timeout 86400s 4 | TEST_EXIT_CODE=$? 5 | 6 | echo "Exit code: $TEST_EXIT_CODE" 7 | 8 | if [ $TEST_EXIT_CODE -eq 0 ]; then 9 | echo "daa test: PASSED" 10 | exit 0 11 | fi 12 | echo "daa test: FAILED" 13 | exit 1 14 | -------------------------------------------------------------------------------- /stability-tests/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG KARLSEND_IMAGE 2 | ARG KARLSENMINER_IMAGE 3 | 4 | FROM ${KARLSEND_IMAGE} as karlsend 5 | FROM ${KARLSENMINER_IMAGE} as karlsenminer 6 | 7 | FROM golang:1.19-alpine 8 | 9 | RUN mkdir -p /go/src/github.com/karlsen-network/karlsend/ 10 | 11 | WORKDIR /go/src/github.com/karlsen-network/karlsend/ 12 | 13 | RUN apk add bash build-base git 14 | 15 | COPY go.mod . 16 | COPY go.sum . 17 | 18 | RUN go mod download 19 | 20 | COPY . . 21 | 22 | COPY --from=karlsend /app/ /app/ 23 | COPY --from=karlsenminer /app/ /app/ 24 | ENV PATH="/app:${PATH}" 25 | 26 | WORKDIR /go/src/github.com/karlsen-network/karlsend/stability-tests 27 | 28 | RUN go install ./... 29 | 30 | ENTRYPOINT ["./run/run.sh"] 31 | -------------------------------------------------------------------------------- /stability-tests/infra-level-garbage/README.md: -------------------------------------------------------------------------------- 1 | # Infra Level Garbage Generator 2 | 3 | This tool sends invalid messages to a node, making sure the node does 4 | not crash as a result. 5 | 6 | ## Running 7 | 8 | 1. `go install` karlsend and infra-level-garbage. 9 | 2. `cd run` 10 | 3. `./run.sh` 11 | -------------------------------------------------------------------------------- /stability-tests/infra-level-garbage/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("IFLG") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/infra-level-garbage/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/profiling" 10 | ) 11 | 12 | const timeout = 5 * time.Second 13 | 14 | func main() { 15 | err := parseConfig() 16 | if err != nil { 17 | fmt.Fprintf(os.Stderr, "Error parsing config: %+v", err) 18 | os.Exit(1) 19 | } 20 | defer backendLog.Close() 21 | common.UseLogger(backendLog, log.Level()) 22 | cfg := activeConfig() 23 | if cfg.Profile != "" { 24 | profiling.Start(cfg.Profile, log) 25 | } 26 | 27 | messagesChan := common.ScanHexFile(cfg.MessagesFilePath) 28 | 29 | err = sendMessages(cfg.NodeP2PAddress, messagesChan) 30 | if err != nil { 31 | log.Errorf("Error sending messages: %+v", err) 32 | backendLog.Close() 33 | os.Exit(1) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /stability-tests/infra-level-garbage/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf /tmp/karlsend-temp 3 | 4 | karlsend --devnet --appdir=/tmp/karlsend-temp --profile=6061 & 5 | KARLSEND_PID=$! 6 | 7 | sleep 1 8 | 9 | infra-level-garbage --devnet -alocalhost:42611 -m messages.dat --profile=7000 10 | TEST_EXIT_CODE=$? 11 | 12 | kill $KARLSEND_PID 13 | 14 | wait $KARLSEND_PID 15 | KARLSEND_EXIT_CODE=$? 16 | 17 | echo "Exit code: $TEST_EXIT_CODE" 18 | echo "Karlsend exit code: $KARLSEND_EXIT_CODE" 19 | 20 | if [ $TEST_EXIT_CODE -eq 0 ] && [ $KARLSEND_EXIT_CODE -eq 0 ]; then 21 | echo "infra-level-garbage test: PASSED" 22 | exit 0 23 | fi 24 | echo "infra-level-garbage test: FAILED" 25 | exit 1 26 | -------------------------------------------------------------------------------- /stability-tests/karlsendsanity/README.md: -------------------------------------------------------------------------------- 1 | # Karlsend Sanity Tool 2 | 3 | This tries to run kapad with different sets of arguments for sanity. 4 | 5 | In order to get clean run for each command, the tool injects its own 6 | `--appdir` argument so it will be able to clean it between runs, so 7 | it's forbidden to use `--appdir` as part of the arguments set. 8 | 9 | ## Running 10 | 11 | 1. `go install` karlsend and karlsendsanity. 12 | 2. `cd run` 13 | 3. `./run.sh` 14 | -------------------------------------------------------------------------------- /stability-tests/karlsendsanity/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var ( 13 | backendLog = logger.NewBackend() 14 | log = backendLog.Logger("KSSA") 15 | spawn = panics.GoroutineWrapperFunc(log) 16 | ) 17 | 18 | func initLog(logFile, errLogFile string) { 19 | level := logger.LevelInfo 20 | if activeConfig().LogLevel != "" { 21 | var ok bool 22 | level, ok = logger.LevelFromString(activeConfig().LogLevel) 23 | if !ok { 24 | fmt.Fprintf(os.Stderr, "Log level %s doesn't exists", activeConfig().LogLevel) 25 | os.Exit(1) 26 | } 27 | } 28 | log.SetLevel(level) 29 | common.InitBackend(backendLog, logFile, errLogFile) 30 | } 31 | -------------------------------------------------------------------------------- /stability-tests/karlsendsanity/read.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "os" 7 | "strings" 8 | 9 | "github.com/pkg/errors" 10 | ) 11 | 12 | func readArgs() <-chan []string { 13 | argsChan := make(chan []string) 14 | spawn("readArgs", func() { 15 | f, err := os.Open(cfg.CommandListFile) 16 | if err != nil { 17 | panic(errors.Wrapf(err, "error in Open")) 18 | } 19 | 20 | r := bufio.NewReader(f) 21 | for { 22 | line, _, err := r.ReadLine() 23 | 24 | if err == io.EOF { 25 | break 26 | } 27 | 28 | if err != nil { 29 | panic(errors.Wrapf(err, "error in ReadLine")) 30 | } 31 | 32 | trimmedLine := strings.TrimSpace(string(line)) 33 | if trimmedLine == "" || strings.HasPrefix(trimmedLine, "//") { 34 | continue 35 | } 36 | 37 | argsChan <- strings.Split(trimmedLine, " ") 38 | } 39 | 40 | close(argsChan) 41 | }) 42 | return argsChan 43 | } 44 | -------------------------------------------------------------------------------- /stability-tests/karlsendsanity/run/commands-list: -------------------------------------------------------------------------------- 1 | --devnet -------------------------------------------------------------------------------- /stability-tests/karlsendsanity/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | karlsendsanity --command-list-file ./commands-list --profile=7000 3 | TEST_EXIT_CODE=$? 4 | 5 | echo "Exit code: $TEST_EXIT_CODE" 6 | 7 | if [ $TEST_EXIT_CODE -eq 0 ]; then 8 | echo "karlsendsanity test: PASSED" 9 | exit 0 10 | fi 11 | echo "karlsendsanity test: FAILED" 12 | exit 1 13 | -------------------------------------------------------------------------------- /stability-tests/many-tips/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var ( 13 | backendLog = logger.NewBackend() 14 | log = backendLog.Logger("MATS") 15 | spawn = panics.GoroutineWrapperFunc(log) 16 | ) 17 | 18 | func initLog(logFile, errLogFile string) { 19 | level := logger.LevelDebug 20 | if activeConfig().LogLevel != "" { 21 | var ok bool 22 | level, ok = logger.LevelFromString(activeConfig().LogLevel) 23 | if !ok { 24 | fmt.Fprintf(os.Stderr, "Log level %s doesn't exists", activeConfig().LogLevel) 25 | os.Exit(1) 26 | } 27 | } 28 | log.SetLevel(level) 29 | common.InitBackend(backendLog, logFile, errLogFile) 30 | } 31 | -------------------------------------------------------------------------------- /stability-tests/many-tips/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | many-tips --devnet -n=1000 --profile=7000 4 | TEST_EXIT_CODE=$? 5 | 6 | echo "Exit code: $TEST_EXIT_CODE" 7 | 8 | if [ $TEST_EXIT_CODE -eq 0 ]; then 9 | echo "many-tips test: PASSED" 10 | exit 0 11 | fi 12 | echo "many-tips test: FAILED" 13 | exit 1 14 | -------------------------------------------------------------------------------- /stability-tests/mempool-limits/README.md: -------------------------------------------------------------------------------- 1 | # Mempool Limits Tool 2 | 3 | This tool: 4 | 5 | 1. Fills up the mempool beyond its transaction limit to make sure 6 | eviction works correctly. 7 | 2. Mines blocks until the mempool is expected to become empty. 8 | 9 | ## Running 10 | 11 | 1. `go install` karlsend and mempool-limits. 12 | 2. `cd run` 13 | 3. `./run.sh` 14 | -------------------------------------------------------------------------------- /stability-tests/mempool-limits/log.go: -------------------------------------------------------------------------------- 1 | package mempoollimits 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var ( 13 | backendLog = logger.NewBackend() 14 | log = backendLog.Logger("MPLM") 15 | spawn = panics.GoroutineWrapperFunc(log) 16 | ) 17 | 18 | func initLog(logFile, errLogFile string) { 19 | level := logger.LevelInfo 20 | if activeConfig().LogLevel != "" { 21 | var ok bool 22 | level, ok = logger.LevelFromString(activeConfig().LogLevel) 23 | if !ok { 24 | fmt.Fprintf(os.Stderr, "Log level %s doesn't exists", activeConfig().LogLevel) 25 | os.Exit(1) 26 | } 27 | } 28 | log.SetLevel(level) 29 | common.InitBackend(backendLog, logFile, errLogFile) 30 | } 31 | -------------------------------------------------------------------------------- /stability-tests/mempool-limits/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APPDIR=/tmp/karlsend-temp 4 | KARLSEND_RPC_PORT=29587 5 | 6 | rm -rf "${APPDIR}" 7 | 8 | karlsend --simnet --appdir="${APPDIR}" --rpclisten=0.0.0.0:"${KARLSEND_RPC_PORT}" --profile=6061 & 9 | KARLSEND_PID=$! 10 | 11 | sleep 1 12 | 13 | RUN_STABILITY_TESTS=true go test ../ -v -timeout 86400s -- --rpc-address=127.0.0.1:"${KARLSEND_RPC_PORT}" --profile=7000 14 | TEST_EXIT_CODE=$? 15 | 16 | kill $KARLSEND_PID 17 | 18 | wait $KARLSEND_PID 19 | KARLSEND_EXIT_CODE=$? 20 | 21 | echo "Exit code: $TEST_EXIT_CODE" 22 | echo "Karlsend exit code: $KARLSEND_EXIT_CODE" 23 | 24 | if [ $TEST_EXIT_CODE -eq 0 ] && [ $KARLSEND_EXIT_CODE -eq 0 ]; then 25 | echo "mempool-limits test: PASSED" 26 | exit 0 27 | fi 28 | echo "mempool-limits test: FAILED" 29 | exit 1 30 | -------------------------------------------------------------------------------- /stability-tests/minejson/example.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "0" 4 | }, 5 | { 6 | "id": "1", 7 | "parents": [ 8 | "0" 9 | ] 10 | }, 11 | { 12 | "id": "2", 13 | "parents": [ 14 | "0" 15 | ] 16 | }, 17 | { 18 | "id": "3", 19 | "parents": [ 20 | "1", 21 | "2" 22 | ] 23 | }, 24 | { 25 | "id": "4", 26 | "parents": [ 27 | "1" 28 | ] 29 | } 30 | ] -------------------------------------------------------------------------------- /stability-tests/minejson/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("MNJS") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/netsync/README.md: -------------------------------------------------------------------------------- 1 | # Netsync Stability Tester 2 | 3 | This tests that the netsync is at least 5 blocks per second. 4 | 5 | Note: the test doesn't delete karlsend's data directory and it's the 6 | user responsibility to delete the data directories that appear in the 7 | log. 8 | 9 | ## Running 10 | 11 | 1. `go install karlsend` 12 | 2. `go install ./...` 13 | 3. `cd run` 14 | 4. `./run.sh` 15 | -------------------------------------------------------------------------------- /stability-tests/netsync/chain_generator/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var ( 13 | backendLog = logger.NewBackend() 14 | log = backendLog.Logger("CHGN") 15 | spawn = panics.GoroutineWrapperFunc(log) 16 | ) 17 | 18 | func initLog(logFile, errLogFile string) { 19 | level := logger.LevelInfo 20 | if activeConfig().LogLevel != "" { 21 | var ok bool 22 | level, ok = logger.LevelFromString(activeConfig().LogLevel) 23 | if !ok { 24 | fmt.Fprintf(os.Stderr, "Log level %s doesn't exists", activeConfig().LogLevel) 25 | os.Exit(1) 26 | } 27 | } 28 | log.SetLevel(level) 29 | common.InitBackend(backendLog, logFile, errLogFile) 30 | } 31 | -------------------------------------------------------------------------------- /stability-tests/netsync/dags-fast/000170-chain.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-fast/000170-chain.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-fast/100-chain.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-fast/100-chain.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-fast/wide-dag-blocks--2^12-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-fast/wide-dag-blocks--2^12-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/100000-chain.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/100000-chain.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/100070-chain.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/100070-chain.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/many-small-chains-and-one-big-chain.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/many-small-chains-and-one-big-chain.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/wide-dag-blocks--2^16-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/wide-dag-blocks--2^16-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--1-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--1-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--2-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--2-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--4-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--4-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--6-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--6-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--8-k--18.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/dags-slow/wide-dag-blocks--2^20-delay-factor--8-k--18.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/fast-pruning-ibd-test/dag-for-fast-pruning-ibd-test.json.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlsen-network/karlsend/1293c9fda8b15374dfb279663c8fa26a9ced5770/stability-tests/netsync/fast-pruning-ibd-test/dag-for-fast-pruning-ibd-test.json.gz -------------------------------------------------------------------------------- /stability-tests/netsync/fast-pruning-ibd-test/fast-pruning-ibd-test-params.json: -------------------------------------------------------------------------------- 1 | { 2 | "skipProofOfWork": true, 3 | "mergeSetSizeLimit": 30, 4 | "finalityDuration": 200000, 5 | "hardForkOmitGenesisFromParentsDaaScore": 2505, 6 | "k": 0 7 | } 8 | -------------------------------------------------------------------------------- /stability-tests/netsync/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var ( 13 | backendLog = logger.NewBackend() 14 | log = backendLog.Logger("NTSN") 15 | spawn = panics.GoroutineWrapperFunc(log) 16 | ) 17 | 18 | func initLog(logFile, errLogFile string) { 19 | level := logger.LevelInfo 20 | if activeConfig().LogLevel != "" { 21 | var ok bool 22 | level, ok = logger.LevelFromString(activeConfig().LogLevel) 23 | if !ok { 24 | fmt.Fprintf(os.Stderr, "Log level %s doesn't exists", activeConfig().LogLevel) 25 | os.Exit(1) 26 | } 27 | } 28 | log.SetLevel(level) 29 | common.InitBackend(backendLog, logFile, errLogFile) 30 | } 31 | -------------------------------------------------------------------------------- /stability-tests/netsync/run/run-slow.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | SLOW_DAGS_DIR="../dags-slow" 5 | mapfile -t DAGS < <( ls $SLOW_DAGS_DIR) 6 | 7 | for dagArchive in "${DAGS[@]}" 8 | do 9 | JSON_FILE=$SLOW_DAGS_DIR/$dagArchive 10 | netsync --simnet --dag-file $JSON_FILE --profile=7000 11 | echo "$dagArchive processed" 12 | if [ $TEST_EXIT_CODE -ne 0 ]; then 13 | echo "netsync (slow) test: FAILED" 14 | exit 1 15 | fi 16 | rm -rf /tmp/STABILITY_TEMP_DIR_* 17 | done 18 | 19 | echo "netsync (slow) test: PASSED" 20 | exit 0 21 | 22 | -------------------------------------------------------------------------------- /stability-tests/netsync/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FAST_DAGS_DIR="../dags-fast" 4 | SLOW_DAGS_DIR="../dags-slow" 5 | mapfile -t FAST_DAGS < <( ls $FAST_DAGS_DIR) 6 | mapfile -t SLOW_DAGS < <( ls $SLOW_DAGS_DIR) 7 | 8 | DAGS=() 9 | 10 | for dagArchive in "${FAST_DAGS[@]}" 11 | do 12 | DAGS+=("$FAST_DAGS_DIR/$dagArchive") 13 | done 14 | 15 | for dagArchive in "${SLOW_DAGS[@]}" 16 | do 17 | DAGS+=("$SLOW_DAGS_DIR/$dagArchive") 18 | done 19 | 20 | for dagArchive in "${DAGS[@]}" 21 | do 22 | JSON_FILE=$FAST_DAGS_DIR/$dagArchive 23 | netsync --simnet --dag-file $JSON_FILE --profile=7000 24 | TEST_EXIT_CODE=$? 25 | echo "$dagArchive processed" 26 | if [ $TEST_EXIT_CODE -ne 0 ]; then 27 | echo "netsync test: FAILED" 28 | exit 1 29 | fi 30 | done 31 | 32 | echo "netsync test: PASSED" 33 | exit 0 34 | -------------------------------------------------------------------------------- /stability-tests/orphans/README.md: -------------------------------------------------------------------------------- 1 | # Orphans 2 | 3 | This tool makes sure orphan resolution works and doesn't crash 4 | karlsend. 5 | 6 | ## Running 7 | 8 | 1. `go install` karlsend and orphans. 9 | 2. `cd run` 10 | 3. `./run.sh` 11 | -------------------------------------------------------------------------------- /stability-tests/orphans/check_top_is_tip.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/domain/consensus/model/externalapi" 5 | "github.com/karlsen-network/karlsend/v2/domain/consensus/utils/consensushashing" 6 | "github.com/karlsen-network/karlsend/v2/stability-tests/common/rpc" 7 | "github.com/pkg/errors" 8 | ) 9 | 10 | func checkTopBlockIsTip(rpcClient *rpc.Client, topBlock *externalapi.DomainBlock) error { 11 | selectedTipHashResponse, err := rpcClient.GetSelectedTipHash() 12 | if err != nil { 13 | return err 14 | } 15 | 16 | topBlockHash := consensushashing.BlockHash(topBlock) 17 | if selectedTipHashResponse.SelectedTipHash != topBlockHash.String() { 18 | return errors.Errorf("selectedTipHash is '%s' while expected to be topBlock's hash `%s`", 19 | selectedTipHashResponse.SelectedTipHash, topBlockHash) 20 | } 21 | 22 | return nil 23 | } 24 | -------------------------------------------------------------------------------- /stability-tests/orphans/connect_to_node.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/config" 8 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/netadapter/standalone" 9 | ) 10 | 11 | func connectToNode() *standalone.Routes { 12 | cfg := activeConfig() 13 | 14 | karlsendConfig := config.DefaultConfig() 15 | karlsendConfig.NetworkFlags = cfg.NetworkFlags 16 | 17 | minimalNetAdapter, err := standalone.NewMinimalNetAdapter(karlsendConfig) 18 | if err != nil { 19 | fmt.Fprintf(os.Stderr, "error creating minimalNetAdapter: %+v", err) 20 | os.Exit(1) 21 | } 22 | routes, err := minimalNetAdapter.Connect(cfg.NodeP2PAddress) 23 | if err != nil { 24 | fmt.Fprintf(os.Stderr, "error connecting to node: %+v", err) 25 | os.Exit(1) 26 | } 27 | return routes 28 | } 29 | -------------------------------------------------------------------------------- /stability-tests/orphans/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("ORPH") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/orphans/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf /tmp/karlsend-temp 3 | 4 | karlsend --simnet --appdir=/tmp/karlsend-temp --profile=6061 & 5 | KARLSEND_PID=$! 6 | 7 | sleep 1 8 | 9 | orphans --simnet -alocalhost:42511 -n20 --profile=7000 10 | TEST_EXIT_CODE=$? 11 | 12 | kill $KARLSEND_PID 13 | 14 | wait $KARLSEND_PID 15 | KARLSEND_EXIT_CODE=$? 16 | 17 | echo "Exit code: $TEST_EXIT_CODE" 18 | echo "Karlsend exit code: $KARLSEND_EXIT_CODE" 19 | 20 | if [ $TEST_EXIT_CODE -eq 0 ] && [ $KARLSEND_EXIT_CODE -eq 0 ]; then 21 | echo "orphans test: PASSED" 22 | exit 0 23 | fi 24 | echo "orphans test: FAILED" 25 | exit 1 26 | -------------------------------------------------------------------------------- /stability-tests/reorg/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("RORG") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/reorg/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 8 | "github.com/karlsen-network/karlsend/v2/util/profiling" 9 | ) 10 | 11 | func main() { 12 | err := parseConfig() 13 | if err != nil { 14 | fmt.Fprintf(os.Stderr, "Error parsing config: %+v", err) 15 | os.Exit(1) 16 | } 17 | defer backendLog.Close() 18 | common.UseLogger(backendLog, log.Level()) 19 | cfg := activeConfig() 20 | if cfg.Profile != "" { 21 | profiling.Start(cfg.Profile, log) 22 | } 23 | 24 | testReorg(cfg) 25 | } 26 | -------------------------------------------------------------------------------- /stability-tests/reorg/run/run-full-finality-window-reorg.sh: -------------------------------------------------------------------------------- 1 | reorg --dag-file ../../netsync/dags-slow/wide-dag-blocks--2^16-delay-factor--1-k--18.json.gz --profile=6061 2 | 3 | TEST_EXIT_CODE=$? 4 | echo "Exit code: $TEST_EXIT_CODE" 5 | 6 | 7 | if [ $TEST_EXIT_CODE -eq 0 ]; then 8 | echo "reorg test: PASSED" 9 | exit 0 10 | fi 11 | echo "reorg test: FAILED" 12 | exit 1 13 | -------------------------------------------------------------------------------- /stability-tests/reorg/run/run.sh: -------------------------------------------------------------------------------- 1 | reorg --dag-file ../../netsync/dags-fast/wide-dag-blocks--2^12-delay-factor--1-k--18.json.gz --profile=6061 2 | 3 | TEST_EXIT_CODE=$? 4 | echo "Exit code: $TEST_EXIT_CODE" 5 | 6 | 7 | if [ $TEST_EXIT_CODE -eq 0 ]; then 8 | echo "reorg test: PASSED" 9 | exit 0 10 | fi 11 | echo "reorg test: FAILED" 12 | exit 1 13 | -------------------------------------------------------------------------------- /stability-tests/rpc-idle-clients/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("RPIC") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/rpc-idle-clients/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf /tmp/karlsend-temp 3 | 4 | NUM_CLIENTS=128 5 | karlsend --devnet --appdir=/tmp/karlsend-temp --profile=6061 --rpcmaxwebsockets=$NUM_CLIENTS & 6 | KARLSEND_PID=$! 7 | KARLSEND_KILLED=0 8 | function killKarlsendIfNotKilled() { 9 | if [ $KARLSEND_KILLED -eq 0 ]; then 10 | kill $KARLSEND_PID 11 | fi 12 | } 13 | trap "killKarlsendIfNotKilled" EXIT 14 | 15 | sleep 1 16 | 17 | rpc-idle-clients --devnet --profile=7000 -n=$NUM_CLIENTS 18 | TEST_EXIT_CODE=$? 19 | 20 | kill $KARLSEND_PID 21 | 22 | wait $KARLSEND_PID 23 | KARLSEND_EXIT_CODE=$? 24 | KARLSEND_KILLED=1 25 | 26 | echo "Exit code: $TEST_EXIT_CODE" 27 | echo "Karlsend exit code: $KARLSEND_EXIT_CODE" 28 | 29 | if [ $TEST_EXIT_CODE -eq 0 ] && [ $KARLSEND_EXIT_CODE -eq 0 ]; then 30 | echo "rpc-idle-clients test: PASSED" 31 | exit 0 32 | fi 33 | echo "rpc-idle-clients test: FAILED" 34 | exit 1 35 | -------------------------------------------------------------------------------- /stability-tests/rpc-stability/README.md: -------------------------------------------------------------------------------- 1 | # RPC Stability Tester 2 | 3 | This tests JSON-RPC stability by sending the node commands and making 4 | sure it does not crash. 5 | 6 | ## Running 7 | 8 | 1. `go install` karlsend and rpc-stability. 9 | 2. `cd run` 10 | 3. `./run.sh` 11 | -------------------------------------------------------------------------------- /stability-tests/rpc-stability/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | "github.com/karlsen-network/karlsend/v2/util/panics" 6 | ) 7 | 8 | var ( 9 | backendLog = logger.NewBackend() 10 | log = backendLog.Logger("JSTT") 11 | spawn = panics.GoroutineWrapperFunc(log) 12 | ) 13 | -------------------------------------------------------------------------------- /stability-tests/rpc-stability/read.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "os" 6 | ) 7 | 8 | func readCommands() (<-chan string, error) { 9 | cfg := activeConfig() 10 | f, err := os.Open(cfg.CommandsFilePath) 11 | if err != nil { 12 | return nil, err 13 | } 14 | scanner := bufio.NewScanner(f) 15 | 16 | commandsChan := make(chan string) 17 | spawn("readCommands", func() { 18 | for scanner.Scan() { 19 | command := scanner.Text() 20 | commandsChan <- command 21 | } 22 | close(commandsChan) 23 | }) 24 | return commandsChan, nil 25 | } 26 | -------------------------------------------------------------------------------- /stability-tests/rpc-stability/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf /tmp/karlsend-temp 3 | 4 | karlsend --devnet --appdir=/tmp/karlsend-temp --profile=6061 --loglevel=debug & 5 | KARLSEND_PID=$! 6 | 7 | sleep 1 8 | 9 | rpc-stability --devnet -p commands.json --profile=7000 10 | TEST_EXIT_CODE=$? 11 | 12 | kill $KARLSEND_PID 13 | 14 | wait $KARLSEND_PID 15 | KARLSEND_EXIT_CODE=$? 16 | 17 | echo "Exit code: $TEST_EXIT_CODE" 18 | echo "Karlsend exit code: $KARLSEND_EXIT_CODE" 19 | 20 | if [ $TEST_EXIT_CODE -eq 0 ] && [ $KARLSEND_EXIT_CODE -eq 0 ]; then 21 | echo "rpc-stability test: PASSED" 22 | exit 0 23 | fi 24 | echo "rpc-stability test: FAILED" 25 | exit 1 26 | -------------------------------------------------------------------------------- /stability-tests/rpc-stability/send.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/network/rpcclient/grpcclient" 5 | "github.com/pkg/errors" 6 | ) 7 | 8 | func sendCommands(rpcClient *grpcclient.GRPCClient, commandsChan <-chan string) error { 9 | for command := range commandsChan { 10 | log.Infof("Sending command %s", command) 11 | response, err := rpcClient.PostJSON(command) 12 | if err != nil { 13 | return errors.Wrap(err, "error sending message") 14 | } 15 | 16 | log.Infof("-> Got response: %s", response) 17 | } 18 | 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /stability-tests/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | TEST_EXIT_CODE=1 4 | BASEDIR=$(dirname "$0") 5 | if [[ $1 == "slow" ]]; 6 | then 7 | echo "Running slow stability tests" 8 | "${BASEDIR}/run-slow.sh" 9 | TEST_EXIT_CODE=$? 10 | echo "Done running slow stability tests" 11 | else 12 | echo "Running fast stability tests" 13 | "${BASEDIR}/run-fast.sh" 14 | TEST_EXIT_CODE=$? 15 | echo "Done running fast stability tests" 16 | fi 17 | 18 | echo "Exit code: $TEST_EXIT_CODE" 19 | exit $TEST_EXIT_CODE -------------------------------------------------------------------------------- /stability-tests/simple-sync/README.md: -------------------------------------------------------------------------------- 1 | # Simple Sync Stability Tester 2 | 3 | This tests that two nodes that are connected to each other stay 4 | synced while one of them mines a chain. 5 | 6 | ## Running 7 | 8 | 1. `go install` karlsend and simple-sync. 9 | 2. `cd run` 10 | 3. `./run.sh` 11 | -------------------------------------------------------------------------------- /stability-tests/simple-sync/cmd.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os/exec" 5 | "syscall" 6 | ) 7 | 8 | func killWithSigterm(cmd *exec.Cmd, commandName string) { 9 | err := cmd.Process.Signal(syscall.SIGTERM) 10 | if err != nil { 11 | log.Criticalf("error sending SIGKILL to %s", commandName) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /stability-tests/simple-sync/log.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | "github.com/karlsen-network/karlsend/v2/stability-tests/common" 9 | "github.com/karlsen-network/karlsend/v2/util/panics" 10 | ) 11 | 12 | var ( 13 | backendLog = logger.NewBackend() 14 | log = backendLog.Logger("KSSA") 15 | spawn = panics.GoroutineWrapperFunc(log) 16 | ) 17 | 18 | func initLog(logFile, errLogFile string) { 19 | level := logger.LevelDebug 20 | if activeConfig().LogLevel != "" { 21 | var ok bool 22 | level, ok = logger.LevelFromString(activeConfig().LogLevel) 23 | if !ok { 24 | fmt.Fprintf(os.Stderr, "Log level %s doesn't exists", activeConfig().LogLevel) 25 | os.Exit(1) 26 | } 27 | } 28 | log.SetLevel(level) 29 | common.InitBackend(backendLog, logFile, errLogFile) 30 | } 31 | -------------------------------------------------------------------------------- /stability-tests/simple-sync/run/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | simple-sync --simnet -n=100 --profile=7000 4 | TEST_EXIT_CODE=$? 5 | 6 | echo "Exit code: $TEST_EXIT_CODE" 7 | 8 | if [ $TEST_EXIT_CODE -eq 0 ]; then 9 | echo "simple-sync test: PASSED" 10 | exit 0 11 | fi 12 | echo "simple-sync test: FAILED" 13 | exit 1 14 | -------------------------------------------------------------------------------- /testing/integration/integration.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | // Because of a bug in Go coverage fails if you have packages with test files only. See https://github.com/golang/go/issues/27333 4 | // So this is a dummy non-test go file in the package. 5 | -------------------------------------------------------------------------------- /testing/integration/log_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2017 The btcsuite developers 2 | // Copyright (c) 2017 The Decred developers 3 | // Use of this source code is governed by an ISC 4 | // license that can be found in the LICENSE file. 5 | 6 | package integration 7 | 8 | import ( 9 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 10 | "github.com/karlsen-network/karlsend/v2/util/panics" 11 | ) 12 | 13 | var log = logger.RegisterSubSystem("INTG") 14 | var spawn = panics.GoroutineWrapperFunc(log) 15 | -------------------------------------------------------------------------------- /testing/integration/main_test.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 8 | ) 9 | 10 | func TestMain(m *testing.M) { 11 | logger.SetLogLevels(logger.LevelDebug) 12 | logger.InitLogStdout(logger.LevelDebug) 13 | 14 | os.Exit(m.Run()) 15 | } 16 | -------------------------------------------------------------------------------- /testing/integration/notifications_test.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/karlsen-network/karlsend/v2/app/appmessage" 7 | ) 8 | 9 | func setOnBlockAddedHandler(t *testing.T, harness *appHarness, handler func(notification *appmessage.BlockAddedNotificationMessage)) { 10 | err := harness.rpcClient.RegisterForBlockAddedNotifications(handler) 11 | if err != nil { 12 | t.Fatalf("Error from RegisterForBlockAddedNotifications: %s", err) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /util/README.md: -------------------------------------------------------------------------------- 1 | # util 2 | 3 | [![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](https://choosealicense.com/licenses/isc/) 4 | [![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/karlsen-network/util) 5 | 6 | Package util provides karlsen-specific convenience functions and 7 | types. 8 | -------------------------------------------------------------------------------- /util/bech32/README.md: -------------------------------------------------------------------------------- 1 | # bech32 2 | 3 | [![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](https://choosealicense.com/licenses/isc/) 4 | [![GoDoc](https://godoc.org/github.com/karlsen-network/karlsend/util/bech32?status.png)](http://godoc.org/github.com/karlsen-network/karlsend/util/bech32) 5 | 6 | Package bech32 provides a Go implementation of the bech32 format. 7 | 8 | ## Examples 9 | 10 | * [Bech32 decode Example](http://godoc.org/github.com/karlsen-network/karlsend/util/bech32#example-Bech32Decode) 11 | Demonstrates how to decode a bech32 encoded string. 12 | * [Bech32 encode Example](http://godoc.org/github.com/karlsen-network/karlsend/util/bech32#example-BechEncode) 13 | Demonstrates how to encode data into a bech32 string. 14 | -------------------------------------------------------------------------------- /util/bech32/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package bech32 provides a Go implementation of the bech32 format. 3 | 4 | Bech32 strings consist of a prefix, followed by the separator :, 5 | then a checksummed data part encoded using the 32 characters 6 | "qpzry9x8gf2tvdw0s3jn54khce6mua7l". 7 | */ 8 | package bech32 9 | -------------------------------------------------------------------------------- /util/blake2b.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2017 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package util 6 | 7 | import ( 8 | "golang.org/x/crypto/blake2b" 9 | ) 10 | 11 | // HashBlake2b calculates the hash blake2b(b). 12 | func HashBlake2b(buf []byte) []byte { 13 | hashedBuf := blake2b.Sum256(buf) 14 | return hashedBuf[:] 15 | } 16 | -------------------------------------------------------------------------------- /util/locks/log.go: -------------------------------------------------------------------------------- 1 | package locks 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var log = logger.RegisterSubSystem("UTIL") 8 | -------------------------------------------------------------------------------- /util/math/min.go: -------------------------------------------------------------------------------- 1 | package math 2 | 3 | // MinInt returns the smaller of x or y. 4 | func MinInt(x, y int) int { 5 | if x < y { 6 | return x 7 | } 8 | return y 9 | } 10 | 11 | // MaxInt64 returns the bigger of x or y. 12 | func MaxInt64(x, y int64) int64 { 13 | if x > y { 14 | return x 15 | } 16 | return y 17 | } 18 | 19 | // MinUint32 returns the smaller of x or y. 20 | func MinUint32(x, y uint32) uint32 { 21 | if x < y { 22 | return x 23 | } 24 | return y 25 | } 26 | -------------------------------------------------------------------------------- /util/panics/log.go: -------------------------------------------------------------------------------- 1 | package panics 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var utilLog = logger.RegisterSubSystem("UTIL") 8 | -------------------------------------------------------------------------------- /util/random/random.go: -------------------------------------------------------------------------------- 1 | package random 2 | 3 | import ( 4 | "crypto/rand" 5 | "encoding/binary" 6 | ) 7 | 8 | // Uint64 returns a cryptographically random uint64 value. 9 | func Uint64() (uint64, error) { 10 | var buf [8]byte 11 | _, err := rand.Read(buf[:]) 12 | if err != nil { 13 | return 0, err 14 | } 15 | return binary.LittleEndian.Uint64(buf[:]), nil 16 | } 17 | -------------------------------------------------------------------------------- /util/staging/log.go: -------------------------------------------------------------------------------- 1 | package staging 2 | 3 | import ( 4 | "github.com/karlsen-network/karlsend/v2/infrastructure/logger" 5 | ) 6 | 7 | var utilLog = logger.RegisterSubSystem("UTIL") 8 | --------------------------------------------------------------------------------