more (more) uint*() (#16324)

This commit is contained in:
Kyle Altendorf 2023-09-15 12:35:21 -04:00 committed by GitHub
parent b1afd4a48d
commit 36070fb19a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 55 deletions

View File

@ -1241,7 +1241,7 @@ def validate_recent_blocks(
if not adjusted:
assert prev_block_record is not None
prev_block_record = dataclasses.replace(
prev_block_record, deficit=uint32(deficit % constants.MIN_BLOCKS_PER_CHALLENGE_BLOCK)
prev_block_record, deficit=uint8(deficit % constants.MIN_BLOCKS_PER_CHALLENGE_BLOCK)
)
sub_blocks.add_block_record(prev_block_record)
adjusted = True

View File

@ -137,19 +137,19 @@ DESERIALIZE_MOD = load_serialized_clvm_maybe_recompile(
test_constants = dataclasses.replace(
DEFAULT_CONSTANTS,
MIN_PLOT_SIZE=18,
MIN_BLOCKS_PER_CHALLENGE_BLOCK=12,
DIFFICULTY_STARTING=2**10,
MIN_BLOCKS_PER_CHALLENGE_BLOCK=uint8(12),
DIFFICULTY_STARTING=uint64(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_EPOCH_BLOCKS=uint32(170),
WEIGHT_PROOF_THRESHOLD=uint8(2),
WEIGHT_PROOF_RECENT_BLOCKS=uint32(380),
DIFFICULTY_CONSTANT_FACTOR=uint128(33554432),
NUM_SPS_SUB_SLOT=uint32(16), # Must be a power of 2
MAX_SUB_SLOT_BLOCKS=uint32(50),
EPOCH_BLOCKS=uint32(340),
BLOCKS_CACHE_SIZE=uint32(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
SUB_SLOT_ITERS_STARTING=uint64(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,
@ -157,7 +157,7 @@ test_constants = dataclasses.replace(
# 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,
HARD_FORK_FIX_HEIGHT=uint32(5496100),
)

View File

@ -559,7 +559,11 @@ 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=dataclasses.replace(constants, SUB_SLOT_ITERS_STARTING=(2**12), DIFFICULTY_STARTING=(2**14)),
constants=dataclasses.replace(
constants,
SUB_SLOT_ITERS_STARTING=uint64(2**12),
DIFFICULTY_STARTING=uint64(2**14),
),
keychain=keychain,
)
bc1, db_wrapper, db_path = await create_blockchain(bt_high_iters.constants, db_version)

View File

@ -52,7 +52,7 @@ from chia.simulator.time_out_assert import time_out_assert
from chia.simulator.wallet_tools import WalletTool
from chia.types.peer_info import PeerInfo
from chia.util.config import create_default_chia_config, lock_and_load_config
from chia.util.ints import uint16, uint64
from chia.util.ints import uint16, uint32, uint64
from chia.util.keychain import Keychain
from chia.util.task_timing import main as task_instrumentation_main
from chia.util.task_timing import start_task_instrumentation, stop_task_instrumentation
@ -126,15 +126,15 @@ def blockchain_constants(consensus_mode) -> ConsensusConstants:
if consensus_mode == ConsensusMode.PLAIN:
return test_constants
if consensus_mode == ConsensusMode.SOFT_FORK3:
return dataclasses.replace(test_constants, SOFT_FORK3_HEIGHT=3)
return dataclasses.replace(test_constants, SOFT_FORK3_HEIGHT=uint32(3))
if consensus_mode == ConsensusMode.HARD_FORK_2_0:
return dataclasses.replace(
test_constants,
HARD_FORK_HEIGHT=2,
HARD_FORK_FIX_HEIGHT=2,
PLOT_FILTER_128_HEIGHT=10,
PLOT_FILTER_64_HEIGHT=15,
PLOT_FILTER_32_HEIGHT=20,
HARD_FORK_HEIGHT=uint32(2),
HARD_FORK_FIX_HEIGHT=uint32(2),
PLOT_FILTER_128_HEIGHT=uint32(10),
PLOT_FILTER_64_HEIGHT=uint32(15),
PLOT_FILTER_32_HEIGHT=uint32(20),
)
raise AssertionError("Invalid Blockchain mode in simulation")

View File

@ -13,9 +13,9 @@ from chia.consensus.pot_iterations import (
is_overflow_block,
)
from chia.util.hash import std_hash
from chia.util.ints import uint8, uint64
from chia.util.ints import uint8, uint32, uint64
test_constants = dataclasses.replace(DEFAULT_CONSTANTS, NUM_SPS_SUB_SLOT=32, SUB_SLOT_TIME_TARGET=300)
test_constants = dataclasses.replace(DEFAULT_CONSTANTS, NUM_SPS_SUB_SLOT=uint32(32), SUB_SLOT_TIME_TARGET=300)
class TestPotIterations:

View File

@ -38,7 +38,7 @@ async def custom_block_tools(blockchain_constants: ConsensusConstants) -> AsyncI
patched_constants = dataclasses.replace(
blockchain_constants,
DISCRIMINANT_SIZE_BITS=32,
SUB_SLOT_ITERS_STARTING=2**12,
SUB_SLOT_ITERS_STARTING=uint64(2**12),
)
yield await create_block_tools_async(constants=patched_constants, keychain=keychain)
@ -48,7 +48,7 @@ async def empty_blockchain(db_version: int, blockchain_constants: ConsensusConst
patched_constants = dataclasses.replace(
blockchain_constants,
DISCRIMINANT_SIZE_BITS=32,
SUB_SLOT_ITERS_STARTING=2**12,
SUB_SLOT_ITERS_STARTING=uint64(2**12),
)
bc1, db_wrapper, db_path = await create_blockchain(patched_constants, db_version)
yield bc1

View File

@ -22,21 +22,21 @@ from chia.simulator.simulator_protocol import FarmNewBlockProtocol, GetAllCoinsP
from chia.simulator.time_out_assert import time_out_assert
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.peer_info import PeerInfo
from chia.util.ints import uint16, uint32, uint64
from chia.util.ints import uint8, uint16, uint32, uint64
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.wallet_node import WalletNode
test_constants_modified = dataclasses.replace(
test_constants,
DIFFICULTY_STARTING=2**8,
DIFFICULTY_STARTING=uint64(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,
SUB_EPOCH_BLOCKS=uint32(140),
WEIGHT_PROOF_THRESHOLD=uint8(2),
WEIGHT_PROOF_RECENT_BLOCKS=uint32(350),
MAX_SUB_SLOT_BLOCKS=uint32(50),
NUM_SPS_SUB_SLOT=uint32(32), # Must be a power of 2
EPOCH_BLOCKS=uint32(280),
SUB_SLOT_ITERS_STARTING=uint64(2**20),
NUMBER_ZERO_BITS_PLOT_FILTER=5,
)

View File

@ -228,7 +228,7 @@ async def test_get_farming_rewards(seeded_random: random.Random) -> None:
name=bytes32.random(seeded_random),
confirmed=conf,
confirmed_at_height=uint32(100 if conf else 0),
type=type,
type=uint32(type.value),
)
)
@ -331,7 +331,12 @@ async def test_all_transactions_for_wallet(seeded_random: random.Random) -> None
TransactionType.OUTGOING_TRADE,
]:
test_trs.append(
dataclasses.replace(tr1, name=bytes32.random(seeded_random), wallet_id=uint32(wallet_id), type=type)
dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
wallet_id=uint32(wallet_id),
type=uint32(type.value),
)
)
for tr in test_trs:
@ -583,28 +588,28 @@ async def test_get_transactions_between_relevance(seeded_random: random.Random)
name=bytes32.random(seeded_random),
confirmed=False,
confirmed_at_height=uint32(2),
created_at_time=uint32(1000),
created_at_time=uint64(1000),
)
t2 = dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
confirmed=False,
confirmed_at_height=uint32(2),
created_at_time=uint32(999),
created_at_time=uint64(999),
)
t3 = dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
confirmed=False,
confirmed_at_height=uint32(1),
created_at_time=uint32(1000),
created_at_time=uint64(1000),
)
t4 = dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
confirmed=False,
confirmed_at_height=uint32(1),
created_at_time=uint32(999),
created_at_time=uint64(999),
)
t5 = dataclasses.replace(
@ -612,28 +617,28 @@ async def test_get_transactions_between_relevance(seeded_random: random.Random)
name=bytes32.random(seeded_random),
confirmed=True,
confirmed_at_height=uint32(2),
created_at_time=uint32(1000),
created_at_time=uint64(1000),
)
t6 = dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
confirmed=True,
confirmed_at_height=uint32(2),
created_at_time=uint32(999),
created_at_time=uint64(999),
)
t7 = dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
confirmed=True,
confirmed_at_height=uint32(1),
created_at_time=uint32(1000),
created_at_time=uint64(1000),
)
t8 = dataclasses.replace(
tr1,
name=bytes32.random(seeded_random),
confirmed=True,
confirmed_at_height=uint32(1),
created_at_time=uint32(999),
created_at_time=uint64(999),
)
await store.add_transaction_record(t1)

