improve dataclasses.replace() usage to improve hint checking (#16286)

This commit is contained in:
Kyle Altendorf 2023-09-13 11:25:13 -04:00 committed by GitHub
parent 0934e3dc4e
commit ebcf74d9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 168 additions and 157 deletions

View File

@ -84,9 +84,6 @@ class ConsensusConstants:
# number of consecutive plot ids required to be distinct
UNIQUE_PLOTS_WINDOW: uint8
def replace(self, **changes: object) -> "ConsensusConstants":
return dataclasses.replace(self, **changes)
def replace_str_to_bytes(self, **changes: Any) -> "ConsensusConstants":
"""
Overrides str (hex) values with bytes.

View File

@ -1,76 +1,74 @@
from __future__ import annotations
from chia.util.ints import uint64
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.ints import uint8, uint32, uint64, uint128
from .constants import ConsensusConstants
default_kwargs = {
"SLOT_BLOCKS_TARGET": 32,
"MIN_BLOCKS_PER_CHALLENGE_BLOCK": 16, # Must be less than half of SLOT_BLOCKS_TARGET
"MAX_SUB_SLOT_BLOCKS": 128, # Must be less than half of SUB_EPOCH_BLOCKS
"NUM_SPS_SUB_SLOT": 64, # Must be a power of 2
"SUB_SLOT_ITERS_STARTING": 2**27,
DEFAULT_CONSTANTS = ConsensusConstants(
SLOT_BLOCKS_TARGET=uint32(32),
MIN_BLOCKS_PER_CHALLENGE_BLOCK=uint8(16), # Must be less than half of SLOT_BLOCKS_TARGET
MAX_SUB_SLOT_BLOCKS=uint32(128), # Must be less than half of SUB_EPOCH_BLOCKS
NUM_SPS_SUB_SLOT=uint32(64), # Must be a power of 2
SUB_SLOT_ITERS_STARTING=uint64(2**27),
# DIFFICULTY_STARTING is the starting difficulty for the first epoch, which is then further
# multiplied by another factor of DIFFICULTY_CONSTANT_FACTOR, to be used in the VDF iter calculation formula.
"DIFFICULTY_CONSTANT_FACTOR": 2**67,
"DIFFICULTY_STARTING": 7,
"DIFFICULTY_CHANGE_MAX_FACTOR": 3, # The next difficulty is truncated to range [prev / FACTOR, prev * FACTOR]
DIFFICULTY_CONSTANT_FACTOR=uint128(2**67),
DIFFICULTY_STARTING=uint64(7),
DIFFICULTY_CHANGE_MAX_FACTOR=uint32(3), # The next difficulty is truncated to range [prev / FACTOR, prev * FACTOR]
# These 3 constants must be changed at the same time
"SUB_EPOCH_BLOCKS": 384, # The number of blocks per sub-epoch, mainnet 384
"EPOCH_BLOCKS": 4608, # The number of blocks per epoch, mainnet 4608. Must be multiple of SUB_EPOCH_SB
"SIGNIFICANT_BITS": 8, # The number of bits to look at in difficulty and min iters. The rest are zeroed
"DISCRIMINANT_SIZE_BITS": 1024, # Max is 1024 (based on ClassGroupElement int size)
"NUMBER_ZERO_BITS_PLOT_FILTER": 9, # H(plot signature of the challenge) must start with these many zeroes
"MIN_PLOT_SIZE": 32, # 32 for mainnet
"MAX_PLOT_SIZE": 50,
"SUB_SLOT_TIME_TARGET": 600, # The target number of seconds per slot, mainnet 600
"NUM_SP_INTERVALS_EXTRA": 3, # The number of sp intervals to add to the signage point
"MAX_FUTURE_TIME2": 2 * 60, # The next block can have a timestamp of at most these many seconds in the future
"NUMBER_OF_TIMESTAMPS": 11, # Than the average of the last NUMBER_OF_TIMESTAMPS blocks
SUB_EPOCH_BLOCKS=uint32(384), # The number of blocks per sub-epoch, mainnet 384
EPOCH_BLOCKS=uint32(4608), # The number of blocks per epoch, mainnet 4608. Must be multiple of SUB_EPOCH_SB
SIGNIFICANT_BITS=8, # The number of bits to look at in difficulty and min iters. The rest are zeroed
DISCRIMINANT_SIZE_BITS=1024, # Max is 1024 (based on ClassGroupElement int size)
NUMBER_ZERO_BITS_PLOT_FILTER=9, # H(plot signature of the challenge) must start with these many zeroes
MIN_PLOT_SIZE=32, # 32 for mainnet
MAX_PLOT_SIZE=50,
SUB_SLOT_TIME_TARGET=600, # The target number of seconds per slot, mainnet 600
NUM_SP_INTERVALS_EXTRA=3, # The number of sp intervals to add to the signage point
MAX_FUTURE_TIME2=2 * 60, # The next block can have a timestamp of at most these many seconds in the future
NUMBER_OF_TIMESTAMPS=11, # Than the average of the last NUMBER_OF_TIMESTAMPS blocks
# Used as the initial cc rc challenges, as well as first block back pointers, and first SES back pointer
# We override this value based on the chain being run (testnet0, testnet1, mainnet, etc)
# Default used for tests is std_hash(b'')
"GENESIS_CHALLENGE": bytes.fromhex("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
GENESIS_CHALLENGE=bytes32.fromhex("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
# Forks of chia should change this value to provide replay attack protection. This is set to mainnet genesis chall
"AGG_SIG_ME_ADDITIONAL_DATA": bytes.fromhex("ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"),
"GENESIS_PRE_FARM_POOL_PUZZLE_HASH": bytes.fromhex(
AGG_SIG_ME_ADDITIONAL_DATA=bytes.fromhex("ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"),
GENESIS_PRE_FARM_POOL_PUZZLE_HASH=bytes32.fromhex(
"d23da14695a188ae5708dd152263c4db883eb27edeb936178d4d988b8f3ce5fc"
),
"GENESIS_PRE_FARM_FARMER_PUZZLE_HASH": bytes.fromhex(
GENESIS_PRE_FARM_FARMER_PUZZLE_HASH=bytes32.fromhex(
"3d8765d3a597ec1d99663f6c9816d915b9f68613ac94009884c4addaefcce6af"
),
"MAX_VDF_WITNESS_SIZE": 64,
MAX_VDF_WITNESS_SIZE=64,
# Size of mempool = 50x the size of block
"MEMPOOL_BLOCK_BUFFER": 50,
MEMPOOL_BLOCK_BUFFER=50,
# Max coin amount, fits into 64 bits
"MAX_COIN_AMOUNT": uint64((1 << 64) - 1),
MAX_COIN_AMOUNT=uint64((1 << 64) - 1),
# Max block cost in clvm cost units
"MAX_BLOCK_COST_CLVM": 11000000000,
MAX_BLOCK_COST_CLVM=11000000000,
# The cost per byte of generator program
"COST_PER_BYTE": 12000,
"WEIGHT_PROOF_THRESHOLD": 2,
"BLOCKS_CACHE_SIZE": 4608 + (128 * 4),
"WEIGHT_PROOF_RECENT_BLOCKS": 1000,
"MAX_BLOCK_COUNT_PER_REQUESTS": 32, # Allow up to 32 blocks per request
"MAX_GENERATOR_SIZE": 1000000,
"MAX_GENERATOR_REF_LIST_SIZE": 512, # Number of references allowed in the block generator ref list
"POOL_SUB_SLOT_ITERS": 37600000000, # iters limit * NUM_SPS
"SOFT_FORK2_HEIGHT": 0,
COST_PER_BYTE=(12000),
WEIGHT_PROOF_THRESHOLD=uint8(2),
BLOCKS_CACHE_SIZE=uint32(4608 + (128 * 4)),
WEIGHT_PROOF_RECENT_BLOCKS=uint32(1000),
MAX_BLOCK_COUNT_PER_REQUESTS=uint32(32), # Allow up to 32 blocks per request
MAX_GENERATOR_SIZE=uint32(1000000),
MAX_GENERATOR_REF_LIST_SIZE=uint32(512), # Number of references allowed in the block generator ref list
POOL_SUB_SLOT_ITERS=uint64(37600000000), # iters limit * NUM_SPS
SOFT_FORK2_HEIGHT=uint32(0),
# November 14, 2023
"SOFT_FORK3_HEIGHT": 4510000,
SOFT_FORK3_HEIGHT=uint32(4510000),
# June 2024
"SOFT_FORK4_HEIGHT": 5496000,
"HARD_FORK_HEIGHT": 5496000,
"HARD_FORK_FIX_HEIGHT": 5496000,
SOFT_FORK4_HEIGHT=uint32(5496000),
HARD_FORK_HEIGHT=uint32(5496000),
HARD_FORK_FIX_HEIGHT=uint32(5496000),
# June 2027
"PLOT_FILTER_128_HEIGHT": 10542000,
PLOT_FILTER_128_HEIGHT=uint32(10542000),
# June 2030
"PLOT_FILTER_64_HEIGHT": 15592000,
PLOT_FILTER_64_HEIGHT=uint32(15592000),
# June 2033
"PLOT_FILTER_32_HEIGHT": 20643000,
PLOT_FILTER_32_HEIGHT=uint32(20643000),
# Disallow plots from passing the plot filter for more than one out of any four consecutive signage points.
"UNIQUE_PLOTS_WINDOW": 4,
}
DEFAULT_CONSTANTS = ConsensusConstants(**default_kwargs) # type: ignore
UNIQUE_PLOTS_WINDOW=uint8(4),
)

View File

@ -2,6 +2,7 @@ from __future__ import annotations
import asyncio
import copy
import dataclasses
import logging
import math
import os
@ -134,32 +135,31 @@ DESERIALIZE_MOD = load_serialized_clvm_maybe_recompile(
"chialisp_deserialisation.clsp", package_or_requirement="chia.consensus.puzzles"
)
test_constants = DEFAULT_CONSTANTS.replace(
**{
"MIN_PLOT_SIZE": 18,
"MIN_BLOCKS_PER_CHALLENGE_BLOCK": 12,
"DIFFICULTY_STARTING": 2**10,
"DISCRIMINANT_SIZE_BITS": 16,
"SUB_EPOCH_BLOCKS": 170,
"WEIGHT_PROOF_THRESHOLD": 2,
"WEIGHT_PROOF_RECENT_BLOCKS": 380,
"DIFFICULTY_CONSTANT_FACTOR": 33554432,
"NUM_SPS_SUB_SLOT": 16, # Must be a power of 2
"MAX_SUB_SLOT_BLOCKS": 50,
"EPOCH_BLOCKS": 340,
"BLOCKS_CACHE_SIZE": 340 + 3 * 50, # Coordinate with the above values
"SUB_SLOT_TIME_TARGET": 600, # The target number of seconds per slot, mainnet 600
"SUB_SLOT_ITERS_STARTING": 2**10, # Must be a multiple of 64
"NUMBER_ZERO_BITS_PLOT_FILTER": 1, # H(plot signature of the challenge) must start with these many zeroes
# Allows creating blockchains with timestamps up to 10 days in the future, for testing
"MAX_FUTURE_TIME2": 3600 * 24 * 10,
"MEMPOOL_BLOCK_BUFFER": 6,
"UNIQUE_PLOTS_WINDOW": 2,
# we deliberately make this different from HARD_FORK_HEIGHT in the
# tests, to ensure they operate independently (which they need to do for
# testnet10)
"HARD_FORK_FIX_HEIGHT": 5496100,
}
test_constants = dataclasses.replace(
DEFAULT_CONSTANTS,
MIN_PLOT_SIZE=18,
MIN_BLOCKS_PER_CHALLENGE_BLOCK=12,
DIFFICULTY_STARTING=2**10,
DISCRIMINANT_SIZE_BITS=16,
SUB_EPOCH_BLOCKS=170,
WEIGHT_PROOF_THRESHOLD=2,
WEIGHT_PROOF_RECENT_BLOCKS=380,
DIFFICULTY_CONSTANT_FACTOR=33554432,
NUM_SPS_SUB_SLOT=16, # Must be a power of 2
MAX_SUB_SLOT_BLOCKS=50,
EPOCH_BLOCKS=340,
BLOCKS_CACHE_SIZE=340 + 3 * 50, # Coordinate with the above values
SUB_SLOT_TIME_TARGET=600, # The target number of seconds per slot, mainnet 600
SUB_SLOT_ITERS_STARTING=2**10, # Must be a multiple of 64
NUMBER_ZERO_BITS_PLOT_FILTER=1, # H(plot signature of the challenge) must start with these many zeroes
# Allows creating blockchains with timestamps up to 10 days in the future, for testing
MAX_FUTURE_TIME2=3600 * 24 * 10,
MEMPOOL_BLOCK_BUFFER=6,
UNIQUE_PLOTS_WINDOW=2,
# we deliberately make this different from HARD_FORK_HEIGHT in the
# tests, to ensure they operate independently (which they need to do for
# testnet10)
HARD_FORK_FIX_HEIGHT=5496100,
)
@ -262,7 +262,7 @@ class BlockTools:
overrides = self._config["network_overrides"]["constants"][self._config["selected_network"]]
updated_constants = constants.replace_str_to_bytes(**overrides)
if const_dict is not None:
updated_constants = updated_constants.replace(**const_dict)
updated_constants = dataclasses.replace(updated_constants, **const_dict)
self.constants = updated_constants
self.plot_dir: Path = get_plot_dir(self.plot_dir_name, self.automated_testing)

View File

@ -16,7 +16,7 @@ from chia.harvester.harvester_api import HarvesterAPI
from chia.protocols.shared_protocol import Capability
from chia.server.server import ChiaServer
from chia.server.start_service import Service
from chia.simulator.block_tools import BlockTools, create_block_tools_async, test_constants
from chia.simulator.block_tools import BlockTools, create_block_tools_async
from chia.simulator.full_node_simulator import FullNodeSimulator
from chia.simulator.keyring import TempKeyring
from chia.simulator.setup_services import (
@ -55,10 +55,6 @@ def cleanup_keyring(keyring: TempKeyring) -> None:
log = logging.getLogger(__name__)
def constants_for_dic(dic: Dict[str, int]) -> ConsensusConstants:
return test_constants.replace(**dic)
@asynccontextmanager
async def setup_two_nodes(
consensus_constants: ConsensusConstants, db_version: int, self_hostname: str

View File

@ -1,10 +0,0 @@
from __future__ import annotations
from typing import Dict
from chia.consensus.constants import ConsensusConstants
from chia.consensus.default_constants import DEFAULT_CONSTANTS
def make_test_constants(test_constants_overrides: Dict) -> ConsensusConstants:
return DEFAULT_CONSTANTS.replace(**test_constants_overrides)

View File

@ -33,7 +33,6 @@ chia.util.hash
chia.util.json_util
chia.util.keychain
chia.util.keyring_wrapper
chia.util.make_test_constants
chia.util.merkle_set
chia.util.partial_func
chia.util.profiler

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
import logging
import multiprocessing
import time
@ -559,7 +560,7 @@ class TestBlockHeaderValidation:
async def do_test_invalid_icc_sub_slot_vdf(self, keychain, db_version, constants: ConsensusConstants):
bt_high_iters = await create_block_tools_async(
constants=constants.replace(SUB_SLOT_ITERS_STARTING=(2**12), DIFFICULTY_STARTING=(2**14)),
constants=dataclasses.replace(constants, SUB_SLOT_ITERS_STARTING=(2**12), DIFFICULTY_STARTING=(2**14)),
keychain=keychain,
)
bc1, db_wrapper, db_path = await create_blockchain(bt_high_iters.constants, db_version)
@ -1511,7 +1512,7 @@ class TestBlockHeaderValidation:
# 26
# the test constants set MAX_FUTURE_TIME to 10 days, restore it to
# default for this test
constants = bt.constants.replace(MAX_FUTURE_TIME2=2 * 60)
constants = dataclasses.replace(bt.constants, MAX_FUTURE_TIME2=2 * 60)
time_delta = 2 * 60 + 1
blocks = bt.get_consecutive_blocks(1)
@ -2682,13 +2683,17 @@ class TestBodyValidation:
pass
#
# with TempKeyring() as keychain:
# new_test_constants = bt.constants.replace(
# **{"GENESIS_PRE_FARM_POOL_PUZZLE_HASH": bt.pool_ph, "GENESIS_PRE_FARM_FARMER_PUZZLE_HASH": bt.pool_ph}
# new_test_constants = dataclasses.replace(
# bt.constants,
# GENESIS_PRE_FARM_POOL_PUZZLE_HASH=bt.pool_ph,
# GENESIS_PRE_FARM_FARMER_PUZZLE_HASH=bt.pool_ph,
# )
# b, db_wrapper, db_path = await create_blockchain(new_test_constants, db_version)
# bt_2 = await create_block_tools_async(constants=new_test_constants, keychain=keychain)
# bt_2.constants = bt_2.constants.replace(
# **{"GENESIS_PRE_FARM_POOL_PUZZLE_HASH": bt.pool_ph, "GENESIS_PRE_FARM_FARMER_PUZZLE_HASH": bt.pool_ph}
# bt_2.constants = dataclasses.replace(
# bt_2.constants,
# GENESIS_PRE_FARM_POOL_PUZZLE_HASH=bt.pool_ph,
# GENESIS_PRE_FARM_FARMER_PUZZLE_HASH=bt.pool_ph,
# )
# blocks = bt_2.get_consecutive_blocks(
# 3,
@ -3623,13 +3628,18 @@ async def test_soft_fork4_activation(
# consecutive plot filter, hence no block would pass CHIP-13).
with TempKeyring() as keychain:
bt = await create_block_tools_async(
constants=blockchain_constants.replace(
constants=dataclasses.replace(
blockchain_constants,
SOFT_FORK4_HEIGHT=(0 if bt_respects_soft_fork4 else 10000),
UNIQUE_PLOTS_WINDOW=unique_plots_window,
),
keychain=keychain,
)
blockchain_constants = bt.constants.replace(SOFT_FORK3_HEIGHT=0, SOFT_FORK4_HEIGHT=soft_fork4_height)
blockchain_constants = dataclasses.replace(
bt.constants,
SOFT_FORK3_HEIGHT=0,
SOFT_FORK4_HEIGHT=soft_fork4_height,
)
b, db_wrapper, db_path = await create_blockchain(blockchain_constants, db_version)
blocks = bt.get_consecutive_blocks(25)
for height, block in enumerate(blocks):

View File

@ -1,6 +1,7 @@
# flake8: noqa E402 # See imports after multiprocessing.set_start_method
from __future__ import annotations
import dataclasses
import datetime
import multiprocessing
import os
@ -119,11 +120,12 @@ def blockchain_constants(consensus_mode) -> ConsensusConstants:
if consensus_mode == ConsensusMode.PLAIN:
return test_constants
if consensus_mode == ConsensusMode.SOFT_FORK3:
return test_constants.replace(SOFT_FORK3_HEIGHT=3)
return dataclasses.replace(test_constants, SOFT_FORK3_HEIGHT=3)
if consensus_mode == ConsensusMode.SOFT_FORK4:
return test_constants.replace(SOFT_FORK3_HEIGHT=3, SOFT_FORK4_HEIGHT=3)
return dataclasses.replace(test_constants, SOFT_FORK3_HEIGHT=3, SOFT_FORK4_HEIGHT=3)
if consensus_mode == ConsensusMode.HARD_FORK_2_0:
return test_constants.replace(
return dataclasses.replace(
test_constants,
HARD_FORK_HEIGHT=2,
HARD_FORK_FIX_HEIGHT=2,
PLOT_FILTER_128_HEIGHT=10,
@ -432,7 +434,7 @@ async def wallet_nodes(blockchain_constants, consensus_mode):
async with setup_simulators_and_wallets(
2,
1,
blockchain_constants.replace(MEMPOOL_BLOCK_BUFFER=1, MAX_BLOCK_COST_CLVM=400000000),
dataclasses.replace(blockchain_constants, MEMPOOL_BLOCK_BUFFER=1, MAX_BLOCK_COST_CLVM=400000000),
) as (nodes, wallets, bt):
full_node_1 = nodes[0]
full_node_2 = nodes[1]

View File

@ -1,5 +1,7 @@
from __future__ import annotations
import dataclasses
from pytest import raises
from chia.consensus.default_constants import DEFAULT_CONSTANTS
@ -13,7 +15,7 @@ from chia.consensus.pot_iterations import (
from chia.util.hash import std_hash
from chia.util.ints import uint8, uint64
test_constants = DEFAULT_CONSTANTS.replace(**{"NUM_SPS_SUB_SLOT": 32, "SUB_SLOT_TIME_TARGET": 300})
test_constants = dataclasses.replace(DEFAULT_CONSTANTS, NUM_SPS_SUB_SLOT=32, SUB_SLOT_TIME_TARGET=300)
class TestPotIterations:

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import asyncio
import dataclasses
import logging
import time
from typing import List
@ -421,10 +422,13 @@ class TestFullSync:
self, two_nodes, default_400_blocks, blockchain_constants, self_hostname, consensus_mode
):
full_node_1, full_node_2, server_1, server_2, bt = two_nodes
bt.constants = blockchain_constants.replace(SOFT_FORK4_HEIGHT=1000000)
bt.constants = dataclasses.replace(blockchain_constants, SOFT_FORK4_HEIGHT=1000000)
blocks = bt.get_consecutive_blocks(700, default_400_blocks)
full_node_2.full_node.blockchain.constants = blockchain_constants.replace(SOFT_FORK4_HEIGHT=1000000)
full_node_1.full_node.blockchain.constants = blockchain_constants.replace(SOFT_FORK4_HEIGHT=400)
full_node_2.full_node.blockchain.constants = dataclasses.replace(
blockchain_constants,
SOFT_FORK4_HEIGHT=1000000,
)
full_node_1.full_node.blockchain.constants = dataclasses.replace(blockchain_constants, SOFT_FORK4_HEIGHT=400)
for block in blocks:
await full_node_2.full_node.add_block(block)
server_1 = full_node_1.full_node.server
@ -445,8 +449,11 @@ class TestFullSync:
):
full_node_1, full_node_2, server_1, server_2, bt = two_nodes
blocks = bt.get_consecutive_blocks(700, default_400_blocks)
full_node_2.full_node.blockchain.constants = blockchain_constants.replace(SOFT_FORK4_HEIGHT=1000000)
full_node_1.full_node.blockchain.constants = blockchain_constants.replace(SOFT_FORK4_HEIGHT=400)
full_node_2.full_node.blockchain.constants = dataclasses.replace(
blockchain_constants,
SOFT_FORK4_HEIGHT=1000000,
)
full_node_1.full_node.blockchain.constants = dataclasses.replace(blockchain_constants, SOFT_FORK4_HEIGHT=400)
for block in blocks:
await full_node_2.full_node.add_block(block)

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
import logging
from secrets import token_bytes
from typing import AsyncIterator, List, Optional
@ -34,16 +35,20 @@ log = logging.getLogger(__name__)
@pytest_asyncio.fixture(scope="function")
async def custom_block_tools(blockchain_constants: ConsensusConstants) -> AsyncIterator[BlockTools]:
with TempKeyring() as keychain:
patched_constants = blockchain_constants.replace(
**{"DISCRIMINANT_SIZE_BITS": 32, "SUB_SLOT_ITERS_STARTING": 2**12}
patched_constants = dataclasses.replace(
blockchain_constants,
DISCRIMINANT_SIZE_BITS=32,
SUB_SLOT_ITERS_STARTING=2**12,
)
yield await create_block_tools_async(constants=patched_constants, keychain=keychain)
@pytest_asyncio.fixture(scope="function")
async def empty_blockchain(db_version: int, blockchain_constants: ConsensusConstants) -> AsyncIterator[Blockchain]:
patched_constants = blockchain_constants.replace(
**{"DISCRIMINANT_SIZE_BITS": 32, "SUB_SLOT_ITERS_STARTING": 2**12}
patched_constants = dataclasses.replace(
blockchain_constants,
DISCRIMINANT_SIZE_BITS=32,
SUB_SLOT_ITERS_STARTING=2**12,
)
bc1, db_wrapper, db_path = await create_blockchain(patched_constants, db_version)
yield bc1

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
import logging
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Tuple, Union
@ -7,8 +8,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
import pytest
from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
from chia.consensus.constants import ConsensusConstants
from chia.consensus.default_constants import DEFAULT_CONSTANTS, default_kwargs
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.farmer.farmer import increment_pool_stats, strip_old_entries
from chia.pools.pool_config import PoolWalletConfig
from chia.protocols import farmer_protocol, harvester_protocol
@ -559,9 +559,7 @@ async def test_farmer_new_proof_of_space_for_pool_stats(
)
p2_singleton_puzzle_hash = case.pool_contract_puzzle_hash
constant_kwargs = default_kwargs.copy()
constant_kwargs["POOL_SUB_SLOT_ITERS"] = case.sub_slot_iters
farmer_api.farmer.constants = ConsensusConstants(**constant_kwargs) # type: ignore
farmer_api.farmer.constants = dataclasses.replace(DEFAULT_CONSTANTS, POOL_SUB_SLOT_ITERS=case.sub_slot_iters)
farmer_api.farmer._private_keys = case.farmer_private_keys
farmer_api.farmer.authentication_keys = case.authentication_keys
farmer_api.farmer.sps[case.sp_hash] = [sp]

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
from pathlib import Path
from typing import Any, AsyncIterator, Dict, List, Optional, Tuple
@ -58,7 +59,7 @@ async def farmer_harvester_with_filter_size_9(
return len(await farmer_rpc_cl.get_connections()) > 0
local_b_tools = await create_block_tools_async(
constants=test_constants.replace(NUMBER_ZERO_BITS_PLOT_FILTER=9), keychain=get_temp_keyring
constants=dataclasses.replace(test_constants, NUMBER_ZERO_BITS_PLOT_FILTER=9), keychain=get_temp_keyring
)
new_config = local_b_tools._config
local_b_tools.change_config(new_config)

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
import logging
from typing import Callable, List, Optional, Tuple
@ -22,8 +23,10 @@ the_puzzle_hash = bytes32(
bytes.fromhex("9dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2")
) # Program.to(1)
NEW_DEFAULT_CONSTANTS: ConsensusConstants = DEFAULT_CONSTANTS.replace(
MAX_BLOCK_COST_CLVM=300000000, MEMPOOL_BLOCK_BUFFER=1
NEW_DEFAULT_CONSTANTS: ConsensusConstants = dataclasses.replace(
DEFAULT_CONSTANTS,
MAX_BLOCK_COST_CLVM=300000000,
MEMPOOL_BLOCK_BUFFER=1,
)

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
from typing import List, Tuple
import pytest
@ -25,19 +26,18 @@ from chia.util.ints import uint16, uint32, uint64
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.wallet_node import WalletNode
test_constants_modified = test_constants.replace(
**{
"DIFFICULTY_STARTING": 2**8,
"DISCRIMINANT_SIZE_BITS": 1024,
"SUB_EPOCH_BLOCKS": 140,
"WEIGHT_PROOF_THRESHOLD": 2,
"WEIGHT_PROOF_RECENT_BLOCKS": 350,
"MAX_SUB_SLOT_BLOCKS": 50,
"NUM_SPS_SUB_SLOT": 32, # Must be a power of 2
"EPOCH_BLOCKS": 280,
"SUB_SLOT_ITERS_STARTING": 2**20,
"NUMBER_ZERO_BITS_PLOT_FILTER": 5,
}
test_constants_modified = dataclasses.replace(
test_constants,
DIFFICULTY_STARTING=2**8,
DISCRIMINANT_SIZE_BITS=1024,
SUB_EPOCH_BLOCKS=140,
WEIGHT_PROOF_THRESHOLD=2,
WEIGHT_PROOF_RECENT_BLOCKS=350,
MAX_SUB_SLOT_BLOCKS=50,
NUM_SPS_SUB_SLOT=32, # Must be a power of 2
EPOCH_BLOCKS=280,
SUB_SLOT_ITERS_STARTING=2**20,
NUMBER_ZERO_BITS_PLOT_FILTER=5,
)

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
import json
from pathlib import Path
from typing import List
@ -25,7 +26,7 @@ testnet10 = {
"MIN_PLOT_SIZE": 18,
}
constants = DEFAULT_CONSTANTS.replace(**testnet10)
constants = dataclasses.replace(DEFAULT_CONSTANTS, **testnet10)
retire_bytes = (
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import dataclasses
from typing import Dict, List, Optional, Tuple
import pytest
@ -498,7 +499,7 @@ class TestWeightProof:
],
)
def test_calculate_prefix_bits_clamp_zero(height: uint32, expected: int):
constants = DEFAULT_CONSTANTS.replace(NUMBER_ZERO_BITS_PLOT_FILTER=3)
constants = dataclasses.replace(DEFAULT_CONSTANTS, NUMBER_ZERO_BITS_PLOT_FILTER=3)
assert calculate_prefix_bits(constants, height) == expected

View File

@ -1,21 +1,22 @@
from __future__ import annotations
import dataclasses
from chia.consensus.default_constants import DEFAULT_CONSTANTS
test_constants = DEFAULT_CONSTANTS.replace(
**{
"MIN_PLOT_SIZE": 18,
"MIN_BLOCKS_PER_CHALLENGE_BLOCK": 12,
"DIFFICULTY_STARTING": 2**9,
"DISCRIMINANT_SIZE_BITS": 16,
"SUB_EPOCH_BLOCKS": 170,
"WEIGHT_PROOF_THRESHOLD": 2,
"WEIGHT_PROOF_RECENT_BLOCKS": 380,
"DIFFICULTY_CONSTANT_FACTOR": 33554432,
"NUM_SPS_SUB_SLOT": 16, # Must be a power of 2
"MAX_SUB_SLOT_BLOCKS": 50,
"EPOCH_BLOCKS": 340,
"SUB_SLOT_ITERS_STARTING": 2**10, # Must be a multiple of 64
"NUMBER_ZERO_BITS_PLOT_FILTER": 1, # H(plot signature of the challenge) must start with these many zeroes
}
test_constants = dataclasses.replace(
DEFAULT_CONSTANTS,
MIN_PLOT_SIZE=18,
MIN_BLOCKS_PER_CHALLENGE_BLOCK=12,
DIFFICULTY_STARTING=2**9,
DISCRIMINANT_SIZE_BITS=16,
SUB_EPOCH_BLOCKS=170,
WEIGHT_PROOF_THRESHOLD=2,
WEIGHT_PROOF_RECENT_BLOCKS=380,
DIFFICULTY_CONSTANT_FACTOR=33554432,
NUM_SPS_SUB_SLOT=16, # Must be a power of 2
MAX_SUB_SLOT_BLOCKS=50,
EPOCH_BLOCKS=340,
SUB_SLOT_ITERS_STARTING=2**10, # Must be a multiple of 64
NUMBER_ZERO_BITS_PLOT_FILTER=1, # H(plot signature of the challenge) must start with these many zeroes
)