Skip to content

Commit

Permalink
Merge branch 'main' into add_rs_merkle_blob
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Oct 28, 2024
2 parents 1d97291 + 6dee78a commit e19839e
Show file tree
Hide file tree
Showing 88 changed files with 728 additions and 1,181 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
* @Chia-Network/required-reviewers
/.github/**/* @Chia-Network/actions-reviewers
/PRETTY_GOOD_PRACTICES.md @altendky @Chia-Network/required-reviewers
/pylintrc @altendky @Chia-Network/required-reviewers
/tests/ether.py @altendky @Chia-Network/required-reviewers
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- name: "Dependency Review"
uses: actions/dependency-review-action@v4
with:
allow-dependencies-licenses: pkg:pypi/pylint, pkg:pypi/pyinstaller
allow-dependencies-licenses: pkg:pypi/pyinstaller
deny-licenses: AGPL-1.0-only, AGPL-1.0-or-later, AGPL-1.0-or-later, AGPL-3.0-or-later, GPL-1.0-only, GPL-1.0-or-later, GPL-2.0-only, GPL-2.0-or-later, GPL-3.0-only, GPL-3.0-or-later
2 changes: 0 additions & 2 deletions .github/workflows/upload-pypi-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ jobs:
command: black --check --diff .
- name: flake8
command: flake8 benchmarks build_scripts chia tools *.py
- name: pylint
command: pylint benchmarks build_scripts chia tools *.py
- name: generated protocol tests
command: |
python3 -m chia._tests.util.build_network_protocol_files
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ repos:
entry: ./activated.py flake8
language: system
types: [python]
- repo: local
hooks:
- id: ruff
name: Ruff
entry: ./activated.py ruff check --fix
language: system
types: [python]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The [black library](https://black.readthedocs.io/en/stable/) is used as an autom
The [flake8 library](https://readthedocs.org/projects/flake8/) helps ensure consistent style.
The [Mypy library](https://mypy.readthedocs.io/en/stable/) is very useful for ensuring objects are of the correct type, so try to always add the type of the return value, and the type of local variables.
The [isort library](https://isort.readthedocs.io) is used to sort, group and validate imports in all python files.
The [pylint library](https://pylint.pycqa.org/en/stable/) is used to further lint all python files.
The [Ruff library](https://docs.astral.sh) is used to further lint all of the python files

If you want verbose logging for tests, edit the `tests/pytest.ini` file.

Expand Down
1 change: 0 additions & 1 deletion benchmarks/block_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ def entry_point(db_path: Path) -> None:


if __name__ == "__main__":
# pylint: disable = no-value-for-parameter
entry_point()
2 changes: 1 addition & 1 deletion benchmarks/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,4 @@ def get_bench_results() -> BenchmarkResults:


if __name__ == "__main__":
run() # pylint: disable = no-value-for-parameter
run()
7 changes: 5 additions & 2 deletions chia/_tests/blockchain/blockchain_test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
from typing import Optional

from chia_rs import BLSCache
Expand All @@ -10,6 +11,7 @@
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_blocks_multiprocessing
from chia.types.full_block import FullBlock
from chia.types.validation_state import ValidationState
from chia.util.augmented_chain import AugmentedBlockchain
from chia.util.errors import Err
from chia.util.ints import uint32, uint64

Expand Down Expand Up @@ -76,15 +78,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 pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
blockchain.constants,
blockchain,
AugmentedBlockchain(blockchain),
[block],
blockchain.pool,
{},
ValidationState(ssi, diff, prev_ses_block),
validate_signatures=False,
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert pre_validation_results is not None
results = pre_validation_results[0]
if results.error is not None:
Expand Down
66 changes: 39 additions & 27 deletions chia/_tests/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import logging
import random
import time
Expand Down Expand Up @@ -52,6 +53,7 @@
from chia.types.spend_bundle import SpendBundle
from chia.types.unfinished_block import UnfinishedBlock
from chia.types.validation_state import ValidationState
from chia.util.augmented_chain import AugmentedBlockchain
from chia.util.cpu import available_logical_cores
from chia.util.errors import Err
from chia.util.generator_tools import get_block_header
Expand Down Expand Up @@ -1790,15 +1792,16 @@ 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 pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
empty_blockchain.constants,
empty_blockchain,
AugmentedBlockchain(empty_blockchain),
[blocks[0], block_bad],
empty_blockchain.pool,
{},
ValidationState(ssi, difficulty, None),
validate_signatures=True,
)
res: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert res[0].error is None
assert res[1].error is not None

Expand All @@ -1817,15 +1820,16 @@ 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 pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
empty_blockchain.constants,
empty_blockchain,
AugmentedBlockchain(empty_blockchain),
blocks_to_validate,
empty_blockchain.pool,
{},
ValidationState(ssi, difficulty, None),
validate_signatures=True,
)
res: list[PreValidationResult] = list(await asyncio.gather(*futures))
end_pv = time.time()
times_pv.append(end_pv - start_pv)
assert res is not None
Expand Down Expand Up @@ -1924,15 +1928,16 @@ async def test_conditions(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: list[PreValidationResult] = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[blocks[-1]],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
# 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))
block = blocks[-1]
Expand Down Expand Up @@ -2050,15 +2055,16 @@ async def test_timelock_conditions(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: list[PreValidationResult] = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[blocks[-1]],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=True,
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert pre_validation_results is not None
block = blocks[-1]
fork_info = ForkInfo(block.height - 1, block.height - 1, block.prev_header_hash)
Expand Down Expand Up @@ -2133,15 +2139,16 @@ async def test_aggsig_garbage(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: list[PreValidationResult] = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[blocks[-1]],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
# 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))
block = blocks[-1]
Expand Down Expand Up @@ -2261,15 +2268,16 @@ async def test_ephemeral_timelock(
)
ssi = b.constants.SUB_SLOT_ITERS_STARTING
diff = b.constants.DIFFICULTY_STARTING
pre_validation_results: list[PreValidationResult] = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[blocks[-1]],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=True,
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert pre_validation_results is not None
block = blocks[-1]
fork_info = ForkInfo(block.height - 1, block.height - 1, block.prev_header_hash)
Expand Down Expand Up @@ -2627,15 +2635,16 @@ async def test_cost_exceeds_max(
)
)[1]
assert err in [Err.BLOCK_COST_EXCEEDS_MAX]
results: list[PreValidationResult] = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[blocks[-1]],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)
results: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert results is not None
assert Err(results[0].error) == Err.BLOCK_COST_EXCEEDS_MAX

Expand Down Expand Up @@ -2808,7 +2817,7 @@ async def test_max_coin_amount(self, db_version: int, bt: BlockTools) -> None:

# wt: WalletTool = bt_2.get_pool_wallet_tool()

# condition_dict: Dict[ConditionOpcode, List[ConditionWithArgs]] = {ConditionOpcode.CREATE_COIN: []}
# condition_dict: dict[ConditionOpcode, list[ConditionWithArgs]] = {ConditionOpcode.CREATE_COIN: []}
# output = ConditionWithArgs(ConditionOpcode.CREATE_COIN, [bt_2.pool_ph, int_to_bytes(2 ** 64)])
# condition_dict[ConditionOpcode.CREATE_COIN].append(output)

Expand Down Expand Up @@ -3233,15 +3242,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 pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[last_block],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=True,
)
preval_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
assert preval_results is not None
assert preval_results[0].error == Err.BAD_AGGREGATE_SIGNATURE.value

Expand Down Expand Up @@ -3352,15 +3362,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 pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
blocks,
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)
pre_validation_results: list[PreValidationResult] = list(await asyncio.gather(*futures))
for i, block in enumerate(blocks):
if block.height != 0 and len(block.finished_sub_slots) > 0:
if block.finished_sub_slots[0].challenge_chain.new_sub_slot_iters is not None:
Expand Down Expand Up @@ -3919,29 +3930,29 @@ async def test_reorg_flip_flop(empty_blockchain: Blockchain, bt: BlockTools) ->
block1, block2 = b1, b2
counter += 1

preval: list[PreValidationResult] = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[block1],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)

preval: list[PreValidationResult] = list(await asyncio.gather(*futures))
fork_info = ForkInfo(block1.height - 1, block1.height - 1, block1.prev_header_hash)
_, err, _ = await b.add_block(block1, preval[0], None, sub_slot_iters=ssi, fork_info=fork_info)
assert err is None
preval = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
b.constants,
b,
AugmentedBlockchain(b),
[block2],
b.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)

preval = list(await asyncio.gather(*futures))
fork_info = ForkInfo(block2.height - 1, block2.height - 1, block2.prev_header_hash)
_, err, _ = await b.add_block(block2, preval[0], None, sub_slot_iters=ssi, fork_info=fork_info)
assert err is None
Expand All @@ -3967,15 +3978,16 @@ async def test_get_tx_peak(default_400_blocks: list[FullBlock], empty_blockchain
test_blocks = default_400_blocks[:100]
ssi = bc.constants.SUB_SLOT_ITERS_STARTING
diff = bc.constants.DIFFICULTY_STARTING
res = await pre_validate_blocks_multiprocessing(
futures = await pre_validate_blocks_multiprocessing(
bc.constants,
bc,
AugmentedBlockchain(bc),
test_blocks,
bc.pool,
{},
ValidationState(ssi, diff, None),
validate_signatures=False,
)
res: list[PreValidationResult] = list(await asyncio.gather(*futures))

last_tx_block_record = None
for b, prevalidation_res in zip(test_blocks, res):
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/build-init-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ def command(verbose, root_str):
raise click.ClickException("At least one __init__.py created or not a regular file")


command() # pylint: disable=no-value-for-parameter
command()
4 changes: 2 additions & 2 deletions chia/_tests/clvm/test_condition_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
def test_condition_codes_is_complete() -> None:
condition_codes_path = importlib_resources.files("chia.wallet.puzzles").joinpath("condition_codes.clib")
contents = condition_codes_path.read_text(encoding="utf-8")
for name, value in ConditionOpcode.__members__.items():
assert f"(defconstant {name} {int_from_bytes(value)})" in contents
for opcode in ConditionOpcode:
assert f"(defconstant {opcode.name} {int_from_bytes(opcode.value)})" in contents
2 changes: 1 addition & 1 deletion chia/_tests/cmds/cmd_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def run_cli_command(capsys: object, chia_root: Path, command_list: list[str]) ->
argv_temp = sys.argv
try:
sys.argv = ["chia", "--root-path", str(chia_root)] + command_list
chia_cli() # pylint: disable=no-value-for-parameter
chia_cli()
except SystemExit as e:
if e.code != 0:
exited_cleanly = False
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/cmds/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def get_block(self, header_hash: bytes32) -> Optional[FullBlock]:
return full_block


RPC_CLIENT_TO_USE = ShowFullNodeRpcClient() # pylint: disable=no-value-for-parameter
RPC_CLIENT_TO_USE = ShowFullNodeRpcClient()


def test_chia_show(capsys: object, get_test_cli_clients: tuple[TestRpcClients, Path]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions chia/_tests/cmds/wallet/test_coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_coins_get_info(capsys: object, get_test_cli_clients: tuple[TestRpcClien

# set RPC Client

inst_rpc_client = TestWalletRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = TestWalletRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = ["wallet", "coins", "list", FINGERPRINT_ARG, "-i1", "-u"]
# these are various things that should be in the output
Expand Down Expand Up @@ -68,7 +68,7 @@ async def combine_coins(
self.add_to_log("combine_coins", (args, tx_config, timelock_info))
return CombineCoinsResponse([STD_UTX], [STD_TX])

inst_rpc_client = CoinsCombineRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = CoinsCombineRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
assert sum(coin.amount for coin in STD_TX.removals) < 500_000_000_000
command_args = [
Expand Down Expand Up @@ -173,7 +173,7 @@ async def get_coin_records_by_names(
else:
return []

inst_rpc_client = CoinsSplitRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = CoinsSplitRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
target_coin_id = test_coin.name()
command_args = [
Expand Down
Loading

0 comments on commit e19839e

Please sign in to comment.