View File

@ -345,7 +345,7 @@ async def test_get_timestamp_for_height_from_peer(
cache = wallet_node.get_cache_for_peer(full_node_peer)
cache.clear_after_height(0)
modified_foliage_transaction_block = dataclasses.replace(
block_at_peak.foliage_transaction_block, timestamp=timestamp_at_peak + 1
block_at_peak.foliage_transaction_block, timestamp=uint64(timestamp_at_peak + 1)
)
modified_peak = dataclasses.replace(peak, foliage_transaction_block=modified_foliage_transaction_block)
cache.add_to_blocks(modified_peak)

View File

@ -3,20 +3,21 @@ from __future__ import annotations
import dataclasses
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.util.ints import uint8, uint32, uint64, uint128
test_constants = dataclasses.replace(
DEFAULT_CONSTANTS,
MIN_PLOT_SIZE=18,
MIN_BLOCKS_PER_CHALLENGE_BLOCK=12,
DIFFICULTY_STARTING=2**9,
MIN_BLOCKS_PER_CHALLENGE_BLOCK=uint8(12),
DIFFICULTY_STARTING=uint64(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
SUB_EPOCH_BLOCKS=uint32(170),
WEIGHT_PROOF_THRESHOLD=uint8(2),
WEIGHT_PROOF_RECENT_BLOCKS=uint32(380),
DIFFICULTY_CONSTANT_FACTOR=uint128(33554432),
NUM_SPS_SUB_SLOT=uint32(16), # Must be a power of 2
MAX_SUB_SLOT_BLOCKS=uint32(50),
EPOCH_BLOCKS=uint32(340),
SUB_SLOT_ITERS_STARTING=uint64(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
)