Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamable: Stop parsing in Streamable.__post_init__, validate only instead #10629

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ extend_skip=
chia/util/profiler.py
chia/util/service_groups.py
chia/util/ssl_check.py
chia/util/streamable.py
chia/util/ws_message.py
chia/wallet/cat_wallet/cat_info.py
chia/wallet/cat_wallet/cat_utils.py
Expand Down Expand Up @@ -192,7 +191,6 @@ extend_skip=
tests/core/util/test_files.py
tests/core/util/test_keychain.py
tests/core/util/test_keyring_wrapper.py
tests/core/util/test_streamable.py
tests/generator/test_compression.py
tests/generator/test_generator_types.py
tests/generator/test_list_to_batches.py
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
_version = 1


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class BenchmarkInner(Streamable):
a: str


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class BenchmarkMiddle(Streamable):
a: uint64
b: List[bytes32]
Expand All @@ -33,8 +33,8 @@ class BenchmarkMiddle(Streamable):
e: BenchmarkInner


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class BenchmarkClass(Streamable):
a: Optional[BenchmarkMiddle]
b: Optional[BenchmarkMiddle]
Expand Down
12 changes: 4 additions & 8 deletions benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from chia.consensus.coinbase import create_farmer_coin, create_pool_coin
from chia.types.blockchain_format.classgroup import ClassgroupElement
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.blockchain_format.sized_bytes import bytes32, bytes100
from chia.types.blockchain_format.vdf import VDFInfo, VDFProof
from chia.types.blockchain_format.foliage import Foliage, FoliageBlockData, FoliageTransactionBlock, TransactionsInfo
from chia.types.blockchain_format.pool_target import PoolTarget
Expand Down Expand Up @@ -56,9 +56,7 @@ def rand_bytes(num) -> bytes:


def rand_hash() -> bytes32:
# TODO: address hint errors and remove ignores
# error: Incompatible return value type (got "bytes", expected "bytes32") [return-value]
return rand_bytes(32) # type: ignore[return-value]
return bytes32(rand_bytes(32))


def rand_g1() -> G1Element:
Expand All @@ -72,9 +70,7 @@ def rand_g2() -> G2Element:


def rand_class_group_element() -> ClassgroupElement:
# TODO: address hint errors and remove ignores
# error: Argument 1 to "ClassgroupElement" has incompatible type "bytes"; expected "bytes100" [arg-type]
return ClassgroupElement(rand_bytes(100)) # type: ignore[arg-type]
return ClassgroupElement(bytes100(rand_bytes(100)))


def rand_vdf() -> VDFInfo:
Expand All @@ -84,7 +80,7 @@ def rand_vdf() -> VDFInfo:
def rand_vdf_proof() -> VDFProof:
return VDFProof(
uint8(1), # witness_type
rand_hash(), # witness
bytes(rand_hash()), # witness
bool(random.randint(0, 1)), # normalized_to_identity
)

Expand Down
2 changes: 1 addition & 1 deletion chia/consensus/block_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from chia.util.streamable import Streamable, streamable


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class BlockRecord(Streamable):
"""
This class is not included or hashed into the blockchain, but it is kept in memory as a more
Expand Down
2 changes: 1 addition & 1 deletion chia/consensus/cost_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from chia.util.streamable import Streamable, streamable


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class NPCResult(Streamable):
error: Optional[uint16]
npc_list: List[NPC]
Expand Down
2 changes: 1 addition & 1 deletion chia/consensus/multiprocess_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
log = logging.getLogger(__name__)


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class PreValidationResult(Streamable):
error: Optional[uint16]
required_iters: Optional[uint64] # Iff error is None
Expand Down
2 changes: 1 addition & 1 deletion chia/full_node/block_height_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
log = logging.getLogger(__name__)


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class SesCache(Streamable):
content: List[Tuple[uint32, bytes]]

Expand Down
2 changes: 1 addition & 1 deletion chia/full_node/full_node_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
log = logging.getLogger(__name__)


@dataclasses.dataclass(frozen=True)
@streamable
@dataclasses.dataclass(frozen=True)
class FullNodeStorePeakResult(Streamable):
added_eos: Optional[EndOfSubSlotBundle]
new_signage_points: List[Tuple[uint8, SignagePoint]]
Expand Down
2 changes: 1 addition & 1 deletion chia/full_node/signage_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from chia.util.streamable import Streamable, streamable


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class SignagePoint(Streamable):
cc_vdf: Optional[VDFInfo]
cc_proof: Optional[VDFProof]
Expand Down
4 changes: 2 additions & 2 deletions chia/plotting/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
CURRENT_VERSION: uint16 = uint16(0)


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class CacheEntry(Streamable):
pool_public_key: Optional[G1Element]
pool_contract_puzzle_hash: Optional[bytes32]
plot_public_key: G1Element


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class DiskCache(Streamable):
version: uint16
data: List[Tuple[bytes32, CacheEntry]]
Expand Down
2 changes: 1 addition & 1 deletion chia/pools/pool_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
log = logging.getLogger(__name__)


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class PoolWalletConfig(Streamable):
launcher_id: bytes32
pool_url: str
Expand Down
4 changes: 2 additions & 2 deletions chia/pools/pool_wallet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class PoolSingletonState(IntEnum):
FARMING_TO_POOL = PoolSingletonState.FARMING_TO_POOL


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class PoolState(Streamable):
"""
`PoolState` is a type that is serialized to the blockchain to track the state of the user's pool singleton
Expand Down Expand Up @@ -97,8 +97,8 @@ def create_pool_state(
return ps


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class PoolWalletInfo(Streamable):
"""
Internal Pool Wallet state, not destined for the blockchain. This can be completely derived with
Expand Down
10 changes: 5 additions & 5 deletions chia/protocols/farmer_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"""


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class NewSignagePoint(Streamable):
challenge_hash: bytes32
challenge_chain_sp: bytes32
Expand All @@ -26,8 +26,8 @@ class NewSignagePoint(Streamable):
signage_point_index: uint8


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class DeclareProofOfSpace(Streamable):
challenge_hash: bytes32
challenge_chain_sp: bytes32
Expand All @@ -41,16 +41,16 @@ class DeclareProofOfSpace(Streamable):
pool_signature: Optional[G2Element]


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class RequestSignedValues(Streamable):
quality_string: bytes32
foliage_block_data_hash: bytes32
foliage_transaction_block_hash: bytes32


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class FarmingInfo(Streamable):
challenge_hash: bytes32
sp_hash: bytes32
Expand All @@ -60,8 +60,8 @@ class FarmingInfo(Streamable):
total_plots: uint32


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class SignedValues(Streamable):
quality_string: bytes32
foliage_block_data_signature: G2Element
Expand Down
Loading