Skip to content

Commit

Permalink
feat(contract-distribution): Update Python serializer to support new …
Browse files Browse the repository at this point in the history
…contract distribution messages (#12342)

Messages are defined in this file:
https://github.com/near/nearcore/blob/master/core/primitives/src/stateless_validation/contract_distribution.rs

The PR updates the schema in Python so that we can parse the new
messages in relevant Nayduck tests.
  • Loading branch information
tayfunelmas authored Oct 30, 2024
1 parent 76268e3 commit 0e97100
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 3 deletions.
178 changes: 177 additions & 1 deletion pytest/lib/messages/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,58 @@ class SignatureDifferentiator:
pass


class ChunkContractAccesses:
pass


class ChunkContractAccessesV1:
pass


class ChunkContractAccessesInner:
pass


class ChunkContractDeployments:
pass


class ChunkContractDeploymentsV1:
pass


class ChunkContractDeploymentsInner:
pass


class ContractCodeRequest:
pass


class ContractCodeRequestV1:
pass


class ContractCodeRequestInner:
pass


class ContractCodeResponse:
pass


class ContractCodeResponseV1:
pass


class ContractCodeResponseInner:
pass


class ChunkProductionKey:
pass


block_schema = [
[
Block, {
Expand Down Expand Up @@ -1132,5 +1184,129 @@ class SignatureDifferentiator:
[SignatureDifferentiator, {
'kind': 'struct',
'fields': [['0', 'string']]
}]
}],
[
ChunkContractAccesses, {
'kind': 'enum',
'field': 'enum',
'values': [['V1', ChunkContractAccessesV1],]
}
],
[
ChunkContractAccessesV1, {
'kind':
'struct',
'fields': [
['inner', ChunkContractAccessesInner],
['signature', Signature],
]
}
],
[
ChunkContractAccessesInner, {
'kind':
'struct',
'fields': [
['next_chunk', ChunkProductionKey],
['contracts', [[32]]],
['signature_differentiator', SignatureDifferentiator],
]
}
],
[
ChunkContractDeployments, {
'kind': 'enum',
'field': 'enum',
'values': [['V1', ChunkContractDeploymentsV1],]
}
],
[
ChunkContractDeploymentsV1, {
'kind':
'struct',
'fields': [
['inner', ChunkContractDeploymentsInner],
['signature', Signature],
]
}
],
[
ChunkContractDeploymentsInner, {
'kind':
'struct',
'fields': [
['next_chunk', ChunkProductionKey],
['contracts', [[32]]],
['signature_differentiator', SignatureDifferentiator],
]
}
],
[
ContractCodeRequest, {
'kind': 'enum',
'field': 'enum',
'values': [['V1', ContractCodeRequestV1],]
}
],
[
ContractCodeRequestV1, {
'kind':
'struct',
'fields': [
['inner', ContractCodeRequestInner],
['signature', Signature],
]
}
],
[
ContractCodeRequestInner, {
'kind':
'struct',
'fields': [
['requester', 'string'],
['next_chunk', ChunkProductionKey],
['contracts', [[32]]],
['signature_differentiator', SignatureDifferentiator],
]
}
],
[
ContractCodeResponse, {
'kind': 'enum',
'field': 'enum',
'values': [['V1', ContractCodeResponseV1],]
}
],
[
ContractCodeResponseV1, {
'kind':
'struct',
'fields': [
['inner', ContractCodeResponseInner],
['signature', Signature],
]
}
],
[
ContractCodeResponseInner, {
'kind':
'struct',
'fields': [
['next_chunk', ChunkProductionKey],
['compressed_contracts', ['u8']],
['signature_differentiator', SignatureDifferentiator],
]
}
],
[
ChunkProductionKey, {
'kind':
'struct',
'fields': [
['shard_id', 'u64'],
['epoch_id', [32]],
['height_created', 'u64'],
]
}
]
]
7 changes: 5 additions & 2 deletions pytest/lib/messages/network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from messages.crypto import Signature, PublicKey, MerklePath, ShardProof
from messages.tx import SignedTransaction, Receipt
from messages.block import Block, Approval, PartialEncodedChunk, PartialEncodedChunkRequestMsg, PartialEncodedChunkResponseMsg, PartialEncodedChunkForwardMsg, BlockHeader, ShardChunk, ShardChunkHeader, ShardChunkHeaderV1, ChunkEndorsement, ChunkEndorsementV1, ChunkStateWitnessAck, PartialEncodedStateWitness
from messages.block import Block, Approval, PartialEncodedChunk, PartialEncodedChunkRequestMsg, PartialEncodedChunkResponseMsg, PartialEncodedChunkForwardMsg, BlockHeader, ShardChunk, ShardChunkHeader, ShardChunkHeaderV1, ChunkEndorsement, ChunkEndorsementV1, ChunkStateWitnessAck, PartialEncodedStateWitness, ChunkContractAccesses, ChunkContractDeployments, ContractCodeRequest, ContractCodeResponse
from messages.shard import StateRootNode


Expand Down Expand Up @@ -397,7 +397,10 @@ class AdvertisedPeerDistance:
PartialEncodedStateWitness
],
['VersionedChunkEndorsement', ChunkEndorsement],
# TODO(11099): Update the schema with the new messages for contract distribution.
['ChunkContractAccesses', ChunkContractAccesses],
['ChunkContractDeployments', ChunkContractDeployments],
['ContractCodeRequest', ContractCodeRequest],
['ContractCodeResponse', ContractCodeResponse],
]
}
],
Expand Down

0 comments on commit 0e97100

Please sign in to comment.