chia-blockchain/chia/protocols/wallet_protocol.py

279 lines
5.6 KiB
Python
Raw Permalink Normal View History

from __future__ import annotations
2019-11-18 07:49:39 +03:00
from dataclasses import dataclass
from typing import List, Optional, Tuple
2019-11-18 07:49:39 +03:00
import chia_rs
2022-10-18 17:12:22 +03:00
from chia.full_node.fee_estimate import FeeEstimateGroup
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.serialized_program import SerializedProgram
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.header_block import HeaderBlock
from chia.types.spend_bundle import SpendBundle
2022-10-18 17:12:22 +03:00
from chia.util.ints import uint8, uint32, uint64, uint128
from chia.util.streamable import Streamable, streamable
"""
Protocol between wallet (SPV node) and full node.
Note: When changing this file, also change protocol_message_types.py, and the protocol version in shared_protocol.py
"""
2020-04-17 15:50:24 +03:00
CoinState = chia_rs.CoinState
RespondToPhUpdates = chia_rs.RespondToPhUpdates
@streamable
@dataclass(frozen=True)
class RequestPuzzleSolution(Streamable):
2021-01-02 06:13:08 +03:00
coin_name: bytes32
height: uint32
2021-01-02 06:13:08 +03:00
2020-12-10 20:11:26 +03:00
@streamable
@dataclass(frozen=True)
2021-01-02 06:13:08 +03:00
class PuzzleSolutionResponse(Streamable):
coin_name: bytes32
height: uint32
puzzle: SerializedProgram
solution: SerializedProgram
2021-01-02 06:13:08 +03:00
@streamable
@dataclass(frozen=True)
class RespondPuzzleSolution(Streamable):
2021-01-02 06:13:08 +03:00
response: PuzzleSolutionResponse
2020-12-10 20:11:26 +03:00
2020-04-17 09:17:28 +03:00
@streamable
@dataclass(frozen=True)
class RejectPuzzleSolution(Streamable):
2021-01-02 06:13:08 +03:00
coin_name: bytes32
height: uint32
2020-04-17 09:17:28 +03:00
@streamable
@dataclass(frozen=True)
class SendTransaction(Streamable):
2020-02-07 23:57:41 +03:00
transaction: SpendBundle
@streamable
@dataclass(frozen=True)
class TransactionAck(Streamable):
2020-02-13 03:16:57 +03:00
txid: bytes32
status: uint8 # MempoolInclusionStatus
error: Optional[str]
2020-02-13 03:16:57 +03:00
@streamable
@dataclass(frozen=True)
class NewPeakWallet(Streamable):
2020-10-30 12:38:56 +03:00
header_hash: bytes32
height: uint32
weight: uint128
2020-11-30 10:29:15 +03:00
fork_point_with_previous_peak: uint32
@streamable
@dataclass(frozen=True)
class RequestBlockHeader(Streamable):
height: uint32
@streamable
@dataclass(frozen=True)
class RespondBlockHeader(Streamable):
header_block: HeaderBlock
@streamable
@dataclass(frozen=True)
class RejectHeaderRequest(Streamable):
2020-02-13 23:15:36 +03:00
height: uint32
2020-02-12 00:00:41 +03:00
@streamable
@dataclass(frozen=True)
class RequestRemovals(Streamable):
height: uint32
header_hash: bytes32
coin_names: Optional[List[bytes32]]
2020-02-12 00:00:41 +03:00
@streamable
@dataclass(frozen=True)
class RespondRemovals(Streamable):
height: uint32
header_hash: bytes32
coins: List[Tuple[bytes32, Optional[Coin]]]
proofs: Optional[List[Tuple[bytes32, bytes]]]
2020-02-23 11:11:31 +03:00
@streamable
@dataclass(frozen=True)
class RejectRemovalsRequest(Streamable):
height: uint32
2020-02-23 11:11:31 +03:00
header_hash: bytes32
@streamable
@dataclass(frozen=True)
class RequestAdditions(Streamable):
height: uint32
header_hash: Optional[bytes32]
puzzle_hashes: Optional[List[bytes32]]
2020-02-23 11:11:31 +03:00
@streamable
@dataclass(frozen=True)
class RespondAdditions(Streamable):
height: uint32
2020-02-23 11:11:31 +03:00
header_hash: bytes32
coins: List[Tuple[bytes32, List[Coin]]]
proofs: Optional[List[Tuple[bytes32, bytes, Optional[bytes]]]]
2020-02-23 11:11:31 +03:00
@streamable
@dataclass(frozen=True)
class RejectAdditionsRequest(Streamable):
height: uint32
2020-04-09 05:54:42 +03:00
header_hash: bytes32
2021-01-11 08:30:42 +03:00
Request header blocks, and new rate limits (#11636) * new blob block api method integrated into wallet * direct msg streaming of headers, rename, tests * perform_handshake call fix * updated trusted sync with new block header calls * add max blocks limit to fetch * added tests for rejected block header msgs * avoid parsing transactions info if not required * avoid looking up capabilities setting * move block tests out of a class * test fix * Merge changes * added docs and increased rate limits * increased block header request interval from 32 to 128 * remove fetching hashes and use height range * fetching by height in db v2 * update capabilities, other fixes * fixed range block header call * Add type hints * Start work on optimizing fetch_last_tx_from_peer * Huge speedup in trusted wallet sync * Revert unintentional changes * Fix trade issue * Improve the code * Str format * Optimize handling of farming rewards * Fix bug * Performance fixes * Optimizations to wallet syncing * Don't return all coins in respond_additions * Revert concurrency numbers * More optimization of the caches * Small optimization in coin_added * Optimize request_additions significantly by using a cache * fixes from feedback * capabilities check fixes * Increase rate limits to allow 250tps in verification requests * Start work on rate limits * New rate limit versioning support * Revert unrelated changes * revert return False * Lint * Revert cbi * try tests with trusted peer * Revert unrelated wallet changes * Revert more debug changes * Add test and throw on an error if not found * Reject invalid requests * Revert bad change with uint32, and change warning to info * Parametrize wallet sync test * Merge and LGTM * More clean way to choose peers * Fix lint * add the new RejectBlockHeaders, RequestBlockHeaders and RespondBlockHeaders to the network protocol regression test and regenerate test files * Rate limit diffs only * Improve performance * Simpler * Lint Co-authored-by: Sebastjan <trepca@gmail.com> Co-authored-by: arvidn <arvid@libtorrent.org>
2022-06-11 09:35:41 +03:00
@streamable
@dataclass(frozen=True)
class RespondBlockHeaders(Streamable):
start_height: uint32
end_height: uint32
header_blocks: List[HeaderBlock]
@streamable
@dataclass(frozen=True)
class RejectBlockHeaders(Streamable):
start_height: uint32
end_height: uint32
@streamable
@dataclass(frozen=True)
class RequestBlockHeaders(Streamable):
start_height: uint32
end_height: uint32
return_filter: bool
@streamable
@dataclass(frozen=True)
class RequestHeaderBlocks(Streamable):
start_height: uint32
end_height: uint32
2021-01-11 08:30:42 +03:00
@streamable
@dataclass(frozen=True)
class RejectHeaderBlocks(Streamable):
start_height: uint32
end_height: uint32
2021-01-11 08:30:42 +03:00
@streamable
@dataclass(frozen=True)
class RespondHeaderBlocks(Streamable):
start_height: uint32
end_height: uint32
2021-01-11 08:30:42 +03:00
header_blocks: List[HeaderBlock]
# This class is implemented in Rust
# @streamable
# @dataclass(frozen=True)
# class CoinState(Streamable):
# coin: Coin
# spent_height: Optional[uint32]
# created_height: Optional[uint32]
@streamable
@dataclass(frozen=True)
class RegisterForPhUpdates(Streamable):
puzzle_hashes: List[bytes32]
min_height: uint32
# This class is implemented in Rust
# @streamable
# @dataclass(frozen=True)
# class RespondToPhUpdates(Streamable):
# puzzle_hashes: List[bytes32]
# min_height: uint32
# coin_states: List[CoinState]
@streamable
@dataclass(frozen=True)
class RegisterForCoinUpdates(Streamable):
coin_ids: List[bytes32]
min_height: uint32
@streamable
@dataclass(frozen=True)
class RespondToCoinUpdates(Streamable):
coin_ids: List[bytes32]
min_height: uint32
coin_states: List[CoinState]
@streamable
@dataclass(frozen=True)
class CoinStateUpdate(Streamable):
height: uint32
fork_height: uint32
peak_hash: bytes32
items: List[CoinState]
@streamable
@dataclass(frozen=True)
class RequestChildren(Streamable):
coin_name: bytes32
@streamable
@dataclass(frozen=True)
class RespondChildren(Streamable):
coin_states: List[CoinState]
@streamable
@dataclass(frozen=True)
class RequestSESInfo(Streamable):
start_height: uint32
end_height: uint32
@streamable
@dataclass(frozen=True)
class RespondSESInfo(Streamable):
reward_chain_hash: List[bytes32]
heights: List[List[uint32]]
2022-10-18 17:12:22 +03:00
@streamable
@dataclass(frozen=True)
class RequestFeeEstimates(Streamable):
"""
time_targets (List[uint64]): Epoch timestamps in seconds to estimate FeeRates for.
"""
time_targets: List[uint64]
@streamable
@dataclass(frozen=True)
class RespondFeeEstimates(Streamable):
estimates: FeeEstimateGroup