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

Feat: module data passing #2205

Merged
merged 11 commits into from
Mar 8, 2024
Merged

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Mar 4, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features
    • Introduced events for sending and receiving gas data across chains.
    • Added a new interface for extending gas oracle functionalities.
    • Implemented library functions for encoding and decoding interchain module data.
    • Enhanced interchain communication modules to handle gas data and additional module data efficiently.
  • Bug Fixes
    • Updated deployment and test scripts to align with the new gas oracle interface and mock implementations.
  • Documentation
    • Added error documentation for scenarios where the gas oracle is not set.
  • Refactor
    • Replaced existing gas oracle interface with an extended version in relevant contracts.
    • Modified internal functions to support the new gas data handling mechanism.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The recent updates focus on enhancing interchain communication by introducing gas data exchange capabilities. A new interface, ISynapseGasOracle, extends gas oracle functionalities, allowing for the receipt and provision of gas data across chains. Additionally, module data handling has been refined with the introduction of ModuleEntryLib, improving the encoding/decoding process. The changes aim to streamline cross-chain interactions and ensure efficient gas data management, encapsulated by the addition of new events, mappings, and internal functions dedicated to handling gas data.

Changes

Files Change Summary
.../events/SynapseModuleEvents.sol Added GasDataSent, GasDataReceived events.
.../interfaces/ISynapseGasOracle.sol Introduced ISynapseGasOracle interface.
.../interfaces/ISynapseModule.sol Added SynapseModule__GasOracleNotSet() error.
.../libs/ModuleEntry.sol New ModuleEntryLib for encoding/decoding InterchainEntry.
.../modules/InterchainModule.sol Implemented ModuleEntryLib, updated entry handling.
.../modules/SynapseModule.sol Integrated ISynapseGasOracle, updated gas data handling.
script/testnet-deploy.sh
.../test/ExecutionService.t.sol
.../test/mocks/SynapseGasOracleMock.sol
.../test/modules/SynapseModule.Destination.t.sol
.../test/modules/SynapseModule.Management.t.sol
.../test/modules/SynapseModule.Source.t.sol
Switched to SynapseGasOracleMock from GasOracleMock.
.../test/harnesses/ModuleEntryLibHarness.sol
.../test/libs/ModuleEntryLib.t.sol
Testing ModuleEntryLib encoding/decoding.

"In the world of chains that intertwine,
A rabbit hopped, leaving marks behind.
🐇💨✨
'Cross the lands, through the digital gate,
It whispered of gas, and of fate.
With every hop, a new connection made,
In bytes and chains, its dreams were laid."

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.41009%. Comparing base (354dc13) to head (70f9198).
Report is 5 commits behind head on feat/communication.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           feat/communication       #2205   +/-   ##
======================================================
  Coverage            49.41009%   49.41009%           
======================================================
  Files                     370         370           
  Lines                   27462       27462           
  Branches                   83          83           
======================================================
  Hits                    13569       13569           
  Misses                  12469       12469           
  Partials                 1424        1424           
Flag Coverage Δ
packages 90.52734% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ChiTimesChi
Copy link
Collaborator Author

