Skip to content

Commit

Permalink
Merge branch 'main' into pin_in_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Sep 25, 2024
2 parents 04ff6b2 + bffb7b1 commit af0d32f
Show file tree
Hide file tree
Showing 54 changed files with 2,226 additions and 988 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ activate
# Editors
.vscode
.idea
.vs

# Packaging
chia-blockchain.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def compare_results(
) -> None:
old_version, new_version = pop_data("version", old=old, new=new)
if old_version != new_version:
sys.exit(f"version missmatch: old: {old_version} vs new: {new_version}")
sys.exit(f"version mismatch: old: {old_version} vs new: {new_version}")
old_commit_hash, new_commit_hash = pop_data("commit_hash", old=old, new=new)
for data, modes in new.items():
if data not in old:
Expand Down
2 changes: 1 addition & 1 deletion build_scripts/remove_brew_rpaths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if [[ -n "$nt_output" ]]; then
echo "$nt_output" | grep "no LC_RPATH load command with path:" >/dev/null
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
>&2 echo "An unexpected error occured when running install_name_tool:"
>&2 echo "An unexpected error occurred when running install_name_tool:"
>&2 echo "$nt_output"
fi
fi
Expand Down
14 changes: 11 additions & 3 deletions chia/_tests/blockchain/blockchain_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from chia.consensus.block_body_validation import ForkInfo
from chia.consensus.blockchain import AddBlockResult, Blockchain
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
from chia.consensus.multiprocess_validation import PreValidationResult
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_blocks_multiprocessing
from chia.types.full_block import FullBlock
from chia.util.errors import Err
from chia.util.ints import uint32, uint64
Expand Down Expand Up @@ -75,8 +75,16 @@ async def _validate_and_add_block(
else:
# validate_signatures must be False in order to trigger add_block() to
# validate the signature.
pre_validation_results: List[PreValidationResult] = await blockchain.pre_validate_blocks_multiprocessing(
[block], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=prev_ses_block, validate_signatures=False
pre_validation_results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
blockchain.constants,
blockchain,
[block],
blockchain.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=prev_ses_block,
validate_signatures=False,
)
assert pre_validation_results is not None
results = pre_validation_results[0]
Expand Down
136 changes: 111 additions & 25 deletions chia/_tests/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from chia.consensus.constants import ConsensusConstants
from chia.consensus.full_block_to_block_record import block_to_block_record
from chia.consensus.get_block_generator import get_block_generator
from chia.consensus.multiprocess_validation import PreValidationResult
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_blocks_multiprocessing
from chia.consensus.pot_iterations import is_overflow_block
from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
from chia.simulator.block_tools import BlockTools, create_block_tools_async
Expand Down Expand Up @@ -1819,8 +1819,11 @@ async def test_pre_validation_fails_bad_blocks(self, empty_blockchain: Blockchai
block_bad = recursive_replace(
blocks[-1], "reward_chain_block.total_iters", blocks[-1].reward_chain_block.total_iters + 1
)
res = await empty_blockchain.pre_validate_blocks_multiprocessing(
res = await pre_validate_blocks_multiprocessing(
empty_blockchain.constants,
empty_blockchain,
[blocks[0], block_bad],
empty_blockchain.pool,
{},
sub_slot_iters=ssi,
difficulty=difficulty,
Expand All @@ -1845,8 +1848,11 @@ async def test_pre_validation(
end_i = min(i + n_at_a_time, len(blocks))
blocks_to_validate = blocks[i:end_i]
start_pv = time.time()
res = await empty_blockchain.pre_validate_blocks_multiprocessing(
res = await pre_validate_blocks_multiprocessing(
empty_blockchain.constants,
empty_blockchain,
blocks_to_validate,
empty_blockchain.pool,
{},
sub_slot_iters=ssi,
difficulty=difficulty,
Expand Down Expand Up @@ -1950,8 +1956,16 @@ async def test_conditions(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
[blocks[-1]], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
pre_validation_results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[blocks[-1]],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)
# Ignore errors from pre-validation, we are testing block_body_validation
repl_preval_results = replace(pre_validation_results[0], error=None, required_iters=uint64(1))
Expand Down Expand Up @@ -2066,8 +2080,16 @@ async def test_timelock_conditions(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
[blocks[-1]], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=True
pre_validation_results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[blocks[-1]],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=True,
)
assert pre_validation_results is not None
assert (await b.add_block(blocks[-1], pre_validation_results[0], None, sub_slot_iters=ssi))[0] == expected
Expand Down Expand Up @@ -2139,8 +2161,16 @@ async def test_aggsig_garbage(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
[blocks[-1]], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
pre_validation_results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[blocks[-1]],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)
# Ignore errors from pre-validation, we are testing block_body_validation
repl_preval_results = replace(pre_validation_results[0], error=None, required_iters=uint64(1))
Expand Down Expand Up @@ -2257,8 +2287,16 @@ async def test_ephemeral_timelock(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
[blocks[-1]], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=True
pre_validation_results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[blocks[-1]],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=True,
)
assert pre_validation_results is not None
assert (await b.add_block(blocks[-1], pre_validation_results[0], None, sub_slot_iters=ssi))[0] == expected
Expand Down Expand Up @@ -2607,8 +2645,16 @@ async def test_cost_exceeds_max(
)
)[1]
assert err in [Err.BLOCK_COST_EXCEEDS_MAX]
results: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
[blocks[-1]], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[blocks[-1]],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)
assert results is not None
assert Err(results[0].error) == Err.BLOCK_COST_EXCEEDS_MAX
Expand Down Expand Up @@ -3178,8 +3224,16 @@ async def test_invalid_agg_sig(self, empty_blockchain: Blockchain, bt: BlockTool
# Bad signature also fails in prevalidation
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
preval_results = await b.pre_validate_blocks_multiprocessing(
[last_block], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=True
preval_results = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[last_block],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=True,
)
assert preval_results is not None
assert preval_results[0].error == Err.BAD_AGGREGATE_SIGNATURE.value
Expand Down Expand Up @@ -3288,8 +3342,16 @@ async def test_long_reorg(
print(f"pre-validating {len(blocks)} blocks")
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
blocks, {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
pre_validation_results: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
blocks,
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)
for i, block in enumerate(blocks):
if block.height != 0 and len(block.finished_sub_slots) > 0:
Expand Down Expand Up @@ -3841,13 +3903,29 @@ async def test_reorg_flip_flop(empty_blockchain: Blockchain, bt: BlockTools) ->
block1, block2 = b1, b2
counter += 1

preval: List[PreValidationResult] = await b.pre_validate_blocks_multiprocessing(
[block1], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
preval: List[PreValidationResult] = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[block1],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)
_, err, _ = await b.add_block(block1, preval[0], None, sub_slot_iters=ssi)
assert err is None
preval = await b.pre_validate_blocks_multiprocessing(
[block2], {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
preval = await pre_validate_blocks_multiprocessing(
b.constants,
b,
[block2],
b.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)
_, err, _ = await b.add_block(block2, preval[0], None, sub_slot_iters=ssi)
assert err is None
Expand All @@ -3871,10 +3949,18 @@ async def test_reorg_flip_flop(empty_blockchain: Blockchain, bt: BlockTools) ->
async def test_get_tx_peak(default_400_blocks: List[FullBlock], empty_blockchain: Blockchain) -> None:
bc = empty_blockchain
test_blocks = default_400_blocks[:100]
ssi = empty_blockchain.constants.SUB_SLOT_ITERS_STARTING
diff = empty_blockchain.constants.DIFFICULTY_STARTING
res = await bc.pre_validate_blocks_multiprocessing(
test_blocks, {}, sub_slot_iters=ssi, difficulty=diff, prev_ses_block=None, validate_signatures=False
ssi = bc.constants.SUB_SLOT_ITERS_STARTING
diff = bc.constants.DIFFICULTY_STARTING
res = await pre_validate_blocks_multiprocessing(
bc.constants,
bc,
test_blocks,
bc.pool,
{},
sub_slot_iters=ssi,
difficulty=diff,
prev_ses_block=None,
validate_signatures=False,
)

last_tx_block_record = None
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/clvm/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_uncurry_top_level_garbage():


def test_uncurry_not_pair():
# the second item in the list is expected to be a pair, with a qoute
# the second item in the list is expected to be a pair, with a quote
plus = Program.to(assemble("(2 1 (c (q . 1) (q . 1)))"))
assert plus.uncurry() == (plus, Program.to(0))

Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/cmds/test_cmd_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def run(self) -> None:
check_click_parsing(expected_command, "-wp", str(port), "-f", str(fingerprint))

async with expected_command.rpc_info.wallet_rpc(consume_errors=False) as client_info:
assert await client_info.client.get_logged_in_fingerprint() == fingerprint
assert (await client_info.client.get_logged_in_fingerprint()).fingerprint == fingerprint

# We don't care about setting the correct arg type here
test_present_client_info = TempCMD(rpc_info=NeedsWalletRPC(client_info="hello world")) # type: ignore[arg-type]
Expand Down
26 changes: 22 additions & 4 deletions chia/_tests/core/cmds/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from chia.cmds.chia import cli
from chia.cmds.keys import delete_all_cmd, generate_and_print_cmd, sign_cmd, verify_cmd
from chia.cmds.keys_funcs import get_private_key_with_fingerprint_or_prompt
from chia.util.config import load_config
from chia.util.default_root import DEFAULT_KEYS_ROOT_PATH
from chia.util.keychain import Keychain, KeyData, generate_mnemonic
Expand Down Expand Up @@ -1347,7 +1348,7 @@ def test_derive_wallet_address(self, tmp_path, keyring_with_one_public_one_priva
],
)
assert result.exit_code == 0
assert result.output.find("Need a private key for non observer derivation of wallet addresses") != -1
assert result.output.find("Could not resolve private key for non-observer derivation") != -1

def test_derive_wallet_testnet_address(self, tmp_path, keyring_with_one_public_one_private_key):
"""
Expand Down Expand Up @@ -1685,9 +1686,7 @@ def test_derive_child_keys(self, tmp_path, keyring_with_one_public_one_private_k
],
)

assert isinstance(result.exception, ValueError) and result.exception.args == (
"Cannot perform non-observer derivation on an observer-only key",
)
assert result.output.find("Could not resolve private key for non-observer derivation") != -1

result: Result = runner.invoke(
cli,
Expand All @@ -1714,3 +1713,22 @@ def test_derive_child_keys(self, tmp_path, keyring_with_one_public_one_private_k
assert isinstance(result.exception, ValueError) and result.exception.args == (
"Hardened path specified for observer key",
)

@pytest.mark.anyio
async def test_get_private_key_with_fingerprint_or_prompt(
self, monkeypatch, keyring_with_one_public_one_private_key
) -> None:
[sk1_plus_ent] = keyring_with_one_public_one_private_key.get_all_private_keys()
sk1, _ = sk1_plus_ent
[pk1, pk2] = keyring_with_one_public_one_private_key.get_all_public_keys()
assert pk1.get_fingerprint() == TEST_FINGERPRINT
assert pk2.get_fingerprint() == TEST_PK_FINGERPRINT

assert get_private_key_with_fingerprint_or_prompt(TEST_FINGERPRINT) == (TEST_FINGERPRINT, sk1)
assert get_private_key_with_fingerprint_or_prompt(TEST_PK_FINGERPRINT) == (TEST_PK_FINGERPRINT, None)

monkeypatch.setattr("builtins.input", lambda _: "1")
assert get_private_key_with_fingerprint_or_prompt(None) == (TEST_FINGERPRINT, sk1)

monkeypatch.setattr("builtins.input", lambda _: "2")
assert get_private_key_with_fingerprint_or_prompt(None) == (TEST_PK_FINGERPRINT, None)
Loading

0 comments on commit af0d32f

Please sign in to comment.