Skip to content

Commit 08732ee

Browse files
committed
Merge branch 'main' into wallentx/chia-peer-command
2 parents 0425770 + 0bc54ae commit 08732ee

File tree

81 files changed

+227
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+227
-192
lines changed

.github/workflows/test-install-scripts.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,6 @@ jobs:
108108
type: ubuntu
109109
# https://packages.ubuntu.com/focal/python3 (20.04, 3.8)
110110
url: "docker://ubuntu:focal"
111-
- name: ubuntu:hirsute (21.04)
112-
type: ubuntu
113-
# https://packages.ubuntu.com/hirsute/python3 (21.04, 3.9)
114-
url: "docker://ubuntu:hirsute"
115-
- name: ubuntu:impish (21.10)
116-
type: ubuntu
117-
# https://packages.ubuntu.com/impish/python3 (21.10, 3.9)
118-
url: "docker://ubuntu:impish"
119111
- name: ubuntu:jammy (22.04)
120112
type: ubuntu
121113
# https://packages.ubuntu.com/jammy/python3 (22.04, 3.10)

chia/cmds/configure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def configure(
101101
bootstrap_peers = ["testnet10-node.chia.net"]
102102
testnet = "testnet10"
103103
config["full_node"]["port"] = int(testnet_port)
104+
if config["full_node"]["introducer_peer"] is None:
105+
config["full_node"]["introducer_peer"] = {}
106+
assert config["full_node"]["introducer_peer"] is not None # mypy
107+
if config["wallet"]["introducer_peer"] is None:
108+
config["wallet"]["introducer_peer"] = {}
109+
assert config["wallet"]["introducer_peer"] is not None # mypy
104110
config["full_node"]["introducer_peer"]["port"] = int(testnet_port)
105111
config["farmer"]["full_node_peer"]["port"] = int(testnet_port)
106112
config["timelord"]["full_node_peer"]["port"] = int(testnet_port)

chia/rpc/full_node_rpc_api.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from typing import Any, Dict, List, Optional
22

3+
from clvm.casts import int_from_bytes
4+
35
from chia.consensus.block_record import BlockRecord
46
from chia.consensus.pos_quality import UI_ACTUAL_SPACE_CONSTANT_FACTOR
57
from chia.full_node.full_node import FullNode
8+
from chia.full_node.generator import setup_generator_args
69
from chia.full_node.mempool_check_conditions import get_puzzle_and_solution_for_coin
710
from chia.rpc.rpc_server import Endpoint, EndpointResult
11+
from chia.types.blockchain_format.coin import Coin
812
from chia.types.blockchain_format.program import Program, SerializedProgram
913
from chia.types.blockchain_format.sized_bytes import bytes32
1014
from chia.types.coin_record import CoinRecord
@@ -18,6 +22,7 @@
1822
from chia.util.ints import uint32, uint64, uint128
1923
from chia.util.log_exceptions import log_exceptions
2024
from chia.util.ws_message import WsRpcMessage, create_payload_dict
25+
from chia.wallet.puzzles.decompress_block_spends import DECOMPRESS_BLOCK_SPENDS
2126

2227

2328
def coin_record_dict_backwards_compat(coin_record: Dict[str, Any]):
@@ -41,6 +46,7 @@ def get_routes(self) -> Dict[str, Endpoint]:
4146
"/get_block_record_by_height": self.get_block_record_by_height,
4247
"/get_block_record": self.get_block_record,
4348
"/get_block_records": self.get_block_records,
49+
"/get_block_spends": self.get_block_spends,
4450
"/get_unfinished_block_headers": self.get_unfinished_block_headers,
4551
"/get_network_space": self.get_network_space,
4652
"/get_additions_and_removals": self.get_additions_and_removals,
@@ -399,6 +405,32 @@ async def get_block_records(self, request: Dict) -> EndpointResult:
399405
records.append(record)
400406
return {"block_records": records}
401407

408+
async def get_block_spends(self, request: Dict) -> EndpointResult:
409+
if "header_hash" not in request:
410+
raise ValueError("No header_hash in request")
411+
header_hash = bytes32.from_hexstr(request["header_hash"])
412+
full_block: Optional[FullBlock] = await self.service.block_store.get_full_block(header_hash)
413+
if full_block is None or full_block.transactions_generator is None:
414+
raise ValueError(f"Block {header_hash.hex()} not found or invalid block generator")
415+
416+
spends: List[CoinSpend] = []
417+
block_generator = await self.service.blockchain.get_block_generator(full_block)
418+
if block_generator is None:
419+
return {"block_spends": spends}
420+
421+
block_program, block_program_args = setup_generator_args(block_generator)
422+
_, coin_spends = DECOMPRESS_BLOCK_SPENDS.run_with_cost(
423+
self.service.constants.MAX_BLOCK_COST_CLVM, block_program, block_program_args
424+
)
425+
426+
for spend in coin_spends.as_iter():
427+
parent, puzzle, amount, solution = spend.as_iter()
428+
puzzle_hash = puzzle.get_tree_hash()
429+
coin = Coin(parent.atom, puzzle_hash, int_from_bytes(amount.atom))
430+
spends.append(CoinSpend(coin, puzzle, solution))
431+
432+
return {"block_spends": spends}
433+
402434
async def get_block_record_by_height(self, request: Dict) -> EndpointResult:
403435
if "height" not in request:
404436
raise ValueError("No height in request")

chia/rpc/full_node_rpc_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ async def get_block_records(self, start: int, end: int) -> List:
200200
# TODO: return block records
201201
return response["block_records"]
202202

203+
async def get_block_spends(self, header_hash: bytes32) -> Optional[List[CoinSpend]]:
204+
try:
205+
response = await self.fetch("get_block_spends", {"header_hash": header_hash.hex()})
206+
block_spends = []
207+
for block_spend in response["block_spends"]:
208+
block_spends.append(CoinSpend.from_json_dict(block_spend))
209+
return block_spends
210+
except Exception:
211+
return None
212+
203213
async def push_tx(self, spend_bundle: SpendBundle):
204214
return await self.fetch("push_tx", {"spend_bundle": spend_bundle.to_json_dict()})
205215

chia/server/start_wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async def async_main() -> int:
9090
# This is simulator
9191
local_test = service_config["testing"]
9292
if local_test is True:
93-
from tests.block_tools import test_constants
93+
from chia.simulator.block_tools import test_constants
9494

9595
constants = test_constants
9696
current = service_config["database_path"]

tests/block_tools.py renamed to chia/simulator/block_tools.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
2-
import math
32
import copy
43
import logging
4+
import math
55
import os
66
import random
77
import shutil
@@ -12,28 +12,18 @@
1212
from argparse import Namespace
1313
from dataclasses import replace
1414
from pathlib import Path
15-
from typing import Callable, Dict, List, Optional, Tuple, Any, Union
15+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
1616

1717
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
18+
from chia_rs import compute_merkle_set_root
1819
from chiabip158 import PyBIP158
1920

2021
from chia.cmds.init_funcs import create_all_ssl, create_default_chia_config
21-
from chia.daemon.keychain_proxy import connect_to_keychain_and_validate, wrap_local_keychain, KeychainProxy
22-
from chia.full_node.bundle_tools import (
23-
best_solution_generator_from_template,
24-
detect_potential_template_generator,
25-
simple_solution_generator,
26-
)
27-
from chia.util.errors import Err
28-
from chia.full_node.generator import setup_generator_args
29-
from chia.full_node.mempool_check_conditions import GENERATOR_MOD
30-
from chia.plotting.create_plots import create_plots, PlotKeys
31-
from chia.plotting.util import add_plot_directory
3222
from chia.consensus.block_creation import unfinished_block_to_full_block
3323
from chia.consensus.block_record import BlockRecord
3424
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
3525
from chia.consensus.blockchain_interface import BlockchainInterface
36-
from chia.consensus.coinbase import create_puzzlehash_for_pk, create_farmer_coin, create_pool_coin
26+
from chia.consensus.coinbase import create_farmer_coin, create_pool_coin, create_puzzlehash_for_pk
3727
from chia.consensus.condition_costs import ConditionCost
3828
from chia.consensus.constants import ConsensusConstants
3929
from chia.consensus.default_constants import DEFAULT_CONSTANTS
@@ -48,10 +38,29 @@
4838
is_overflow_block,
4939
)
5040
from chia.consensus.vdf_info_computation import get_signage_point_vdf_info
41+
from chia.daemon.keychain_proxy import KeychainProxy, connect_to_keychain_and_validate, wrap_local_keychain
42+
from chia.full_node.bundle_tools import (
43+
best_solution_generator_from_template,
44+
detect_potential_template_generator,
45+
simple_solution_generator,
46+
)
47+
from chia.full_node.generator import setup_generator_args
48+
from chia.full_node.mempool_check_conditions import GENERATOR_MOD
5149
from chia.full_node.signage_point import SignagePoint
52-
from chia.plotting.util import PlotsRefreshParameter, PlotRefreshResult, PlotRefreshEvents, parse_plot_info
50+
from chia.plotting.create_plots import PlotKeys, create_plots
5351
from chia.plotting.manager import PlotManager
52+
from chia.plotting.util import (
53+
PlotRefreshEvents,
54+
PlotRefreshResult,
55+
PlotsRefreshParameter,
56+
add_plot_directory,
57+
parse_plot_info,
58+
)
5459
from chia.server.server import ssl_context_for_client
60+
from chia.simulator.socket import find_available_listen_port
61+
from chia.simulator.ssl_certs import get_next_nodes_certs_and_keys, get_next_private_ca_cert_and_key
62+
from chia.simulator.time_out_assert import time_out_assert_custom_interval
63+
from chia.simulator.wallet_tools import WalletTool
5564
from chia.types.blockchain_format.classgroup import ClassgroupElement
5665
from chia.types.blockchain_format.coin import Coin, hash_coin_ids
5766
from chia.types.blockchain_format.foliage import Foliage, FoliageBlockData, FoliageTransactionBlock, TransactionsInfo
@@ -76,24 +85,20 @@
7685
from chia.types.unfinished_block import UnfinishedBlock
7786
from chia.util.bech32m import encode_puzzle_hash
7887
from chia.util.block_cache import BlockCache
79-
from chia.util.config import load_config, lock_config, save_config, override_config
88+
from chia.util.config import load_config, lock_config, override_config, save_config
8089
from chia.util.default_root import DEFAULT_ROOT_PATH
90+
from chia.util.errors import Err
8191
from chia.util.hash import std_hash
8292
from chia.util.ints import uint8, uint16, uint32, uint64, uint128
8393
from chia.util.keychain import Keychain, bytes_to_mnemonic
8494
from chia.util.prev_transaction_block import get_prev_transaction_block
8595
from chia.util.vdf_prover import get_vdf_info_and_proof
86-
from tests.time_out_assert import time_out_assert_custom_interval
87-
from tests.wallet_tools import WalletTool
88-
from tests.util.socket import find_available_listen_port
89-
from tests.util.ssl_certs import get_next_nodes_certs_and_keys, get_next_private_ca_cert_and_key
9096
from chia.wallet.derive_keys import (
9197
master_sk_to_farmer_sk,
9298
master_sk_to_local_sk,
9399
master_sk_to_pool_sk,
94100
master_sk_to_wallet_sk,
95101
)
96-
from chia_rs import compute_merkle_set_root
97102

98103
test_constants = DEFAULT_CONSTANTS.replace(
99104
**{
@@ -215,7 +220,7 @@ def test_callback(event: PlotRefreshEvents, update_result: PlotRefreshResult):
215220
self.total_result.loaded += update_result.loaded
216221
self.total_result.processed += update_result.processed
217222
self.total_result.duration += update_result.duration
218-
assert update_result.remaining == len(self.expected_plots) - self.total_result.processed
223+
assert update_result.remaining >= len(self.expected_plots) - self.total_result.processed
219224
assert len(update_result.loaded) <= self.plot_manager.refresh_parameter.batch_size
220225

221226
if event == PlotRefreshEvents.done:
@@ -269,7 +274,10 @@ async def setup_keys(self, fingerprint: Optional[int] = None, reward_ph: Optiona
269274
else:
270275
self.farmer_ph = reward_ph
271276
self.pool_ph = reward_ph
272-
self.all_sks: List[PrivateKey] = [sk for sk, _ in await self.keychain_proxy.get_all_private_keys()]
277+
if self.automated_testing:
278+
self.all_sks: List[PrivateKey] = [sk for sk, _ in await self.keychain_proxy.get_all_private_keys()]
279+
else:
280+
self.all_sks = [self.farmer_master_sk] # we only want to include plots under the same fingerprint
273281
self.pool_pubkeys: List[G1Element] = [master_sk_to_pool_sk(sk).get_g1() for sk in self.all_sks]
274282

275283
self.farmer_pubkeys: List[G1Element] = [master_sk_to_farmer_sk(sk).get_g1() for sk in self.all_sks]

chia/simulator/full_node_simulator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from chia.full_node.full_node import FullNode
88
from chia.full_node.full_node_api import FullNodeAPI
99
from chia.protocols.full_node_protocol import RespondBlock
10+
from chia.simulator.block_tools import BlockTools
1011
from chia.simulator.simulator_protocol import FarmNewBlockProtocol, ReorgProtocol
1112
from chia.types.blockchain_format.sized_bytes import bytes32
1213
from chia.types.full_block import FullBlock
1314
from chia.util.api_decorators import api_request
1415
from chia.util.config import lock_and_load_config, save_config
1516
from chia.util.ints import uint8
16-
from tests.block_tools import BlockTools
1717

1818

1919
class FullNodeSimulator(FullNodeAPI):

chia/simulator/simulator_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
if __name__ == "__main__":
22
from chia.util.default_root import DEFAULT_ROOT_PATH
3-
from tests.block_tools import create_block_tools, test_constants
3+
from chia.simulator.block_tools import create_block_tools, test_constants
44
from tests.util.keyring import TempKeyring
55

66
with TempKeyring() as keychain:
File renamed without changes.

tests/util/ssl_certs.py renamed to chia/simulator/ssl_certs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import itertools
22
from typing import Dict, List, Tuple
33

4-
from tests.util.ssl_certs_1 import SSL_TEST_NODE_CERTS_AND_KEYS_1, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_1
5-
from tests.util.ssl_certs_2 import SSL_TEST_NODE_CERTS_AND_KEYS_2, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_2
6-
from tests.util.ssl_certs_3 import SSL_TEST_NODE_CERTS_AND_KEYS_3, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_3
7-
from tests.util.ssl_certs_4 import SSL_TEST_NODE_CERTS_AND_KEYS_4, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_4
8-
from tests.util.ssl_certs_5 import SSL_TEST_NODE_CERTS_AND_KEYS_5, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_5
9-
from tests.util.ssl_certs_6 import SSL_TEST_NODE_CERTS_AND_KEYS_6, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_6
10-
from tests.util.ssl_certs_7 import SSL_TEST_NODE_CERTS_AND_KEYS_7, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_7
4+
from chia.simulator.ssl_certs_1 import SSL_TEST_NODE_CERTS_AND_KEYS_1, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_1
5+
from chia.simulator.ssl_certs_2 import SSL_TEST_NODE_CERTS_AND_KEYS_2, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_2
6+
from chia.simulator.ssl_certs_3 import SSL_TEST_NODE_CERTS_AND_KEYS_3, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_3
7+
from chia.simulator.ssl_certs_4 import SSL_TEST_NODE_CERTS_AND_KEYS_4, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_4
8+
from chia.simulator.ssl_certs_5 import SSL_TEST_NODE_CERTS_AND_KEYS_5, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_5
9+
from chia.simulator.ssl_certs_6 import SSL_TEST_NODE_CERTS_AND_KEYS_6, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_6
10+
from chia.simulator.ssl_certs_7 import SSL_TEST_NODE_CERTS_AND_KEYS_7, SSL_TEST_PRIVATE_CA_CERT_AND_KEY_7
1111

1212
# ---------------------------------------------------------------------------
1313
# Private CA certs/keys
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

chia/simulator/start_simulator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
from chia.util.config import load_config_cli, override_config
1313
from chia.util.default_root import DEFAULT_ROOT_PATH
1414
from chia.util.path import path_from_root
15-
from tests.block_tools import BlockTools, test_constants
15+
from chia.simulator.block_tools import BlockTools, test_constants
1616
from chia.util.ints import uint16
1717
from chia.simulator.full_node_simulator import FullNodeSimulator
1818

1919
# See: https://bugs.python.org/issue29288
2020
"".encode("idna")
2121

2222
SERVICE_NAME = "full_node"
23+
PLOTS = 3 # 3 plots should be enough
24+
PLOT_SIZE = 19 # anything under k19 is a bit buggy
2325

2426

2527
def create_full_node_simulator_service(
@@ -66,8 +68,6 @@ async def async_main(test_mode: bool = False, root_path: Path = DEFAULT_ROOT_PAT
6668
fingerprint: Optional[int] = None
6769
farming_puzzle_hash: Optional[bytes32] = None
6870
plot_dir: str = "simulator-plots"
69-
plots = 3 # 3 plots should be enough
70-
plot_size = 19 # anything under k19 is a bit buggy
7171
if "simulator" in config:
7272
overrides = {}
7373
plot_dir = config["simulator"].get("plot_directory", "simulator-plots")
@@ -93,7 +93,7 @@ async def async_main(test_mode: bool = False, root_path: Path = DEFAULT_ROOT_PAT
9393
plot_dir=plot_dir,
9494
)
9595
await bt.setup_keys(fingerprint=fingerprint, reward_ph=farming_puzzle_hash)
96-
await bt.setup_plots(num_og_plots=plots, num_pool_plots=0, num_non_keychain_plots=0, plot_size=plot_size)
96+
await bt.setup_plots(num_og_plots=PLOTS, num_pool_plots=0, num_non_keychain_plots=0, plot_size=PLOT_SIZE)
9797
service = create_full_node_simulator_service(root_path, override_config(config, overrides), bt)
9898
if test_mode:
9999
return service
File renamed without changes.

tests/wallet_tools.py renamed to chia/simulator/wallet_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from typing import Dict, List, Optional, Tuple, Any
1+
from typing import Any, Dict, List, Optional, Tuple
22

3-
from blspy import AugSchemeMPL, G2Element, PrivateKey, G1Element
3+
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
44
from clvm.casts import int_from_bytes, int_to_bytes
55

66
from chia.consensus.constants import ConsensusConstants
7-
from chia.util.hash import std_hash
87
from chia.types.announcement import Announcement
98
from chia.types.blockchain_format.coin import Coin
109
from chia.types.blockchain_format.program import Program, SerializedProgram
@@ -14,6 +13,7 @@
1413
from chia.types.condition_with_args import ConditionWithArgs
1514
from chia.types.spend_bundle import SpendBundle
1615
from chia.util.condition_tools import conditions_by_opcode, conditions_for_solution
16+
from chia.util.hash import std_hash
1717
from chia.util.ints import uint32, uint64
1818
from chia.wallet.derive_keys import master_sk_to_wallet_sk
1919
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import (

chia/util/dump_keyring.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -78,48 +78,6 @@ def dump(keyring_file, full_payload: bool, passphrase_file: Optional[TextIOWrapp
7878
break
7979

8080

81-
def dump_to_string(
82-
keyring_file, full_payload: bool, passphrase_file: Optional[TextIOWrapper], pretty_print: bool
83-
) -> str:
84-
saved_passphrase: Optional[str] = KeyringWrapper.get_shared_instance().get_master_passphrase_from_credential_store()
85-
passphrase: str = saved_passphrase or DEFAULT_PASSPHRASE_IF_NO_MASTER_PASSPHRASE
86-
prompt: str = get_passphrase_prompt(str(keyring_file))
87-
data: Dict[str, Any] = {}
88-
89-
print(f"Attempting to dump contents of keyring file: {keyring_file}\n")
90-
91-
if passphrase_file is not None:
92-
passphrase = read_passphrase_from_file(passphrase_file)
93-
94-
keyring_path = Path(keyring_file)
95-
keyring = FileKeyring(keyring_path, FileKeyring.lockfile_path_for_file_path(keyring_path))
96-
97-
if full_payload:
98-
keyring.load_outer_payload()
99-
data = keyring.outer_payload_cache
100-
101-
s: str = ""
102-
for i in range(5):
103-
try:
104-
keyring.load_keyring(passphrase)
105-
if len(data) > 0:
106-
data["data"] = keyring.payload_cache
107-
else:
108-
data = keyring.payload_cache
109-
110-
if pretty_print:
111-
s = yaml.dump(data)
112-
else:
113-
s = str(data)
114-
break
115-
except (ValueError, InvalidTag):
116-
passphrase = prompt_for_passphrase(prompt)
117-
except Exception as e:
118-
print(f"Unhandled exception: {e}")
119-
break
120-
return s
121-
122-
12381
def main():
12482
colorama.init()
12583
dump() # pylint: disable=no-value-for-parameter

0 commit comments

Comments
 (0)