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

chore(ssz): Use the correct transactions root merkleization based on version #1791

Merged
merged 5 commits into from
Jul 26, 2024

Conversation

calbera
Copy link
Contributor

@calbera calbera commented Jul 26, 2024

Summary by CodeRabbit

  • New Features

    • Added constants for DevnetEth1ChainID and TestnetEth1ChainID to centralize blockchain environment identifiers.
    • Introduced mock implementations for BeaconBlock, BeaconBlockHeader, and Deposit types to enhance unit testing capabilities.
  • Enhancements

    • Updated transaction handling methods to improve flexibility and configurability by incorporating new parameters.
    • Enhanced the StateProcessor type for more sophisticated transaction data processing.
  • Bug Fixes

    • Improved maintainability by replacing hardcoded values with references to constants in chain specifications.
  • Tests

    • Modified test functions to align with changes in method signatures and improved parameter handling.

Copy link
Contributor

coderabbitai bot commented Jul 26, 2024

Walkthrough

Recent changes enhance the clarity and maintainability of the codebase by introducing constants for blockchain chain IDs and refactoring functions to utilize these constants instead of hardcoded values. Additional modifications improve transaction handling by updating method signatures and parameters across various components, ensuring better flexibility and configurability in transaction processing.

Changes

Files Change Summary
mod/config/pkg/spec/constants.go,
mod/config/pkg/spec/devnet.go,
mod/config/pkg/spec/testnet.go
Introduced constants for chain IDs and updated relevant functions to use these constants.
mod/consensus-types/pkg/types/payload.go,
mod/consensus-types/pkg/types/payload_test.go
Modified ToHeader method to accept new parameters for enhanced transaction root handling.
mod/node-api/backend/mocks/beacon_block.mock.go,
mod/node-api/backend/mocks/beacon_block_header.mock.go,
mod/node-api/backend/mocks/deposit.mock.go
Introduced mock implementations for testing, enhancing flexibility with generic type parameters.
mod/state-transition/pkg/core/state_processor.go,
mod/state-transition/pkg/core/state_processor_payload.go,
mod/state-transition/pkg/core/types.go
Enhanced StateProcessor and ExecutionPayload types; updated methods for improved transaction processing.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Codebase
    participant Constants
    participant TransactionHandler

    Developer->>Codebase: Implement constants for chain IDs
    Codebase->>Constants: Define Devnet and Testnet IDs
    Codebase->>TransactionHandler: Update methods to use constants
    TransactionHandler->>Constants: Retrieve chain ID for processing
    TransactionHandler->>TransactionHandler: Handle transactions flexibly
Loading

Poem

In fields of code where rabbits roam,
New constants sprout, a useful home.
With methods refined and mocks in play,
We hop along a clearer way! 🐇✨
Cheers to changes, bright and neat,
In our code, we find our beat!

@itsdevbear
Copy link
Contributor

hood af but works, can you put some comments saying that this is a temporary hack

Copy link

codecov bot commented Jul 26, 2024

Codecov Report

Attention: Patch coverage is 26.08696% with 17 lines in your changes missing coverage. Please review.

Project coverage is 26.33%. Comparing base (3626963) to head (88dd96c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1791      +/-   ##
==========================================
- Coverage   26.35%   26.33%   -0.03%     
==========================================
  Files         316      316              
  Lines       14213    14224      +11     
  Branches       27       27              
==========================================
  Hits         3746     3746              
- Misses      10357    10366       +9     
- Partials      110      112       +2     
Files Coverage Δ
mod/config/pkg/spec/devnet.go 100.00% <100.00%> (ø)
mod/config/pkg/spec/testnet.go 95.00% <0.00%> (ø)
...ate-transition/pkg/core/state_processor_payload.go 0.00% <0.00%> (ø)
mod/consensus-types/pkg/types/payload.go 91.29% <50.00%> (-1.15%) ⬇️
mod/state-transition/pkg/core/state_processor.go 0.00% <0.00%> (ø)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 4d33e16 and f348868.

Files selected for processing (11)
  • mod/config/pkg/spec/constants.go (1 hunks)
  • mod/config/pkg/spec/devnet.go (1 hunks)
  • mod/config/pkg/spec/testnet.go (1 hunks)
  • mod/consensus-types/pkg/types/payload.go (3 hunks)
  • mod/consensus-types/pkg/types/payload_test.go (1 hunks)
  • mod/node-api/backend/mocks/beacon_block.mock.go (1 hunks)
  • mod/node-api/backend/mocks/beacon_block_header.mock.go (1 hunks)
  • mod/node-api/backend/mocks/deposit.mock.go (4 hunks)
  • mod/state-transition/pkg/core/state_processor.go (3 hunks)
  • mod/state-transition/pkg/core/state_processor_payload.go (1 hunks)
  • mod/state-transition/pkg/core/types.go (2 hunks)
Additional comments not posted (70)
mod/config/pkg/spec/constants.go (2)

1-20: License Header Looks Good

The license header is correctly included and follows the standard format.


21-29: Constants Declaration Looks Good

The constants for DevnetEth1ChainID and TestnetEth1ChainID are correctly declared and appropriately named.

mod/config/pkg/spec/devnet.go (2)

Line range hint 1-1:
License Header Looks Good

The license header is correctly included and follows the standard format.


39-39: Improved Maintainability

Replacing the hardcoded value with DevnetEth1ChainID enhances maintainability and readability.

mod/config/pkg/spec/testnet.go (2)

Line range hint 1-1:
License Header Looks Good

The license header is correctly included and follows the standard format.


41-41: Improved Maintainability

Replacing the hardcoded value with TestnetEth1ChainID enhances maintainability and readability.

mod/node-api/backend/mocks/deposit.mock.go (22)

11-13: LGTM! The introduction of generics enhances flexibility and type safety.

The Deposit struct now accepts a type parameter DepositT, allowing it to be more versatile.


15-17: LGTM! The introduction of generics enhances flexibility and type safety.

The Deposit_Expecter struct now accepts a type parameter DepositT, allowing it to be more versatile.


19-21: LGTM! The method update ensures type safety.

The EXPECT method now returns a pointer to Deposit_Expecter[DepositT].


Line range hint 24-38:
LGTM! The method update ensures type safety.

The GetIndex method now uses the new generic type parameter.


42-44: LGTM! The introduction of generics enhances flexibility and type safety.

The Deposit_GetIndex_Call struct now accepts a type parameter DepositT, allowing it to be more versatile.


47-49: LGTM! The method update ensures type safety.

The GetIndex method in Deposit_Expecter now returns a pointer to Deposit_GetIndex_Call[DepositT].


51-56: LGTM! The method update ensures type safety.

The Run method in Deposit_GetIndex_Call now uses the new generic type parameter.


58-60: LGTM! The method update ensures type safety.

The Return method in Deposit_GetIndex_Call now uses the new generic type parameter.


63-65: LGTM! The method update ensures type safety.

The RunAndReturn method in Deposit_GetIndex_Call now uses the new generic type parameter.


Line range hint 69-95:
LGTM! The method update ensures type safety.

The MarshalSSZ method now uses the new generic type parameter.


99-101: LGTM! The introduction of generics enhances flexibility and type safety.

The Deposit_MarshalSSZ_Call struct now accepts a type parameter DepositT, allowing it to be more versatile.


104-106: LGTM! The method update ensures type safety.

The MarshalSSZ method in Deposit_Expecter now returns a pointer to Deposit_MarshalSSZ_Call[DepositT].


108-113: LGTM! The method update ensures type safety.

The Run method in Deposit_MarshalSSZ_Call now uses the new generic type parameter.


115-117: LGTM! The method update ensures type safety.

The Return method in Deposit_MarshalSSZ_Call now uses the new generic type parameter.


120-122: LGTM! The method update ensures type safety.

The RunAndReturn method in Deposit_MarshalSSZ_Call now uses the new generic type parameter.


Line range hint 126-140:
LGTM! The method update ensures type safety.

The UnmarshalSSZ method now uses the new generic type parameter.


144-146: LGTM! The introduction of generics enhances flexibility and type safety.

The Deposit_UnmarshalSSZ_Call struct now accepts a type parameter DepositT, allowing it to be more versatile.


150-152: LGTM! The method update ensures type safety.

The UnmarshalSSZ method in Deposit_Expecter now returns a pointer to Deposit_UnmarshalSSZ_Call[DepositT].


154-159: LGTM! The method update ensures type safety.

The Run method in Deposit_UnmarshalSSZ_Call now uses the new generic type parameter.


161-163: LGTM! The method update ensures type safety.

The Return method in Deposit_UnmarshalSSZ_Call now uses the new generic type parameter.


166-168: LGTM! The method update ensures type safety.

The RunAndReturn method in Deposit_UnmarshalSSZ_Call now uses the new generic type parameter.


173-180: LGTM! The method update enhances usability in tests.

The NewDeposit function now accepts a type parameter for the Deposit instance it creates.

mod/state-transition/pkg/core/state_processor_payload.go (1)

61-64: LGTM! The method update enhances the handling of transaction types and improves contextual integrity.

The ToHeader method call now includes additional parameters: sp.bartioTxsMerkleizer, sp.properTxsMerkleizer, and sp.cs.DepositEth1ChainID().

mod/state-transition/pkg/core/types.go (1)

168-172: LGTM! The method update enhances flexibility and functionality.

The

mod/consensus-types/pkg/types/payload_test.go (1)

206-208: LGTM! Ensure the new parameters are correctly handled in the ToHeader method.

The additional parameters in the ToHeader method call enhance the flexibility of the payload processing. Verify that these parameters are correctly handled in the ToHeader method.

mod/state-transition/pkg/core/state_processor.go (2)

81-82: LGTM! Ensure the new fields are correctly used in the relevant methods.

The new fields bartioTxsMerkleizer and properTxsMerkleizer enhance the transaction processing capabilities of the StateProcessor. Verify that these fields are correctly used in the relevant methods.


138-144: LGTM! Ensure the new fields are correctly initialized.

The new fields bartioTxsMerkleizer and properTxsMerkleizer are correctly initialized in the NewStateProcessor function. Verify that the initialization logic is correct and complete.

mod/node-api/backend/mocks/beacon_block_header.mock.go (11)

25-43: LGTM! Ensure the return value is correctly handled.

The GetBodyRoot method provides a mock implementation for the GetBodyRoot method of the BeaconBlockHeader type. Verify that the return value is correctly handled.


72-90: LGTM! Ensure the return value is correctly handled.

The GetParentBlockRoot method provides a mock implementation for the GetParentBlockRoot method of the BeaconBlockHeader type. Verify that the return value is correctly handled.


119-135: LGTM! Ensure the return value is correctly handled.

The GetProposerIndex method provides a mock implementation for the GetProposerIndex method of the BeaconBlockHeader type. Verify that the return value is correctly handled.


164-180: LGTM! Ensure the return value is correctly handled.

The GetSlot method provides a mock implementation for the GetSlot method of the BeaconBlockHeader type. Verify that the return value is correctly handled.


209-227: LGTM! Ensure the return value is correctly handled.

The GetStateRoot method provides a mock implementation for the GetStateRoot method of the BeaconBlockHeader type. Verify that the return value is correctly handled.


256-284: LGTM! Ensure the return values are correctly handled.

The HashTreeRoot method provides a mock implementation for the HashTreeRoot method of the BeaconBlockHeader type. Verify that the return values are correctly handled.


313-341: LGTM! Ensure the return values are correctly handled.

The MarshalSSZ method provides a mock implementation for the MarshalSSZ method of the BeaconBlockHeader type. Verify that the return values are correctly handled.


370-385: LGTM! Ensure the parameters and return value are correctly handled.

The New method provides a mock implementation for the New method of the BeaconBlockHeader type. Verify that the parameters and return value are correctly handled.


420-423: LGTM! Ensure the parameter is correctly handled.

The SetStateRoot method provides a mock implementation for the SetStateRoot method of the BeaconBlockHeader type. Verify that the parameter is correctly handled.


453-469: LGTM! Ensure the parameter and return value are correctly handled.

The UnmarshalSSZ method provides a mock implementation for the UnmarshalSSZ method of the BeaconBlockHeader type. Verify that the parameter and return value are correctly handled.


499-511: LGTM! Ensure the parameters and return value are correctly handled.

The NewBeaconBlockHeader method provides a mock implementation for creating a new instance of BeaconBlockHeader. Verify that the parameters and return value are correctly handled.

mod/consensus-types/pkg/types/payload.go (2)

Line range hint 557-587:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to ToHeader match the new signature.

Verification successful

Verification successful: All function calls to ToHeader match the new signature.

  • mod/state-transition/pkg/core/types.go
  • mod/state-transition/pkg/core/state_processor_payload.go
  • mod/consensus-types/pkg/types/payload.go
  • mod/consensus-types/pkg/types/payload_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `ToHeader` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 'ToHeader'

Length of output: 2642


557-560: Verify correctness of the conditional logic.

The conditional logic based on eth1ChainID ensures the correct merkleizer is used. However, verify that spec.TestnetEth1ChainID is correctly defined and used.

Verification successful

Verify correctness of the conditional logic.

The conditional logic based on eth1ChainID ensures the correct merkleizer is used. The definition and usage of spec.TestnetEth1ChainID are correct and consistent within the codebase.

  • spec.TestnetEth1ChainID is defined in mod/config/pkg/spec/constants.go with a value of 80084.
  • It is used in the conditional logic in mod/consensus-types/pkg/types/payload.go.
  • It is assigned in mod/config/pkg/spec/testnet.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of spec.TestnetEth1ChainID.

# Test: Search for the definition and usage of spec.TestnetEth1ChainID. Expect: Correct definition and usage.
rg --type go 'TestnetEth1ChainID'

Length of output: 368

mod/node-api/backend/mocks/beacon_block.mock.go (24)

25-41: LGTM!

The code changes are approved.


70-86: LGTM!

The code changes are approved.


115-133: LGTM!

The code changes are approved.


162-178: LGTM!

The code changes are approved.


207-223: LGTM!

The code changes are approved.


252-270: LGTM!

The code changes are approved.


299-315: LGTM!

The code changes are approved.


344-372: LGTM!

The code changes are approved.


401-404: LGTM!

The code changes are approved.


434-450: LGTM!

The code changes are approved.


480-496: LGTM!

The code changes are approved.


525-537: LGTM!

The code changes are approved.


70-86: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

  • The type assertions in the provided code snippet are correct and follow the standard pattern for mock functions in Go. The code checks if the return value is a function and calls it if so; otherwise, it directly assigns the return value.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


25-41: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Verify correctness of type assertions.

The type assertions for the return value in the GetBody method are consistent with other similar implementations in the codebase and handle potential panics appropriately.

  • mod/node-api/backend/mocks/beacon_block.mock.go: The type assertion for BeaconBlockBodyT is correctly implemented.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


299-315: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Type assertions in IsNil method are correct.

The type assertions for the return value in the IsNil method are consistent with the patterns used in other mock methods and handle potential panics gracefully.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


115-133: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Verify correctness of type assertions.

The type assertions for the return value in the GetParentBlockRoot method are correct and consistent with the patterns used in other mock methods in the codebase.

  • mod/node-api/backend/mocks/beacon_block.mock.go: ret.Get(0).(bytes.B32)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


162-178: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Verify correctness of type assertions.

The type assertions in the GetProposerIndex method are correct and consistent with other mock methods in the codebase. The implementation handles potential panics gracefully.

  • mod/node-api/backend/mocks/beacon_block.mock.go: Lines 162-178
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


480-496: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Verified correctness of type assertions.

The type assertions for the return value in the Version method are correct and handle potential panics gracefully.

  • mod/node-api/backend/mocks/beacon_block.mock.go:
    • Line 490: r0 = ret.Get(0).(uint32)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


525-537: Verify correctness of the initialization.

Ensure that the initialization of the mock and the registration of the testing interface are correct.


344-372: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Verify correctness of type assertions.

The type assertions for the return values in the MarshalSSZ method appear to be correct and handle potential errors gracefully.

  • mod/node-api/backend/mocks/beacon_block.mock.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


434-450: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Type assertions in mock methods are correctly implemented.

The type assertions for the return value in the UnmarshalSSZ method are consistent with the patterns used in other mock methods and handle potential panics gracefully.

  • mod/node-api/backend/mocks/beacon_block.mock.go lines 434-450
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


207-223: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Type assertions in the GetSlot method are correct.

The type assertions for the return value in the GetSlot method are implemented correctly and follow the same pattern as other mock methods in the codebase.

  • The type assertion checks if the returned value is a function, and if not, it directly assigns the value.
  • This pattern is consistent and correctly implemented throughout the codebase.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


252-270: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

Verification successful

Type assertions in GetStateRoot method are correct.

The type assertions for the return value in the GetStateRoot method are correctly implemented and handle potential panics gracefully.

  • mod/node-api/backend/mocks/beacon_block.mock.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of type assertions in mock methods.

# Test: Search for type assertions in mock methods. Expect: Correct type assertions.
rg --type go 'ret.Get\(0\)\.\(.*\)'

Length of output: 26130


401-404: Verify correctness of type assertions.

Ensure that the type assertions for the return value are correct and handle potential panics gracefully.

mod/consensus-types/pkg/types/payload.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between f348868 and 8fd1497.

Files selected for processing (3)
  • mod/consensus-types/pkg/types/payload.go (3 hunks)
  • mod/state-transition/pkg/core/state_processor.go (3 hunks)
  • mod/state-transition/pkg/core/state_processor_payload.go (1 hunks)
Additional comments not posted (3)
mod/state-transition/pkg/core/state_processor.go (2)

144-150: LGTM!

The constructor changes are straightforward and align with the new fields added to the struct.


80-88: Ensure proper documentation for temporary solution.

The TODO comment indicates that bartioTxsMerkleizer is a temporary solution. Add comments to clarify this in the code for future maintainability.

+  // TODO: This is a temporary solution to avoid breaking changes. Needs to be hardforked off of.
  bartioTxsMerkleizer *merkle.Merkleizer[[32]byte, common.Root]

Likely invalid or redundant comment.

mod/consensus-types/pkg/types/payload.go (1)

Line range hint 557-581:
Ensure proper error handling for transaction root calculation.

The error handling for txsRootErr should be more explicit to provide better debugging information.

  return txsRootErr
+  if txsRootErr != nil {
+    return fmt.Errorf("failed to calculate transactions root: %w", txsRootErr)
+  }

@calbera calbera merged commit a5853c7 into main Jul 26, 2024
18 checks passed
@calbera calbera deleted the bartio-fixx branch July 26, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants