Skip to content

Commit

Permalink
streamable: Simplify and force correct usage (#10509)
Browse files Browse the repository at this point in the history
* streamable: Merge `strictdataclass` into `Streamable` class

* tests: Test not supported streamable types

* streamable: Reorder decorators

* streamable: Simplify streamable decorator and force correct usage/syntax

* streamable: Just move some stuff around in the file

* streamable: Improve syntax error messages

* mypy: Drop `type_checking.py` and `test_type_checking.py` from exclusion

* streamable: Use cached fields instead of `__annotations__`

This is now possible after merging `__post_init__` into `Streamable`

* Introduce `DefinitionError` as `StreamableError`

* `/t` -> `    `
  • Loading branch information
xdustinface authored Apr 9, 2022
1 parent 930a4b6 commit a48fd43
Show file tree
Hide file tree
Showing 61 changed files with 549 additions and 461 deletions.
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
6 changes: 3 additions & 3 deletions chia/clvm/spend_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"""


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class SimFullBlock(Streamable):
transactions_generator: Optional[BlockGenerator]
height: uint32 # Note that height is not on a regular FullBlock


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class SimBlockRecord(Streamable):
reward_claims_incorporated: List[Coin]
height: uint32
Expand All @@ -69,8 +69,8 @@ def create(cls, rci: List[Coin], height: uint32, timestamp: uint64):
)


@dataclass(frozen=True)
@streamable
@dataclass(frozen=True)
class SimStore(Streamable):
timestamp: uint64
block_height: uint32
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]
conds: Optional[SpendBundleConditions]
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 @@ -35,8 +35,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

0 comments on commit a48fd43

Please sign in to comment.