@coderabbitai review

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.

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 5057635 and 0835a90.
Files selected for processing (14)
  • packages/contracts-communication/contracts/events/SynapseModuleEvents.sol (1 hunks)
  • packages/contracts-communication/contracts/interfaces/ISynapseGasOracle.sol (1 hunks)
  • packages/contracts-communication/contracts/interfaces/ISynapseModule.sol (1 hunks)
  • packages/contracts-communication/contracts/libs/ModuleEntry.sol (1 hunks)
  • packages/contracts-communication/contracts/modules/InterchainModule.sol (3 hunks)
  • packages/contracts-communication/contracts/modules/SynapseModule.sol (4 hunks)
  • packages/contracts-communication/script/testnet-deploy.sh (1 hunks)
  • packages/contracts-communication/test/ExecutionService.t.sol (1 hunks)
  • packages/contracts-communication/test/harnesses/ModuleEntryLibHarness.sol (1 hunks)
  • packages/contracts-communication/test/libs/ModuleEntryLib.t.sol (1 hunks)
  • packages/contracts-communication/test/mocks/SynapseGasOracleMock.sol (1 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (7 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Management.t.sol (3 hunks)
  • packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (4 hunks)
Additional comments: 25
packages/contracts-communication/contracts/events/SynapseModuleEvents.sol (1)
  • 16-17: The addition of GasDataSent and GasDataReceived events aligns well with the PR's objective to enhance interchain communication by facilitating the sending and receiving of gas data. The events are correctly defined and follow Solidity's event declaration syntax.
packages/contracts-communication/contracts/interfaces/ISynapseGasOracle.sol (1)
  • 6-14: The ISynapseGasOracle interface is well-defined, extending IGasOracle with two additional functions: receiveRemoteGasData and getLocalGasData. These functions are crucial for managing gas data from remote chains and obtaining gas data for the local chain, aligning with the PR's objectives to enhance interchain communication. The function signatures are clear, and the comments provide useful context.
packages/contracts-communication/test/harnesses/ModuleEntryLibHarness.sol (1)
  • 6-24: The ModuleEntryLibHarness contract provides a testing harness for the ModuleEntryLib library, including encodeModuleEntry and decodeModuleEntry functions. These functions are correctly implemented, using the ModuleEntryLib for encoding and decoding, which aligns with the PR's objectives to facilitate efficient data handling in interchain communication. The use of pure for these functions is appropriate since they do not modify state or read from the blockchain.
packages/contracts-communication/test/ExecutionService.t.sol (1)
  • 6-17: The replacement of GasOracleMock with SynapseGasOracleMock in the ExecutionServiceTest setup is correctly implemented and aligns with the PR's objectives to update the gas oracle contract across the package. This change ensures that the tests reflect the new contract's functionality and interactions, which is crucial for maintaining test accuracy and relevance.
packages/contracts-communication/test/mocks/SynapseGasOracleMock.sol (1)
  • 6-9: The SynapseGasOracleMock contract correctly implements the ISynapseGasOracle interface, providing mock implementations for receiveRemoteGasData and getLocalGasData. These mock functions are essential for testing the interaction with the gas oracle in a controlled environment. The empty implementations are appropriate for a mock contract, allowing tests to simulate the contract's presence without specific logic.
packages/contracts-communication/script/testnet-deploy.sh (1)
  • 24-24: The update to the deployment script to deploy SynapseGasOracleMock instead of GasOracleMock is correctly implemented. This change aligns with the PR's objectives to update the gas oracle contract across the package and ensures that the testnet deployment script reflects the new contract's deployment.
packages/contracts-communication/contracts/libs/ModuleEntry.sol (1)
  • 6-31: The ModuleEntryLib library is well-implemented, providing encodeModuleEntry and decodeModuleEntry functions for handling module entries. These functions use Solidity's abi.encode and abi.decode for encoding and decoding, which is efficient and aligns with best practices. The library's functionality is crucial for the PR's objectives to facilitate efficient data handling in interchain communication.
packages/contracts-communication/test/libs/ModuleEntryLib.t.sol (1)
  • 8-28: The tests for the ModuleEntryLib library, including the round-trip test for encoding and decoding module entries, are correctly implemented. The use of the forge-std/Test.sol library for assertions and the custom assertEq for InterchainEntry comparisons are appropriate and align with best practices for Solidity testing. These tests are crucial for ensuring the correctness of the ModuleEntryLib functionality.
packages/contracts-communication/contracts/modules/InterchainModule.sol (1)
  • 47-73: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [8-70]

The modifications to InterchainModule to incorporate ModuleEntryLib for encoding and decoding module entries and the introduction of new internal functions _fillModuleData and _receiveModuleData are well-implemented. These changes align with the PR's objectives to enhance interchain communication by integrating efficient data handling mechanisms. The use of ModuleEntryLib for encoding and decoding ensures modularity and reusability of code, which is a best practice in Solidity development.

packages/contracts-communication/contracts/interfaces/ISynapseModule.sol (1)
  • 10-10: The addition of the SynapseModule__GasOracleNotSet() error to the ISynapseModule interface is correctly implemented and aligns with the PR's objectives to enhance error handling and clarity in scenarios where the gas oracle is not set. This addition improves the robustness of the contract by providing a clear and specific error message for this scenario.
packages/contracts-communication/contracts/modules/SynapseModule.sol (4)
  • 7-7: The import of ISynapseGasOracle is correctly added to support the new functionality for handling gas data across chains. This aligns with the PR objectives.
  • 180-202: The _fillModuleData function is updated to include handling for gas data, which is a crucial part of the PR objectives. The approach of checking for empty data and avoiding sending duplicate data is efficient. However, it's important to ensure that the emit GasDataSent(destChainId, moduleData); event is only triggered when new data is sent to avoid misleading event logs.
  • 204-216: The _receiveModuleData function correctly handles the reception of module data, including gas data from remote chains. The check for outdated data using nonces is a good practice for ensuring data integrity. This implementation aligns with the PR objectives of enhancing interchain communication.
  • 236-242: The _getSynapseGasOracle function is a useful addition for retrieving the Synapse Gas Oracle instance. The check for the gas oracle not being set is crucial for avoiding calls to an uninitialized address. This function supports the new gas data handling functionality effectively.
packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (4)
  • 10-10: Renaming GasOracleMock to SynapseGasOracleMock in the import statement is consistent with the changes made in the contract files and ensures that the tests are aligned with the updated contract functionality.
  • 18-18: The declaration of SynapseGasOracleMock as gasOracle is correctly updated to reflect the new mock contract name. This change is necessary for the tests to interact with the updated gas oracle functionality.
  • 38-38: Introducing mockModuleData as an empty byte array is a good setup for future tests that may require non-empty module data. It's important to ensure that tests covering various module data scenarios are added to fully validate the module's functionality.
  • 67-70: The encodeAndHashEntry function is updated to include mockModuleData in the encoding process. This change is crucial for testing the module's ability to handle additional data alongside the InterchainEntry. It would be beneficial to add tests that utilize non-empty mockModuleData to ensure the module correctly handles various data payloads.
packages/contracts-communication/test/modules/SynapseModule.Management.t.sol (2)
  • 8-8: Renaming GasOracleMock to SynapseGasOracleMock in the import statement is consistent with the changes made in the contract files and ensures that the management tests are aligned with the updated contract functionality.
  • 18-18: The declaration of SynapseGasOracleMock as gasOracle is correctly updated to reflect the new mock contract name. This change is necessary for the management tests to interact with the updated gas oracle functionality.
packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (5)
  • 11-11: Renaming GasOracleMock to SynapseGasOracleMock aligns with the PR objectives to use the new SynapseGasOracleMock contract. This change is straightforward and correctly updates the import statement.
  • 53-53: The instantiation of SynapseGasOracleMock and its configuration within the setUp function is correctly implemented. This change is part of the PR objectives to replace GasOracleMock with SynapseGasOracleMock and is done properly here.
  • 92-92: Changing the encodeAndHashEntry function from pure to view is necessary because the function now accesses the state variable mockModuleData. This change is correctly applied and aligns with the Solidity requirements for function modifiers when accessing state variables.
  • 104-104: Similarly, changing the signEntry function from pure to view is appropriate due to the indirect access to the state variable mockModuleData through the call to encodeAndHashEntry. This modification is consistent with Solidity's rules for function modifiers.
  • 116-116: The verifyEntry function correctly uses the mockModuleData variable to encode the entry alongside module data before verification. This change is part of the PR's objective to enhance module data handling and is implemented correctly.

…le.sol

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ChiTimesChi ChiTimesChi merged commit 0afc282 into feat/communication Mar 8, 2024
34 of 35 checks passed
@ChiTimesChi ChiTimesChi deleted the feat/module-data-passing branch March 8, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants