Files
chia-blockchain/chia/protocols/shared_protocol.py
T
ab53d48995 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 01:35:41 -05:00

46 lines
1.5 KiB
Python

from dataclasses import dataclass
from enum import IntEnum
from typing import List, Tuple
from chia.util.ints import uint8, uint16
from chia.util.streamable import Streamable, streamable
protocol_version = "0.0.34"
"""
Handshake when establishing a connection between two servers.
Note: When changing this file, also change protocol_message_types.py
"""
# Capabilities can be added here when new features are added to the protocol
# These are passed in as uint16 into the Handshake
class Capability(IntEnum):
BASE = 1 # Base capability just means it supports the chia protocol at mainnet
# introduces RequestBlockHeaders, which is a faster API for fetching header blocks
# !! the old API is *RequestHeaderBlock* !!
BLOCK_HEADERS = 2
# Specifies support for v1 and v2 versions of rate limits. Peers will ues the lowest shared capability:
# if peer A support v3 and peer B supports v2, they should send:
# (BASE, RATE_LIMITS_V2, RATE_LIMITS_V3), and (BASE, RATE_LIMITS_V2) respectively. They will use the V2 limits.
RATE_LIMITS_V2 = 3
@streamable
@dataclass(frozen=True)
class Handshake(Streamable):
network_id: str
protocol_version: str
software_version: str
server_port: uint16
node_type: uint8
capabilities: List[Tuple[uint16, str]]
# "1" means capability is enabled
capabilities = [
(uint16(Capability.BASE.value), "1"),
(uint16(Capability.BLOCK_HEADERS.value), "1"),
(uint16(Capability.RATE_LIMITS_V2.value), "1"),
]