chia-blockchain 2.5.1rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chia/__init__.py +10 -0
- chia/__main__.py +5 -0
- chia/_tests/README.md +53 -0
- chia/_tests/__init__.py +0 -0
- chia/_tests/blockchain/__init__.py +0 -0
- chia/_tests/blockchain/blockchain_test_utils.py +195 -0
- chia/_tests/blockchain/config.py +4 -0
- chia/_tests/blockchain/test_augmented_chain.py +145 -0
- chia/_tests/blockchain/test_blockchain.py +4202 -0
- chia/_tests/blockchain/test_blockchain_transactions.py +1031 -0
- chia/_tests/blockchain/test_build_chains.py +59 -0
- chia/_tests/blockchain/test_get_block_generator.py +72 -0
- chia/_tests/blockchain/test_lookup_fork_chain.py +194 -0
- chia/_tests/build-init-files.py +92 -0
- chia/_tests/build-job-matrix.py +204 -0
- chia/_tests/check_pytest_monitor_output.py +34 -0
- chia/_tests/check_sql_statements.py +72 -0
- chia/_tests/chia-start-sim +42 -0
- chia/_tests/clvm/__init__.py +0 -0
- chia/_tests/clvm/benchmark_costs.py +23 -0
- chia/_tests/clvm/coin_store.py +149 -0
- chia/_tests/clvm/test_chialisp_deserialization.py +101 -0
- chia/_tests/clvm/test_clvm_step.py +37 -0
- chia/_tests/clvm/test_condition_codes.py +13 -0
- chia/_tests/clvm/test_curry_and_treehash.py +55 -0
- chia/_tests/clvm/test_message_conditions.py +184 -0
- chia/_tests/clvm/test_program.py +150 -0
- chia/_tests/clvm/test_puzzle_compression.py +143 -0
- chia/_tests/clvm/test_puzzle_drivers.py +45 -0
- chia/_tests/clvm/test_puzzles.py +242 -0
- chia/_tests/clvm/test_singletons.py +540 -0
- chia/_tests/clvm/test_spend_sim.py +181 -0
- chia/_tests/cmds/__init__.py +0 -0
- chia/_tests/cmds/cmd_test_utils.py +469 -0
- chia/_tests/cmds/config.py +3 -0
- chia/_tests/cmds/conftest.py +23 -0
- chia/_tests/cmds/test_click_types.py +200 -0
- chia/_tests/cmds/test_cmd_framework.py +620 -0
- chia/_tests/cmds/test_cmds_util.py +97 -0
- chia/_tests/cmds/test_daemon.py +92 -0
- chia/_tests/cmds/test_dev_gh.py +131 -0
- chia/_tests/cmds/test_farm_cmd.py +66 -0
- chia/_tests/cmds/test_show.py +116 -0
- chia/_tests/cmds/test_sim.py +207 -0
- chia/_tests/cmds/test_timelock_args.py +75 -0
- chia/_tests/cmds/test_tx_config_args.py +154 -0
- chia/_tests/cmds/testing_classes.py +59 -0
- chia/_tests/cmds/wallet/__init__.py +0 -0
- chia/_tests/cmds/wallet/test_consts.py +47 -0
- chia/_tests/cmds/wallet/test_dao.py +565 -0
- chia/_tests/cmds/wallet/test_did.py +403 -0
- chia/_tests/cmds/wallet/test_nft.py +471 -0
- chia/_tests/cmds/wallet/test_notifications.py +124 -0
- chia/_tests/cmds/wallet/test_offer.toffer +1 -0
- chia/_tests/cmds/wallet/test_tx_decorators.py +27 -0
- chia/_tests/cmds/wallet/test_vcs.py +400 -0
- chia/_tests/cmds/wallet/test_wallet.py +1125 -0
- chia/_tests/cmds/wallet/test_wallet_check.py +109 -0
- chia/_tests/conftest.py +1419 -0
- chia/_tests/connection_utils.py +125 -0
- chia/_tests/core/__init__.py +0 -0
- chia/_tests/core/cmds/__init__.py +0 -0
- chia/_tests/core/cmds/test_beta.py +382 -0
- chia/_tests/core/cmds/test_keys.py +1734 -0
- chia/_tests/core/cmds/test_wallet.py +126 -0
- chia/_tests/core/config.py +3 -0
- chia/_tests/core/consensus/__init__.py +0 -0
- chia/_tests/core/consensus/test_block_creation.py +54 -0
- chia/_tests/core/consensus/test_pot_iterations.py +117 -0
- chia/_tests/core/custom_types/__init__.py +0 -0
- chia/_tests/core/custom_types/test_coin.py +107 -0
- chia/_tests/core/custom_types/test_proof_of_space.py +144 -0
- chia/_tests/core/custom_types/test_spend_bundle.py +70 -0
- chia/_tests/core/daemon/__init__.py +0 -0
- chia/_tests/core/daemon/config.py +4 -0
- chia/_tests/core/daemon/test_daemon.py +2128 -0
- chia/_tests/core/daemon/test_daemon_register.py +109 -0
- chia/_tests/core/daemon/test_keychain_proxy.py +101 -0
- chia/_tests/core/data_layer/__init__.py +0 -0
- chia/_tests/core/data_layer/config.py +5 -0
- chia/_tests/core/data_layer/conftest.py +106 -0
- chia/_tests/core/data_layer/test_data_cli.py +56 -0
- chia/_tests/core/data_layer/test_data_layer.py +83 -0
- chia/_tests/core/data_layer/test_data_layer_util.py +218 -0
- chia/_tests/core/data_layer/test_data_rpc.py +3847 -0
- chia/_tests/core/data_layer/test_data_store.py +2424 -0
- chia/_tests/core/data_layer/test_data_store_schema.py +381 -0
- chia/_tests/core/data_layer/test_plugin.py +91 -0
- chia/_tests/core/data_layer/util.py +233 -0
- chia/_tests/core/farmer/__init__.py +0 -0
- chia/_tests/core/farmer/config.py +3 -0
- chia/_tests/core/farmer/test_farmer_api.py +103 -0
- chia/_tests/core/full_node/__init__.py +0 -0
- chia/_tests/core/full_node/config.py +4 -0
- chia/_tests/core/full_node/dos/__init__.py +0 -0
- chia/_tests/core/full_node/dos/config.py +3 -0
- chia/_tests/core/full_node/full_sync/__init__.py +0 -0
- chia/_tests/core/full_node/full_sync/config.py +4 -0
- chia/_tests/core/full_node/full_sync/test_full_sync.py +443 -0
- chia/_tests/core/full_node/ram_db.py +27 -0
- chia/_tests/core/full_node/stores/__init__.py +0 -0
- chia/_tests/core/full_node/stores/config.py +4 -0
- chia/_tests/core/full_node/stores/test_block_store.py +590 -0
- chia/_tests/core/full_node/stores/test_coin_store.py +897 -0
- chia/_tests/core/full_node/stores/test_full_node_store.py +1219 -0
- chia/_tests/core/full_node/stores/test_hint_store.py +229 -0
- chia/_tests/core/full_node/stores/test_sync_store.py +135 -0
- chia/_tests/core/full_node/test_address_manager.py +588 -0
- chia/_tests/core/full_node/test_block_height_map.py +556 -0
- chia/_tests/core/full_node/test_conditions.py +556 -0
- chia/_tests/core/full_node/test_full_node.py +2700 -0
- chia/_tests/core/full_node/test_generator_tools.py +82 -0
- chia/_tests/core/full_node/test_hint_management.py +104 -0
- chia/_tests/core/full_node/test_node_load.py +34 -0
- chia/_tests/core/full_node/test_performance.py +179 -0
- chia/_tests/core/full_node/test_subscriptions.py +492 -0
- chia/_tests/core/full_node/test_transactions.py +203 -0
- chia/_tests/core/full_node/test_tx_processing_queue.py +155 -0
- chia/_tests/core/large_block.py +2388 -0
- chia/_tests/core/make_block_generator.py +70 -0
- chia/_tests/core/mempool/__init__.py +0 -0
- chia/_tests/core/mempool/config.py +4 -0
- chia/_tests/core/mempool/test_mempool.py +3255 -0
- chia/_tests/core/mempool/test_mempool_fee_estimator.py +104 -0
- chia/_tests/core/mempool/test_mempool_fee_protocol.py +55 -0
- chia/_tests/core/mempool/test_mempool_item_queries.py +190 -0
- chia/_tests/core/mempool/test_mempool_manager.py +2084 -0
- chia/_tests/core/mempool/test_mempool_performance.py +64 -0
- chia/_tests/core/mempool/test_singleton_fast_forward.py +567 -0
- chia/_tests/core/node_height.py +28 -0
- chia/_tests/core/server/__init__.py +0 -0
- chia/_tests/core/server/config.py +3 -0
- chia/_tests/core/server/flood.py +84 -0
- chia/_tests/core/server/serve.py +135 -0
- chia/_tests/core/server/test_api_protocol.py +21 -0
- chia/_tests/core/server/test_capabilities.py +66 -0
- chia/_tests/core/server/test_dos.py +319 -0
- chia/_tests/core/server/test_event_loop.py +109 -0
- chia/_tests/core/server/test_loop.py +294 -0
- chia/_tests/core/server/test_node_discovery.py +73 -0
- chia/_tests/core/server/test_rate_limits.py +482 -0
- chia/_tests/core/server/test_server.py +226 -0
- chia/_tests/core/server/test_upnp.py +8 -0
- chia/_tests/core/services/__init__.py +0 -0
- chia/_tests/core/services/config.py +3 -0
- chia/_tests/core/services/test_services.py +188 -0
- chia/_tests/core/ssl/__init__.py +0 -0
- chia/_tests/core/ssl/config.py +3 -0
- chia/_tests/core/ssl/test_ssl.py +202 -0
- chia/_tests/core/test_coins.py +33 -0
- chia/_tests/core/test_cost_calculation.py +313 -0
- chia/_tests/core/test_crawler.py +175 -0
- chia/_tests/core/test_crawler_rpc.py +53 -0
- chia/_tests/core/test_daemon_rpc.py +24 -0
- chia/_tests/core/test_db_conversion.py +130 -0
- chia/_tests/core/test_db_validation.py +162 -0
- chia/_tests/core/test_farmer_harvester_rpc.py +505 -0
- chia/_tests/core/test_filter.py +35 -0
- chia/_tests/core/test_full_node_rpc.py +768 -0
- chia/_tests/core/test_merkle_set.py +343 -0
- chia/_tests/core/test_program.py +47 -0
- chia/_tests/core/test_rpc_util.py +86 -0
- chia/_tests/core/test_seeder.py +420 -0
- chia/_tests/core/test_setproctitle.py +13 -0
- chia/_tests/core/util/__init__.py +0 -0
- chia/_tests/core/util/config.py +4 -0
- chia/_tests/core/util/test_block_cache.py +44 -0
- chia/_tests/core/util/test_cached_bls.py +57 -0
- chia/_tests/core/util/test_config.py +337 -0
- chia/_tests/core/util/test_file_keyring_synchronization.py +105 -0
- chia/_tests/core/util/test_files.py +391 -0
- chia/_tests/core/util/test_jsonify.py +146 -0
- chia/_tests/core/util/test_keychain.py +522 -0
- chia/_tests/core/util/test_keyring_wrapper.py +491 -0
- chia/_tests/core/util/test_lockfile.py +380 -0
- chia/_tests/core/util/test_log_exceptions.py +187 -0
- chia/_tests/core/util/test_lru_cache.py +56 -0
- chia/_tests/core/util/test_significant_bits.py +40 -0
- chia/_tests/core/util/test_streamable.py +883 -0
- chia/_tests/db/__init__.py +0 -0
- chia/_tests/db/test_db_wrapper.py +566 -0
- chia/_tests/environments/__init__.py +0 -0
- chia/_tests/environments/common.py +35 -0
- chia/_tests/environments/full_node.py +47 -0
- chia/_tests/environments/wallet.py +429 -0
- chia/_tests/ether.py +19 -0
- chia/_tests/farmer_harvester/__init__.py +0 -0
- chia/_tests/farmer_harvester/config.py +3 -0
- chia/_tests/farmer_harvester/test_farmer.py +1264 -0
- chia/_tests/farmer_harvester/test_farmer_harvester.py +292 -0
- chia/_tests/farmer_harvester/test_filter_prefix_bits.py +131 -0
- chia/_tests/farmer_harvester/test_third_party_harvesters.py +528 -0
- chia/_tests/farmer_harvester/test_third_party_harvesters_data.json +29 -0
- chia/_tests/fee_estimation/__init__.py +0 -0
- chia/_tests/fee_estimation/config.py +3 -0
- chia/_tests/fee_estimation/test_fee_estimation_integration.py +262 -0
- chia/_tests/fee_estimation/test_fee_estimation_rpc.py +287 -0
- chia/_tests/fee_estimation/test_fee_estimation_unit_tests.py +144 -0
- chia/_tests/fee_estimation/test_mempoolitem_height_added.py +146 -0
- chia/_tests/generator/__init__.py +0 -0
- chia/_tests/generator/puzzles/__init__.py +0 -0
- chia/_tests/generator/puzzles/test_generator_deserialize.clsp +3 -0
- chia/_tests/generator/puzzles/test_generator_deserialize.clsp.hex +1 -0
- chia/_tests/generator/puzzles/test_multiple_generator_input_arguments.clsp +19 -0
- chia/_tests/generator/puzzles/test_multiple_generator_input_arguments.clsp.hex +1 -0
- chia/_tests/generator/test_compression.py +201 -0
- chia/_tests/generator/test_generator_types.py +44 -0
- chia/_tests/generator/test_rom.py +180 -0
- chia/_tests/plot_sync/__init__.py +0 -0
- chia/_tests/plot_sync/config.py +3 -0
- chia/_tests/plot_sync/test_delta.py +101 -0
- chia/_tests/plot_sync/test_plot_sync.py +618 -0
- chia/_tests/plot_sync/test_receiver.py +451 -0
- chia/_tests/plot_sync/test_sender.py +116 -0
- chia/_tests/plot_sync/test_sync_simulated.py +451 -0
- chia/_tests/plot_sync/util.py +68 -0
- chia/_tests/plotting/__init__.py +0 -0
- chia/_tests/plotting/config.py +3 -0
- chia/_tests/plotting/test_plot_manager.py +781 -0
- chia/_tests/plotting/util.py +12 -0
- chia/_tests/pools/__init__.py +0 -0
- chia/_tests/pools/config.py +5 -0
- chia/_tests/pools/test_pool_cli_parsing.py +128 -0
- chia/_tests/pools/test_pool_cmdline.py +1001 -0
- chia/_tests/pools/test_pool_config.py +42 -0
- chia/_tests/pools/test_pool_puzzles_lifecycle.py +397 -0
- chia/_tests/pools/test_pool_rpc.py +1123 -0
- chia/_tests/pools/test_pool_wallet.py +205 -0
- chia/_tests/pools/test_wallet_pool_store.py +161 -0
- chia/_tests/process_junit.py +348 -0
- chia/_tests/rpc/__init__.py +0 -0
- chia/_tests/rpc/test_rpc_client.py +138 -0
- chia/_tests/rpc/test_rpc_server.py +183 -0
- chia/_tests/simulation/__init__.py +0 -0
- chia/_tests/simulation/config.py +6 -0
- chia/_tests/simulation/test_simulation.py +501 -0
- chia/_tests/simulation/test_simulator.py +232 -0
- chia/_tests/simulation/test_start_simulator.py +107 -0
- chia/_tests/testconfig.py +13 -0
- chia/_tests/timelord/__init__.py +0 -0
- chia/_tests/timelord/config.py +3 -0
- chia/_tests/timelord/test_new_peak.py +437 -0
- chia/_tests/timelord/test_timelord.py +11 -0
- chia/_tests/tools/1315537.json +170 -0
- chia/_tests/tools/1315544.json +160 -0
- chia/_tests/tools/1315630.json +150 -0
- chia/_tests/tools/300000.json +105 -0
- chia/_tests/tools/442734.json +140 -0
- chia/_tests/tools/466212.json +130 -0
- chia/_tests/tools/__init__.py +0 -0
- chia/_tests/tools/config.py +5 -0
- chia/_tests/tools/test-blockchain-db.sqlite +0 -0
- chia/_tests/tools/test_full_sync.py +30 -0
- chia/_tests/tools/test_legacy_keyring.py +82 -0
- chia/_tests/tools/test_run_block.py +128 -0
- chia/_tests/tools/test_virtual_project.py +591 -0
- chia/_tests/util/__init__.py +0 -0
- chia/_tests/util/benchmark_cost.py +170 -0
- chia/_tests/util/benchmarks.py +153 -0
- chia/_tests/util/bip39_test_vectors.json +148 -0
- chia/_tests/util/blockchain.py +134 -0
- chia/_tests/util/blockchain_mock.py +132 -0
- chia/_tests/util/build_network_protocol_files.py +302 -0
- chia/_tests/util/clvm_generator.bin +0 -0
- chia/_tests/util/config.py +3 -0
- chia/_tests/util/constants.py +20 -0
- chia/_tests/util/db_connection.py +37 -0
- chia/_tests/util/full_sync.py +253 -0
- chia/_tests/util/gen_ssl_certs.py +114 -0
- chia/_tests/util/generator_tools_testing.py +45 -0
- chia/_tests/util/get_name_puzzle_conditions.py +52 -0
- chia/_tests/util/key_tool.py +36 -0
- chia/_tests/util/misc.py +675 -0
- chia/_tests/util/network_protocol_data.py +1072 -0
- chia/_tests/util/protocol_messages_bytes-v1.0 +0 -0
- chia/_tests/util/protocol_messages_json.py +2701 -0
- chia/_tests/util/rpc.py +26 -0
- chia/_tests/util/run_block.py +163 -0
- chia/_tests/util/setup_nodes.py +481 -0
- chia/_tests/util/spend_sim.py +492 -0
- chia/_tests/util/split_managers.py +102 -0
- chia/_tests/util/temp_file.py +14 -0
- chia/_tests/util/test_action_scope.py +144 -0
- chia/_tests/util/test_async_pool.py +366 -0
- chia/_tests/util/test_build_job_matrix.py +42 -0
- chia/_tests/util/test_build_network_protocol_files.py +7 -0
- chia/_tests/util/test_chia_version.py +50 -0
- chia/_tests/util/test_collection.py +11 -0
- chia/_tests/util/test_condition_tools.py +229 -0
- chia/_tests/util/test_config.py +426 -0
- chia/_tests/util/test_dump_keyring.py +60 -0
- chia/_tests/util/test_errors.py +10 -0
- chia/_tests/util/test_full_block_utils.py +279 -0
- chia/_tests/util/test_installed.py +20 -0
- chia/_tests/util/test_limited_semaphore.py +53 -0
- chia/_tests/util/test_logging_filter.py +42 -0
- chia/_tests/util/test_misc.py +445 -0
- chia/_tests/util/test_network.py +73 -0
- chia/_tests/util/test_network_protocol_files.py +578 -0
- chia/_tests/util/test_network_protocol_json.py +267 -0
- chia/_tests/util/test_network_protocol_test.py +256 -0
- chia/_tests/util/test_paginator.py +71 -0
- chia/_tests/util/test_pprint.py +17 -0
- chia/_tests/util/test_priority_mutex.py +488 -0
- chia/_tests/util/test_recursive_replace.py +116 -0
- chia/_tests/util/test_replace_str_to_bytes.py +137 -0
- chia/_tests/util/test_service_groups.py +15 -0
- chia/_tests/util/test_ssl_check.py +31 -0
- chia/_tests/util/test_testnet_overrides.py +19 -0
- chia/_tests/util/test_tests_misc.py +38 -0
- chia/_tests/util/test_timing.py +37 -0
- chia/_tests/util/test_trusted_peer.py +51 -0
- chia/_tests/util/time_out_assert.py +191 -0
- chia/_tests/wallet/__init__.py +0 -0
- chia/_tests/wallet/cat_wallet/__init__.py +0 -0
- chia/_tests/wallet/cat_wallet/config.py +4 -0
- chia/_tests/wallet/cat_wallet/test_cat_lifecycle.py +468 -0
- chia/_tests/wallet/cat_wallet/test_cat_outer_puzzle.py +69 -0
- chia/_tests/wallet/cat_wallet/test_cat_wallet.py +1826 -0
- chia/_tests/wallet/cat_wallet/test_offer_lifecycle.py +291 -0
- chia/_tests/wallet/cat_wallet/test_trades.py +2600 -0
- chia/_tests/wallet/clawback/__init__.py +0 -0
- chia/_tests/wallet/clawback/config.py +3 -0
- chia/_tests/wallet/clawback/test_clawback_decorator.py +78 -0
- chia/_tests/wallet/clawback/test_clawback_lifecycle.py +292 -0
- chia/_tests/wallet/clawback/test_clawback_metadata.py +50 -0
- chia/_tests/wallet/config.py +4 -0
- chia/_tests/wallet/conftest.py +278 -0
- chia/_tests/wallet/dao_wallet/__init__.py +0 -0
- chia/_tests/wallet/dao_wallet/config.py +3 -0
- chia/_tests/wallet/dao_wallet/test_dao_clvm.py +1330 -0
- chia/_tests/wallet/dao_wallet/test_dao_wallets.py +3488 -0
- chia/_tests/wallet/db_wallet/__init__.py +0 -0
- chia/_tests/wallet/db_wallet/config.py +3 -0
- chia/_tests/wallet/db_wallet/test_db_graftroot.py +141 -0
- chia/_tests/wallet/db_wallet/test_dl_offers.py +491 -0
- chia/_tests/wallet/db_wallet/test_dl_wallet.py +823 -0
- chia/_tests/wallet/did_wallet/__init__.py +0 -0
- chia/_tests/wallet/did_wallet/config.py +4 -0
- chia/_tests/wallet/did_wallet/test_did.py +2284 -0
- chia/_tests/wallet/nft_wallet/__init__.py +0 -0
- chia/_tests/wallet/nft_wallet/config.py +4 -0
- chia/_tests/wallet/nft_wallet/test_nft_1_offers.py +1493 -0
- chia/_tests/wallet/nft_wallet/test_nft_bulk_mint.py +1024 -0
- chia/_tests/wallet/nft_wallet/test_nft_lifecycle.py +375 -0
- chia/_tests/wallet/nft_wallet/test_nft_offers.py +1209 -0
- chia/_tests/wallet/nft_wallet/test_nft_puzzles.py +172 -0
- chia/_tests/wallet/nft_wallet/test_nft_wallet.py +2584 -0
- chia/_tests/wallet/nft_wallet/test_ownership_outer_puzzle.py +70 -0
- chia/_tests/wallet/rpc/__init__.py +0 -0
- chia/_tests/wallet/rpc/config.py +4 -0
- chia/_tests/wallet/rpc/test_dl_wallet_rpc.py +285 -0
- chia/_tests/wallet/rpc/test_wallet_rpc.py +3153 -0
- chia/_tests/wallet/simple_sync/__init__.py +0 -0
- chia/_tests/wallet/simple_sync/config.py +3 -0
- chia/_tests/wallet/simple_sync/test_simple_sync_protocol.py +718 -0
- chia/_tests/wallet/sync/__init__.py +0 -0
- chia/_tests/wallet/sync/config.py +4 -0
- chia/_tests/wallet/sync/test_wallet_sync.py +1692 -0
- chia/_tests/wallet/test_address_type.py +189 -0
- chia/_tests/wallet/test_bech32m.py +45 -0
- chia/_tests/wallet/test_clvm_streamable.py +244 -0
- chia/_tests/wallet/test_coin_management.py +354 -0
- chia/_tests/wallet/test_coin_selection.py +588 -0
- chia/_tests/wallet/test_conditions.py +400 -0
- chia/_tests/wallet/test_debug_spend_bundle.py +218 -0
- chia/_tests/wallet/test_new_wallet_protocol.py +1174 -0
- chia/_tests/wallet/test_nft_store.py +192 -0
- chia/_tests/wallet/test_notifications.py +196 -0
- chia/_tests/wallet/test_offer_parsing_performance.py +48 -0
- chia/_tests/wallet/test_puzzle_store.py +132 -0
- chia/_tests/wallet/test_sign_coin_spends.py +159 -0
- chia/_tests/wallet/test_signer_protocol.py +947 -0
- chia/_tests/wallet/test_singleton.py +122 -0
- chia/_tests/wallet/test_singleton_lifecycle_fast.py +772 -0
- chia/_tests/wallet/test_singleton_store.py +152 -0
- chia/_tests/wallet/test_taproot.py +19 -0
- chia/_tests/wallet/test_transaction_store.py +945 -0
- chia/_tests/wallet/test_util.py +185 -0
- chia/_tests/wallet/test_wallet.py +2139 -0
- chia/_tests/wallet/test_wallet_action_scope.py +85 -0
- chia/_tests/wallet/test_wallet_blockchain.py +111 -0
- chia/_tests/wallet/test_wallet_coin_store.py +1002 -0
- chia/_tests/wallet/test_wallet_interested_store.py +43 -0
- chia/_tests/wallet/test_wallet_key_val_store.py +40 -0
- chia/_tests/wallet/test_wallet_node.py +780 -0
- chia/_tests/wallet/test_wallet_retry.py +95 -0
- chia/_tests/wallet/test_wallet_state_manager.py +259 -0
- chia/_tests/wallet/test_wallet_test_framework.py +275 -0
- chia/_tests/wallet/test_wallet_trade_store.py +218 -0
- chia/_tests/wallet/test_wallet_user_store.py +34 -0
- chia/_tests/wallet/test_wallet_utils.py +156 -0
- chia/_tests/wallet/vc_wallet/__init__.py +0 -0
- chia/_tests/wallet/vc_wallet/config.py +3 -0
- chia/_tests/wallet/vc_wallet/test_cr_outer_puzzle.py +70 -0
- chia/_tests/wallet/vc_wallet/test_vc_lifecycle.py +883 -0
- chia/_tests/wallet/vc_wallet/test_vc_wallet.py +830 -0
- chia/_tests/wallet/wallet_block_tools.py +327 -0
- chia/_tests/weight_proof/__init__.py +0 -0
- chia/_tests/weight_proof/config.py +3 -0
- chia/_tests/weight_proof/test_weight_proof.py +528 -0
- chia/apis.py +19 -0
- chia/clvm/__init__.py +0 -0
- chia/cmds/__init__.py +0 -0
- chia/cmds/beta.py +184 -0
- chia/cmds/beta_funcs.py +137 -0
- chia/cmds/check_wallet_db.py +420 -0
- chia/cmds/chia.py +151 -0
- chia/cmds/cmd_classes.py +323 -0
- chia/cmds/cmd_helpers.py +242 -0
- chia/cmds/cmds_util.py +488 -0
- chia/cmds/coin_funcs.py +275 -0
- chia/cmds/coins.py +182 -0
- chia/cmds/completion.py +49 -0
- chia/cmds/configure.py +332 -0
- chia/cmds/dao.py +1064 -0
- chia/cmds/dao_funcs.py +598 -0
- chia/cmds/data.py +708 -0
- chia/cmds/data_funcs.py +385 -0
- chia/cmds/db.py +87 -0
- chia/cmds/db_backup_func.py +77 -0
- chia/cmds/db_upgrade_func.py +452 -0
- chia/cmds/db_validate_func.py +184 -0
- chia/cmds/dev.py +18 -0
- chia/cmds/farm.py +100 -0
- chia/cmds/farm_funcs.py +200 -0
- chia/cmds/gh.py +275 -0
- chia/cmds/init.py +63 -0
- chia/cmds/init_funcs.py +367 -0
- chia/cmds/installers.py +131 -0
- chia/cmds/keys.py +527 -0
- chia/cmds/keys_funcs.py +863 -0
- chia/cmds/netspace.py +50 -0
- chia/cmds/netspace_funcs.py +54 -0
- chia/cmds/options.py +32 -0
- chia/cmds/param_types.py +238 -0
- chia/cmds/passphrase.py +131 -0
- chia/cmds/passphrase_funcs.py +292 -0
- chia/cmds/peer.py +51 -0
- chia/cmds/peer_funcs.py +129 -0
- chia/cmds/plotnft.py +260 -0
- chia/cmds/plotnft_funcs.py +405 -0
- chia/cmds/plots.py +230 -0
- chia/cmds/plotters.py +18 -0
- chia/cmds/rpc.py +208 -0
- chia/cmds/show.py +72 -0
- chia/cmds/show_funcs.py +215 -0
- chia/cmds/signer.py +296 -0
- chia/cmds/sim.py +225 -0
- chia/cmds/sim_funcs.py +509 -0
- chia/cmds/start.py +24 -0
- chia/cmds/start_funcs.py +109 -0
- chia/cmds/stop.py +62 -0
- chia/cmds/units.py +9 -0
- chia/cmds/wallet.py +1901 -0
- chia/cmds/wallet_funcs.py +1874 -0
- chia/consensus/__init__.py +0 -0
- chia/consensus/block_body_validation.py +562 -0
- chia/consensus/block_creation.py +546 -0
- chia/consensus/block_header_validation.py +1059 -0
- chia/consensus/block_record.py +31 -0
- chia/consensus/block_rewards.py +53 -0
- chia/consensus/blockchain.py +1087 -0
- chia/consensus/blockchain_interface.py +56 -0
- chia/consensus/coinbase.py +30 -0
- chia/consensus/condition_costs.py +9 -0
- chia/consensus/constants.py +49 -0
- chia/consensus/cost_calculator.py +15 -0
- chia/consensus/default_constants.py +89 -0
- chia/consensus/deficit.py +55 -0
- chia/consensus/difficulty_adjustment.py +412 -0
- chia/consensus/find_fork_point.py +111 -0
- chia/consensus/full_block_to_block_record.py +167 -0
- chia/consensus/get_block_challenge.py +106 -0
- chia/consensus/get_block_generator.py +27 -0
- chia/consensus/make_sub_epoch_summary.py +210 -0
- chia/consensus/multiprocess_validation.py +268 -0
- chia/consensus/pos_quality.py +19 -0
- chia/consensus/pot_iterations.py +67 -0
- chia/consensus/puzzles/__init__.py +0 -0
- chia/consensus/puzzles/chialisp_deserialisation.clsp +69 -0
- chia/consensus/puzzles/chialisp_deserialisation.clsp.hex +1 -0
- chia/consensus/puzzles/rom_bootstrap_generator.clsp +37 -0
- chia/consensus/puzzles/rom_bootstrap_generator.clsp.hex +1 -0
- chia/consensus/vdf_info_computation.py +156 -0
- chia/daemon/__init__.py +0 -0
- chia/daemon/client.py +252 -0
- chia/daemon/keychain_proxy.py +502 -0
- chia/daemon/keychain_server.py +365 -0
- chia/daemon/server.py +1606 -0
- chia/daemon/windows_signal.py +56 -0
- chia/data_layer/__init__.py +0 -0
- chia/data_layer/data_layer.py +1291 -0
- chia/data_layer/data_layer_api.py +33 -0
- chia/data_layer/data_layer_errors.py +50 -0
- chia/data_layer/data_layer_server.py +170 -0
- chia/data_layer/data_layer_util.py +985 -0
- chia/data_layer/data_layer_wallet.py +1311 -0
- chia/data_layer/data_store.py +2267 -0
- chia/data_layer/dl_wallet_store.py +407 -0
- chia/data_layer/download_data.py +389 -0
- chia/data_layer/puzzles/__init__.py +0 -0
- chia/data_layer/puzzles/graftroot_dl_offers.clsp +100 -0
- chia/data_layer/puzzles/graftroot_dl_offers.clsp.hex +1 -0
- chia/data_layer/s3_plugin_config.yml +33 -0
- chia/data_layer/s3_plugin_service.py +468 -0
- chia/data_layer/util/__init__.py +0 -0
- chia/data_layer/util/benchmark.py +107 -0
- chia/data_layer/util/plugin.py +40 -0
- chia/farmer/__init__.py +0 -0
- chia/farmer/farmer.py +923 -0
- chia/farmer/farmer_api.py +820 -0
- chia/full_node/__init__.py +0 -0
- chia/full_node/bitcoin_fee_estimator.py +85 -0
- chia/full_node/block_height_map.py +271 -0
- chia/full_node/block_store.py +576 -0
- chia/full_node/bundle_tools.py +19 -0
- chia/full_node/coin_store.py +647 -0
- chia/full_node/fee_estimate.py +54 -0
- chia/full_node/fee_estimate_store.py +24 -0
- chia/full_node/fee_estimation.py +92 -0
- chia/full_node/fee_estimator.py +90 -0
- chia/full_node/fee_estimator_constants.py +38 -0
- chia/full_node/fee_estimator_interface.py +42 -0
- chia/full_node/fee_history.py +25 -0
- chia/full_node/fee_tracker.py +564 -0
- chia/full_node/full_node.py +3327 -0
- chia/full_node/full_node_api.py +2025 -0
- chia/full_node/full_node_store.py +1033 -0
- chia/full_node/hint_management.py +56 -0
- chia/full_node/hint_store.py +93 -0
- chia/full_node/mempool.py +589 -0
- chia/full_node/mempool_check_conditions.py +146 -0
- chia/full_node/mempool_manager.py +853 -0
- chia/full_node/pending_tx_cache.py +112 -0
- chia/full_node/puzzles/__init__.py +0 -0
- chia/full_node/puzzles/block_program_zero.clsp +14 -0
- chia/full_node/puzzles/block_program_zero.clsp.hex +1 -0
- chia/full_node/puzzles/decompress_coin_spend_entry.clsp +5 -0
- chia/full_node/puzzles/decompress_coin_spend_entry.clsp.hex +1 -0
- chia/full_node/puzzles/decompress_coin_spend_entry_with_prefix.clsp +7 -0
- chia/full_node/puzzles/decompress_coin_spend_entry_with_prefix.clsp.hex +1 -0
- chia/full_node/puzzles/decompress_puzzle.clsp +6 -0
- chia/full_node/puzzles/decompress_puzzle.clsp.hex +1 -0
- chia/full_node/signage_point.py +16 -0
- chia/full_node/subscriptions.py +247 -0
- chia/full_node/sync_store.py +146 -0
- chia/full_node/tx_processing_queue.py +78 -0
- chia/full_node/util/__init__.py +0 -0
- chia/full_node/weight_proof.py +1720 -0
- chia/harvester/__init__.py +0 -0
- chia/harvester/harvester.py +272 -0
- chia/harvester/harvester_api.py +380 -0
- chia/introducer/__init__.py +0 -0
- chia/introducer/introducer.py +122 -0
- chia/introducer/introducer_api.py +70 -0
- chia/legacy/__init__.py +0 -0
- chia/legacy/keyring.py +155 -0
- chia/plot_sync/__init__.py +0 -0
- chia/plot_sync/delta.py +61 -0
- chia/plot_sync/exceptions.py +56 -0
- chia/plot_sync/receiver.py +386 -0
- chia/plot_sync/sender.py +340 -0
- chia/plot_sync/util.py +43 -0
- chia/plotters/__init__.py +0 -0
- chia/plotters/bladebit.py +388 -0
- chia/plotters/chiapos.py +63 -0
- chia/plotters/madmax.py +224 -0
- chia/plotters/plotters.py +577 -0
- chia/plotters/plotters_util.py +133 -0
- chia/plotting/__init__.py +0 -0
- chia/plotting/cache.py +213 -0
- chia/plotting/check_plots.py +283 -0
- chia/plotting/create_plots.py +278 -0
- chia/plotting/manager.py +436 -0
- chia/plotting/util.py +336 -0
- chia/pools/__init__.py +0 -0
- chia/pools/pool_config.py +110 -0
- chia/pools/pool_puzzles.py +459 -0
- chia/pools/pool_wallet.py +933 -0
- chia/pools/pool_wallet_info.py +118 -0
- chia/pools/puzzles/__init__.py +0 -0
- chia/pools/puzzles/pool_member_innerpuz.clsp +70 -0
- chia/pools/puzzles/pool_member_innerpuz.clsp.hex +1 -0
- chia/pools/puzzles/pool_waitingroom_innerpuz.clsp +69 -0
- chia/pools/puzzles/pool_waitingroom_innerpuz.clsp.hex +1 -0
- chia/protocols/__init__.py +0 -0
- chia/protocols/farmer_protocol.py +102 -0
- chia/protocols/full_node_protocol.py +219 -0
- chia/protocols/harvester_protocol.py +216 -0
- chia/protocols/introducer_protocol.py +25 -0
- chia/protocols/pool_protocol.py +177 -0
- chia/protocols/protocol_message_types.py +139 -0
- chia/protocols/protocol_state_machine.py +87 -0
- chia/protocols/protocol_timing.py +8 -0
- chia/protocols/shared_protocol.py +86 -0
- chia/protocols/timelord_protocol.py +93 -0
- chia/protocols/wallet_protocol.py +401 -0
- chia/py.typed +0 -0
- chia/rpc/__init__.py +0 -0
- chia/rpc/crawler_rpc_api.py +80 -0
- chia/rpc/data_layer_rpc_api.py +644 -0
- chia/rpc/data_layer_rpc_client.py +188 -0
- chia/rpc/data_layer_rpc_util.py +58 -0
- chia/rpc/farmer_rpc_api.py +365 -0
- chia/rpc/farmer_rpc_client.py +86 -0
- chia/rpc/full_node_rpc_api.py +959 -0
- chia/rpc/full_node_rpc_client.py +292 -0
- chia/rpc/harvester_rpc_api.py +141 -0
- chia/rpc/harvester_rpc_client.py +54 -0
- chia/rpc/rpc_client.py +164 -0
- chia/rpc/rpc_server.py +521 -0
- chia/rpc/timelord_rpc_api.py +32 -0
- chia/rpc/util.py +93 -0
- chia/rpc/wallet_request_types.py +904 -0
- chia/rpc/wallet_rpc_api.py +4943 -0
- chia/rpc/wallet_rpc_client.py +1814 -0
- chia/seeder/__init__.py +0 -0
- chia/seeder/crawl_store.py +425 -0
- chia/seeder/crawler.py +410 -0
- chia/seeder/crawler_api.py +135 -0
- chia/seeder/dns_server.py +593 -0
- chia/seeder/peer_record.py +146 -0
- chia/seeder/start_crawler.py +92 -0
- chia/server/__init__.py +0 -0
- chia/server/address_manager.py +658 -0
- chia/server/address_manager_store.py +237 -0
- chia/server/api_protocol.py +116 -0
- chia/server/capabilities.py +24 -0
- chia/server/chia_policy.py +346 -0
- chia/server/introducer_peers.py +76 -0
- chia/server/node_discovery.py +714 -0
- chia/server/outbound_message.py +33 -0
- chia/server/rate_limit_numbers.py +214 -0
- chia/server/rate_limits.py +153 -0
- chia/server/server.py +741 -0
- chia/server/signal_handlers.py +120 -0
- chia/server/ssl_context.py +32 -0
- chia/server/start_data_layer.py +151 -0
- chia/server/start_farmer.py +98 -0
- chia/server/start_full_node.py +112 -0
- chia/server/start_harvester.py +93 -0
- chia/server/start_introducer.py +81 -0
- chia/server/start_service.py +316 -0
- chia/server/start_timelord.py +89 -0
- chia/server/start_wallet.py +113 -0
- chia/server/upnp.py +118 -0
- chia/server/ws_connection.py +766 -0
- chia/simulator/__init__.py +0 -0
- chia/simulator/add_blocks_in_batches.py +54 -0
- chia/simulator/block_tools.py +2054 -0
- chia/simulator/full_node_simulator.py +794 -0
- chia/simulator/keyring.py +128 -0
- chia/simulator/setup_services.py +506 -0
- chia/simulator/simulator_constants.py +13 -0
- chia/simulator/simulator_full_node_rpc_api.py +99 -0
- chia/simulator/simulator_full_node_rpc_client.py +60 -0
- chia/simulator/simulator_protocol.py +29 -0
- chia/simulator/simulator_test_tools.py +164 -0
- chia/simulator/socket.py +24 -0
- chia/simulator/ssl_certs.py +114 -0
- chia/simulator/ssl_certs_1.py +697 -0
- chia/simulator/ssl_certs_10.py +697 -0
- chia/simulator/ssl_certs_2.py +697 -0
- chia/simulator/ssl_certs_3.py +697 -0
- chia/simulator/ssl_certs_4.py +697 -0
- chia/simulator/ssl_certs_5.py +697 -0
- chia/simulator/ssl_certs_6.py +697 -0
- chia/simulator/ssl_certs_7.py +697 -0
- chia/simulator/ssl_certs_8.py +697 -0
- chia/simulator/ssl_certs_9.py +697 -0
- chia/simulator/start_simulator.py +143 -0
- chia/simulator/wallet_tools.py +246 -0
- chia/ssl/__init__.py +0 -0
- chia/ssl/chia_ca.crt +19 -0
- chia/ssl/chia_ca.key +28 -0
- chia/ssl/create_ssl.py +249 -0
- chia/ssl/dst_root_ca.pem +20 -0
- chia/timelord/__init__.py +0 -0
- chia/timelord/iters_from_block.py +50 -0
- chia/timelord/timelord.py +1226 -0
- chia/timelord/timelord_api.py +138 -0
- chia/timelord/timelord_launcher.py +190 -0
- chia/timelord/timelord_state.py +244 -0
- chia/timelord/types.py +22 -0
- chia/types/__init__.py +0 -0
- chia/types/aliases.py +35 -0
- chia/types/block_protocol.py +20 -0
- chia/types/blockchain_format/__init__.py +0 -0
- chia/types/blockchain_format/classgroup.py +5 -0
- chia/types/blockchain_format/coin.py +28 -0
- chia/types/blockchain_format/foliage.py +8 -0
- chia/types/blockchain_format/pool_target.py +5 -0
- chia/types/blockchain_format/program.py +269 -0
- chia/types/blockchain_format/proof_of_space.py +135 -0
- chia/types/blockchain_format/reward_chain_block.py +6 -0
- chia/types/blockchain_format/serialized_program.py +5 -0
- chia/types/blockchain_format/sized_bytes.py +11 -0
- chia/types/blockchain_format/slots.py +9 -0
- chia/types/blockchain_format/sub_epoch_summary.py +5 -0
- chia/types/blockchain_format/tree_hash.py +72 -0
- chia/types/blockchain_format/vdf.py +86 -0
- chia/types/clvm_cost.py +13 -0
- chia/types/coin_record.py +43 -0
- chia/types/coin_spend.py +115 -0
- chia/types/condition_opcodes.py +73 -0
- chia/types/condition_with_args.py +16 -0
- chia/types/eligible_coin_spends.py +365 -0
- chia/types/end_of_slot_bundle.py +5 -0
- chia/types/fee_rate.py +38 -0
- chia/types/full_block.py +5 -0
- chia/types/generator_types.py +13 -0
- chia/types/header_block.py +5 -0
- chia/types/internal_mempool_item.py +18 -0
- chia/types/mempool_inclusion_status.py +9 -0
- chia/types/mempool_item.py +85 -0
- chia/types/mempool_submission_status.py +30 -0
- chia/types/mojos.py +7 -0
- chia/types/peer_info.py +64 -0
- chia/types/signing_mode.py +29 -0
- chia/types/spend_bundle.py +30 -0
- chia/types/spend_bundle_conditions.py +7 -0
- chia/types/transaction_queue_entry.py +55 -0
- chia/types/unfinished_block.py +5 -0
- chia/types/unfinished_header_block.py +37 -0
- chia/types/validation_state.py +14 -0
- chia/types/weight_proof.py +49 -0
- chia/util/__init__.py +0 -0
- chia/util/action_scope.py +168 -0
- chia/util/async_pool.py +226 -0
- chia/util/augmented_chain.py +134 -0
- chia/util/batches.py +42 -0
- chia/util/bech32m.py +126 -0
- chia/util/beta_metrics.py +119 -0
- chia/util/block_cache.py +56 -0
- chia/util/byte_types.py +12 -0
- chia/util/check_fork_next_block.py +33 -0
- chia/util/chia_logging.py +144 -0
- chia/util/chia_version.py +33 -0
- chia/util/collection.py +17 -0
- chia/util/condition_tools.py +201 -0
- chia/util/config.py +367 -0
- chia/util/cpu.py +22 -0
- chia/util/db_synchronous.py +23 -0
- chia/util/db_version.py +32 -0
- chia/util/db_wrapper.py +430 -0
- chia/util/default_root.py +27 -0
- chia/util/dump_keyring.py +93 -0
- chia/util/english.txt +2048 -0
- chia/util/errors.py +353 -0
- chia/util/file_keyring.py +469 -0
- chia/util/files.py +97 -0
- chia/util/full_block_utils.py +345 -0
- chia/util/generator_tools.py +72 -0
- chia/util/hash.py +31 -0
- chia/util/initial-config.yaml +694 -0
- chia/util/inline_executor.py +26 -0
- chia/util/ints.py +19 -0
- chia/util/ip_address.py +39 -0
- chia/util/json_util.py +37 -0
- chia/util/keychain.py +676 -0
- chia/util/keyring_wrapper.py +327 -0
- chia/util/limited_semaphore.py +41 -0
- chia/util/lock.py +49 -0
- chia/util/log_exceptions.py +32 -0
- chia/util/logging.py +36 -0
- chia/util/lru_cache.py +31 -0
- chia/util/math.py +20 -0
- chia/util/network.py +182 -0
- chia/util/paginator.py +48 -0
- chia/util/path.py +31 -0
- chia/util/permissions.py +20 -0
- chia/util/prev_transaction_block.py +21 -0
- chia/util/priority_mutex.py +95 -0
- chia/util/profiler.py +197 -0
- chia/util/recursive_replace.py +24 -0
- chia/util/safe_cancel_task.py +16 -0
- chia/util/service_groups.py +47 -0
- chia/util/setproctitle.py +22 -0
- chia/util/significant_bits.py +32 -0
- chia/util/ssl_check.py +213 -0
- chia/util/streamable.py +642 -0
- chia/util/task_referencer.py +59 -0
- chia/util/task_timing.py +382 -0
- chia/util/timing.py +67 -0
- chia/util/vdf_prover.py +30 -0
- chia/util/virtual_project_analysis.py +540 -0
- chia/util/ws_message.py +66 -0
- chia/wallet/__init__.py +0 -0
- chia/wallet/cat_wallet/__init__.py +0 -0
- chia/wallet/cat_wallet/cat_constants.py +75 -0
- chia/wallet/cat_wallet/cat_info.py +47 -0
- chia/wallet/cat_wallet/cat_outer_puzzle.py +120 -0
- chia/wallet/cat_wallet/cat_utils.py +164 -0
- chia/wallet/cat_wallet/cat_wallet.py +855 -0
- chia/wallet/cat_wallet/dao_cat_info.py +28 -0
- chia/wallet/cat_wallet/dao_cat_wallet.py +669 -0
- chia/wallet/cat_wallet/lineage_store.py +74 -0
- chia/wallet/cat_wallet/puzzles/__init__.py +0 -0
- chia/wallet/cat_wallet/puzzles/cat_truths.clib +31 -0
- chia/wallet/cat_wallet/puzzles/cat_v2.clsp +397 -0
- chia/wallet/cat_wallet/puzzles/cat_v2.clsp.hex +1 -0
- chia/wallet/cat_wallet/puzzles/delegated_tail.clsp +25 -0
- chia/wallet/cat_wallet/puzzles/delegated_tail.clsp.hex +1 -0
- chia/wallet/cat_wallet/puzzles/everything_with_signature.clsp +15 -0
- chia/wallet/cat_wallet/puzzles/everything_with_signature.clsp.hex +1 -0
- chia/wallet/cat_wallet/puzzles/genesis_by_coin_id.clsp +26 -0
- chia/wallet/cat_wallet/puzzles/genesis_by_coin_id.clsp.hex +1 -0
- chia/wallet/cat_wallet/puzzles/genesis_by_coin_id_or_singleton.clsp +42 -0
- chia/wallet/cat_wallet/puzzles/genesis_by_coin_id_or_singleton.clsp.hex +1 -0
- chia/wallet/cat_wallet/puzzles/genesis_by_puzzle_hash.clsp +24 -0
- chia/wallet/cat_wallet/puzzles/genesis_by_puzzle_hash.clsp.hex +1 -0
- chia/wallet/coin_selection.py +188 -0
- chia/wallet/conditions.py +1512 -0
- chia/wallet/dao_wallet/__init__.py +0 -0
- chia/wallet/dao_wallet/dao_info.py +61 -0
- chia/wallet/dao_wallet/dao_utils.py +811 -0
- chia/wallet/dao_wallet/dao_wallet.py +2119 -0
- chia/wallet/db_wallet/__init__.py +0 -0
- chia/wallet/db_wallet/db_wallet_puzzles.py +111 -0
- chia/wallet/derivation_record.py +30 -0
- chia/wallet/derive_keys.py +146 -0
- chia/wallet/did_wallet/__init__.py +0 -0
- chia/wallet/did_wallet/did_info.py +39 -0
- chia/wallet/did_wallet/did_wallet.py +1494 -0
- chia/wallet/did_wallet/did_wallet_puzzles.py +221 -0
- chia/wallet/did_wallet/puzzles/__init__.py +0 -0
- chia/wallet/did_wallet/puzzles/did_innerpuz.clsp +135 -0
- chia/wallet/did_wallet/puzzles/did_innerpuz.clsp.hex +1 -0
- chia/wallet/driver_protocol.py +26 -0
- chia/wallet/key_val_store.py +55 -0
- chia/wallet/lineage_proof.py +58 -0
- chia/wallet/nft_wallet/__init__.py +0 -0
- chia/wallet/nft_wallet/metadata_outer_puzzle.py +92 -0
- chia/wallet/nft_wallet/nft_info.py +120 -0
- chia/wallet/nft_wallet/nft_puzzles.py +305 -0
- chia/wallet/nft_wallet/nft_wallet.py +1687 -0
- chia/wallet/nft_wallet/ownership_outer_puzzle.py +101 -0
- chia/wallet/nft_wallet/puzzles/__init__.py +0 -0
- chia/wallet/nft_wallet/puzzles/create_nft_launcher_from_did.clsp +6 -0
- chia/wallet/nft_wallet/puzzles/create_nft_launcher_from_did.clsp.hex +1 -0
- chia/wallet/nft_wallet/puzzles/nft_intermediate_launcher.clsp +6 -0
- chia/wallet/nft_wallet/puzzles/nft_intermediate_launcher.clsp.hex +1 -0
- chia/wallet/nft_wallet/puzzles/nft_metadata_updater_default.clsp +30 -0
- chia/wallet/nft_wallet/puzzles/nft_metadata_updater_default.clsp.hex +1 -0
- chia/wallet/nft_wallet/puzzles/nft_metadata_updater_updateable.clsp +28 -0
- chia/wallet/nft_wallet/puzzles/nft_metadata_updater_updateable.clsp.hex +1 -0
- chia/wallet/nft_wallet/puzzles/nft_ownership_layer.clsp +100 -0
- chia/wallet/nft_wallet/puzzles/nft_ownership_layer.clsp.hex +1 -0
- chia/wallet/nft_wallet/puzzles/nft_ownership_transfer_program_one_way_claim_with_royalties.clsp +78 -0
- chia/wallet/nft_wallet/puzzles/nft_ownership_transfer_program_one_way_claim_with_royalties.clsp.hex +1 -0
- chia/wallet/nft_wallet/puzzles/nft_state_layer.clsp +74 -0
- chia/wallet/nft_wallet/puzzles/nft_state_layer.clsp.hex +1 -0
- chia/wallet/nft_wallet/singleton_outer_puzzle.py +101 -0
- chia/wallet/nft_wallet/transfer_program_puzzle.py +82 -0
- chia/wallet/nft_wallet/uncurry_nft.py +217 -0
- chia/wallet/notification_manager.py +117 -0
- chia/wallet/notification_store.py +178 -0
- chia/wallet/outer_puzzles.py +84 -0
- chia/wallet/payment.py +33 -0
- chia/wallet/puzzle_drivers.py +118 -0
- chia/wallet/puzzles/__init__.py +0 -0
- chia/wallet/puzzles/augmented_condition.clsp +13 -0
- chia/wallet/puzzles/augmented_condition.clsp.hex +1 -0
- chia/wallet/puzzles/clawback/__init__.py +0 -0
- chia/wallet/puzzles/clawback/drivers.py +188 -0
- chia/wallet/puzzles/clawback/metadata.py +38 -0
- chia/wallet/puzzles/clawback/puzzle_decorator.py +67 -0
- chia/wallet/puzzles/condition_codes.clib +77 -0
- chia/wallet/puzzles/curry-and-treehash.clib +102 -0
- chia/wallet/puzzles/curry.clib +135 -0
- chia/wallet/puzzles/curry_by_index.clib +16 -0
- chia/wallet/puzzles/dao_cat_eve.clsp +17 -0
- chia/wallet/puzzles/dao_cat_eve.clsp.hex +1 -0
- chia/wallet/puzzles/dao_cat_launcher.clsp +36 -0
- chia/wallet/puzzles/dao_cat_launcher.clsp.hex +1 -0
- chia/wallet/puzzles/dao_finished_state.clsp +35 -0
- chia/wallet/puzzles/dao_finished_state.clsp.hex +1 -0
- chia/wallet/puzzles/dao_finished_state.clsp.hex.sha256tree +1 -0
- chia/wallet/puzzles/dao_lockup.clsp +288 -0
- chia/wallet/puzzles/dao_lockup.clsp.hex +1 -0
- chia/wallet/puzzles/dao_lockup.clsp.hex.sha256tree +1 -0
- chia/wallet/puzzles/dao_proposal.clsp +377 -0
- chia/wallet/puzzles/dao_proposal.clsp.hex +1 -0
- chia/wallet/puzzles/dao_proposal.clsp.hex.sha256tree +1 -0
- chia/wallet/puzzles/dao_proposal_timer.clsp +78 -0
- chia/wallet/puzzles/dao_proposal_timer.clsp.hex +1 -0
- chia/wallet/puzzles/dao_proposal_timer.clsp.hex.sha256tree +1 -0
- chia/wallet/puzzles/dao_proposal_validator.clsp +87 -0
- chia/wallet/puzzles/dao_proposal_validator.clsp.hex +1 -0
- chia/wallet/puzzles/dao_proposal_validator.clsp.hex.sha256tree +1 -0
- chia/wallet/puzzles/dao_spend_p2_singleton_v2.clsp +240 -0
- chia/wallet/puzzles/dao_spend_p2_singleton_v2.clsp.hex +1 -0
- chia/wallet/puzzles/dao_spend_p2_singleton_v2.clsp.hex.sha256tree +1 -0
- chia/wallet/puzzles/dao_treasury.clsp +115 -0
- chia/wallet/puzzles/dao_treasury.clsp.hex +1 -0
- chia/wallet/puzzles/dao_update_proposal.clsp +44 -0
- chia/wallet/puzzles/dao_update_proposal.clsp.hex +1 -0
- chia/wallet/puzzles/deployed_puzzle_hashes.json +67 -0
- chia/wallet/puzzles/json.clib +25 -0
- chia/wallet/puzzles/load_clvm.py +161 -0
- chia/wallet/puzzles/merkle_utils.clib +18 -0
- chia/wallet/puzzles/notification.clsp +7 -0
- chia/wallet/puzzles/notification.clsp.hex +1 -0
- chia/wallet/puzzles/p2_1_of_n.clsp +22 -0
- chia/wallet/puzzles/p2_1_of_n.clsp.hex +1 -0
- chia/wallet/puzzles/p2_conditions.clsp +3 -0
- chia/wallet/puzzles/p2_conditions.clsp.hex +1 -0
- chia/wallet/puzzles/p2_conditions.py +26 -0
- chia/wallet/puzzles/p2_delegated_conditions.clsp +18 -0
- chia/wallet/puzzles/p2_delegated_conditions.clsp.hex +1 -0
- chia/wallet/puzzles/p2_delegated_conditions.py +21 -0
- chia/wallet/puzzles/p2_delegated_puzzle.clsp +19 -0
- chia/wallet/puzzles/p2_delegated_puzzle.clsp.hex +1 -0
- chia/wallet/puzzles/p2_delegated_puzzle.py +34 -0
- chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.clsp +91 -0
- chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.clsp.hex +1 -0
- chia/wallet/puzzles/p2_delegated_puzzle_or_hidden_puzzle.py +160 -0
- chia/wallet/puzzles/p2_m_of_n_delegate_direct.clsp +108 -0
- chia/wallet/puzzles/p2_m_of_n_delegate_direct.clsp.hex +1 -0
- chia/wallet/puzzles/p2_m_of_n_delegate_direct.py +21 -0
- chia/wallet/puzzles/p2_parent.clsp +19 -0
- chia/wallet/puzzles/p2_parent.clsp.hex +1 -0
- chia/wallet/puzzles/p2_puzzle_hash.clsp +18 -0
- chia/wallet/puzzles/p2_puzzle_hash.clsp.hex +1 -0
- chia/wallet/puzzles/p2_puzzle_hash.py +27 -0
- chia/wallet/puzzles/p2_singleton.clsp +30 -0
- chia/wallet/puzzles/p2_singleton.clsp.hex +1 -0
- chia/wallet/puzzles/p2_singleton_aggregator.clsp +81 -0
- chia/wallet/puzzles/p2_singleton_aggregator.clsp.hex +1 -0
- chia/wallet/puzzles/p2_singleton_or_delayed_puzhash.clsp +50 -0
- chia/wallet/puzzles/p2_singleton_or_delayed_puzhash.clsp.hex +1 -0
- chia/wallet/puzzles/p2_singleton_via_delegated_puzzle.clsp +47 -0
- chia/wallet/puzzles/p2_singleton_via_delegated_puzzle.clsp.hex +1 -0
- chia/wallet/puzzles/puzzle_utils.py +34 -0
- chia/wallet/puzzles/settlement_payments.clsp +49 -0
- chia/wallet/puzzles/settlement_payments.clsp.hex +1 -0
- chia/wallet/puzzles/sha256tree.clib +11 -0
- chia/wallet/puzzles/singleton_launcher.clsp +16 -0
- chia/wallet/puzzles/singleton_launcher.clsp.hex +1 -0
- chia/wallet/puzzles/singleton_top_layer.clsp +177 -0
- chia/wallet/puzzles/singleton_top_layer.clsp.hex +1 -0
- chia/wallet/puzzles/singleton_top_layer.py +296 -0
- chia/wallet/puzzles/singleton_top_layer_v1_1.clsp +107 -0
- chia/wallet/puzzles/singleton_top_layer_v1_1.clsp.hex +1 -0
- chia/wallet/puzzles/singleton_top_layer_v1_1.py +345 -0
- chia/wallet/puzzles/singleton_truths.clib +21 -0
- chia/wallet/puzzles/tails.py +348 -0
- chia/wallet/puzzles/utility_macros.clib +48 -0
- chia/wallet/signer_protocol.py +125 -0
- chia/wallet/singleton.py +106 -0
- chia/wallet/singleton_record.py +30 -0
- chia/wallet/trade_manager.py +1102 -0
- chia/wallet/trade_record.py +67 -0
- chia/wallet/trading/__init__.py +0 -0
- chia/wallet/trading/offer.py +702 -0
- chia/wallet/trading/trade_status.py +13 -0
- chia/wallet/trading/trade_store.py +526 -0
- chia/wallet/transaction_record.py +158 -0
- chia/wallet/transaction_sorting.py +14 -0
- chia/wallet/uncurried_puzzle.py +17 -0
- chia/wallet/util/__init__.py +0 -0
- chia/wallet/util/address_type.py +55 -0
- chia/wallet/util/blind_signer_tl.py +164 -0
- chia/wallet/util/clvm_streamable.py +203 -0
- chia/wallet/util/compute_hints.py +66 -0
- chia/wallet/util/compute_memos.py +43 -0
- chia/wallet/util/curry_and_treehash.py +91 -0
- chia/wallet/util/debug_spend_bundle.py +232 -0
- chia/wallet/util/merkle_tree.py +100 -0
- chia/wallet/util/merkle_utils.py +102 -0
- chia/wallet/util/new_peak_queue.py +82 -0
- chia/wallet/util/notifications.py +12 -0
- chia/wallet/util/peer_request_cache.py +174 -0
- chia/wallet/util/pprint.py +39 -0
- chia/wallet/util/puzzle_compression.py +95 -0
- chia/wallet/util/puzzle_decorator.py +100 -0
- chia/wallet/util/puzzle_decorator_type.py +7 -0
- chia/wallet/util/query_filter.py +59 -0
- chia/wallet/util/transaction_type.py +23 -0
- chia/wallet/util/tx_config.py +158 -0
- chia/wallet/util/wallet_sync_utils.py +351 -0
- chia/wallet/util/wallet_types.py +72 -0
- chia/wallet/vc_wallet/__init__.py +0 -0
- chia/wallet/vc_wallet/cr_cat_drivers.py +664 -0
- chia/wallet/vc_wallet/cr_cat_wallet.py +877 -0
- chia/wallet/vc_wallet/cr_outer_puzzle.py +102 -0
- chia/wallet/vc_wallet/cr_puzzles/__init__.py +0 -0
- chia/wallet/vc_wallet/cr_puzzles/conditions_w_fee_announce.clsp +3 -0
- chia/wallet/vc_wallet/cr_puzzles/conditions_w_fee_announce.clsp.hex +1 -0
- chia/wallet/vc_wallet/cr_puzzles/credential_restriction.clsp +304 -0
- chia/wallet/vc_wallet/cr_puzzles/credential_restriction.clsp.hex +1 -0
- chia/wallet/vc_wallet/cr_puzzles/flag_proofs_checker.clsp +45 -0
- chia/wallet/vc_wallet/cr_puzzles/flag_proofs_checker.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_drivers.py +838 -0
- chia/wallet/vc_wallet/vc_puzzles/__init__.py +0 -0
- chia/wallet/vc_wallet/vc_puzzles/covenant_layer.clsp +30 -0
- chia/wallet/vc_wallet/vc_puzzles/covenant_layer.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/eml_covenant_morpher.clsp +75 -0
- chia/wallet/vc_wallet/vc_puzzles/eml_covenant_morpher.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/eml_transfer_program_covenant_adapter.clsp +32 -0
- chia/wallet/vc_wallet/vc_puzzles/eml_transfer_program_covenant_adapter.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/eml_update_metadata_with_DID.clsp +80 -0
- chia/wallet/vc_wallet/vc_puzzles/eml_update_metadata_with_DID.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/exigent_metadata_layer.clsp +163 -0
- chia/wallet/vc_wallet/vc_puzzles/exigent_metadata_layer.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/p2_announced_delegated_puzzle.clsp +16 -0
- chia/wallet/vc_wallet/vc_puzzles/p2_announced_delegated_puzzle.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/standard_vc_backdoor_puzzle.clsp +74 -0
- chia/wallet/vc_wallet/vc_puzzles/standard_vc_backdoor_puzzle.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/std_parent_morpher.clsp +23 -0
- chia/wallet/vc_wallet/vc_puzzles/std_parent_morpher.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_puzzles/viral_backdoor.clsp +64 -0
- chia/wallet/vc_wallet/vc_puzzles/viral_backdoor.clsp.hex +1 -0
- chia/wallet/vc_wallet/vc_store.py +263 -0
- chia/wallet/vc_wallet/vc_wallet.py +638 -0
- chia/wallet/wallet.py +698 -0
- chia/wallet/wallet_action_scope.py +96 -0
- chia/wallet/wallet_blockchain.py +244 -0
- chia/wallet/wallet_coin_record.py +72 -0
- chia/wallet/wallet_coin_store.py +351 -0
- chia/wallet/wallet_info.py +35 -0
- chia/wallet/wallet_interested_store.py +188 -0
- chia/wallet/wallet_nft_store.py +279 -0
- chia/wallet/wallet_node.py +1765 -0
- chia/wallet/wallet_node_api.py +207 -0
- chia/wallet/wallet_pool_store.py +119 -0
- chia/wallet/wallet_protocol.py +90 -0
- chia/wallet/wallet_puzzle_store.py +396 -0
- chia/wallet/wallet_retry_store.py +70 -0
- chia/wallet/wallet_singleton_store.py +259 -0
- chia/wallet/wallet_spend_bundle.py +25 -0
- chia/wallet/wallet_state_manager.py +2819 -0
- chia/wallet/wallet_transaction_store.py +496 -0
- chia/wallet/wallet_user_store.py +110 -0
- chia/wallet/wallet_weight_proof_handler.py +126 -0
- chia_blockchain-2.5.1rc1.dist-info/LICENSE +201 -0
- chia_blockchain-2.5.1rc1.dist-info/METADATA +156 -0
- chia_blockchain-2.5.1rc1.dist-info/RECORD +1042 -0
- chia_blockchain-2.5.1rc1.dist-info/WHEEL +4 -0
- chia_blockchain-2.5.1rc1.dist-info/entry_points.txt +17 -0
- mozilla-ca/cacert.pem +3611 -0
|
@@ -0,0 +1,2025 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
import time
|
|
6
|
+
import traceback
|
|
7
|
+
from collections.abc import Collection
|
|
8
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
from typing import TYPE_CHECKING, ClassVar, Optional, cast
|
|
11
|
+
|
|
12
|
+
import anyio
|
|
13
|
+
from chia_rs import (
|
|
14
|
+
AugSchemeMPL,
|
|
15
|
+
G1Element,
|
|
16
|
+
G2Element,
|
|
17
|
+
MerkleSet,
|
|
18
|
+
additions_and_removals,
|
|
19
|
+
get_flags_for_height_and_constants,
|
|
20
|
+
)
|
|
21
|
+
from chiabip158 import PyBIP158
|
|
22
|
+
|
|
23
|
+
from chia.consensus.block_creation import create_unfinished_block
|
|
24
|
+
from chia.consensus.block_record import BlockRecord
|
|
25
|
+
from chia.consensus.blockchain import BlockchainMutexPriority
|
|
26
|
+
from chia.consensus.get_block_generator import get_block_generator
|
|
27
|
+
from chia.consensus.pot_iterations import calculate_ip_iters, calculate_iterations_quality, calculate_sp_iters
|
|
28
|
+
from chia.full_node.bundle_tools import simple_solution_generator, simple_solution_generator_backrefs
|
|
29
|
+
from chia.full_node.coin_store import CoinStore
|
|
30
|
+
from chia.full_node.fee_estimate import FeeEstimate, FeeEstimateGroup, fee_rate_v2_to_v1
|
|
31
|
+
from chia.full_node.fee_estimator_interface import FeeEstimatorInterface
|
|
32
|
+
from chia.full_node.mempool_check_conditions import get_puzzle_and_solution_for_coin
|
|
33
|
+
from chia.full_node.signage_point import SignagePoint
|
|
34
|
+
from chia.full_node.tx_processing_queue import TransactionQueueFull
|
|
35
|
+
from chia.protocols import farmer_protocol, full_node_protocol, introducer_protocol, timelord_protocol, wallet_protocol
|
|
36
|
+
from chia.protocols.full_node_protocol import RejectBlock, RejectBlocks
|
|
37
|
+
from chia.protocols.protocol_message_types import ProtocolMessageTypes
|
|
38
|
+
from chia.protocols.protocol_timing import RATE_LIMITER_BAN_SECONDS
|
|
39
|
+
from chia.protocols.shared_protocol import Capability
|
|
40
|
+
from chia.protocols.wallet_protocol import (
|
|
41
|
+
CoinState,
|
|
42
|
+
PuzzleSolutionResponse,
|
|
43
|
+
RejectBlockHeaders,
|
|
44
|
+
RejectHeaderBlocks,
|
|
45
|
+
RejectHeaderRequest,
|
|
46
|
+
RespondFeeEstimates,
|
|
47
|
+
RespondSESInfo,
|
|
48
|
+
)
|
|
49
|
+
from chia.server.api_protocol import ApiMetadata
|
|
50
|
+
from chia.server.outbound_message import Message, make_msg
|
|
51
|
+
from chia.server.server import ChiaServer
|
|
52
|
+
from chia.server.ws_connection import WSChiaConnection
|
|
53
|
+
from chia.types.block_protocol import BlockInfo
|
|
54
|
+
from chia.types.blockchain_format.coin import Coin, hash_coin_ids
|
|
55
|
+
from chia.types.blockchain_format.foliage import FoliageBlockData, FoliageTransactionBlock
|
|
56
|
+
from chia.types.blockchain_format.pool_target import PoolTarget
|
|
57
|
+
from chia.types.blockchain_format.proof_of_space import verify_and_get_quality_string
|
|
58
|
+
from chia.types.blockchain_format.reward_chain_block import RewardChainBlockUnfinished
|
|
59
|
+
from chia.types.blockchain_format.sized_bytes import bytes32
|
|
60
|
+
from chia.types.blockchain_format.sub_epoch_summary import SubEpochSummary
|
|
61
|
+
from chia.types.coin_record import CoinRecord
|
|
62
|
+
from chia.types.end_of_slot_bundle import EndOfSubSlotBundle
|
|
63
|
+
from chia.types.full_block import FullBlock
|
|
64
|
+
from chia.types.generator_types import BlockGenerator
|
|
65
|
+
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
|
|
66
|
+
from chia.types.peer_info import PeerInfo
|
|
67
|
+
from chia.types.spend_bundle import SpendBundle
|
|
68
|
+
from chia.types.transaction_queue_entry import TransactionQueueEntry
|
|
69
|
+
from chia.types.unfinished_block import UnfinishedBlock
|
|
70
|
+
from chia.util.batches import to_batches
|
|
71
|
+
from chia.util.db_wrapper import SQLITE_MAX_VARIABLE_NUMBER
|
|
72
|
+
from chia.util.full_block_utils import get_height_and_tx_status_from_block, header_block_from_block
|
|
73
|
+
from chia.util.generator_tools import get_block_header
|
|
74
|
+
from chia.util.hash import std_hash
|
|
75
|
+
from chia.util.ints import uint8, uint32, uint64, uint128
|
|
76
|
+
from chia.util.limited_semaphore import LimitedSemaphoreFullError
|
|
77
|
+
from chia.util.task_referencer import create_referenced_task
|
|
78
|
+
|
|
79
|
+
if TYPE_CHECKING:
|
|
80
|
+
from chia.full_node.full_node import FullNode
|
|
81
|
+
else:
|
|
82
|
+
FullNode = object
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class FullNodeAPI:
|
|
86
|
+
if TYPE_CHECKING:
|
|
87
|
+
from chia.server.api_protocol import ApiProtocol
|
|
88
|
+
|
|
89
|
+
_protocol_check: ClassVar[ApiProtocol] = cast("FullNodeAPI", None)
|
|
90
|
+
|
|
91
|
+
log: logging.Logger
|
|
92
|
+
full_node: FullNode
|
|
93
|
+
executor: ThreadPoolExecutor
|
|
94
|
+
metadata: ClassVar[ApiMetadata] = ApiMetadata()
|
|
95
|
+
|
|
96
|
+
def __init__(self, full_node: FullNode) -> None:
|
|
97
|
+
self.log = logging.getLogger(__name__)
|
|
98
|
+
self.full_node = full_node
|
|
99
|
+
self.executor = ThreadPoolExecutor(max_workers=1)
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def server(self) -> ChiaServer:
|
|
103
|
+
assert self.full_node.server is not None
|
|
104
|
+
return self.full_node.server
|
|
105
|
+
|
|
106
|
+
def ready(self) -> bool:
|
|
107
|
+
return self.full_node.initialized
|
|
108
|
+
|
|
109
|
+
@metadata.request(peer_required=True, reply_types=[ProtocolMessageTypes.respond_peers])
|
|
110
|
+
async def request_peers(
|
|
111
|
+
self, _request: full_node_protocol.RequestPeers, peer: WSChiaConnection
|
|
112
|
+
) -> Optional[Message]:
|
|
113
|
+
if peer.peer_server_port is None:
|
|
114
|
+
return None
|
|
115
|
+
peer_info = PeerInfo(peer.peer_info.host, peer.peer_server_port)
|
|
116
|
+
if self.full_node.full_node_peers is not None:
|
|
117
|
+
msg = await self.full_node.full_node_peers.request_peers(peer_info)
|
|
118
|
+
return msg
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
@metadata.request(peer_required=True)
|
|
122
|
+
async def respond_peers(
|
|
123
|
+
self, request: full_node_protocol.RespondPeers, peer: WSChiaConnection
|
|
124
|
+
) -> Optional[Message]:
|
|
125
|
+
self.log.debug(f"Received {len(request.peer_list)} peers")
|
|
126
|
+
if self.full_node.full_node_peers is not None:
|
|
127
|
+
await self.full_node.full_node_peers.add_peers(request.peer_list, peer.get_peer_info(), True)
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
@metadata.request(peer_required=True)
|
|
131
|
+
async def respond_peers_introducer(
|
|
132
|
+
self, request: introducer_protocol.RespondPeersIntroducer, peer: WSChiaConnection
|
|
133
|
+
) -> Optional[Message]:
|
|
134
|
+
self.log.debug(f"Received {len(request.peer_list)} peers from introducer")
|
|
135
|
+
if self.full_node.full_node_peers is not None:
|
|
136
|
+
await self.full_node.full_node_peers.add_peers(request.peer_list, peer.get_peer_info(), False)
|
|
137
|
+
|
|
138
|
+
await peer.close()
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
@metadata.request(peer_required=True, execute_task=True)
|
|
142
|
+
async def new_peak(self, request: full_node_protocol.NewPeak, peer: WSChiaConnection) -> None:
|
|
143
|
+
"""
|
|
144
|
+
A peer notifies us that they have added a new peak to their blockchain. If we don't have it,
|
|
145
|
+
we can ask for it.
|
|
146
|
+
"""
|
|
147
|
+
# this semaphore limits the number of tasks that can call new_peak() at
|
|
148
|
+
# the same time, since it can be expensive
|
|
149
|
+
try:
|
|
150
|
+
async with self.full_node.new_peak_sem.acquire():
|
|
151
|
+
await self.full_node.new_peak(request, peer)
|
|
152
|
+
except LimitedSemaphoreFullError:
|
|
153
|
+
self.log.debug("Ignoring NewPeak, limited semaphore full: %s %s", peer.get_peer_logging(), request)
|
|
154
|
+
return None
|
|
155
|
+
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
@metadata.request(peer_required=True)
|
|
159
|
+
async def new_transaction(
|
|
160
|
+
self, transaction: full_node_protocol.NewTransaction, peer: WSChiaConnection
|
|
161
|
+
) -> Optional[Message]:
|
|
162
|
+
"""
|
|
163
|
+
A peer notifies us of a new transaction.
|
|
164
|
+
Requests a full transaction if we haven't seen it previously, and if the fees are enough.
|
|
165
|
+
"""
|
|
166
|
+
# Ignore if syncing
|
|
167
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
168
|
+
return None
|
|
169
|
+
if not (await self.full_node.synced()):
|
|
170
|
+
return None
|
|
171
|
+
|
|
172
|
+
# Ignore if already seen
|
|
173
|
+
if self.full_node.mempool_manager.seen(transaction.transaction_id):
|
|
174
|
+
return None
|
|
175
|
+
|
|
176
|
+
if self.full_node.mempool_manager.is_fee_enough(transaction.fees, transaction.cost):
|
|
177
|
+
# If there's current pending request just add this peer to the set of peers that have this tx
|
|
178
|
+
if transaction.transaction_id in self.full_node.full_node_store.pending_tx_request:
|
|
179
|
+
if transaction.transaction_id in self.full_node.full_node_store.peers_with_tx:
|
|
180
|
+
current_set = self.full_node.full_node_store.peers_with_tx[transaction.transaction_id]
|
|
181
|
+
if peer.peer_node_id in current_set:
|
|
182
|
+
return None
|
|
183
|
+
current_set.add(peer.peer_node_id)
|
|
184
|
+
return None
|
|
185
|
+
else:
|
|
186
|
+
new_set = set()
|
|
187
|
+
new_set.add(peer.peer_node_id)
|
|
188
|
+
self.full_node.full_node_store.peers_with_tx[transaction.transaction_id] = new_set
|
|
189
|
+
return None
|
|
190
|
+
|
|
191
|
+
self.full_node.full_node_store.pending_tx_request[transaction.transaction_id] = peer.peer_node_id
|
|
192
|
+
new_set = set()
|
|
193
|
+
new_set.add(peer.peer_node_id)
|
|
194
|
+
self.full_node.full_node_store.peers_with_tx[transaction.transaction_id] = new_set
|
|
195
|
+
|
|
196
|
+
async def tx_request_and_timeout(full_node: FullNode, transaction_id: bytes32, task_id: bytes32) -> None:
|
|
197
|
+
counter = 0
|
|
198
|
+
try:
|
|
199
|
+
while True:
|
|
200
|
+
# Limit to asking a few peers, it's possible that this tx got included on chain already
|
|
201
|
+
# Highly unlikely that the peers that advertised a tx don't respond to a request. Also, if we
|
|
202
|
+
# drop some transactions, we don't want to re-fetch too many times
|
|
203
|
+
if counter == 5:
|
|
204
|
+
break
|
|
205
|
+
if transaction_id not in full_node.full_node_store.peers_with_tx:
|
|
206
|
+
break
|
|
207
|
+
peers_with_tx: set[bytes32] = full_node.full_node_store.peers_with_tx[transaction_id]
|
|
208
|
+
if len(peers_with_tx) == 0:
|
|
209
|
+
break
|
|
210
|
+
peer_id = peers_with_tx.pop()
|
|
211
|
+
assert full_node.server is not None
|
|
212
|
+
if peer_id not in full_node.server.all_connections:
|
|
213
|
+
continue
|
|
214
|
+
random_peer = full_node.server.all_connections[peer_id]
|
|
215
|
+
request_tx = full_node_protocol.RequestTransaction(transaction.transaction_id)
|
|
216
|
+
msg = make_msg(ProtocolMessageTypes.request_transaction, request_tx)
|
|
217
|
+
await random_peer.send_message(msg)
|
|
218
|
+
await asyncio.sleep(5)
|
|
219
|
+
counter += 1
|
|
220
|
+
if full_node.mempool_manager.seen(transaction_id):
|
|
221
|
+
break
|
|
222
|
+
except asyncio.CancelledError:
|
|
223
|
+
pass
|
|
224
|
+
finally:
|
|
225
|
+
# Always Cleanup
|
|
226
|
+
if transaction_id in full_node.full_node_store.peers_with_tx:
|
|
227
|
+
full_node.full_node_store.peers_with_tx.pop(transaction_id)
|
|
228
|
+
if transaction_id in full_node.full_node_store.pending_tx_request:
|
|
229
|
+
full_node.full_node_store.pending_tx_request.pop(transaction_id)
|
|
230
|
+
if task_id in full_node.full_node_store.tx_fetch_tasks:
|
|
231
|
+
full_node.full_node_store.tx_fetch_tasks.pop(task_id)
|
|
232
|
+
|
|
233
|
+
task_id: bytes32 = bytes32.secret()
|
|
234
|
+
fetch_task = create_referenced_task(
|
|
235
|
+
tx_request_and_timeout(self.full_node, transaction.transaction_id, task_id)
|
|
236
|
+
)
|
|
237
|
+
self.full_node.full_node_store.tx_fetch_tasks[task_id] = fetch_task
|
|
238
|
+
return None
|
|
239
|
+
return None
|
|
240
|
+
|
|
241
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_transaction])
|
|
242
|
+
async def request_transaction(self, request: full_node_protocol.RequestTransaction) -> Optional[Message]:
|
|
243
|
+
"""Peer has requested a full transaction from us."""
|
|
244
|
+
# Ignore if syncing
|
|
245
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
246
|
+
return None
|
|
247
|
+
spend_bundle = self.full_node.mempool_manager.get_spendbundle(request.transaction_id)
|
|
248
|
+
if spend_bundle is None:
|
|
249
|
+
return None
|
|
250
|
+
|
|
251
|
+
transaction = full_node_protocol.RespondTransaction(spend_bundle)
|
|
252
|
+
|
|
253
|
+
msg = make_msg(ProtocolMessageTypes.respond_transaction, transaction)
|
|
254
|
+
return msg
|
|
255
|
+
|
|
256
|
+
@metadata.request(peer_required=True, bytes_required=True)
|
|
257
|
+
async def respond_transaction(
|
|
258
|
+
self,
|
|
259
|
+
tx: full_node_protocol.RespondTransaction,
|
|
260
|
+
peer: WSChiaConnection,
|
|
261
|
+
tx_bytes: bytes = b"",
|
|
262
|
+
test: bool = False,
|
|
263
|
+
) -> Optional[Message]:
|
|
264
|
+
"""
|
|
265
|
+
Receives a full transaction from peer.
|
|
266
|
+
If tx is added to mempool, send tx_id to others. (new_transaction)
|
|
267
|
+
"""
|
|
268
|
+
assert tx_bytes != b""
|
|
269
|
+
spend_name = std_hash(tx_bytes)
|
|
270
|
+
if spend_name in self.full_node.full_node_store.pending_tx_request:
|
|
271
|
+
self.full_node.full_node_store.pending_tx_request.pop(spend_name)
|
|
272
|
+
if spend_name in self.full_node.full_node_store.peers_with_tx:
|
|
273
|
+
self.full_node.full_node_store.peers_with_tx.pop(spend_name)
|
|
274
|
+
|
|
275
|
+
# TODO: Use fee in priority calculation, to prioritize high fee TXs
|
|
276
|
+
try:
|
|
277
|
+
await self.full_node.transaction_queue.put(
|
|
278
|
+
TransactionQueueEntry(tx.transaction, tx_bytes, spend_name, peer, test), peer.peer_node_id
|
|
279
|
+
)
|
|
280
|
+
except TransactionQueueFull:
|
|
281
|
+
pass # we can't do anything here, the tx will be dropped. We might do something in the future.
|
|
282
|
+
return None
|
|
283
|
+
|
|
284
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_proof_of_weight])
|
|
285
|
+
async def request_proof_of_weight(self, request: full_node_protocol.RequestProofOfWeight) -> Optional[Message]:
|
|
286
|
+
if self.full_node.weight_proof_handler is None:
|
|
287
|
+
return None
|
|
288
|
+
if not self.full_node.blockchain.contains_block(request.tip):
|
|
289
|
+
self.log.error(f"got weight proof request for unknown peak {request.tip}")
|
|
290
|
+
return None
|
|
291
|
+
if request.tip in self.full_node.pow_creation:
|
|
292
|
+
event = self.full_node.pow_creation[request.tip]
|
|
293
|
+
await event.wait()
|
|
294
|
+
wp = await self.full_node.weight_proof_handler.get_proof_of_weight(request.tip)
|
|
295
|
+
else:
|
|
296
|
+
event = asyncio.Event()
|
|
297
|
+
self.full_node.pow_creation[request.tip] = event
|
|
298
|
+
wp = await self.full_node.weight_proof_handler.get_proof_of_weight(request.tip)
|
|
299
|
+
event.set()
|
|
300
|
+
tips = list(self.full_node.pow_creation.keys())
|
|
301
|
+
|
|
302
|
+
if len(tips) > 4:
|
|
303
|
+
# Remove old from cache
|
|
304
|
+
for i in range(0, 4):
|
|
305
|
+
self.full_node.pow_creation.pop(tips[i])
|
|
306
|
+
|
|
307
|
+
if wp is None:
|
|
308
|
+
self.log.error(f"failed creating weight proof for peak {request.tip}")
|
|
309
|
+
return None
|
|
310
|
+
|
|
311
|
+
# Serialization of wp is slow
|
|
312
|
+
if (
|
|
313
|
+
self.full_node.full_node_store.serialized_wp_message_tip is not None
|
|
314
|
+
and self.full_node.full_node_store.serialized_wp_message_tip == request.tip
|
|
315
|
+
):
|
|
316
|
+
return self.full_node.full_node_store.serialized_wp_message
|
|
317
|
+
message = make_msg(
|
|
318
|
+
ProtocolMessageTypes.respond_proof_of_weight, full_node_protocol.RespondProofOfWeight(wp, request.tip)
|
|
319
|
+
)
|
|
320
|
+
self.full_node.full_node_store.serialized_wp_message_tip = request.tip
|
|
321
|
+
self.full_node.full_node_store.serialized_wp_message = message
|
|
322
|
+
return message
|
|
323
|
+
|
|
324
|
+
@metadata.request()
|
|
325
|
+
async def respond_proof_of_weight(self, request: full_node_protocol.RespondProofOfWeight) -> Optional[Message]:
|
|
326
|
+
self.log.warning("Received proof of weight too late.")
|
|
327
|
+
return None
|
|
328
|
+
|
|
329
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_block, ProtocolMessageTypes.reject_block])
|
|
330
|
+
async def request_block(self, request: full_node_protocol.RequestBlock) -> Optional[Message]:
|
|
331
|
+
if not self.full_node.blockchain.contains_height(request.height):
|
|
332
|
+
reject = RejectBlock(request.height)
|
|
333
|
+
msg = make_msg(ProtocolMessageTypes.reject_block, reject)
|
|
334
|
+
return msg
|
|
335
|
+
header_hash: Optional[bytes32] = self.full_node.blockchain.height_to_hash(request.height)
|
|
336
|
+
if header_hash is None:
|
|
337
|
+
return make_msg(ProtocolMessageTypes.reject_block, RejectBlock(request.height))
|
|
338
|
+
|
|
339
|
+
block: Optional[FullBlock] = await self.full_node.block_store.get_full_block(header_hash)
|
|
340
|
+
if block is not None:
|
|
341
|
+
if not request.include_transaction_block and block.transactions_generator is not None:
|
|
342
|
+
block = block.replace(transactions_generator=None)
|
|
343
|
+
return make_msg(ProtocolMessageTypes.respond_block, full_node_protocol.RespondBlock(block))
|
|
344
|
+
return make_msg(ProtocolMessageTypes.reject_block, RejectBlock(request.height))
|
|
345
|
+
|
|
346
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_blocks, ProtocolMessageTypes.reject_blocks])
|
|
347
|
+
async def request_blocks(self, request: full_node_protocol.RequestBlocks) -> Optional[Message]:
|
|
348
|
+
# note that we treat the request range as *inclusive*, but we check the
|
|
349
|
+
# size before we bump end_height. So MAX_BLOCK_COUNT_PER_REQUESTS is off
|
|
350
|
+
# by one
|
|
351
|
+
if (
|
|
352
|
+
request.end_height < request.start_height
|
|
353
|
+
or request.end_height - request.start_height > self.full_node.constants.MAX_BLOCK_COUNT_PER_REQUESTS
|
|
354
|
+
):
|
|
355
|
+
reject = RejectBlocks(request.start_height, request.end_height)
|
|
356
|
+
msg: Message = make_msg(ProtocolMessageTypes.reject_blocks, reject)
|
|
357
|
+
return msg
|
|
358
|
+
for i in range(request.start_height, request.end_height + 1):
|
|
359
|
+
if not self.full_node.blockchain.contains_height(uint32(i)):
|
|
360
|
+
reject = RejectBlocks(request.start_height, request.end_height)
|
|
361
|
+
msg = make_msg(ProtocolMessageTypes.reject_blocks, reject)
|
|
362
|
+
return msg
|
|
363
|
+
|
|
364
|
+
if not request.include_transaction_block:
|
|
365
|
+
blocks: list[FullBlock] = []
|
|
366
|
+
for i in range(request.start_height, request.end_height + 1):
|
|
367
|
+
header_hash_i: Optional[bytes32] = self.full_node.blockchain.height_to_hash(uint32(i))
|
|
368
|
+
if header_hash_i is None:
|
|
369
|
+
reject = RejectBlocks(request.start_height, request.end_height)
|
|
370
|
+
return make_msg(ProtocolMessageTypes.reject_blocks, reject)
|
|
371
|
+
|
|
372
|
+
block: Optional[FullBlock] = await self.full_node.block_store.get_full_block(header_hash_i)
|
|
373
|
+
if block is None:
|
|
374
|
+
reject = RejectBlocks(request.start_height, request.end_height)
|
|
375
|
+
return make_msg(ProtocolMessageTypes.reject_blocks, reject)
|
|
376
|
+
block = block.replace(transactions_generator=None)
|
|
377
|
+
blocks.append(block)
|
|
378
|
+
msg = make_msg(
|
|
379
|
+
ProtocolMessageTypes.respond_blocks,
|
|
380
|
+
full_node_protocol.RespondBlocks(request.start_height, request.end_height, blocks),
|
|
381
|
+
)
|
|
382
|
+
else:
|
|
383
|
+
blocks_bytes: list[bytes] = []
|
|
384
|
+
for i in range(request.start_height, request.end_height + 1):
|
|
385
|
+
header_hash_i = self.full_node.blockchain.height_to_hash(uint32(i))
|
|
386
|
+
if header_hash_i is None:
|
|
387
|
+
reject = RejectBlocks(request.start_height, request.end_height)
|
|
388
|
+
return make_msg(ProtocolMessageTypes.reject_blocks, reject)
|
|
389
|
+
block_bytes: Optional[bytes] = await self.full_node.block_store.get_full_block_bytes(header_hash_i)
|
|
390
|
+
if block_bytes is None:
|
|
391
|
+
reject = RejectBlocks(request.start_height, request.end_height)
|
|
392
|
+
msg = make_msg(ProtocolMessageTypes.reject_blocks, reject)
|
|
393
|
+
return msg
|
|
394
|
+
|
|
395
|
+
blocks_bytes.append(block_bytes)
|
|
396
|
+
|
|
397
|
+
respond_blocks_manually_streamed: bytes = (
|
|
398
|
+
uint32(request.start_height).stream_to_bytes()
|
|
399
|
+
+ uint32(request.end_height).stream_to_bytes()
|
|
400
|
+
+ uint32(len(blocks_bytes)).stream_to_bytes()
|
|
401
|
+
)
|
|
402
|
+
for block_bytes in blocks_bytes:
|
|
403
|
+
respond_blocks_manually_streamed += block_bytes
|
|
404
|
+
msg = make_msg(ProtocolMessageTypes.respond_blocks, respond_blocks_manually_streamed)
|
|
405
|
+
|
|
406
|
+
return msg
|
|
407
|
+
|
|
408
|
+
@metadata.request(peer_required=True)
|
|
409
|
+
async def reject_block(
|
|
410
|
+
self,
|
|
411
|
+
request: full_node_protocol.RejectBlock,
|
|
412
|
+
peer: WSChiaConnection,
|
|
413
|
+
) -> None:
|
|
414
|
+
self.log.warning(f"unsolicited reject_block {request.height}")
|
|
415
|
+
await peer.close(RATE_LIMITER_BAN_SECONDS)
|
|
416
|
+
|
|
417
|
+
@metadata.request(peer_required=True)
|
|
418
|
+
async def reject_blocks(
|
|
419
|
+
self,
|
|
420
|
+
request: full_node_protocol.RejectBlocks,
|
|
421
|
+
peer: WSChiaConnection,
|
|
422
|
+
) -> None:
|
|
423
|
+
self.log.warning(f"reject_blocks {request.start_height} {request.end_height}")
|
|
424
|
+
await peer.close(RATE_LIMITER_BAN_SECONDS)
|
|
425
|
+
|
|
426
|
+
@metadata.request(peer_required=True)
|
|
427
|
+
async def respond_blocks(
|
|
428
|
+
self,
|
|
429
|
+
request: full_node_protocol.RespondBlocks,
|
|
430
|
+
peer: WSChiaConnection,
|
|
431
|
+
) -> None:
|
|
432
|
+
self.log.warning("Received unsolicited/late blocks")
|
|
433
|
+
await peer.close(RATE_LIMITER_BAN_SECONDS)
|
|
434
|
+
|
|
435
|
+
@metadata.request(peer_required=True)
|
|
436
|
+
async def respond_block(
|
|
437
|
+
self,
|
|
438
|
+
respond_block: full_node_protocol.RespondBlock,
|
|
439
|
+
peer: WSChiaConnection,
|
|
440
|
+
) -> Optional[Message]:
|
|
441
|
+
self.log.warning(f"Received unsolicited/late block from peer {peer.get_peer_logging()}")
|
|
442
|
+
await peer.close(RATE_LIMITER_BAN_SECONDS)
|
|
443
|
+
return None
|
|
444
|
+
|
|
445
|
+
@metadata.request()
|
|
446
|
+
async def new_unfinished_block(
|
|
447
|
+
self, new_unfinished_block: full_node_protocol.NewUnfinishedBlock
|
|
448
|
+
) -> Optional[Message]:
|
|
449
|
+
# Ignore if syncing
|
|
450
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
451
|
+
return None
|
|
452
|
+
block_hash = new_unfinished_block.unfinished_reward_hash
|
|
453
|
+
if self.full_node.full_node_store.get_unfinished_block(block_hash) is not None:
|
|
454
|
+
return None
|
|
455
|
+
|
|
456
|
+
# This prevents us from downloading the same block from many peers
|
|
457
|
+
requesting, count = self.full_node.full_node_store.is_requesting_unfinished_block(block_hash, None)
|
|
458
|
+
if requesting:
|
|
459
|
+
self.log.debug(
|
|
460
|
+
f"Already have or requesting {count} Unfinished Blocks with partial "
|
|
461
|
+
f"hash {block_hash}. Ignoring this one"
|
|
462
|
+
)
|
|
463
|
+
return None
|
|
464
|
+
|
|
465
|
+
msg = make_msg(
|
|
466
|
+
ProtocolMessageTypes.request_unfinished_block,
|
|
467
|
+
full_node_protocol.RequestUnfinishedBlock(block_hash),
|
|
468
|
+
)
|
|
469
|
+
self.full_node.full_node_store.mark_requesting_unfinished_block(block_hash, None)
|
|
470
|
+
|
|
471
|
+
# However, we want to eventually download from other peers, if this peer does not respond
|
|
472
|
+
# Todo: keep track of who it was
|
|
473
|
+
async def eventually_clear() -> None:
|
|
474
|
+
await asyncio.sleep(5)
|
|
475
|
+
self.full_node.full_node_store.remove_requesting_unfinished_block(block_hash, None)
|
|
476
|
+
|
|
477
|
+
create_referenced_task(eventually_clear(), known_unreferenced=True)
|
|
478
|
+
|
|
479
|
+
return msg
|
|
480
|
+
|
|
481
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_unfinished_block])
|
|
482
|
+
async def request_unfinished_block(
|
|
483
|
+
self, request_unfinished_block: full_node_protocol.RequestUnfinishedBlock
|
|
484
|
+
) -> Optional[Message]:
|
|
485
|
+
unfinished_block: Optional[UnfinishedBlock] = self.full_node.full_node_store.get_unfinished_block(
|
|
486
|
+
request_unfinished_block.unfinished_reward_hash
|
|
487
|
+
)
|
|
488
|
+
if unfinished_block is not None:
|
|
489
|
+
msg = make_msg(
|
|
490
|
+
ProtocolMessageTypes.respond_unfinished_block,
|
|
491
|
+
full_node_protocol.RespondUnfinishedBlock(unfinished_block),
|
|
492
|
+
)
|
|
493
|
+
return msg
|
|
494
|
+
return None
|
|
495
|
+
|
|
496
|
+
@metadata.request()
|
|
497
|
+
async def new_unfinished_block2(
|
|
498
|
+
self, new_unfinished_block: full_node_protocol.NewUnfinishedBlock2
|
|
499
|
+
) -> Optional[Message]:
|
|
500
|
+
# Ignore if syncing
|
|
501
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
502
|
+
return None
|
|
503
|
+
block_hash = new_unfinished_block.unfinished_reward_hash
|
|
504
|
+
foliage_hash = new_unfinished_block.foliage_hash
|
|
505
|
+
entry, count, have_better = self.full_node.full_node_store.get_unfinished_block2(block_hash, foliage_hash)
|
|
506
|
+
|
|
507
|
+
if entry is not None:
|
|
508
|
+
return None
|
|
509
|
+
|
|
510
|
+
if have_better:
|
|
511
|
+
self.log.info(
|
|
512
|
+
f"Already have a better Unfinished Block with partial hash {block_hash.hex()} ignoring this one"
|
|
513
|
+
)
|
|
514
|
+
return None
|
|
515
|
+
|
|
516
|
+
max_duplicate_unfinished_blocks = self.full_node.config.get("max_duplicate_unfinished_blocks", 3)
|
|
517
|
+
if count > max_duplicate_unfinished_blocks:
|
|
518
|
+
self.log.info(
|
|
519
|
+
f"Already have {count} Unfinished Blocks with partial hash {block_hash.hex()} ignoring another one"
|
|
520
|
+
)
|
|
521
|
+
return None
|
|
522
|
+
|
|
523
|
+
# This prevents us from downloading the same block from many peers
|
|
524
|
+
requesting, count = self.full_node.full_node_store.is_requesting_unfinished_block(block_hash, foliage_hash)
|
|
525
|
+
if requesting:
|
|
526
|
+
return None
|
|
527
|
+
if count >= max_duplicate_unfinished_blocks:
|
|
528
|
+
self.log.info(
|
|
529
|
+
f"Already requesting {count} Unfinished Blocks with partial hash {block_hash} ignoring another one"
|
|
530
|
+
)
|
|
531
|
+
return None
|
|
532
|
+
|
|
533
|
+
msg = make_msg(
|
|
534
|
+
ProtocolMessageTypes.request_unfinished_block2,
|
|
535
|
+
full_node_protocol.RequestUnfinishedBlock2(block_hash, foliage_hash),
|
|
536
|
+
)
|
|
537
|
+
self.full_node.full_node_store.mark_requesting_unfinished_block(block_hash, foliage_hash)
|
|
538
|
+
|
|
539
|
+
# However, we want to eventually download from other peers, if this peer does not respond
|
|
540
|
+
# Todo: keep track of who it was
|
|
541
|
+
async def eventually_clear() -> None:
|
|
542
|
+
await asyncio.sleep(5)
|
|
543
|
+
self.full_node.full_node_store.remove_requesting_unfinished_block(block_hash, foliage_hash)
|
|
544
|
+
|
|
545
|
+
create_referenced_task(eventually_clear(), known_unreferenced=True)
|
|
546
|
+
|
|
547
|
+
return msg
|
|
548
|
+
|
|
549
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_unfinished_block])
|
|
550
|
+
async def request_unfinished_block2(
|
|
551
|
+
self, request_unfinished_block: full_node_protocol.RequestUnfinishedBlock2
|
|
552
|
+
) -> Optional[Message]:
|
|
553
|
+
unfinished_block: Optional[UnfinishedBlock]
|
|
554
|
+
unfinished_block, _, _ = self.full_node.full_node_store.get_unfinished_block2(
|
|
555
|
+
request_unfinished_block.unfinished_reward_hash,
|
|
556
|
+
request_unfinished_block.foliage_hash,
|
|
557
|
+
)
|
|
558
|
+
if unfinished_block is not None:
|
|
559
|
+
msg = make_msg(
|
|
560
|
+
ProtocolMessageTypes.respond_unfinished_block,
|
|
561
|
+
full_node_protocol.RespondUnfinishedBlock(unfinished_block),
|
|
562
|
+
)
|
|
563
|
+
return msg
|
|
564
|
+
return None
|
|
565
|
+
|
|
566
|
+
@metadata.request(peer_required=True)
|
|
567
|
+
async def respond_unfinished_block(
|
|
568
|
+
self,
|
|
569
|
+
respond_unfinished_block: full_node_protocol.RespondUnfinishedBlock,
|
|
570
|
+
peer: WSChiaConnection,
|
|
571
|
+
) -> Optional[Message]:
|
|
572
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
573
|
+
return None
|
|
574
|
+
await self.full_node.add_unfinished_block(respond_unfinished_block.unfinished_block, peer)
|
|
575
|
+
return None
|
|
576
|
+
|
|
577
|
+
@metadata.request(peer_required=True)
|
|
578
|
+
async def new_signage_point_or_end_of_sub_slot(
|
|
579
|
+
self, new_sp: full_node_protocol.NewSignagePointOrEndOfSubSlot, peer: WSChiaConnection
|
|
580
|
+
) -> Optional[Message]:
|
|
581
|
+
# Ignore if syncing
|
|
582
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
583
|
+
return None
|
|
584
|
+
if (
|
|
585
|
+
self.full_node.full_node_store.get_signage_point_by_index(
|
|
586
|
+
new_sp.challenge_hash,
|
|
587
|
+
new_sp.index_from_challenge,
|
|
588
|
+
new_sp.last_rc_infusion,
|
|
589
|
+
)
|
|
590
|
+
is not None
|
|
591
|
+
):
|
|
592
|
+
return None
|
|
593
|
+
if self.full_node.full_node_store.have_newer_signage_point(
|
|
594
|
+
new_sp.challenge_hash, new_sp.index_from_challenge, new_sp.last_rc_infusion
|
|
595
|
+
):
|
|
596
|
+
return None
|
|
597
|
+
|
|
598
|
+
if new_sp.index_from_challenge == 0 and new_sp.prev_challenge_hash is not None:
|
|
599
|
+
if self.full_node.full_node_store.get_sub_slot(new_sp.prev_challenge_hash) is None:
|
|
600
|
+
collected_eos = []
|
|
601
|
+
challenge_hash_to_request = new_sp.challenge_hash
|
|
602
|
+
last_rc = new_sp.last_rc_infusion
|
|
603
|
+
num_non_empty_sub_slots_seen = 0
|
|
604
|
+
for _ in range(30):
|
|
605
|
+
if num_non_empty_sub_slots_seen >= 3:
|
|
606
|
+
self.log.debug("Diverged from peer. Don't have the same blocks")
|
|
607
|
+
return None
|
|
608
|
+
# If this is an end of sub slot, and we don't have the prev, request the prev instead
|
|
609
|
+
# We want to catch up to the latest slot so we can receive signage points
|
|
610
|
+
full_node_request = full_node_protocol.RequestSignagePointOrEndOfSubSlot(
|
|
611
|
+
challenge_hash_to_request, uint8(0), last_rc
|
|
612
|
+
)
|
|
613
|
+
response = await peer.call_api(
|
|
614
|
+
FullNodeAPI.request_signage_point_or_end_of_sub_slot, full_node_request, timeout=10
|
|
615
|
+
)
|
|
616
|
+
if not isinstance(response, full_node_protocol.RespondEndOfSubSlot):
|
|
617
|
+
self.full_node.log.debug(f"Invalid response for slot {response}")
|
|
618
|
+
return None
|
|
619
|
+
collected_eos.append(response)
|
|
620
|
+
if (
|
|
621
|
+
self.full_node.full_node_store.get_sub_slot(
|
|
622
|
+
response.end_of_slot_bundle.challenge_chain.challenge_chain_end_of_slot_vdf.challenge
|
|
623
|
+
)
|
|
624
|
+
is not None
|
|
625
|
+
or response.end_of_slot_bundle.challenge_chain.challenge_chain_end_of_slot_vdf.challenge
|
|
626
|
+
== self.full_node.constants.GENESIS_CHALLENGE
|
|
627
|
+
):
|
|
628
|
+
for eos in reversed(collected_eos):
|
|
629
|
+
await self.respond_end_of_sub_slot(eos, peer)
|
|
630
|
+
return None
|
|
631
|
+
if (
|
|
632
|
+
response.end_of_slot_bundle.challenge_chain.challenge_chain_end_of_slot_vdf.number_of_iterations
|
|
633
|
+
!= response.end_of_slot_bundle.reward_chain.end_of_slot_vdf.number_of_iterations
|
|
634
|
+
):
|
|
635
|
+
num_non_empty_sub_slots_seen += 1
|
|
636
|
+
challenge_hash_to_request = (
|
|
637
|
+
response.end_of_slot_bundle.challenge_chain.challenge_chain_end_of_slot_vdf.challenge
|
|
638
|
+
)
|
|
639
|
+
last_rc = response.end_of_slot_bundle.reward_chain.end_of_slot_vdf.challenge
|
|
640
|
+
self.full_node.log.warning("Failed to catch up in sub-slots")
|
|
641
|
+
return None
|
|
642
|
+
|
|
643
|
+
if new_sp.index_from_challenge > 0:
|
|
644
|
+
if (
|
|
645
|
+
new_sp.challenge_hash != self.full_node.constants.GENESIS_CHALLENGE
|
|
646
|
+
and self.full_node.full_node_store.get_sub_slot(new_sp.challenge_hash) is None
|
|
647
|
+
):
|
|
648
|
+
# If this is a normal signage point,, and we don't have the end of sub slot, request the end of sub slot
|
|
649
|
+
full_node_request = full_node_protocol.RequestSignagePointOrEndOfSubSlot(
|
|
650
|
+
new_sp.challenge_hash, uint8(0), new_sp.last_rc_infusion
|
|
651
|
+
)
|
|
652
|
+
return make_msg(ProtocolMessageTypes.request_signage_point_or_end_of_sub_slot, full_node_request)
|
|
653
|
+
|
|
654
|
+
# Otherwise (we have the prev or the end of sub slot), request it normally
|
|
655
|
+
full_node_request = full_node_protocol.RequestSignagePointOrEndOfSubSlot(
|
|
656
|
+
new_sp.challenge_hash, new_sp.index_from_challenge, new_sp.last_rc_infusion
|
|
657
|
+
)
|
|
658
|
+
|
|
659
|
+
return make_msg(ProtocolMessageTypes.request_signage_point_or_end_of_sub_slot, full_node_request)
|
|
660
|
+
|
|
661
|
+
@metadata.request(
|
|
662
|
+
reply_types=[ProtocolMessageTypes.respond_signage_point, ProtocolMessageTypes.respond_end_of_sub_slot]
|
|
663
|
+
)
|
|
664
|
+
async def request_signage_point_or_end_of_sub_slot(
|
|
665
|
+
self, request: full_node_protocol.RequestSignagePointOrEndOfSubSlot
|
|
666
|
+
) -> Optional[Message]:
|
|
667
|
+
if request.index_from_challenge == 0:
|
|
668
|
+
sub_slot: Optional[tuple[EndOfSubSlotBundle, int, uint128]] = self.full_node.full_node_store.get_sub_slot(
|
|
669
|
+
request.challenge_hash
|
|
670
|
+
)
|
|
671
|
+
if sub_slot is not None:
|
|
672
|
+
return make_msg(
|
|
673
|
+
ProtocolMessageTypes.respond_end_of_sub_slot,
|
|
674
|
+
full_node_protocol.RespondEndOfSubSlot(sub_slot[0]),
|
|
675
|
+
)
|
|
676
|
+
else:
|
|
677
|
+
if self.full_node.full_node_store.get_sub_slot(request.challenge_hash) is None:
|
|
678
|
+
if request.challenge_hash != self.full_node.constants.GENESIS_CHALLENGE:
|
|
679
|
+
self.log.info(f"Don't have challenge hash {request.challenge_hash.hex()}")
|
|
680
|
+
|
|
681
|
+
sp: Optional[SignagePoint] = self.full_node.full_node_store.get_signage_point_by_index(
|
|
682
|
+
request.challenge_hash,
|
|
683
|
+
request.index_from_challenge,
|
|
684
|
+
request.last_rc_infusion,
|
|
685
|
+
)
|
|
686
|
+
if sp is not None:
|
|
687
|
+
assert (
|
|
688
|
+
sp.cc_vdf is not None
|
|
689
|
+
and sp.cc_proof is not None
|
|
690
|
+
and sp.rc_vdf is not None
|
|
691
|
+
and sp.rc_proof is not None
|
|
692
|
+
)
|
|
693
|
+
full_node_response = full_node_protocol.RespondSignagePoint(
|
|
694
|
+
request.index_from_challenge,
|
|
695
|
+
sp.cc_vdf,
|
|
696
|
+
sp.cc_proof,
|
|
697
|
+
sp.rc_vdf,
|
|
698
|
+
sp.rc_proof,
|
|
699
|
+
)
|
|
700
|
+
return make_msg(ProtocolMessageTypes.respond_signage_point, full_node_response)
|
|
701
|
+
else:
|
|
702
|
+
self.log.info(f"Don't have signage point {request}")
|
|
703
|
+
return None
|
|
704
|
+
|
|
705
|
+
@metadata.request(peer_required=True)
|
|
706
|
+
async def respond_signage_point(
|
|
707
|
+
self, request: full_node_protocol.RespondSignagePoint, peer: WSChiaConnection
|
|
708
|
+
) -> Optional[Message]:
|
|
709
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
710
|
+
return None
|
|
711
|
+
async with self.full_node.timelord_lock:
|
|
712
|
+
# Already have signage point
|
|
713
|
+
|
|
714
|
+
if self.full_node.full_node_store.have_newer_signage_point(
|
|
715
|
+
request.challenge_chain_vdf.challenge,
|
|
716
|
+
request.index_from_challenge,
|
|
717
|
+
request.reward_chain_vdf.challenge,
|
|
718
|
+
):
|
|
719
|
+
return None
|
|
720
|
+
existing_sp = self.full_node.full_node_store.get_signage_point(
|
|
721
|
+
request.challenge_chain_vdf.output.get_hash()
|
|
722
|
+
)
|
|
723
|
+
if existing_sp is not None and existing_sp.rc_vdf == request.reward_chain_vdf:
|
|
724
|
+
return None
|
|
725
|
+
peak = self.full_node.blockchain.get_peak()
|
|
726
|
+
if peak is not None and peak.height > self.full_node.constants.MAX_SUB_SLOT_BLOCKS:
|
|
727
|
+
next_sub_slot_iters = self.full_node.blockchain.get_next_slot_iters(peak.header_hash, True)
|
|
728
|
+
sub_slots_for_peak = await self.full_node.blockchain.get_sp_and_ip_sub_slots(peak.header_hash)
|
|
729
|
+
assert sub_slots_for_peak is not None
|
|
730
|
+
ip_sub_slot: Optional[EndOfSubSlotBundle] = sub_slots_for_peak[1]
|
|
731
|
+
else:
|
|
732
|
+
sub_slot_iters = self.full_node.constants.SUB_SLOT_ITERS_STARTING
|
|
733
|
+
next_sub_slot_iters = sub_slot_iters
|
|
734
|
+
ip_sub_slot = None
|
|
735
|
+
|
|
736
|
+
added = self.full_node.full_node_store.new_signage_point(
|
|
737
|
+
request.index_from_challenge,
|
|
738
|
+
self.full_node.blockchain,
|
|
739
|
+
self.full_node.blockchain.get_peak(),
|
|
740
|
+
next_sub_slot_iters,
|
|
741
|
+
SignagePoint(
|
|
742
|
+
request.challenge_chain_vdf,
|
|
743
|
+
request.challenge_chain_proof,
|
|
744
|
+
request.reward_chain_vdf,
|
|
745
|
+
request.reward_chain_proof,
|
|
746
|
+
),
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
if added:
|
|
750
|
+
await self.full_node.signage_point_post_processing(request, peer, ip_sub_slot)
|
|
751
|
+
else:
|
|
752
|
+
self.log.debug(
|
|
753
|
+
f"Signage point {request.index_from_challenge} not added, CC challenge: "
|
|
754
|
+
f"{request.challenge_chain_vdf.challenge.hex()}, "
|
|
755
|
+
f"RC challenge: {request.reward_chain_vdf.challenge.hex()}"
|
|
756
|
+
)
|
|
757
|
+
|
|
758
|
+
return None
|
|
759
|
+
|
|
760
|
+
@metadata.request(peer_required=True)
|
|
761
|
+
async def respond_end_of_sub_slot(
|
|
762
|
+
self, request: full_node_protocol.RespondEndOfSubSlot, peer: WSChiaConnection
|
|
763
|
+
) -> Optional[Message]:
|
|
764
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
765
|
+
return None
|
|
766
|
+
msg, _ = await self.full_node.add_end_of_sub_slot(request.end_of_slot_bundle, peer)
|
|
767
|
+
return msg
|
|
768
|
+
|
|
769
|
+
@metadata.request(peer_required=True)
|
|
770
|
+
async def request_mempool_transactions(
|
|
771
|
+
self,
|
|
772
|
+
request: full_node_protocol.RequestMempoolTransactions,
|
|
773
|
+
peer: WSChiaConnection,
|
|
774
|
+
) -> Optional[Message]:
|
|
775
|
+
received_filter = PyBIP158(bytearray(request.filter))
|
|
776
|
+
|
|
777
|
+
items: list[SpendBundle] = self.full_node.mempool_manager.get_items_not_in_filter(received_filter)
|
|
778
|
+
|
|
779
|
+
for item in items:
|
|
780
|
+
transaction = full_node_protocol.RespondTransaction(item)
|
|
781
|
+
msg = make_msg(ProtocolMessageTypes.respond_transaction, transaction)
|
|
782
|
+
await peer.send_message(msg)
|
|
783
|
+
return None
|
|
784
|
+
|
|
785
|
+
# FARMER PROTOCOL
|
|
786
|
+
@metadata.request(peer_required=True)
|
|
787
|
+
async def declare_proof_of_space(
|
|
788
|
+
self, request: farmer_protocol.DeclareProofOfSpace, peer: WSChiaConnection
|
|
789
|
+
) -> Optional[Message]:
|
|
790
|
+
"""
|
|
791
|
+
Creates a block body and header, with the proof of space, coinbase, and fee targets provided
|
|
792
|
+
by the farmer, and sends the hash of the header data back to the farmer.
|
|
793
|
+
"""
|
|
794
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
795
|
+
return None
|
|
796
|
+
|
|
797
|
+
async with self.full_node.timelord_lock:
|
|
798
|
+
sp_vdfs: Optional[SignagePoint] = self.full_node.full_node_store.get_signage_point(
|
|
799
|
+
request.challenge_chain_sp
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
if sp_vdfs is None:
|
|
803
|
+
self.log.warning(f"Received proof of space for an unknown signage point {request.challenge_chain_sp}")
|
|
804
|
+
return None
|
|
805
|
+
if request.signage_point_index > 0:
|
|
806
|
+
assert sp_vdfs.rc_vdf is not None
|
|
807
|
+
if sp_vdfs.rc_vdf.output.get_hash() != request.reward_chain_sp:
|
|
808
|
+
self.log.debug(
|
|
809
|
+
f"Received proof of space for a potentially old signage point {request.challenge_chain_sp}. "
|
|
810
|
+
f"Current sp: {sp_vdfs.rc_vdf.output.get_hash().hex()}"
|
|
811
|
+
)
|
|
812
|
+
return None
|
|
813
|
+
|
|
814
|
+
if request.signage_point_index == 0:
|
|
815
|
+
cc_challenge_hash: bytes32 = request.challenge_chain_sp
|
|
816
|
+
else:
|
|
817
|
+
assert sp_vdfs.cc_vdf is not None
|
|
818
|
+
cc_challenge_hash = sp_vdfs.cc_vdf.challenge
|
|
819
|
+
|
|
820
|
+
pos_sub_slot: Optional[tuple[EndOfSubSlotBundle, int, uint128]] = None
|
|
821
|
+
if request.challenge_hash != self.full_node.constants.GENESIS_CHALLENGE:
|
|
822
|
+
# Checks that the proof of space is a response to a recent challenge and valid SP
|
|
823
|
+
pos_sub_slot = self.full_node.full_node_store.get_sub_slot(cc_challenge_hash)
|
|
824
|
+
if pos_sub_slot is None:
|
|
825
|
+
self.log.warning(f"Received proof of space for an unknown sub slot: {request}")
|
|
826
|
+
return None
|
|
827
|
+
total_iters_pos_slot: uint128 = pos_sub_slot[2]
|
|
828
|
+
else:
|
|
829
|
+
total_iters_pos_slot = uint128(0)
|
|
830
|
+
assert cc_challenge_hash == request.challenge_hash
|
|
831
|
+
|
|
832
|
+
# Now we know that the proof of space has a signage point either:
|
|
833
|
+
# 1. In the previous sub-slot of the peak (overflow)
|
|
834
|
+
# 2. In the same sub-slot as the peak
|
|
835
|
+
# 3. In a future sub-slot that we already know of
|
|
836
|
+
|
|
837
|
+
# Grab best transactions from Mempool for given tip target
|
|
838
|
+
aggregate_signature: G2Element = G2Element()
|
|
839
|
+
block_generator: Optional[BlockGenerator] = None
|
|
840
|
+
additions: Optional[list[Coin]] = []
|
|
841
|
+
removals: Optional[list[Coin]] = []
|
|
842
|
+
async with self.full_node.blockchain.priority_mutex.acquire(priority=BlockchainMutexPriority.high):
|
|
843
|
+
peak: Optional[BlockRecord] = self.full_node.blockchain.get_peak()
|
|
844
|
+
|
|
845
|
+
# Checks that the proof of space is valid
|
|
846
|
+
height: uint32
|
|
847
|
+
if peak is None:
|
|
848
|
+
height = uint32(0)
|
|
849
|
+
else:
|
|
850
|
+
height = peak.height
|
|
851
|
+
quality_string: Optional[bytes32] = verify_and_get_quality_string(
|
|
852
|
+
request.proof_of_space,
|
|
853
|
+
self.full_node.constants,
|
|
854
|
+
cc_challenge_hash,
|
|
855
|
+
request.challenge_chain_sp,
|
|
856
|
+
height=height,
|
|
857
|
+
)
|
|
858
|
+
assert quality_string is not None and len(quality_string) == 32
|
|
859
|
+
|
|
860
|
+
if peak is not None:
|
|
861
|
+
# Finds the last transaction block before this one
|
|
862
|
+
curr_l_tb: BlockRecord = peak
|
|
863
|
+
while not curr_l_tb.is_transaction_block:
|
|
864
|
+
curr_l_tb = self.full_node.blockchain.block_record(curr_l_tb.prev_hash)
|
|
865
|
+
try:
|
|
866
|
+
mempool_bundle = await self.full_node.mempool_manager.create_bundle_from_mempool(
|
|
867
|
+
curr_l_tb.header_hash, self.full_node.coin_store.get_unspent_lineage_info_for_puzzle_hash
|
|
868
|
+
)
|
|
869
|
+
except Exception as e:
|
|
870
|
+
self.log.error(f"Traceback: {traceback.format_exc()}")
|
|
871
|
+
self.full_node.log.error(f"Error making spend bundle {e} peak: {peak}")
|
|
872
|
+
mempool_bundle = None
|
|
873
|
+
if mempool_bundle is not None:
|
|
874
|
+
spend_bundle, additions = mempool_bundle
|
|
875
|
+
removals = spend_bundle.removals()
|
|
876
|
+
self.full_node.log.info(f"Add rem: {len(additions)} {len(removals)}")
|
|
877
|
+
aggregate_signature = spend_bundle.aggregated_signature
|
|
878
|
+
# when the hard fork activates, block generators are
|
|
879
|
+
# allowed to be serialized with the improved CLVM
|
|
880
|
+
# serialization format, supporting back-references
|
|
881
|
+
start_time = time.monotonic()
|
|
882
|
+
if peak.height >= self.full_node.constants.HARD_FORK_HEIGHT:
|
|
883
|
+
block_generator = simple_solution_generator_backrefs(spend_bundle)
|
|
884
|
+
else:
|
|
885
|
+
block_generator = simple_solution_generator(spend_bundle)
|
|
886
|
+
end_time = time.monotonic()
|
|
887
|
+
duration = end_time - start_time
|
|
888
|
+
self.log.log(
|
|
889
|
+
logging.INFO if duration < 1 else logging.WARNING,
|
|
890
|
+
f"serializing block generator took {duration:0.2f} seconds",
|
|
891
|
+
)
|
|
892
|
+
|
|
893
|
+
def get_plot_sig(to_sign: bytes32, _extra: G1Element) -> G2Element:
|
|
894
|
+
if to_sign == request.challenge_chain_sp:
|
|
895
|
+
return request.challenge_chain_sp_signature
|
|
896
|
+
elif to_sign == request.reward_chain_sp:
|
|
897
|
+
return request.reward_chain_sp_signature
|
|
898
|
+
return G2Element()
|
|
899
|
+
|
|
900
|
+
def get_pool_sig(_1: PoolTarget, _2: Optional[G1Element]) -> Optional[G2Element]:
|
|
901
|
+
return request.pool_signature
|
|
902
|
+
|
|
903
|
+
prev_b: Optional[BlockRecord] = peak
|
|
904
|
+
|
|
905
|
+
# Finds the previous block from the signage point, ensuring that the reward chain VDF is correct
|
|
906
|
+
if prev_b is not None:
|
|
907
|
+
if request.signage_point_index == 0:
|
|
908
|
+
if pos_sub_slot is None:
|
|
909
|
+
self.log.warning("Pos sub slot is None")
|
|
910
|
+
return None
|
|
911
|
+
rc_challenge = pos_sub_slot[0].reward_chain.end_of_slot_vdf.challenge
|
|
912
|
+
else:
|
|
913
|
+
assert sp_vdfs.rc_vdf is not None
|
|
914
|
+
rc_challenge = sp_vdfs.rc_vdf.challenge
|
|
915
|
+
|
|
916
|
+
# Backtrack through empty sub-slots
|
|
917
|
+
for eos, _, _ in reversed(self.full_node.full_node_store.finished_sub_slots):
|
|
918
|
+
if eos is not None and eos.reward_chain.get_hash() == rc_challenge:
|
|
919
|
+
rc_challenge = eos.reward_chain.end_of_slot_vdf.challenge
|
|
920
|
+
|
|
921
|
+
found = False
|
|
922
|
+
attempts = 0
|
|
923
|
+
while prev_b is not None and attempts < 10:
|
|
924
|
+
if prev_b.reward_infusion_new_challenge == rc_challenge:
|
|
925
|
+
found = True
|
|
926
|
+
break
|
|
927
|
+
if prev_b.finished_reward_slot_hashes is not None and len(prev_b.finished_reward_slot_hashes) > 0:
|
|
928
|
+
if prev_b.finished_reward_slot_hashes[-1] == rc_challenge:
|
|
929
|
+
# This block includes a sub-slot which is where our SP vdf starts. Go back one more
|
|
930
|
+
# to find the prev block
|
|
931
|
+
prev_b = self.full_node.blockchain.try_block_record(prev_b.prev_hash)
|
|
932
|
+
found = True
|
|
933
|
+
break
|
|
934
|
+
prev_b = self.full_node.blockchain.try_block_record(prev_b.prev_hash)
|
|
935
|
+
attempts += 1
|
|
936
|
+
if not found:
|
|
937
|
+
self.log.warning("Did not find a previous block with the correct reward chain hash")
|
|
938
|
+
return None
|
|
939
|
+
|
|
940
|
+
try:
|
|
941
|
+
finished_sub_slots: Optional[list[EndOfSubSlotBundle]] = (
|
|
942
|
+
self.full_node.full_node_store.get_finished_sub_slots(
|
|
943
|
+
self.full_node.blockchain, prev_b, cc_challenge_hash
|
|
944
|
+
)
|
|
945
|
+
)
|
|
946
|
+
if finished_sub_slots is None:
|
|
947
|
+
return None
|
|
948
|
+
|
|
949
|
+
if (
|
|
950
|
+
len(finished_sub_slots) > 0
|
|
951
|
+
and pos_sub_slot is not None
|
|
952
|
+
and finished_sub_slots[-1] != pos_sub_slot[0]
|
|
953
|
+
):
|
|
954
|
+
self.log.error("Have different sub-slots than is required to farm this block")
|
|
955
|
+
return None
|
|
956
|
+
except ValueError as e:
|
|
957
|
+
self.log.warning(f"Value Error: {e}")
|
|
958
|
+
return None
|
|
959
|
+
if prev_b is None:
|
|
960
|
+
pool_target = PoolTarget(
|
|
961
|
+
self.full_node.constants.GENESIS_PRE_FARM_POOL_PUZZLE_HASH,
|
|
962
|
+
uint32(0),
|
|
963
|
+
)
|
|
964
|
+
farmer_ph = self.full_node.constants.GENESIS_PRE_FARM_FARMER_PUZZLE_HASH
|
|
965
|
+
else:
|
|
966
|
+
farmer_ph = request.farmer_puzzle_hash
|
|
967
|
+
if request.proof_of_space.pool_contract_puzzle_hash is not None:
|
|
968
|
+
pool_target = PoolTarget(request.proof_of_space.pool_contract_puzzle_hash, uint32(0))
|
|
969
|
+
else:
|
|
970
|
+
assert request.pool_target is not None
|
|
971
|
+
pool_target = request.pool_target
|
|
972
|
+
|
|
973
|
+
if peak is None or peak.height <= self.full_node.constants.MAX_SUB_SLOT_BLOCKS:
|
|
974
|
+
difficulty = self.full_node.constants.DIFFICULTY_STARTING
|
|
975
|
+
sub_slot_iters = self.full_node.constants.SUB_SLOT_ITERS_STARTING
|
|
976
|
+
else:
|
|
977
|
+
difficulty = uint64(peak.weight - self.full_node.blockchain.block_record(peak.prev_hash).weight)
|
|
978
|
+
sub_slot_iters = peak.sub_slot_iters
|
|
979
|
+
for sub_slot in finished_sub_slots:
|
|
980
|
+
if sub_slot.challenge_chain.new_difficulty is not None:
|
|
981
|
+
difficulty = sub_slot.challenge_chain.new_difficulty
|
|
982
|
+
if sub_slot.challenge_chain.new_sub_slot_iters is not None:
|
|
983
|
+
sub_slot_iters = sub_slot.challenge_chain.new_sub_slot_iters
|
|
984
|
+
|
|
985
|
+
required_iters: uint64 = calculate_iterations_quality(
|
|
986
|
+
self.full_node.constants.DIFFICULTY_CONSTANT_FACTOR,
|
|
987
|
+
quality_string,
|
|
988
|
+
request.proof_of_space.size,
|
|
989
|
+
difficulty,
|
|
990
|
+
request.challenge_chain_sp,
|
|
991
|
+
)
|
|
992
|
+
sp_iters: uint64 = calculate_sp_iters(self.full_node.constants, sub_slot_iters, request.signage_point_index)
|
|
993
|
+
ip_iters: uint64 = calculate_ip_iters(
|
|
994
|
+
self.full_node.constants,
|
|
995
|
+
sub_slot_iters,
|
|
996
|
+
request.signage_point_index,
|
|
997
|
+
required_iters,
|
|
998
|
+
)
|
|
999
|
+
|
|
1000
|
+
# The block's timestamp must be greater than the previous transaction block's timestamp
|
|
1001
|
+
timestamp = uint64(int(time.time()))
|
|
1002
|
+
curr: Optional[BlockRecord] = prev_b
|
|
1003
|
+
while curr is not None and not curr.is_transaction_block and curr.height != 0:
|
|
1004
|
+
curr = self.full_node.blockchain.try_block_record(curr.prev_hash)
|
|
1005
|
+
if curr is not None:
|
|
1006
|
+
assert curr.timestamp is not None
|
|
1007
|
+
if timestamp <= curr.timestamp:
|
|
1008
|
+
timestamp = uint64(int(curr.timestamp + 1))
|
|
1009
|
+
|
|
1010
|
+
self.log.info("Starting to make the unfinished block")
|
|
1011
|
+
unfinished_block: UnfinishedBlock = create_unfinished_block(
|
|
1012
|
+
self.full_node.constants,
|
|
1013
|
+
total_iters_pos_slot,
|
|
1014
|
+
sub_slot_iters,
|
|
1015
|
+
request.signage_point_index,
|
|
1016
|
+
sp_iters,
|
|
1017
|
+
ip_iters,
|
|
1018
|
+
request.proof_of_space,
|
|
1019
|
+
cc_challenge_hash,
|
|
1020
|
+
farmer_ph,
|
|
1021
|
+
pool_target,
|
|
1022
|
+
get_plot_sig,
|
|
1023
|
+
get_pool_sig,
|
|
1024
|
+
sp_vdfs,
|
|
1025
|
+
timestamp,
|
|
1026
|
+
self.full_node.blockchain,
|
|
1027
|
+
b"",
|
|
1028
|
+
block_generator,
|
|
1029
|
+
aggregate_signature,
|
|
1030
|
+
additions,
|
|
1031
|
+
removals,
|
|
1032
|
+
prev_b,
|
|
1033
|
+
finished_sub_slots,
|
|
1034
|
+
)
|
|
1035
|
+
self.log.info("Made the unfinished block")
|
|
1036
|
+
if prev_b is not None:
|
|
1037
|
+
height = uint32(prev_b.height + 1)
|
|
1038
|
+
else:
|
|
1039
|
+
height = uint32(0)
|
|
1040
|
+
self.full_node.full_node_store.add_candidate_block(quality_string, height, unfinished_block)
|
|
1041
|
+
|
|
1042
|
+
foliage_sb_data_hash = unfinished_block.foliage.foliage_block_data.get_hash()
|
|
1043
|
+
if unfinished_block.is_transaction_block():
|
|
1044
|
+
foliage_transaction_block_hash = unfinished_block.foliage.foliage_transaction_block_hash
|
|
1045
|
+
else:
|
|
1046
|
+
foliage_transaction_block_hash = bytes32.zeros
|
|
1047
|
+
assert foliage_transaction_block_hash is not None
|
|
1048
|
+
|
|
1049
|
+
foliage_block_data: Optional[FoliageBlockData] = None
|
|
1050
|
+
foliage_transaction_block_data: Optional[FoliageTransactionBlock] = None
|
|
1051
|
+
rc_block_unfinished: Optional[RewardChainBlockUnfinished] = None
|
|
1052
|
+
if request.include_signature_source_data:
|
|
1053
|
+
foliage_block_data = unfinished_block.foliage.foliage_block_data
|
|
1054
|
+
rc_block_unfinished = unfinished_block.reward_chain_block
|
|
1055
|
+
if unfinished_block.is_transaction_block():
|
|
1056
|
+
foliage_transaction_block_data = unfinished_block.foliage_transaction_block
|
|
1057
|
+
|
|
1058
|
+
message = farmer_protocol.RequestSignedValues(
|
|
1059
|
+
quality_string,
|
|
1060
|
+
foliage_sb_data_hash,
|
|
1061
|
+
foliage_transaction_block_hash,
|
|
1062
|
+
foliage_block_data=foliage_block_data,
|
|
1063
|
+
foliage_transaction_block_data=foliage_transaction_block_data,
|
|
1064
|
+
rc_block_unfinished=rc_block_unfinished,
|
|
1065
|
+
)
|
|
1066
|
+
await peer.send_message(make_msg(ProtocolMessageTypes.request_signed_values, message))
|
|
1067
|
+
|
|
1068
|
+
# Adds backup in case the first one fails
|
|
1069
|
+
if unfinished_block.is_transaction_block() and unfinished_block.transactions_generator is not None:
|
|
1070
|
+
unfinished_block_backup = create_unfinished_block(
|
|
1071
|
+
self.full_node.constants,
|
|
1072
|
+
total_iters_pos_slot,
|
|
1073
|
+
sub_slot_iters,
|
|
1074
|
+
request.signage_point_index,
|
|
1075
|
+
sp_iters,
|
|
1076
|
+
ip_iters,
|
|
1077
|
+
request.proof_of_space,
|
|
1078
|
+
cc_challenge_hash,
|
|
1079
|
+
farmer_ph,
|
|
1080
|
+
pool_target,
|
|
1081
|
+
get_plot_sig,
|
|
1082
|
+
get_pool_sig,
|
|
1083
|
+
sp_vdfs,
|
|
1084
|
+
timestamp,
|
|
1085
|
+
self.full_node.blockchain,
|
|
1086
|
+
b"",
|
|
1087
|
+
None,
|
|
1088
|
+
G2Element(),
|
|
1089
|
+
None,
|
|
1090
|
+
None,
|
|
1091
|
+
prev_b,
|
|
1092
|
+
finished_sub_slots,
|
|
1093
|
+
)
|
|
1094
|
+
|
|
1095
|
+
self.full_node.full_node_store.add_candidate_block(
|
|
1096
|
+
quality_string, height, unfinished_block_backup, backup=True
|
|
1097
|
+
)
|
|
1098
|
+
return None
|
|
1099
|
+
|
|
1100
|
+
@metadata.request(peer_required=True)
|
|
1101
|
+
async def signed_values(
|
|
1102
|
+
self, farmer_request: farmer_protocol.SignedValues, peer: WSChiaConnection
|
|
1103
|
+
) -> Optional[Message]:
|
|
1104
|
+
"""
|
|
1105
|
+
Signature of header hash, by the harvester. This is enough to create an unfinished
|
|
1106
|
+
block, which only needs a Proof of Time to be finished. If the signature is valid,
|
|
1107
|
+
we call the unfinished_block routine.
|
|
1108
|
+
"""
|
|
1109
|
+
candidate_tuple: Optional[tuple[uint32, UnfinishedBlock]] = self.full_node.full_node_store.get_candidate_block(
|
|
1110
|
+
farmer_request.quality_string
|
|
1111
|
+
)
|
|
1112
|
+
|
|
1113
|
+
if candidate_tuple is None:
|
|
1114
|
+
self.log.warning(f"Quality string {farmer_request.quality_string} not found in database")
|
|
1115
|
+
return None
|
|
1116
|
+
height, candidate = candidate_tuple
|
|
1117
|
+
|
|
1118
|
+
if not AugSchemeMPL.verify(
|
|
1119
|
+
candidate.reward_chain_block.proof_of_space.plot_public_key,
|
|
1120
|
+
candidate.foliage.foliage_block_data.get_hash(),
|
|
1121
|
+
farmer_request.foliage_block_data_signature,
|
|
1122
|
+
):
|
|
1123
|
+
self.log.warning("Signature not valid. There might be a collision in plots. Ignore this during tests.")
|
|
1124
|
+
return None
|
|
1125
|
+
|
|
1126
|
+
fsb2 = candidate.foliage.replace(foliage_block_data_signature=farmer_request.foliage_block_data_signature)
|
|
1127
|
+
if candidate.is_transaction_block():
|
|
1128
|
+
fsb2 = fsb2.replace(foliage_transaction_block_signature=farmer_request.foliage_transaction_block_signature)
|
|
1129
|
+
|
|
1130
|
+
new_candidate = candidate.replace(foliage=fsb2)
|
|
1131
|
+
if not self.full_node.has_valid_pool_sig(new_candidate):
|
|
1132
|
+
self.log.warning("Trying to make a pre-farm block but height is not 0")
|
|
1133
|
+
return None
|
|
1134
|
+
|
|
1135
|
+
# Propagate to ourselves (which validates and does further propagations)
|
|
1136
|
+
try:
|
|
1137
|
+
await self.full_node.add_unfinished_block(new_candidate, None, True)
|
|
1138
|
+
except Exception as e:
|
|
1139
|
+
# If we have an error with this block, try making an empty block
|
|
1140
|
+
self.full_node.log.error(f"Error farming block {e} {new_candidate}")
|
|
1141
|
+
candidate_tuple = self.full_node.full_node_store.get_candidate_block(
|
|
1142
|
+
farmer_request.quality_string, backup=True
|
|
1143
|
+
)
|
|
1144
|
+
if candidate_tuple is not None:
|
|
1145
|
+
height, unfinished_block = candidate_tuple
|
|
1146
|
+
self.full_node.full_node_store.add_candidate_block(
|
|
1147
|
+
farmer_request.quality_string, height, unfinished_block, False
|
|
1148
|
+
)
|
|
1149
|
+
# All unfinished blocks that we create will have the foliage transaction block and hash
|
|
1150
|
+
assert unfinished_block.foliage.foliage_transaction_block_hash is not None
|
|
1151
|
+
message = farmer_protocol.RequestSignedValues(
|
|
1152
|
+
farmer_request.quality_string,
|
|
1153
|
+
unfinished_block.foliage.foliage_block_data.get_hash(),
|
|
1154
|
+
unfinished_block.foliage.foliage_transaction_block_hash,
|
|
1155
|
+
)
|
|
1156
|
+
await peer.send_message(make_msg(ProtocolMessageTypes.request_signed_values, message))
|
|
1157
|
+
return None
|
|
1158
|
+
|
|
1159
|
+
# TIMELORD PROTOCOL
|
|
1160
|
+
@metadata.request(peer_required=True)
|
|
1161
|
+
async def new_infusion_point_vdf(
|
|
1162
|
+
self, request: timelord_protocol.NewInfusionPointVDF, peer: WSChiaConnection
|
|
1163
|
+
) -> Optional[Message]:
|
|
1164
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1165
|
+
return None
|
|
1166
|
+
# Lookup unfinished blocks
|
|
1167
|
+
async with self.full_node.timelord_lock:
|
|
1168
|
+
return await self.full_node.new_infusion_point_vdf(request, peer)
|
|
1169
|
+
|
|
1170
|
+
@metadata.request(peer_required=True)
|
|
1171
|
+
async def new_signage_point_vdf(
|
|
1172
|
+
self, request: timelord_protocol.NewSignagePointVDF, peer: WSChiaConnection
|
|
1173
|
+
) -> None:
|
|
1174
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1175
|
+
return None
|
|
1176
|
+
|
|
1177
|
+
full_node_message = full_node_protocol.RespondSignagePoint(
|
|
1178
|
+
request.index_from_challenge,
|
|
1179
|
+
request.challenge_chain_sp_vdf,
|
|
1180
|
+
request.challenge_chain_sp_proof,
|
|
1181
|
+
request.reward_chain_sp_vdf,
|
|
1182
|
+
request.reward_chain_sp_proof,
|
|
1183
|
+
)
|
|
1184
|
+
await self.respond_signage_point(full_node_message, peer)
|
|
1185
|
+
|
|
1186
|
+
@metadata.request(peer_required=True)
|
|
1187
|
+
async def new_end_of_sub_slot_vdf(
|
|
1188
|
+
self, request: timelord_protocol.NewEndOfSubSlotVDF, peer: WSChiaConnection
|
|
1189
|
+
) -> Optional[Message]:
|
|
1190
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1191
|
+
return None
|
|
1192
|
+
if (
|
|
1193
|
+
self.full_node.full_node_store.get_sub_slot(request.end_of_sub_slot_bundle.challenge_chain.get_hash())
|
|
1194
|
+
is not None
|
|
1195
|
+
):
|
|
1196
|
+
return None
|
|
1197
|
+
# Calls our own internal message to handle the end of sub slot, and potentially broadcasts to other peers.
|
|
1198
|
+
msg, added = await self.full_node.add_end_of_sub_slot(request.end_of_sub_slot_bundle, peer)
|
|
1199
|
+
if not added:
|
|
1200
|
+
self.log.error(
|
|
1201
|
+
f"Was not able to add end of sub-slot: "
|
|
1202
|
+
f"{request.end_of_sub_slot_bundle.challenge_chain.challenge_chain_end_of_slot_vdf.challenge.hex()}. "
|
|
1203
|
+
f"Re-sending new-peak to timelord"
|
|
1204
|
+
)
|
|
1205
|
+
await self.full_node.send_peak_to_timelords(peer=peer)
|
|
1206
|
+
return None
|
|
1207
|
+
else:
|
|
1208
|
+
return msg
|
|
1209
|
+
|
|
1210
|
+
@metadata.request()
|
|
1211
|
+
async def request_block_header(self, request: wallet_protocol.RequestBlockHeader) -> Optional[Message]:
|
|
1212
|
+
header_hash = self.full_node.blockchain.height_to_hash(request.height)
|
|
1213
|
+
if header_hash is None:
|
|
1214
|
+
msg = make_msg(ProtocolMessageTypes.reject_header_request, RejectHeaderRequest(request.height))
|
|
1215
|
+
return msg
|
|
1216
|
+
block: Optional[FullBlock] = await self.full_node.block_store.get_full_block(header_hash)
|
|
1217
|
+
if block is None:
|
|
1218
|
+
return None
|
|
1219
|
+
|
|
1220
|
+
removals_and_additions: Optional[tuple[Collection[bytes32], Collection[Coin]]] = None
|
|
1221
|
+
|
|
1222
|
+
if block.transactions_generator is not None:
|
|
1223
|
+
block_generator: Optional[BlockGenerator] = await get_block_generator(
|
|
1224
|
+
self.full_node.blockchain.lookup_block_generators, block
|
|
1225
|
+
)
|
|
1226
|
+
# get_block_generator() returns None in case the block we specify
|
|
1227
|
+
# does not have a generator (i.e. is not a transaction block).
|
|
1228
|
+
# in this case we've already made sure `block` does have a
|
|
1229
|
+
# transactions_generator, so the block_generator should always be set
|
|
1230
|
+
assert block_generator is not None, "failed to get block_generator for tx-block"
|
|
1231
|
+
|
|
1232
|
+
flags = get_flags_for_height_and_constants(request.height, self.full_node.constants)
|
|
1233
|
+
additions, removals = await asyncio.get_running_loop().run_in_executor(
|
|
1234
|
+
self.executor,
|
|
1235
|
+
additions_and_removals,
|
|
1236
|
+
bytes(block.transactions_generator),
|
|
1237
|
+
block_generator.generator_refs,
|
|
1238
|
+
flags,
|
|
1239
|
+
self.full_node.constants,
|
|
1240
|
+
)
|
|
1241
|
+
# strip the hint from additions, and compute the puzzle hash for
|
|
1242
|
+
# removals
|
|
1243
|
+
removals_and_additions = ([r.name() for r in removals], [a[0] for a in additions])
|
|
1244
|
+
elif block.is_transaction_block():
|
|
1245
|
+
# This is a transaction block with just reward coins.
|
|
1246
|
+
removals_and_additions = ([], [])
|
|
1247
|
+
|
|
1248
|
+
header_block = get_block_header(block, removals_and_additions)
|
|
1249
|
+
msg = make_msg(
|
|
1250
|
+
ProtocolMessageTypes.respond_block_header,
|
|
1251
|
+
wallet_protocol.RespondBlockHeader(header_block),
|
|
1252
|
+
)
|
|
1253
|
+
return msg
|
|
1254
|
+
|
|
1255
|
+
@metadata.request()
|
|
1256
|
+
async def request_additions(self, request: wallet_protocol.RequestAdditions) -> Optional[Message]:
|
|
1257
|
+
if request.header_hash is None:
|
|
1258
|
+
header_hash: Optional[bytes32] = self.full_node.blockchain.height_to_hash(request.height)
|
|
1259
|
+
else:
|
|
1260
|
+
header_hash = request.header_hash
|
|
1261
|
+
if header_hash is None:
|
|
1262
|
+
raise ValueError(f"Block at height {request.height} not found")
|
|
1263
|
+
|
|
1264
|
+
# Note: this might return bad data if there is a reorg in this time
|
|
1265
|
+
additions = await self.full_node.coin_store.get_coins_added_at_height(request.height)
|
|
1266
|
+
|
|
1267
|
+
if self.full_node.blockchain.height_to_hash(request.height) != header_hash:
|
|
1268
|
+
raise ValueError(f"Block {header_hash} no longer in chain, or invalid header_hash")
|
|
1269
|
+
|
|
1270
|
+
puzzlehash_coins_map: dict[bytes32, list[Coin]] = {}
|
|
1271
|
+
for coin_record in additions:
|
|
1272
|
+
if coin_record.coin.puzzle_hash in puzzlehash_coins_map:
|
|
1273
|
+
puzzlehash_coins_map[coin_record.coin.puzzle_hash].append(coin_record.coin)
|
|
1274
|
+
else:
|
|
1275
|
+
puzzlehash_coins_map[coin_record.coin.puzzle_hash] = [coin_record.coin]
|
|
1276
|
+
|
|
1277
|
+
coins_map: list[tuple[bytes32, list[Coin]]] = []
|
|
1278
|
+
proofs_map: list[tuple[bytes32, bytes, Optional[bytes]]] = []
|
|
1279
|
+
|
|
1280
|
+
if request.puzzle_hashes is None:
|
|
1281
|
+
for puzzle_hash, coins in puzzlehash_coins_map.items():
|
|
1282
|
+
coins_map.append((puzzle_hash, coins))
|
|
1283
|
+
response = wallet_protocol.RespondAdditions(request.height, header_hash, coins_map, None)
|
|
1284
|
+
else:
|
|
1285
|
+
# Create addition Merkle set
|
|
1286
|
+
# Addition Merkle set contains puzzlehash and hash of all coins with that puzzlehash
|
|
1287
|
+
leafs: list[bytes32] = []
|
|
1288
|
+
for puzzle, coins in puzzlehash_coins_map.items():
|
|
1289
|
+
leafs.append(puzzle)
|
|
1290
|
+
leafs.append(hash_coin_ids([c.name() for c in coins]))
|
|
1291
|
+
|
|
1292
|
+
addition_merkle_set = MerkleSet(leafs)
|
|
1293
|
+
|
|
1294
|
+
for puzzle_hash in request.puzzle_hashes:
|
|
1295
|
+
# This is a proof of inclusion if it's in (result==True), or exclusion of it's not in
|
|
1296
|
+
result, proof = addition_merkle_set.is_included_already_hashed(puzzle_hash)
|
|
1297
|
+
if puzzle_hash in puzzlehash_coins_map:
|
|
1298
|
+
coins_map.append((puzzle_hash, puzzlehash_coins_map[puzzle_hash]))
|
|
1299
|
+
hash_coin_str = hash_coin_ids([c.name() for c in puzzlehash_coins_map[puzzle_hash]])
|
|
1300
|
+
# This is a proof of inclusion of all coin ids that have this ph
|
|
1301
|
+
result_2, proof_2 = addition_merkle_set.is_included_already_hashed(hash_coin_str)
|
|
1302
|
+
assert result
|
|
1303
|
+
assert result_2
|
|
1304
|
+
proofs_map.append((puzzle_hash, proof, proof_2))
|
|
1305
|
+
else:
|
|
1306
|
+
coins_map.append((puzzle_hash, []))
|
|
1307
|
+
assert not result
|
|
1308
|
+
proofs_map.append((puzzle_hash, proof, None))
|
|
1309
|
+
response = wallet_protocol.RespondAdditions(request.height, header_hash, coins_map, proofs_map)
|
|
1310
|
+
return make_msg(ProtocolMessageTypes.respond_additions, response)
|
|
1311
|
+
|
|
1312
|
+
@metadata.request()
|
|
1313
|
+
async def request_removals(self, request: wallet_protocol.RequestRemovals) -> Optional[Message]:
|
|
1314
|
+
block: Optional[FullBlock] = await self.full_node.block_store.get_full_block(request.header_hash)
|
|
1315
|
+
|
|
1316
|
+
# We lock so that the coin store does not get modified
|
|
1317
|
+
peak_height = self.full_node.blockchain.get_peak_height()
|
|
1318
|
+
if (
|
|
1319
|
+
block is None
|
|
1320
|
+
or block.is_transaction_block() is False
|
|
1321
|
+
or block.height != request.height
|
|
1322
|
+
or (peak_height is not None and block.height > peak_height)
|
|
1323
|
+
or self.full_node.blockchain.height_to_hash(block.height) != request.header_hash
|
|
1324
|
+
):
|
|
1325
|
+
reject = wallet_protocol.RejectRemovalsRequest(request.height, request.header_hash)
|
|
1326
|
+
msg = make_msg(ProtocolMessageTypes.reject_removals_request, reject)
|
|
1327
|
+
return msg
|
|
1328
|
+
|
|
1329
|
+
assert block is not None and block.foliage_transaction_block is not None
|
|
1330
|
+
|
|
1331
|
+
# Note: this might return bad data if there is a reorg in this time
|
|
1332
|
+
all_removals: list[CoinRecord] = await self.full_node.coin_store.get_coins_removed_at_height(block.height)
|
|
1333
|
+
|
|
1334
|
+
if self.full_node.blockchain.height_to_hash(block.height) != request.header_hash:
|
|
1335
|
+
raise ValueError(f"Block {block.header_hash} no longer in chain")
|
|
1336
|
+
|
|
1337
|
+
all_removals_dict: dict[bytes32, Coin] = {}
|
|
1338
|
+
for coin_record in all_removals:
|
|
1339
|
+
all_removals_dict[coin_record.coin.name()] = coin_record.coin
|
|
1340
|
+
|
|
1341
|
+
coins_map: list[tuple[bytes32, Optional[Coin]]] = []
|
|
1342
|
+
proofs_map: list[tuple[bytes32, bytes]] = []
|
|
1343
|
+
|
|
1344
|
+
# If there are no transactions, respond with empty lists
|
|
1345
|
+
if block.transactions_generator is None:
|
|
1346
|
+
proofs: Optional[list[tuple[bytes32, bytes]]]
|
|
1347
|
+
if request.coin_names is None:
|
|
1348
|
+
proofs = None
|
|
1349
|
+
else:
|
|
1350
|
+
proofs = []
|
|
1351
|
+
response = wallet_protocol.RespondRemovals(block.height, block.header_hash, [], proofs)
|
|
1352
|
+
elif request.coin_names is None or len(request.coin_names) == 0:
|
|
1353
|
+
for removed_name, removed_coin in all_removals_dict.items():
|
|
1354
|
+
coins_map.append((removed_name, removed_coin))
|
|
1355
|
+
response = wallet_protocol.RespondRemovals(block.height, block.header_hash, coins_map, None)
|
|
1356
|
+
else:
|
|
1357
|
+
assert block.transactions_generator
|
|
1358
|
+
leafs: list[bytes32] = []
|
|
1359
|
+
for removed_name, removed_coin in all_removals_dict.items():
|
|
1360
|
+
leafs.append(removed_name)
|
|
1361
|
+
removal_merkle_set = MerkleSet(leafs)
|
|
1362
|
+
assert removal_merkle_set.get_root() == block.foliage_transaction_block.removals_root
|
|
1363
|
+
for coin_name in request.coin_names:
|
|
1364
|
+
result, proof = removal_merkle_set.is_included_already_hashed(coin_name)
|
|
1365
|
+
proofs_map.append((coin_name, proof))
|
|
1366
|
+
if coin_name in all_removals_dict:
|
|
1367
|
+
removed_coin = all_removals_dict[coin_name]
|
|
1368
|
+
coins_map.append((coin_name, removed_coin))
|
|
1369
|
+
assert result
|
|
1370
|
+
else:
|
|
1371
|
+
coins_map.append((coin_name, None))
|
|
1372
|
+
assert not result
|
|
1373
|
+
response = wallet_protocol.RespondRemovals(block.height, block.header_hash, coins_map, proofs_map)
|
|
1374
|
+
|
|
1375
|
+
msg = make_msg(ProtocolMessageTypes.respond_removals, response)
|
|
1376
|
+
return msg
|
|
1377
|
+
|
|
1378
|
+
@metadata.request()
|
|
1379
|
+
async def send_transaction(
|
|
1380
|
+
self, request: wallet_protocol.SendTransaction, *, test: bool = False
|
|
1381
|
+
) -> Optional[Message]:
|
|
1382
|
+
spend_name = request.transaction.name()
|
|
1383
|
+
if self.full_node.mempool_manager.get_spendbundle(spend_name) is not None:
|
|
1384
|
+
self.full_node.mempool_manager.remove_seen(spend_name)
|
|
1385
|
+
response = wallet_protocol.TransactionAck(spend_name, uint8(MempoolInclusionStatus.SUCCESS), None)
|
|
1386
|
+
return make_msg(ProtocolMessageTypes.transaction_ack, response)
|
|
1387
|
+
|
|
1388
|
+
queue_entry = TransactionQueueEntry(request.transaction, None, spend_name, None, test)
|
|
1389
|
+
await self.full_node.transaction_queue.put(queue_entry, peer_id=None, high_priority=True)
|
|
1390
|
+
try:
|
|
1391
|
+
with anyio.fail_after(delay=45):
|
|
1392
|
+
status, error = await queue_entry.done.wait()
|
|
1393
|
+
except TimeoutError:
|
|
1394
|
+
response = wallet_protocol.TransactionAck(spend_name, uint8(MempoolInclusionStatus.PENDING), None)
|
|
1395
|
+
else:
|
|
1396
|
+
error_name = error.name if error is not None else None
|
|
1397
|
+
if status == MempoolInclusionStatus.SUCCESS:
|
|
1398
|
+
response = wallet_protocol.TransactionAck(spend_name, uint8(status.value), error_name)
|
|
1399
|
+
else:
|
|
1400
|
+
# If if failed/pending, but it previously succeeded (in mempool), this is idempotence, return SUCCESS
|
|
1401
|
+
if self.full_node.mempool_manager.get_spendbundle(spend_name) is not None:
|
|
1402
|
+
response = wallet_protocol.TransactionAck(
|
|
1403
|
+
spend_name, uint8(MempoolInclusionStatus.SUCCESS.value), None
|
|
1404
|
+
)
|
|
1405
|
+
else:
|
|
1406
|
+
response = wallet_protocol.TransactionAck(spend_name, uint8(status.value), error_name)
|
|
1407
|
+
return make_msg(ProtocolMessageTypes.transaction_ack, response)
|
|
1408
|
+
|
|
1409
|
+
@metadata.request()
|
|
1410
|
+
async def request_puzzle_solution(self, request: wallet_protocol.RequestPuzzleSolution) -> Optional[Message]:
|
|
1411
|
+
coin_name = request.coin_name
|
|
1412
|
+
height = request.height
|
|
1413
|
+
coin_record = await self.full_node.coin_store.get_coin_record(coin_name)
|
|
1414
|
+
reject = wallet_protocol.RejectPuzzleSolution(coin_name, height)
|
|
1415
|
+
reject_msg = make_msg(ProtocolMessageTypes.reject_puzzle_solution, reject)
|
|
1416
|
+
if coin_record is None or coin_record.spent_block_index != height:
|
|
1417
|
+
return reject_msg
|
|
1418
|
+
|
|
1419
|
+
header_hash: Optional[bytes32] = self.full_node.blockchain.height_to_hash(height)
|
|
1420
|
+
if header_hash is None:
|
|
1421
|
+
return reject_msg
|
|
1422
|
+
|
|
1423
|
+
block: Optional[BlockInfo] = await self.full_node.block_store.get_block_info(header_hash)
|
|
1424
|
+
|
|
1425
|
+
if block is None or block.transactions_generator is None:
|
|
1426
|
+
return reject_msg
|
|
1427
|
+
|
|
1428
|
+
block_generator: Optional[BlockGenerator] = await get_block_generator(
|
|
1429
|
+
self.full_node.blockchain.lookup_block_generators, block
|
|
1430
|
+
)
|
|
1431
|
+
assert block_generator is not None
|
|
1432
|
+
try:
|
|
1433
|
+
spend_info = await asyncio.get_running_loop().run_in_executor(
|
|
1434
|
+
self.executor,
|
|
1435
|
+
get_puzzle_and_solution_for_coin,
|
|
1436
|
+
block_generator,
|
|
1437
|
+
coin_record.coin,
|
|
1438
|
+
height,
|
|
1439
|
+
self.full_node.constants,
|
|
1440
|
+
)
|
|
1441
|
+
except ValueError:
|
|
1442
|
+
return reject_msg
|
|
1443
|
+
wrapper = PuzzleSolutionResponse(coin_name, height, spend_info.puzzle, spend_info.solution)
|
|
1444
|
+
response = wallet_protocol.RespondPuzzleSolution(wrapper)
|
|
1445
|
+
response_msg = make_msg(ProtocolMessageTypes.respond_puzzle_solution, response)
|
|
1446
|
+
return response_msg
|
|
1447
|
+
|
|
1448
|
+
@metadata.request()
|
|
1449
|
+
async def request_block_headers(self, request: wallet_protocol.RequestBlockHeaders) -> Optional[Message]:
|
|
1450
|
+
"""Returns header blocks by directly streaming bytes into Message
|
|
1451
|
+
|
|
1452
|
+
This method should be used instead of RequestHeaderBlocks
|
|
1453
|
+
"""
|
|
1454
|
+
reject = RejectBlockHeaders(request.start_height, request.end_height)
|
|
1455
|
+
|
|
1456
|
+
if request.end_height < request.start_height or request.end_height - request.start_height > 128:
|
|
1457
|
+
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
|
|
1458
|
+
if self.full_node.block_store.db_wrapper.db_version == 2:
|
|
1459
|
+
try:
|
|
1460
|
+
blocks_bytes = await self.full_node.block_store.get_block_bytes_in_range(
|
|
1461
|
+
request.start_height, request.end_height
|
|
1462
|
+
)
|
|
1463
|
+
except ValueError:
|
|
1464
|
+
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
|
|
1465
|
+
|
|
1466
|
+
else:
|
|
1467
|
+
height_to_hash = self.full_node.blockchain.height_to_hash
|
|
1468
|
+
header_hashes: list[bytes32] = []
|
|
1469
|
+
for i in range(request.start_height, request.end_height + 1):
|
|
1470
|
+
header_hash: Optional[bytes32] = height_to_hash(uint32(i))
|
|
1471
|
+
if header_hash is None:
|
|
1472
|
+
return make_msg(ProtocolMessageTypes.reject_header_blocks, reject)
|
|
1473
|
+
header_hashes.append(header_hash)
|
|
1474
|
+
|
|
1475
|
+
blocks_bytes = await self.full_node.block_store.get_block_bytes_by_hash(header_hashes)
|
|
1476
|
+
if len(blocks_bytes) != (request.end_height - request.start_height + 1): # +1 because interval is inclusive
|
|
1477
|
+
return make_msg(ProtocolMessageTypes.reject_block_headers, reject)
|
|
1478
|
+
return_filter = request.return_filter
|
|
1479
|
+
header_blocks_bytes: list[bytes] = []
|
|
1480
|
+
for b in blocks_bytes:
|
|
1481
|
+
b_mem_view = memoryview(b)
|
|
1482
|
+
height, is_tx_block = get_height_and_tx_status_from_block(b_mem_view)
|
|
1483
|
+
if not is_tx_block:
|
|
1484
|
+
tx_addition_coins = []
|
|
1485
|
+
removal_names = []
|
|
1486
|
+
else:
|
|
1487
|
+
added_coins_records_coroutine = self.full_node.coin_store.get_coins_added_at_height(height)
|
|
1488
|
+
removed_coins_records_coroutine = self.full_node.coin_store.get_coins_removed_at_height(height)
|
|
1489
|
+
added_coins_records, removed_coins_records = await asyncio.gather(
|
|
1490
|
+
added_coins_records_coroutine, removed_coins_records_coroutine
|
|
1491
|
+
)
|
|
1492
|
+
tx_addition_coins = [record.coin for record in added_coins_records if not record.coinbase]
|
|
1493
|
+
removal_names = [record.coin.name() for record in removed_coins_records]
|
|
1494
|
+
header_blocks_bytes.append(
|
|
1495
|
+
header_block_from_block(b_mem_view, return_filter, tx_addition_coins, removal_names)
|
|
1496
|
+
)
|
|
1497
|
+
|
|
1498
|
+
# we're building the RespondHeaderBlocks manually to avoid cost of
|
|
1499
|
+
# dynamic serialization
|
|
1500
|
+
# ---
|
|
1501
|
+
# we start building RespondBlockHeaders response (start_height, end_height)
|
|
1502
|
+
# and then need to define size of list object
|
|
1503
|
+
respond_header_blocks_manually_streamed: bytes = (
|
|
1504
|
+
uint32(request.start_height).stream_to_bytes()
|
|
1505
|
+
+ uint32(request.end_height).stream_to_bytes()
|
|
1506
|
+
+ uint32(len(header_blocks_bytes)).stream_to_bytes()
|
|
1507
|
+
)
|
|
1508
|
+
# and now stream the whole list in bytes
|
|
1509
|
+
respond_header_blocks_manually_streamed += b"".join(header_blocks_bytes)
|
|
1510
|
+
return make_msg(ProtocolMessageTypes.respond_block_headers, respond_header_blocks_manually_streamed)
|
|
1511
|
+
|
|
1512
|
+
@metadata.request()
|
|
1513
|
+
async def request_header_blocks(self, request: wallet_protocol.RequestHeaderBlocks) -> Optional[Message]:
|
|
1514
|
+
"""DEPRECATED: please use RequestBlockHeaders"""
|
|
1515
|
+
if (
|
|
1516
|
+
request.end_height < request.start_height
|
|
1517
|
+
or request.end_height - request.start_height > self.full_node.constants.MAX_BLOCK_COUNT_PER_REQUESTS
|
|
1518
|
+
):
|
|
1519
|
+
return None
|
|
1520
|
+
height_to_hash = self.full_node.blockchain.height_to_hash
|
|
1521
|
+
header_hashes: list[bytes32] = []
|
|
1522
|
+
for i in range(request.start_height, request.end_height + 1):
|
|
1523
|
+
header_hash: Optional[bytes32] = height_to_hash(uint32(i))
|
|
1524
|
+
if header_hash is None:
|
|
1525
|
+
reject = RejectHeaderBlocks(request.start_height, request.end_height)
|
|
1526
|
+
msg = make_msg(ProtocolMessageTypes.reject_header_blocks, reject)
|
|
1527
|
+
return msg
|
|
1528
|
+
header_hashes.append(header_hash)
|
|
1529
|
+
|
|
1530
|
+
blocks: list[FullBlock] = await self.full_node.block_store.get_blocks_by_hash(header_hashes)
|
|
1531
|
+
header_blocks = []
|
|
1532
|
+
for block in blocks:
|
|
1533
|
+
added_coins_records_coroutine = self.full_node.coin_store.get_coins_added_at_height(block.height)
|
|
1534
|
+
removed_coins_records_coroutine = self.full_node.coin_store.get_coins_removed_at_height(block.height)
|
|
1535
|
+
added_coins_records, removed_coins_records = await asyncio.gather(
|
|
1536
|
+
added_coins_records_coroutine, removed_coins_records_coroutine
|
|
1537
|
+
)
|
|
1538
|
+
added_coins = [record.coin for record in added_coins_records if not record.coinbase]
|
|
1539
|
+
removal_names = [record.coin.name() for record in removed_coins_records]
|
|
1540
|
+
header_block = get_block_header(block, (removal_names, added_coins))
|
|
1541
|
+
header_blocks.append(header_block)
|
|
1542
|
+
|
|
1543
|
+
msg = make_msg(
|
|
1544
|
+
ProtocolMessageTypes.respond_header_blocks,
|
|
1545
|
+
wallet_protocol.RespondHeaderBlocks(request.start_height, request.end_height, header_blocks),
|
|
1546
|
+
)
|
|
1547
|
+
return msg
|
|
1548
|
+
|
|
1549
|
+
@metadata.request(bytes_required=True, execute_task=True)
|
|
1550
|
+
async def respond_compact_proof_of_time(
|
|
1551
|
+
self, request: timelord_protocol.RespondCompactProofOfTime, request_bytes: bytes = b""
|
|
1552
|
+
) -> None:
|
|
1553
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1554
|
+
return None
|
|
1555
|
+
name = std_hash(request_bytes)
|
|
1556
|
+
if name in self.full_node.compact_vdf_requests:
|
|
1557
|
+
self.log.debug(f"Ignoring CompactProofOfTime: {request}, already requested")
|
|
1558
|
+
return None
|
|
1559
|
+
|
|
1560
|
+
self.full_node.compact_vdf_requests.add(name)
|
|
1561
|
+
|
|
1562
|
+
# this semaphore will only allow a limited number of tasks call
|
|
1563
|
+
# new_compact_vdf() at a time, since it can be expensive
|
|
1564
|
+
try:
|
|
1565
|
+
async with self.full_node.compact_vdf_sem.acquire():
|
|
1566
|
+
try:
|
|
1567
|
+
await self.full_node.add_compact_proof_of_time(request)
|
|
1568
|
+
finally:
|
|
1569
|
+
self.full_node.compact_vdf_requests.remove(name)
|
|
1570
|
+
except LimitedSemaphoreFullError:
|
|
1571
|
+
self.log.debug(f"Ignoring CompactProofOfTime: {request}, _waiters")
|
|
1572
|
+
|
|
1573
|
+
return None
|
|
1574
|
+
|
|
1575
|
+
@metadata.request(peer_required=True, bytes_required=True, execute_task=True)
|
|
1576
|
+
async def new_compact_vdf(
|
|
1577
|
+
self, request: full_node_protocol.NewCompactVDF, peer: WSChiaConnection, request_bytes: bytes = b""
|
|
1578
|
+
) -> None:
|
|
1579
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1580
|
+
return None
|
|
1581
|
+
|
|
1582
|
+
name = std_hash(request_bytes)
|
|
1583
|
+
if name in self.full_node.compact_vdf_requests:
|
|
1584
|
+
self.log.debug("Ignoring NewCompactVDF, already requested: %s %s", peer.get_peer_logging(), request)
|
|
1585
|
+
return None
|
|
1586
|
+
self.full_node.compact_vdf_requests.add(name)
|
|
1587
|
+
|
|
1588
|
+
# this semaphore will only allow a limited number of tasks call
|
|
1589
|
+
# new_compact_vdf() at a time, since it can be expensive
|
|
1590
|
+
try:
|
|
1591
|
+
async with self.full_node.compact_vdf_sem.acquire():
|
|
1592
|
+
try:
|
|
1593
|
+
await self.full_node.new_compact_vdf(request, peer)
|
|
1594
|
+
finally:
|
|
1595
|
+
self.full_node.compact_vdf_requests.remove(name)
|
|
1596
|
+
except LimitedSemaphoreFullError:
|
|
1597
|
+
self.log.debug("Ignoring NewCompactVDF, limited semaphore full: %s %s", peer.get_peer_logging(), request)
|
|
1598
|
+
return None
|
|
1599
|
+
|
|
1600
|
+
return None
|
|
1601
|
+
|
|
1602
|
+
@metadata.request(peer_required=True, reply_types=[ProtocolMessageTypes.respond_compact_vdf])
|
|
1603
|
+
async def request_compact_vdf(self, request: full_node_protocol.RequestCompactVDF, peer: WSChiaConnection) -> None:
|
|
1604
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1605
|
+
return None
|
|
1606
|
+
await self.full_node.request_compact_vdf(request, peer)
|
|
1607
|
+
return None
|
|
1608
|
+
|
|
1609
|
+
@metadata.request(peer_required=True)
|
|
1610
|
+
async def respond_compact_vdf(self, request: full_node_protocol.RespondCompactVDF, peer: WSChiaConnection) -> None:
|
|
1611
|
+
if self.full_node.sync_store.get_sync_mode():
|
|
1612
|
+
return None
|
|
1613
|
+
await self.full_node.add_compact_vdf(request, peer)
|
|
1614
|
+
return None
|
|
1615
|
+
|
|
1616
|
+
@metadata.request(peer_required=True)
|
|
1617
|
+
async def register_for_ph_updates(
|
|
1618
|
+
self, request: wallet_protocol.RegisterForPhUpdates, peer: WSChiaConnection
|
|
1619
|
+
) -> Message:
|
|
1620
|
+
trusted = self.is_trusted(peer)
|
|
1621
|
+
max_items = self.max_subscribe_response_items(peer)
|
|
1622
|
+
max_subscriptions = self.max_subscriptions(peer)
|
|
1623
|
+
|
|
1624
|
+
# the returned puzzle hashes are the ones we ended up subscribing to.
|
|
1625
|
+
# It will have filtered duplicates and ones exceeding the subscription
|
|
1626
|
+
# limit.
|
|
1627
|
+
puzzle_hashes = self.full_node.subscriptions.add_puzzle_subscriptions(
|
|
1628
|
+
peer.peer_node_id, request.puzzle_hashes, max_subscriptions
|
|
1629
|
+
)
|
|
1630
|
+
|
|
1631
|
+
start_time = time.monotonic()
|
|
1632
|
+
|
|
1633
|
+
# Note that coin state updates may arrive out-of-order on the client side.
|
|
1634
|
+
# We add the subscription before we're done collecting all the coin
|
|
1635
|
+
# state that goes into the response. CoinState updates may be sent
|
|
1636
|
+
# before we send the response
|
|
1637
|
+
|
|
1638
|
+
# Send all coins with requested puzzle hash that have been created after the specified height
|
|
1639
|
+
states: set[CoinState] = await self.full_node.coin_store.get_coin_states_by_puzzle_hashes(
|
|
1640
|
+
include_spent_coins=True, puzzle_hashes=puzzle_hashes, min_height=request.min_height, max_items=max_items
|
|
1641
|
+
)
|
|
1642
|
+
max_items -= len(states)
|
|
1643
|
+
|
|
1644
|
+
hint_coin_ids = await self.full_node.hint_store.get_coin_ids_multi(
|
|
1645
|
+
cast(set[bytes], puzzle_hashes), max_items=max_items
|
|
1646
|
+
)
|
|
1647
|
+
|
|
1648
|
+
hint_states: list[CoinState] = []
|
|
1649
|
+
if len(hint_coin_ids) > 0:
|
|
1650
|
+
hint_states = await self.full_node.coin_store.get_coin_states_by_ids(
|
|
1651
|
+
include_spent_coins=True,
|
|
1652
|
+
coin_ids=hint_coin_ids,
|
|
1653
|
+
min_height=request.min_height,
|
|
1654
|
+
max_items=len(hint_coin_ids),
|
|
1655
|
+
)
|
|
1656
|
+
states.update(hint_states)
|
|
1657
|
+
|
|
1658
|
+
end_time = time.monotonic()
|
|
1659
|
+
|
|
1660
|
+
truncated = max_items <= 0
|
|
1661
|
+
|
|
1662
|
+
if truncated or end_time - start_time > 5:
|
|
1663
|
+
self.log.log(
|
|
1664
|
+
logging.WARNING if trusted and truncated else logging.INFO,
|
|
1665
|
+
"RegisterForPhUpdates resulted in %d coin states. "
|
|
1666
|
+
"Request had %d (unique) puzzle hashes and matched %d hints. %s"
|
|
1667
|
+
"The request took %0.2fs",
|
|
1668
|
+
len(states),
|
|
1669
|
+
len(puzzle_hashes),
|
|
1670
|
+
len(hint_states),
|
|
1671
|
+
"The response was truncated. " if truncated else "",
|
|
1672
|
+
end_time - start_time,
|
|
1673
|
+
)
|
|
1674
|
+
|
|
1675
|
+
response = wallet_protocol.RespondToPhUpdates(request.puzzle_hashes, request.min_height, list(states))
|
|
1676
|
+
msg = make_msg(ProtocolMessageTypes.respond_to_ph_updates, response)
|
|
1677
|
+
return msg
|
|
1678
|
+
|
|
1679
|
+
@metadata.request(peer_required=True)
|
|
1680
|
+
async def register_for_coin_updates(
|
|
1681
|
+
self, request: wallet_protocol.RegisterForCoinUpdates, peer: WSChiaConnection
|
|
1682
|
+
) -> Message:
|
|
1683
|
+
max_items = self.max_subscribe_response_items(peer)
|
|
1684
|
+
max_subscriptions = self.max_subscriptions(peer)
|
|
1685
|
+
|
|
1686
|
+
# TODO: apparently we have tests that expect to receive a
|
|
1687
|
+
# RespondToCoinUpdates even when subscribing to the same coin multiple
|
|
1688
|
+
# times, so we can't optimize away such DB lookups (yet)
|
|
1689
|
+
self.full_node.subscriptions.add_coin_subscriptions(peer.peer_node_id, request.coin_ids, max_subscriptions)
|
|
1690
|
+
|
|
1691
|
+
states: list[CoinState] = await self.full_node.coin_store.get_coin_states_by_ids(
|
|
1692
|
+
include_spent_coins=True, coin_ids=set(request.coin_ids), min_height=request.min_height, max_items=max_items
|
|
1693
|
+
)
|
|
1694
|
+
|
|
1695
|
+
response = wallet_protocol.RespondToCoinUpdates(request.coin_ids, request.min_height, states)
|
|
1696
|
+
msg = make_msg(ProtocolMessageTypes.respond_to_coin_updates, response)
|
|
1697
|
+
return msg
|
|
1698
|
+
|
|
1699
|
+
@metadata.request()
|
|
1700
|
+
async def request_children(self, request: wallet_protocol.RequestChildren) -> Optional[Message]:
|
|
1701
|
+
coin_records: list[CoinRecord] = await self.full_node.coin_store.get_coin_records_by_parent_ids(
|
|
1702
|
+
True, [request.coin_name]
|
|
1703
|
+
)
|
|
1704
|
+
states = [record.coin_state for record in coin_records]
|
|
1705
|
+
response = wallet_protocol.RespondChildren(states)
|
|
1706
|
+
msg = make_msg(ProtocolMessageTypes.respond_children, response)
|
|
1707
|
+
return msg
|
|
1708
|
+
|
|
1709
|
+
@metadata.request()
|
|
1710
|
+
async def request_ses_hashes(self, request: wallet_protocol.RequestSESInfo) -> Message:
|
|
1711
|
+
"""Returns the start and end height of a sub-epoch for the height specified in request"""
|
|
1712
|
+
|
|
1713
|
+
ses_height = self.full_node.blockchain.get_ses_heights()
|
|
1714
|
+
start_height = request.start_height
|
|
1715
|
+
end_height = request.end_height
|
|
1716
|
+
ses_hash_heights = []
|
|
1717
|
+
ses_reward_hashes = []
|
|
1718
|
+
|
|
1719
|
+
for idx, ses_start_height in enumerate(ses_height):
|
|
1720
|
+
if idx == len(ses_height) - 1:
|
|
1721
|
+
break
|
|
1722
|
+
|
|
1723
|
+
next_ses_height = ses_height[idx + 1]
|
|
1724
|
+
# start_ses_hash
|
|
1725
|
+
if ses_start_height <= start_height < next_ses_height:
|
|
1726
|
+
ses_hash_heights.append([ses_start_height, next_ses_height])
|
|
1727
|
+
ses: SubEpochSummary = self.full_node.blockchain.get_ses(ses_start_height)
|
|
1728
|
+
ses_reward_hashes.append(ses.reward_chain_hash)
|
|
1729
|
+
if ses_start_height < end_height < next_ses_height:
|
|
1730
|
+
break
|
|
1731
|
+
else:
|
|
1732
|
+
if idx == len(ses_height) - 2:
|
|
1733
|
+
break
|
|
1734
|
+
# else add extra ses as request start <-> end spans two ses
|
|
1735
|
+
next_next_height = ses_height[idx + 2]
|
|
1736
|
+
ses_hash_heights.append([next_ses_height, next_next_height])
|
|
1737
|
+
nex_ses: SubEpochSummary = self.full_node.blockchain.get_ses(next_ses_height)
|
|
1738
|
+
ses_reward_hashes.append(nex_ses.reward_chain_hash)
|
|
1739
|
+
break
|
|
1740
|
+
|
|
1741
|
+
response = RespondSESInfo(ses_reward_hashes, ses_hash_heights)
|
|
1742
|
+
msg = make_msg(ProtocolMessageTypes.respond_ses_hashes, response)
|
|
1743
|
+
return msg
|
|
1744
|
+
|
|
1745
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_fee_estimates])
|
|
1746
|
+
async def request_fee_estimates(self, request: wallet_protocol.RequestFeeEstimates) -> Message:
|
|
1747
|
+
def get_fee_estimates(est: FeeEstimatorInterface, req_times: list[uint64]) -> list[FeeEstimate]:
|
|
1748
|
+
now = datetime.now(timezone.utc)
|
|
1749
|
+
utc_time = now.replace(tzinfo=timezone.utc)
|
|
1750
|
+
utc_now = int(utc_time.timestamp())
|
|
1751
|
+
deltas = [max(0, req_ts - utc_now) for req_ts in req_times]
|
|
1752
|
+
fee_rates = [est.estimate_fee_rate(time_offset_seconds=d) for d in deltas]
|
|
1753
|
+
v1_fee_rates = [fee_rate_v2_to_v1(est) for est in fee_rates]
|
|
1754
|
+
return [FeeEstimate(None, req_ts, fee_rate) for req_ts, fee_rate in zip(req_times, v1_fee_rates)]
|
|
1755
|
+
|
|
1756
|
+
fee_estimates: list[FeeEstimate] = get_fee_estimates(
|
|
1757
|
+
self.full_node.mempool_manager.mempool.fee_estimator, request.time_targets
|
|
1758
|
+
)
|
|
1759
|
+
response = RespondFeeEstimates(FeeEstimateGroup(error=None, estimates=fee_estimates))
|
|
1760
|
+
msg = make_msg(ProtocolMessageTypes.respond_fee_estimates, response)
|
|
1761
|
+
return msg
|
|
1762
|
+
|
|
1763
|
+
@metadata.request(
|
|
1764
|
+
peer_required=True,
|
|
1765
|
+
reply_types=[ProtocolMessageTypes.respond_remove_puzzle_subscriptions],
|
|
1766
|
+
)
|
|
1767
|
+
async def request_remove_puzzle_subscriptions(
|
|
1768
|
+
self, request: wallet_protocol.RequestRemovePuzzleSubscriptions, peer: WSChiaConnection
|
|
1769
|
+
) -> Message:
|
|
1770
|
+
peer_id = peer.peer_node_id
|
|
1771
|
+
subs = self.full_node.subscriptions
|
|
1772
|
+
|
|
1773
|
+
if request.puzzle_hashes is None:
|
|
1774
|
+
removed = list(subs.puzzle_subscriptions(peer_id))
|
|
1775
|
+
subs.clear_puzzle_subscriptions(peer_id)
|
|
1776
|
+
else:
|
|
1777
|
+
removed = list(subs.remove_puzzle_subscriptions(peer_id, request.puzzle_hashes))
|
|
1778
|
+
|
|
1779
|
+
response = wallet_protocol.RespondRemovePuzzleSubscriptions(removed)
|
|
1780
|
+
msg = make_msg(ProtocolMessageTypes.respond_remove_puzzle_subscriptions, response)
|
|
1781
|
+
return msg
|
|
1782
|
+
|
|
1783
|
+
@metadata.request(
|
|
1784
|
+
peer_required=True,
|
|
1785
|
+
reply_types=[ProtocolMessageTypes.respond_remove_coin_subscriptions],
|
|
1786
|
+
)
|
|
1787
|
+
async def request_remove_coin_subscriptions(
|
|
1788
|
+
self, request: wallet_protocol.RequestRemoveCoinSubscriptions, peer: WSChiaConnection
|
|
1789
|
+
) -> Message:
|
|
1790
|
+
peer_id = peer.peer_node_id
|
|
1791
|
+
subs = self.full_node.subscriptions
|
|
1792
|
+
|
|
1793
|
+
if request.coin_ids is None:
|
|
1794
|
+
removed = list(subs.coin_subscriptions(peer_id))
|
|
1795
|
+
subs.clear_coin_subscriptions(peer_id)
|
|
1796
|
+
else:
|
|
1797
|
+
removed = list(subs.remove_coin_subscriptions(peer_id, request.coin_ids))
|
|
1798
|
+
|
|
1799
|
+
response = wallet_protocol.RespondRemoveCoinSubscriptions(removed)
|
|
1800
|
+
msg = make_msg(ProtocolMessageTypes.respond_remove_coin_subscriptions, response)
|
|
1801
|
+
return msg
|
|
1802
|
+
|
|
1803
|
+
@metadata.request(peer_required=True, reply_types=[ProtocolMessageTypes.respond_puzzle_state])
|
|
1804
|
+
async def request_puzzle_state(
|
|
1805
|
+
self, request: wallet_protocol.RequestPuzzleState, peer: WSChiaConnection
|
|
1806
|
+
) -> Message:
|
|
1807
|
+
max_items = self.max_subscribe_response_items(peer)
|
|
1808
|
+
max_subscriptions = self.max_subscriptions(peer)
|
|
1809
|
+
subs = self.full_node.subscriptions
|
|
1810
|
+
|
|
1811
|
+
request_puzzle_hashes = list(dict.fromkeys(request.puzzle_hashes))
|
|
1812
|
+
|
|
1813
|
+
# This is a limit imposed by `batch_coin_states_by_puzzle_hashes`, due to the SQLite variable limit.
|
|
1814
|
+
# It can be increased in the future, and this protocol should be written and tested in a way that
|
|
1815
|
+
# this increase would not break the API.
|
|
1816
|
+
count = CoinStore.MAX_PUZZLE_HASH_BATCH_SIZE
|
|
1817
|
+
puzzle_hashes = request_puzzle_hashes[:count]
|
|
1818
|
+
|
|
1819
|
+
previous_header_hash = (
|
|
1820
|
+
self.full_node.blockchain.height_to_hash(request.previous_height)
|
|
1821
|
+
if request.previous_height is not None
|
|
1822
|
+
else self.full_node.blockchain.constants.GENESIS_CHALLENGE
|
|
1823
|
+
)
|
|
1824
|
+
assert previous_header_hash is not None
|
|
1825
|
+
|
|
1826
|
+
if request.header_hash != previous_header_hash:
|
|
1827
|
+
rejection = wallet_protocol.RejectPuzzleState(uint8(wallet_protocol.RejectStateReason.REORG))
|
|
1828
|
+
msg = make_msg(ProtocolMessageTypes.reject_puzzle_state, rejection)
|
|
1829
|
+
return msg
|
|
1830
|
+
|
|
1831
|
+
# Check if the request would exceed the subscription limit now.
|
|
1832
|
+
def check_subscription_limit() -> Optional[Message]:
|
|
1833
|
+
new_subscription_count = len(puzzle_hashes) + subs.peer_subscription_count(peer.peer_node_id)
|
|
1834
|
+
|
|
1835
|
+
if request.subscribe_when_finished and new_subscription_count > max_subscriptions:
|
|
1836
|
+
rejection = wallet_protocol.RejectPuzzleState(
|
|
1837
|
+
uint8(wallet_protocol.RejectStateReason.EXCEEDED_SUBSCRIPTION_LIMIT)
|
|
1838
|
+
)
|
|
1839
|
+
msg = make_msg(ProtocolMessageTypes.reject_puzzle_state, rejection)
|
|
1840
|
+
return msg
|
|
1841
|
+
|
|
1842
|
+
return None
|
|
1843
|
+
|
|
1844
|
+
sub_rejection = check_subscription_limit()
|
|
1845
|
+
if sub_rejection is not None:
|
|
1846
|
+
return sub_rejection
|
|
1847
|
+
|
|
1848
|
+
min_height = uint32((request.previous_height + 1) if request.previous_height is not None else 0)
|
|
1849
|
+
|
|
1850
|
+
(coin_states, next_min_height) = await self.full_node.coin_store.batch_coin_states_by_puzzle_hashes(
|
|
1851
|
+
puzzle_hashes,
|
|
1852
|
+
min_height=min_height,
|
|
1853
|
+
include_spent=request.filters.include_spent,
|
|
1854
|
+
include_unspent=request.filters.include_unspent,
|
|
1855
|
+
include_hinted=request.filters.include_hinted,
|
|
1856
|
+
min_amount=request.filters.min_amount,
|
|
1857
|
+
max_items=max_items,
|
|
1858
|
+
)
|
|
1859
|
+
is_done = next_min_height is None
|
|
1860
|
+
|
|
1861
|
+
peak_height = self.full_node.blockchain.get_peak_height()
|
|
1862
|
+
assert peak_height is not None
|
|
1863
|
+
|
|
1864
|
+
height = uint32(next_min_height - 1) if next_min_height is not None else peak_height
|
|
1865
|
+
header_hash = self.full_node.blockchain.height_to_hash(height)
|
|
1866
|
+
assert header_hash is not None
|
|
1867
|
+
|
|
1868
|
+
# Check if the request would exceed the subscription limit.
|
|
1869
|
+
# We do this again since we've crossed an `await` point, to prevent a race condition.
|
|
1870
|
+
sub_rejection = check_subscription_limit()
|
|
1871
|
+
if sub_rejection is not None:
|
|
1872
|
+
return sub_rejection
|
|
1873
|
+
|
|
1874
|
+
if is_done and request.subscribe_when_finished:
|
|
1875
|
+
subs.add_puzzle_subscriptions(peer.peer_node_id, puzzle_hashes, max_subscriptions)
|
|
1876
|
+
await self.mempool_updates_for_puzzle_hashes(peer, set(puzzle_hashes), request.filters.include_hinted)
|
|
1877
|
+
|
|
1878
|
+
response = wallet_protocol.RespondPuzzleState(puzzle_hashes, height, header_hash, is_done, coin_states)
|
|
1879
|
+
msg = make_msg(ProtocolMessageTypes.respond_puzzle_state, response)
|
|
1880
|
+
return msg
|
|
1881
|
+
|
|
1882
|
+
@metadata.request(peer_required=True, reply_types=[ProtocolMessageTypes.respond_coin_state])
|
|
1883
|
+
async def request_coin_state(self, request: wallet_protocol.RequestCoinState, peer: WSChiaConnection) -> Message:
|
|
1884
|
+
max_items = self.max_subscribe_response_items(peer)
|
|
1885
|
+
max_subscriptions = self.max_subscriptions(peer)
|
|
1886
|
+
subs = self.full_node.subscriptions
|
|
1887
|
+
|
|
1888
|
+
request_coin_ids = list(dict.fromkeys(request.coin_ids))
|
|
1889
|
+
coin_ids = request_coin_ids[:max_items]
|
|
1890
|
+
|
|
1891
|
+
previous_header_hash = (
|
|
1892
|
+
self.full_node.blockchain.height_to_hash(request.previous_height)
|
|
1893
|
+
if request.previous_height is not None
|
|
1894
|
+
else self.full_node.blockchain.constants.GENESIS_CHALLENGE
|
|
1895
|
+
)
|
|
1896
|
+
assert previous_header_hash is not None
|
|
1897
|
+
|
|
1898
|
+
if request.header_hash != previous_header_hash:
|
|
1899
|
+
rejection = wallet_protocol.RejectCoinState(uint8(wallet_protocol.RejectStateReason.REORG))
|
|
1900
|
+
msg = make_msg(ProtocolMessageTypes.reject_coin_state, rejection)
|
|
1901
|
+
return msg
|
|
1902
|
+
|
|
1903
|
+
# Check if the request would exceed the subscription limit now.
|
|
1904
|
+
def check_subscription_limit() -> Optional[Message]:
|
|
1905
|
+
new_subscription_count = len(coin_ids) + subs.peer_subscription_count(peer.peer_node_id)
|
|
1906
|
+
|
|
1907
|
+
if request.subscribe and new_subscription_count > max_subscriptions:
|
|
1908
|
+
rejection = wallet_protocol.RejectCoinState(
|
|
1909
|
+
uint8(wallet_protocol.RejectStateReason.EXCEEDED_SUBSCRIPTION_LIMIT)
|
|
1910
|
+
)
|
|
1911
|
+
msg = make_msg(ProtocolMessageTypes.reject_coin_state, rejection)
|
|
1912
|
+
return msg
|
|
1913
|
+
|
|
1914
|
+
return None
|
|
1915
|
+
|
|
1916
|
+
sub_rejection = check_subscription_limit()
|
|
1917
|
+
if sub_rejection is not None:
|
|
1918
|
+
return sub_rejection
|
|
1919
|
+
|
|
1920
|
+
min_height = uint32(request.previous_height + 1 if request.previous_height is not None else 0)
|
|
1921
|
+
|
|
1922
|
+
coin_states = await self.full_node.coin_store.get_coin_states_by_ids(
|
|
1923
|
+
True, coin_ids, min_height=min_height, max_items=max_items
|
|
1924
|
+
)
|
|
1925
|
+
|
|
1926
|
+
# Check if the request would exceed the subscription limit.
|
|
1927
|
+
# We do this again since we've crossed an `await` point, to prevent a race condition.
|
|
1928
|
+
sub_rejection = check_subscription_limit()
|
|
1929
|
+
if sub_rejection is not None:
|
|
1930
|
+
return sub_rejection
|
|
1931
|
+
|
|
1932
|
+
if request.subscribe:
|
|
1933
|
+
subs.add_coin_subscriptions(peer.peer_node_id, coin_ids, max_subscriptions)
|
|
1934
|
+
await self.mempool_updates_for_coin_ids(peer, set(coin_ids))
|
|
1935
|
+
|
|
1936
|
+
response = wallet_protocol.RespondCoinState(coin_ids, coin_states)
|
|
1937
|
+
msg = make_msg(ProtocolMessageTypes.respond_coin_state, response)
|
|
1938
|
+
return msg
|
|
1939
|
+
|
|
1940
|
+
@metadata.request(reply_types=[ProtocolMessageTypes.respond_cost_info])
|
|
1941
|
+
async def request_cost_info(self, _request: wallet_protocol.RequestCostInfo) -> Optional[Message]:
|
|
1942
|
+
mempool_manager = self.full_node.mempool_manager
|
|
1943
|
+
response = wallet_protocol.RespondCostInfo(
|
|
1944
|
+
max_transaction_cost=mempool_manager.max_tx_clvm_cost,
|
|
1945
|
+
max_block_cost=mempool_manager.max_block_clvm_cost,
|
|
1946
|
+
max_mempool_cost=uint64(mempool_manager.mempool_max_total_cost),
|
|
1947
|
+
mempool_cost=uint64(mempool_manager.mempool._total_cost),
|
|
1948
|
+
mempool_fee=uint64(mempool_manager.mempool._total_fee),
|
|
1949
|
+
bump_fee_per_cost=uint8(mempool_manager.nonzero_fee_minimum_fpc),
|
|
1950
|
+
)
|
|
1951
|
+
msg = make_msg(ProtocolMessageTypes.respond_cost_info, response)
|
|
1952
|
+
return msg
|
|
1953
|
+
|
|
1954
|
+
async def mempool_updates_for_puzzle_hashes(
|
|
1955
|
+
self, peer: WSChiaConnection, puzzle_hashes: set[bytes32], include_hints: bool
|
|
1956
|
+
) -> None:
|
|
1957
|
+
if Capability.MEMPOOL_UPDATES not in peer.peer_capabilities:
|
|
1958
|
+
return
|
|
1959
|
+
|
|
1960
|
+
start_time = time.monotonic()
|
|
1961
|
+
|
|
1962
|
+
async with self.full_node.db_wrapper.reader() as conn:
|
|
1963
|
+
transaction_ids = set(
|
|
1964
|
+
self.full_node.mempool_manager.mempool.items_with_puzzle_hashes(puzzle_hashes, include_hints)
|
|
1965
|
+
)
|
|
1966
|
+
|
|
1967
|
+
hinted_coin_ids: set[bytes32] = set()
|
|
1968
|
+
|
|
1969
|
+
for batch in to_batches(puzzle_hashes, SQLITE_MAX_VARIABLE_NUMBER):
|
|
1970
|
+
hints_db: tuple[bytes, ...] = tuple(batch.entries)
|
|
1971
|
+
cursor = await conn.execute(
|
|
1972
|
+
f"SELECT coin_id from hints INDEXED BY hint_index "
|
|
1973
|
+
f'WHERE hint IN ({"?," * (len(batch.entries) - 1)}?)',
|
|
1974
|
+
hints_db,
|
|
1975
|
+
)
|
|
1976
|
+
for row in await cursor.fetchall():
|
|
1977
|
+
hinted_coin_ids.add(bytes32(row[0]))
|
|
1978
|
+
await cursor.close()
|
|
1979
|
+
|
|
1980
|
+
transaction_ids |= set(self.full_node.mempool_manager.mempool.items_with_coin_ids(hinted_coin_ids))
|
|
1981
|
+
|
|
1982
|
+
if len(transaction_ids) > 0:
|
|
1983
|
+
message = wallet_protocol.MempoolItemsAdded(list(transaction_ids))
|
|
1984
|
+
await peer.send_message(make_msg(ProtocolMessageTypes.mempool_items_added, message))
|
|
1985
|
+
|
|
1986
|
+
total_time = time.monotonic() - start_time
|
|
1987
|
+
|
|
1988
|
+
self.log.log(
|
|
1989
|
+
logging.DEBUG if total_time < 2.0 else logging.WARNING,
|
|
1990
|
+
f"Sending initial mempool items to peer {peer.peer_node_id} took {total_time:.4f}s",
|
|
1991
|
+
)
|
|
1992
|
+
|
|
1993
|
+
async def mempool_updates_for_coin_ids(self, peer: WSChiaConnection, coin_ids: set[bytes32]) -> None:
|
|
1994
|
+
if Capability.MEMPOOL_UPDATES not in peer.peer_capabilities:
|
|
1995
|
+
return
|
|
1996
|
+
|
|
1997
|
+
start_time = time.monotonic()
|
|
1998
|
+
|
|
1999
|
+
transaction_ids = self.full_node.mempool_manager.mempool.items_with_coin_ids(coin_ids)
|
|
2000
|
+
|
|
2001
|
+
if len(transaction_ids) > 0:
|
|
2002
|
+
message = wallet_protocol.MempoolItemsAdded(list(transaction_ids))
|
|
2003
|
+
await peer.send_message(make_msg(ProtocolMessageTypes.mempool_items_added, message))
|
|
2004
|
+
|
|
2005
|
+
total_time = time.monotonic() - start_time
|
|
2006
|
+
|
|
2007
|
+
self.log.log(
|
|
2008
|
+
logging.DEBUG if total_time < 2.0 else logging.WARNING,
|
|
2009
|
+
f"Sending initial mempool items to peer {peer.peer_node_id} took {total_time:.4f}s",
|
|
2010
|
+
)
|
|
2011
|
+
|
|
2012
|
+
def max_subscriptions(self, peer: WSChiaConnection) -> int:
|
|
2013
|
+
if self.is_trusted(peer):
|
|
2014
|
+
return cast(int, self.full_node.config.get("trusted_max_subscribe_items", 2000000))
|
|
2015
|
+
else:
|
|
2016
|
+
return cast(int, self.full_node.config.get("max_subscribe_items", 200000))
|
|
2017
|
+
|
|
2018
|
+
def max_subscribe_response_items(self, peer: WSChiaConnection) -> int:
|
|
2019
|
+
if self.is_trusted(peer):
|
|
2020
|
+
return cast(int, self.full_node.config.get("trusted_max_subscribe_response_items", 500000))
|
|
2021
|
+
else:
|
|
2022
|
+
return cast(int, self.full_node.config.get("max_subscribe_response_items", 100000))
|
|
2023
|
+
|
|
2024
|
+
def is_trusted(self, peer: WSChiaConnection) -> bool:
|
|
2025
|
+
return self.server.is_trusted_peer(peer, self.full_node.config.get("trusted_peers", {}))
|