From 7d3f9c2016d6dac3a454557bf021031323e68edf Mon Sep 17 00:00:00 2001 From: Harold B <152330941+haorldbchi@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:09:58 -0500 Subject: [PATCH] Send RewardChainBlockUnfinished to third-party harvesters (#17435) * Send RewardChainBlockUnfinished to the harvester - Simplify data pasing in request_signed_values * Fix instances where the rc_block_unfinished must be sent * Lint, fix test, generate protocol messages * Rate Limit Adjustment for RequestSignedValues (#17481) * Further bump request_signed_values rate limit --------- Co-authored-by: Amine Khaldi Co-authored-by: Luna <96448399+DaOneLuna@users.noreply.github.com> --- chia/farmer/farmer_api.py | 32 +++++++++--------- chia/full_node/full_node_api.py | 8 +++-- chia/protocols/farmer_protocol.py | 2 ++ chia/protocols/harvester_protocol.py | 3 ++ chia/server/rate_limit_numbers.py | 2 +- .../test_third_party_harvesters.py | 5 +++ tests/util/network_protocol_data.py | 7 +++- tests/util/protocol_messages_bytes-v1.0 | Bin 48552 -> 49356 bytes tests/util/protocol_messages_json.py | 30 ++++++++++++++++ 9 files changed, 69 insertions(+), 20 deletions(-) diff --git a/chia/farmer/farmer_api.py b/chia/farmer/farmer_api.py index 80bfea058b42..9316c6839180 100644 --- a/chia/farmer/farmer_api.py +++ b/chia/farmer/farmer_api.py @@ -153,6 +153,7 @@ async def new_proof_of_space( new_proof_of_space.sp_hash, [sp.challenge_chain_sp, sp.reward_chain_sp], message_data=sp_src_data, + rc_block_unfinished=None, ) if new_proof_of_space.sp_hash not in self.farmer.proofs_of_space: @@ -284,6 +285,7 @@ async def new_proof_of_space( new_proof_of_space.sp_hash, [m_to_sign], message_data=m_src_data, + rc_block_unfinished=None, ) response: Any = await peer.call_api(HarvesterAPI.request_signatures, request) if not isinstance(response, harvester_protocol.RespondSignatures): @@ -565,30 +567,28 @@ async def request_signed_values(self, full_node_request: farmer_protocol.Request full_node_request.quality_string ] - foliage_block_data: Optional[SignatureRequestSourceData] = None - foliage_transaction_block_data: Optional[SignatureRequestSourceData] = None - include_source_data = False + message_data: Optional[List[Optional[SignatureRequestSourceData]]] = None if full_node_request.foliage_block_data is not None: - include_source_data = True - foliage_block_data = SignatureRequestSourceData( - uint8(SigningDataKind.FOLIAGE_BLOCK_DATA), bytes(full_node_request.foliage_block_data) - ) - - if full_node_request.foliage_transaction_block_data is not None: - assert foliage_block_data - include_source_data = True - foliage_transaction_block_data = SignatureRequestSourceData( - uint8(SigningDataKind.FOLIAGE_TRANSACTION_BLOCK), - bytes(full_node_request.foliage_transaction_block_data), - ) + message_data = [ + SignatureRequestSourceData( + uint8(SigningDataKind.FOLIAGE_BLOCK_DATA), bytes(full_node_request.foliage_block_data) + ), + None + if full_node_request.foliage_transaction_block_data is None + else SignatureRequestSourceData( + uint8(SigningDataKind.FOLIAGE_TRANSACTION_BLOCK), + bytes(full_node_request.foliage_transaction_block_data), + ), + ] request = harvester_protocol.RequestSignatures( plot_identifier, challenge_hash, sp_hash, [full_node_request.foliage_block_data_hash, full_node_request.foliage_transaction_block_hash], - message_data=[foliage_block_data, foliage_transaction_block_data] if include_source_data else None, + message_data=message_data, + rc_block_unfinished=full_node_request.rc_block_unfinished, ) response = await self.farmer.server.call_api_of_specific(HarvesterAPI.request_signatures, request, node_id) diff --git a/chia/full_node/full_node_api.py b/chia/full_node/full_node_api.py index a54a3baff1e9..cea8c270c26b 100644 --- a/chia/full_node/full_node_api.py +++ b/chia/full_node/full_node_api.py @@ -48,6 +48,7 @@ from chia.types.blockchain_format.foliage import FoliageBlockData, FoliageTransactionBlock from chia.types.blockchain_format.pool_target import PoolTarget from chia.types.blockchain_format.proof_of_space import verify_and_get_quality_string +from chia.types.blockchain_format.reward_chain_block import RewardChainBlockUnfinished from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.blockchain_format.sub_epoch_summary import SubEpochSummary from chia.types.coin_record import CoinRecord @@ -1021,8 +1022,10 @@ def get_pool_sig(_1: PoolTarget, _2: Optional[G1Element]) -> Optional[G2Element] foliage_block_data: Optional[FoliageBlockData] = None foliage_transaction_block_data: Optional[FoliageTransactionBlock] = None + rc_block_unfinished: Optional[RewardChainBlockUnfinished] = None if request.include_signature_source_data: foliage_block_data = unfinished_block.foliage.foliage_block_data + rc_block_unfinished = unfinished_block.reward_chain_block if unfinished_block.is_transaction_block(): foliage_transaction_block_data = unfinished_block.foliage_transaction_block @@ -1030,8 +1033,9 @@ def get_pool_sig(_1: PoolTarget, _2: Optional[G1Element]) -> Optional[G2Element] quality_string, foliage_sb_data_hash, foliage_transaction_block_hash, - foliage_block_data, - foliage_transaction_block_data, + foliage_block_data=foliage_block_data, + foliage_transaction_block_data=foliage_transaction_block_data, + rc_block_unfinished=rc_block_unfinished, ) await peer.send_message(make_msg(ProtocolMessageTypes.request_signed_values, message)) diff --git a/chia/protocols/farmer_protocol.py b/chia/protocols/farmer_protocol.py index d633112507d1..f38cf5d96d20 100644 --- a/chia/protocols/farmer_protocol.py +++ b/chia/protocols/farmer_protocol.py @@ -9,6 +9,7 @@ from chia.types.blockchain_format.foliage import FoliageBlockData, FoliageTransactionBlock from chia.types.blockchain_format.pool_target import PoolTarget from chia.types.blockchain_format.proof_of_space import ProofOfSpace +from chia.types.blockchain_format.reward_chain_block import RewardChainBlockUnfinished from chia.types.blockchain_format.sized_bytes import bytes32 from chia.types.blockchain_format.slots import ChallengeChainSubSlot, RewardChainSubSlot from chia.util.ints import uint8, uint32, uint64 @@ -78,6 +79,7 @@ class RequestSignedValues(Streamable): foliage_transaction_block_hash: bytes32 foliage_block_data: Optional[FoliageBlockData] = None foliage_transaction_block_data: Optional[FoliageTransactionBlock] = None + rc_block_unfinished: Optional[RewardChainBlockUnfinished] = None @streamable diff --git a/chia/protocols/harvester_protocol.py b/chia/protocols/harvester_protocol.py index 509e9985e7e0..bf820da33d2d 100644 --- a/chia/protocols/harvester_protocol.py +++ b/chia/protocols/harvester_protocol.py @@ -7,6 +7,7 @@ from chia_rs import G1Element, G2Element from chia.types.blockchain_format.proof_of_space import ProofOfSpace +from chia.types.blockchain_format.reward_chain_block import RewardChainBlockUnfinished from chia.types.blockchain_format.sized_bytes import bytes32 from chia.util.ints import int16, uint8, uint32, uint64 from chia.util.streamable import Streamable, streamable @@ -90,7 +91,9 @@ class RequestSignatures(Streamable): challenge_hash: bytes32 sp_hash: bytes32 messages: List[bytes32] + # This, and rc_block_unfinished are only set when using a third-party harvester (see CHIP-22) message_data: Optional[List[Optional[SignatureRequestSourceData]]] + rc_block_unfinished: Optional[RewardChainBlockUnfinished] @streamable diff --git a/chia/server/rate_limit_numbers.py b/chia/server/rate_limit_numbers.py index fed3faa08a7b..0def5ff3e392 100644 --- a/chia/server/rate_limit_numbers.py +++ b/chia/server/rate_limit_numbers.py @@ -80,7 +80,7 @@ def compose_rate_limits(old_rate_limits: Dict[str, Any], new_rate_limits: Dict[s ProtocolMessageTypes.respond_signatures: RLSettings(100, 2048), ProtocolMessageTypes.new_signage_point: RLSettings(200, 2048), ProtocolMessageTypes.declare_proof_of_space: RLSettings(100, 10 * 1024), - ProtocolMessageTypes.request_signed_values: RLSettings(100, 512), + ProtocolMessageTypes.request_signed_values: RLSettings(100, 10 * 1024), ProtocolMessageTypes.farming_info: RLSettings(100, 1024), ProtocolMessageTypes.signed_values: RLSettings(100, 1024), ProtocolMessageTypes.new_peak_timelord: RLSettings(100, 20 * 1024), diff --git a/tests/farmer_harvester/test_third_party_harvesters.py b/tests/farmer_harvester/test_third_party_harvesters.py index 13758c738bd3..50374c49c98e 100644 --- a/tests/farmer_harvester/test_third_party_harvesters.py +++ b/tests/farmer_harvester/test_third_party_harvesters.py @@ -129,6 +129,7 @@ async def intercept_harvester_request_signatures(*args: Any) -> Message: return make_msg(ProtocolMessageTypes.respond_signatures, response) def validate_harvester_request_signatures(request: harvester_protocol.RequestSignatures) -> None: + nonlocal farmer nonlocal full_node_2 nonlocal farmer_reward_address nonlocal validated_foliage_data @@ -163,6 +164,10 @@ def validate_harvester_request_signatures(request: harvester_protocol.RequestSig or data.farmer_reward_puzzle_hash == bytes32(full_node_2.constants.GENESIS_PRE_FARM_FARMER_PUZZLE_HASH) ) + # RC block unfinished must always be present when foliage block data is present + assert request.rc_block_unfinished + assert request.rc_block_unfinished.get_hash() == data.unfinished_reward_block_hash + if data.farmer_reward_puzzle_hash == farmer_reward_address: validated_foliage_data = True elif src.kind == uint8(SigningDataKind.FOLIAGE_TRANSACTION_BLOCK): diff --git a/tests/util/network_protocol_data.py b/tests/util/network_protocol_data.py index 637fd83c5b66..48625ddeb105 100644 --- a/tests/util/network_protocol_data.py +++ b/tests/util/network_protocol_data.py @@ -2,7 +2,7 @@ from __future__ import annotations -from chia_rs import G1Element, G2Element +from chia_rs import G1Element, G2Element, RewardChainBlockUnfinished from chia.protocols import ( farmer_protocol, @@ -777,6 +777,11 @@ bytes(post_partial_payload), ), ], + RewardChainBlockUnfinished.from_bytes( + bytes.fromhex( + "000000000000000000000000000e006704e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85511ddefb0e56532907ceee3d48b23896b55863b9ba71e06441caf274389616c7600011b9d1eaa3c6a9b27cd90ad9070eb012794a74b277446417bc7b904145010c0878fde05dff50c7409c6ac3c5c42d7cdf596e6232bdfa833e715dbd19cfec3e9d08a407b11288a0a6fd25a932ebd0d6a3f14000000a06b99913f88112ab38726b8119e7f7006b24274f1a8c4c552c2a23c8076bdf0d4e8546c4a47fb5b82041e429a3fd44936ce5e9d811a4996a6f0d2896805b6ae018430d944db57080b1abb5863cb48c6deeaf86e93e6c2f0f8f88f527aa4966d88e1e607dadb45869f18225ef1b987d2b43a08a8defff0b0320106fdaad531edfca2b7b78d873d3f20a3780b2baaea3caafb8ad47f43e649872d16e69afd06527d01e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855000000000008000003005f4faabe7ceb8796e2d8db3db666212273962e2bf1e951717352e0d284ec7b18f4595dafdb7edd4e0e2ae7b231bce7ca75f551afcea51b32679713aa01faf62f375f821e835c333cc2d2a4d8c9e5edaae1702dd82f1f9dd63841e572df587d110100b243a5388d5858bcfa76cc93f53eba8479136480ae9c1b892ebdae4180f4f4c2fbf9a1ae01a59e634f877cb1b74cbc7805c0be9c97e6c133a0e7c29a9d89bfc8b08250184d85275c8cb64401ade1bb06443c92df171ca527dee1af4e81cd931001e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855000000000008000003005f4faabe7ceb8796e2d8db3db666212273962e2bf1e951717352e0d284ec7b18f4595dafdb7edd4e0e2ae7b231bce7ca75f551afcea51b32679713aa01faf62f375f821e835c333cc2d2a4d8c9e5edaae1702dd82f1f9dd63841e572df587d110100b243a5388d5858bcfa76cc93f53eba8479136480ae9c1b892ebdae4180f4f4c2fbf9a1ae01a59e634f877cb1b74cbc7805c0be9c97e6c133a0e7c29a9d89bfc8b08250184d85275c8cb64401ade1bb06443c92df171ca527dee1af4e81cd9310" + ) + ), ) respond_signatures = harvester_protocol.RespondSignatures( diff --git a/tests/util/protocol_messages_bytes-v1.0 b/tests/util/protocol_messages_bytes-v1.0 index edc76ec2665c6947160adeb773656f3e0ab3a8e7..ffca91cb6f486706cf28c4a883a03aee746f5fc6 100644 GIT binary patch delta 843 zcmZ4So9Rp=^M(dy#^lM3%&D87GVh(l#M!-h$+Qf%dPW9hz{ilz@_54$rx|}_L}vZ| za$;uwP8Icaj!#l%Pxe_db*6Mh(2h{SyYDwVO*NWO^X~DLZspGG&^GJY%jMWyWY()Y zcP8ePF)&Kcm0M+#HCz4cgtZe2UNfpsS?;Y~;^tU=d?$-YfWU$F{(G$Vzw(rD9$RBm zALDfW?AK|}l(p}#Fn%t2`{JB`hhJXka;O&6=;F%16g63IFK?E;2+)lSvS&`T?-115 z+^)7ma9(`@+a{-yk1LKG4LY>QrlD-_hbu2aa=hGsM>ny^InA=a;%Rm+Zf>KL=d@)X zE_G(GZd=FLVsO*tb~p#O)b5Dn(;mm}z50X4UVmEA`ILJll1} zp3VBp7F5efDCEE)&B4IH%nzi2s delta 33 rcmV++0N(%1fdi=f0