Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing calltable serialization to TransactionV1 structures subtree. #4823

Conversation

zajko
Copy link
Contributor

@zajko zajko commented Aug 6, 2024

This is an extension to the bytesrepr serialization used in the rest of the node and it also uses the FromBytes and ToBytes traits.
From now on selected types will use a specific serialization approach which will be called "calltable" serialization.
A "calltable-serialized" type is serialized as follow:

  • For structs:
    • Given type X with N attributes we assign a unique (in the scope of X) u16 index to each of the structs attribute. The assumption is that the indexes are 0-based
    • We serialize each of the structs attribute using it's ToBytes implementation, producing binary payloads: binary_vec0, binary_vec1, ..., binary_ve
      cN-1
      . We don't allow any of the binary_veci to be empty.
    • We construct a bytes vector which is a concatenation of binary_vec0, binary_vec1, ..., binary_vecN-1
    • We construct a fields vector. The i-th element of fields is a description of the i-th attribute:
      • For field with index 0 this description will be:
        field0 = Field {
        index: 0
        offset: 0
        }
      • For each next field:
        fieldi = Field {
        index: i
        offset: fieldi - 1.offset + length(binary_veci - 1)
        }
    • We construct an instance of CalltableSerializationEnvelope {fields, bytes} and serialize it using it's ToBytes implementation.
  • For enums:
    • Given an enum E with M variants we assign a u8 unique index for each of the variant. The variant-index should start from 0 and be contiguous.
    • Given an enum instance e of variant Ej (having variant index j) which has N attributes:
      • we assign a unique (in the scope of *Ej) u16 index to each of the enum variants attribute. The assumption is that the indexes are 1-based.
      • We serialize value of j as binary_vec0 and each of e attribute as subsequent binary_vec (binary_vec1, binary_vec2,..., bi
        nary_vecN). We don't allow any of the binary_veci to be empty.
      • We construct a bytes vector which is a concatenation of binary_vec0, binary_vec1, ..., binary_vecN.
      • We construct a fields vector. The i-th element of fields is a description of the i-th attribute:
        • For field with index 0 this description will be:
          field0 = Field {
          index: 0
          offset: 0
          }
        • For each next field:
          fieldi = Field {
          index: i
          offset: fieldi - 1.offset + length(binary_veci - 1)
          }
      • We construct an instance of CalltableSerializationEnvelope {fields, bytes} and serialize it using it's ToBytes implementation.
      • To recap, each enum variant we serialize analogously to a struct, but we prepend a synthetic u8 field which identifies the variant.

This PR applies calltable serialization to the following types:

  • InitiatorAddr enum
  • PricingMode enum
  • TransactionEntryPoint enum
  • TransactionInvocationTarget enum
  • TransactionScheduling enum
  • TransactionTarget enum
  • TransactionV1 struct
  • TransactionV1Body struct
  • TransactionV1Header struct

All other types (especially legacy ones, including those nested in "calltable-serialized" types) should use "regular" serialization logic.

@zajko zajko force-pushed the transaction_serialization_protocol branch 5 times, most recently from da19e00 to ea4442b Compare August 9, 2024 13:59
@zajko zajko marked this pull request as ready for review August 9, 2024 14:37
@zajko zajko force-pushed the transaction_serialization_protocol branch 3 times, most recently from 6897039 to d4f05d0 Compare August 16, 2024 11:31
@@ -660,10 +660,10 @@ fn faucet_costs() {
// This test will fail if execution costs vary. The expected costs should not be updated
// without understanding why the cost has changed. If the costs do change, it should be
// reflected in the "Costs by Entry Point" section of the faucet crate's README.md.
const EXPECTED_FAUCET_INSTALL_COST: u64 = 160_878_698_504;
const EXPECTED_FAUCET_INSTALL_COST: u64 = 160_967_026_637;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gas values changed here because:

  • A new public function was introduced in types (allocate_buffer_for_size)
  • InitiatorAddr is used and passed to the engine and it's serialization schema changed

@zajko zajko force-pushed the transaction_serialization_protocol branch from d4f05d0 to 00f132d Compare August 23, 2024 15:40
@zajko zajko changed the title Adding a serialization schema to the TransactionV1 type subtree bas… Introducing calltable serialization to TransactionV1 structures subtree. Aug 23, 2024
@zajko zajko force-pushed the transaction_serialization_protocol branch 5 times, most recently from 0c6e7e7 to dfeb2bf Compare August 30, 2024 12:52
@zajko zajko force-pushed the transaction_serialization_protocol branch from dfeb2bf to b87f1b3 Compare September 6, 2024 14:41
@devendran-m devendran-m added the rc-5 Release Candidate 5 label Sep 9, 2024
@darthsiroftardis
Copy link
Contributor

bors r+

Copy link
Contributor

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rc-5 Release Candidate 5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants