mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
b084813b12
* Avoid importing `test_constants` as it takes a long time. * Factor out `parse_*` functions. * First crack at refactoring `Streamable.parse`. * Don't add `_parse_functions` attribute to `Streamable`. This no longer requires an extra `_parse_functions` attribute on a `Streamable`, as it may be confusing serializers or other functions that use `__annotations__`. * Fix lint problems with `black`. * Fix `parse_tuple`. * Defer some parsing failures to parse time rather than class-creation time. * Tidy up & remove some obsolete stuff. * Decorate `RequestBlocks` as `streamable`. * Fix wrong uses of Streamable class Revert an earlier commit and error out on class creation in case a Streamable subclass is instantiated incorrectly, e.g. containing a non-serializable member. Fix cases where Streamable parent class was forgotten. * Fix wrong types when creating DerivationRecord and WalletCoinRecord * additional unit tests for streamable parsers * add type annotations (#3222) Co-authored-by: Rostislav <rostislav@users.noreply.github.com> Co-authored-by: arvidn <arvid@libtorrent.org>
204 lines
4.1 KiB
Python
204 lines
4.1 KiB
Python
from dataclasses import dataclass
|
|
from typing import List, Optional
|
|
|
|
from chia.types.blockchain_format.sized_bytes import bytes32
|
|
from chia.types.blockchain_format.vdf import VDFInfo, VDFProof
|
|
from chia.types.end_of_slot_bundle import EndOfSubSlotBundle
|
|
from chia.types.full_block import FullBlock
|
|
from chia.types.peer_info import TimestampedPeerInfo
|
|
from chia.types.spend_bundle import SpendBundle
|
|
from chia.types.unfinished_block import UnfinishedBlock
|
|
from chia.types.weight_proof import WeightProof
|
|
from chia.util.ints import uint8, uint32, uint64, uint128
|
|
from chia.util.streamable import Streamable, streamable
|
|
|
|
"""
|
|
Protocol between full nodes.
|
|
Note: When changing this file, also change protocol_message_types.py, and the protocol version in shared_protocol.py
|
|
"""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class NewPeak(Streamable):
|
|
header_hash: bytes32
|
|
height: uint32
|
|
weight: uint128
|
|
fork_point_with_previous_peak: uint32
|
|
unfinished_reward_block_hash: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class NewTransaction(Streamable):
|
|
transaction_id: bytes32
|
|
cost: uint64
|
|
fees: uint64
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestTransaction(Streamable):
|
|
transaction_id: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondTransaction(Streamable):
|
|
transaction: SpendBundle
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestProofOfWeight(Streamable):
|
|
total_number_of_blocks: uint32
|
|
tip: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondProofOfWeight(Streamable):
|
|
wp: WeightProof
|
|
tip: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestBlock(Streamable):
|
|
height: uint32
|
|
include_transaction_block: bool
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RejectBlock(Streamable):
|
|
height: uint32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestBlocks(Streamable):
|
|
start_height: uint32
|
|
end_height: uint32
|
|
include_transaction_block: bool
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondBlocks(Streamable):
|
|
start_height: uint32
|
|
end_height: uint32
|
|
blocks: List[FullBlock]
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RejectBlocks(Streamable):
|
|
start_height: uint32
|
|
end_height: uint32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondBlock(Streamable):
|
|
block: FullBlock
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class NewUnfinishedBlock(Streamable):
|
|
unfinished_reward_hash: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestUnfinishedBlock(Streamable):
|
|
unfinished_reward_hash: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondUnfinishedBlock(Streamable):
|
|
unfinished_block: UnfinishedBlock
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class NewSignagePointOrEndOfSubSlot(Streamable):
|
|
prev_challenge_hash: Optional[bytes32]
|
|
challenge_hash: bytes32
|
|
index_from_challenge: uint8
|
|
last_rc_infusion: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestSignagePointOrEndOfSubSlot(Streamable):
|
|
challenge_hash: bytes32
|
|
index_from_challenge: uint8
|
|
last_rc_infusion: bytes32
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondSignagePoint(Streamable):
|
|
index_from_challenge: uint8
|
|
challenge_chain_vdf: VDFInfo
|
|
challenge_chain_proof: VDFProof
|
|
reward_chain_vdf: VDFInfo
|
|
reward_chain_proof: VDFProof
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondEndOfSubSlot(Streamable):
|
|
end_of_slot_bundle: EndOfSubSlotBundle
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestMempoolTransactions(Streamable):
|
|
filter: bytes
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class NewCompactVDF(Streamable):
|
|
height: uint32
|
|
header_hash: bytes32
|
|
field_vdf: uint8
|
|
vdf_info: VDFInfo
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestCompactVDF(Streamable):
|
|
height: uint32
|
|
header_hash: bytes32
|
|
field_vdf: uint8
|
|
vdf_info: VDFInfo
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondCompactVDF(Streamable):
|
|
height: uint32
|
|
header_hash: bytes32
|
|
field_vdf: uint8
|
|
vdf_info: VDFInfo
|
|
vdf_proof: VDFProof
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RequestPeers(Streamable):
|
|
"""
|
|
Return full list of peers
|
|
"""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
@streamable
|
|
class RespondPeers(Streamable):
|
|
peer_list: List[TimestampedPeerInfo]
|