-
Notifications
You must be signed in to change notification settings - Fork 33
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
Global db nonces in InterchainDB
#2068
Global db nonces in InterchainDB
#2068
Conversation
Important Auto Review SkippedAuto 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 To trigger a single review, invoke the WalkthroughThe recent updates encompass a comprehensive overhaul of the interchain communication contracts, focusing on renaming Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
@coderabbitai review |
There was a problem hiding this 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: 0
Configuration used: CodeRabbit UI
Files selected for processing (14)
- packages/contracts-communication/contracts/InterchainClientV1.sol (7 hunks)
- packages/contracts-communication/contracts/InterchainDB.sol (6 hunks)
- packages/contracts-communication/contracts/events/InterchainDBEvents.sol (1 hunks)
- packages/contracts-communication/contracts/interfaces/IInterchainDB.sol (3 hunks)
- packages/contracts-communication/contracts/libs/InterchainEntry.sol (2 hunks)
- packages/contracts-communication/test/InterchainClientV1Test.t.sol (2 hunks)
- packages/contracts-communication/test/InterchainDB.Dst.t.sol (8 hunks)
- packages/contracts-communication/test/InterchainDB.Src.t.sol (6 hunks)
- packages/contracts-communication/test/harnesses/InterchainClientV1Harness.sol (2 hunks)
- packages/contracts-communication/test/harnesses/InterchainEntryLibHarness.sol (1 hunks)
- packages/contracts-communication/test/libs/InterchainEntryLib.t.sol (1 hunks)
- packages/contracts-communication/test/mocks/InterchainDBMock.sol (2 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Destination.t.sol (1 hunks)
- packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (1 hunks)
Files skipped from review due to trivial changes (1)
- packages/contracts-communication/test/harnesses/InterchainClientV1Harness.sol
Additional comments: 66
packages/contracts-communication/contracts/events/InterchainDBEvents.sol (3)
- 6-6: The change from
writerNonce
todbNonce
in theInterchainEntryWritten
event aligns with the PR's objective to refactor nonce management. This modification is consistent and correctly implemented.- 8-8: The update in the
InterchainEntryVerified
event to includedbNonce
instead ofwriterNonce
is consistent with the overall goal of transitioning to a global nonce system. This change is correctly applied.- 11-11: The modification in the
InterchainVerificationRequested
event to usedbNonce
instead ofwriterNonce
is in line with the PR's objectives and is correctly implemented.packages/contracts-communication/test/harnesses/InterchainEntryLibHarness.sol (3)
- 8-16: The addition of
dbNonce
as a parameter to theconstructLocalEntry
function aligns with the PR's objective to refactor nonce management. This change is correctly implemented.- 19-21: The
entryKey
function correctly calculates the globally unique identifier of the entry, which is consistent with the new nonce management approach.- 23-24: The
entryValue
function correctly calculates the value of the entry, which is consistent with the new nonce management approach.packages/contracts-communication/test/mocks/InterchainDBMock.sol (3)
- 9-9: The update to the
requestVerification
function signature to includedbNonce
aligns with the PR's objective to refactor nonce management. This change is correctly implemented.- 25-25: The modification in the
getEntry
function to acceptdbNonce
instead ofwriterNonce
is consistent with the transition to a global nonce system. This change is correctly applied.- 27-27: Replacing
getWriterNonce
withgetDBNonce
to get the database nonce is in line with the PR's objectives and is correctly implemented.packages/contracts-communication/contracts/libs/InterchainEntry.sol (4)
- 6-16: The addition of
dbNonce
to theInterchainEntry
struct is a key part of the PR's objective to refactor nonce management. This change is correctly implemented and aligns with the transition to a global nonce system.- 3-32: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [23-39]
The modification of the
constructLocalEntry
function to includedbNonce
is consistent with the new nonce management approach. This change is correctly applied.
- 45-47: The
entryKey
function correctly calculates the globally unique identifier of the entry, which is consistent with the new nonce management approach.- 49-51: The
entryValue
function correctly calculates the value of the entry, which is consistent with the new nonce management approach.packages/contracts-communication/test/libs/InterchainEntryLib.t.sol (8)
- 12-12: The modification to include
dbNonce
in theInterchainEntry
struct for testing purposes aligns with the PR's objective to refactor nonce management. This change is correctly implemented.- 20-20: The update to the
assertEq
function to include a check fordbNonce
is consistent with the new nonce management approach. This change is correctly applied.- 27-30: The update to the
test_constructLocalEntry
function to acceptdbNonce
as a parameter is in line with the PR's objectives and is correctly implemented.- 34-42: The parameterized test function
test_constructLocalEntry
correctly includesdbNonce
, which is consistent with the new nonce management approach.- 46-48: The
test_entryKey
function correctly calculates the key based onsrcChainId
anddbNonce
, aligning with the new nonce management approach.- 51-53: The parameterized
test_entryKey
function correctly calculates the key based onsrcChainId
anddbNonce
, which is consistent with the new nonce management approach.- 56-58: The
test_entryValue
function correctly calculates the value based onsrcWriter
anddataHash
, aligning with the new nonce management approach.- 61-63: The parameterized
test_entryValue
function correctly calculates the value based onsrcWriter
anddataHash
, which is consistent with the new nonce management approach.packages/contracts-communication/test/modules/SynapseModule.Source.t.sol (1)
- 31-32: The modification to the initialization of the
mockEntry
struct, including the correct order and values fordbNonce
andsrcWriter
, aligns with the PR's objective to refactor nonce management. This change is correctly implemented.packages/contracts-communication/contracts/interfaces/IInterchainDB.sol (8)
- 7-13: The addition of the
LocalEntry
struct withwriter
anddataHash
fields is a new introduction that aligns with the PR's objective to refactor nonce management. This change is correctly implemented.- 17-20: Renaming
dataHash
toentryValue
in theRemoteEntry
struct is consistent with the new approach to nonce management and entry representation. This change is correctly applied.- 23-24: The changes to the parameters of
InterchainDB__ConflictingEntries
andInterchainDB__EntryDoesNotExist
errors are in line with the transition to a global nonce system. These changes are correctly implemented.- 33-34: Updating the return type and parameter names in the
writeEntry
function to reflect the new nonce management approach is correctly done.- 42-44: The update to the
requestVerification
function signature to includedbNonce
aligns with the PR's objective to refactor nonce management. This change is correctly implemented.- 50-56: Clarification in comments for
writeEntryWithVerification
and the update to returndbNonce
are consistent with the new nonce management approach. These changes are correctly applied.- 79-80: Changing the parameter in
getEntry
fromaddress writer, uint256 writerNonce
todbNonce
is in line with the PR's objectives and is correctly implemented.- 82-83: Replacing
getWriterNonce
withgetDBNonce
to get the database nonce aligns with the transition to a global nonce system. This change is correctly implemented.packages/contracts-communication/test/InterchainClientV1Test.t.sol (2)
- 129-129: The change from
writerNonce
todbNonce
in theInterchainEntry
struct within the test setup aligns with the PR's objective to refactor nonce management. This modification is consistent and correctly implemented.- 142-142: The update in the
InterchainClientV1.InterchainTransaction
struct to includedbNonce
instead ofwriterNonce
is consistent with the overall goal of transitioning to a unified global database nonce (dbNonce
). This change is correctly applied.packages/contracts-communication/contracts/InterchainDB.sol (10)
- 12-13: The introduction of
LocalEntry[] internal _entries;
and the modification of_remoteEntries
mapping to includeRemoteEntry
struct directly are significant changes. Ensure that all interactions with these storage variables are correctly updated throughout the contract to reflect the new nonce management system. This change should improve data organization and access patterns, potentially enhancing gas efficiency for operations involving these structures.- 25-25: The
writeEntry
function now returns auint256 dbNonce
, which is a significant change aligning with the global nonce management strategy. Ensure that all external calls to this function correctly handle the returned nonce value. This change simplifies the interface and makes it more intuitive for contract users.- 32-39: The
requestVerification
function's signature has been updated to includeuint256 dbNonce
as a parameter, reflecting the shift to global nonce management. This change requires careful validation to ensure that the correct nonce is passed by callers, and it enhances the function's clarity by explicitly requiring the nonce associated with the entry to be verified.- 52-55: The
writeEntryWithVerification
function combines entry writing and verification request into a single operation, which is a useful abstraction for users. The explicit return ofuint256 dbNonce
and its subsequent use within the function demonstrate a clear and efficient handling of the new global nonce system. This pattern should be encouraged for its simplicity and effectiveness.- 63-75: The
verifyEntry
function's logic for handling the verification of entries has been carefully updated to work with the new global nonce system. The use ofInterchainEntryLib
for constructing keys and values, and the conditional logic for handling new versus existing entries, are correctly implemented. However, ensure that the timestamp (block.timestamp
) used forverifiedAt
is the desired approach for recording verification times, considering potential issues around block time manipulation by miners.- 91-94: The
readEntry
function's implementation, which checks the entry value against the one verified by the module and returns the verification timestamp, is a critical part of the verification logic. This function's correctness directly impacts the security and reliability of the verification process. Ensure that the comparison logic (remoteEntry.entryValue == entryValue
) and the conditional return value are thoroughly tested, especially in edge cases where entry values might not match due to unexpected reasons.- 103-107: The
getEntry
function correctly handles the retrieval of entries based on the global nonce, including error handling for non-existent entries. This function is a key component of the new nonce management system, and its implementation appears to be correct and efficient. However, ensure that the conditiongetDBNonce() <= dbNonce
correctly accounts for all valid nonces, especially considering zero-based indexing versus one-based nonce values.- 111-112: The
getDBNonce
function, which returns the current global nonce value, is a straightforward and essential part of the new nonce management system. This function's implementation is simple and appears to be correct. It's important to ensure that all parts of the contract and any interacting contracts correctly interpret and use the returned nonce value, especially in the context of zero-based array indexing.- 118-121: The
_writeEntry
internal function's implementation, which updates the global nonce and stores a newLocalEntry
, is crucial for the new nonce management system. The use of_entries.length
to determine the new nonce and the subsequent push to the_entries
array are correctly implemented. Ensure that the eventInterchainEntryWritten
is emitted with the correct parameters, as this is vital for external observers to track entry creation.- 141-141: The emission of the
InterchainVerificationRequested
event in the_requestVerification
internal function is an important aspect of the contract's transparency and auditability. Ensure that the event parameters, especiallyentry.dbNonce
andsrcModules
, accurately reflect the verification request's details. This event's correct emission is crucial for external systems monitoring verification requests.packages/contracts-communication/test/InterchainDB.Src.t.sol (14)
- 16-18: The introduction of
INITIAL_DB_NONCE
as the sum ofINITIAL_WRITER_F
andINITIAL_WRITER_S
is a clear and logical way to initialize the global nonce based on the initial values for two hypothetical writers. This change aligns with the PR's objective to centralize nonce management.- 27-27: The addition of the
initialEntries
array is a good practice for managing initial entries in a structured manner. This facilitates easier manipulation and access to these entries throughout the test suite.- 50-59: The
initialWrites
function effectively replaces the previoussetupWriterNonce
function, adapting to the new global nonce system. It initializes entries for two writers based onINITIAL_WRITER_F
andINITIAL_WRITER_S
, which is a practical approach to simulate initial conditions for testing. However, ensure that the logic correctly reflects the intended behavior in the context of the updated nonce management system.- 63-66: The
getInitialEntry
function provides a straightforward way to retrieve an entry based on itsdbNonce
. The use of a require statement to check if thedbNonce
is within the range ofinitialEntries
is a good practice for input validation, preventing out-of-bounds access.- 72-77: The
getMockEntry
function is well-implemented, creating mockInterchainEntry
instances for testing purposes. It correctly assigns thesrcChainId
,dbNonce
,srcWriter
, anddataHash
, which are essential for simulating realistic test scenarios.- 96-98: The
writeEntry
function simplifies the process of writing an entry and obtaining the resultingdbNonce
. Usingvm.prank
to simulate the action being performed by the specified writer is a clever use of the Foundry testing framework's capabilities.- 104-111: The
requestVerification
function correctly encapsulates the logic for requesting verification of an entry, including dealing with the caller's balance and usingvm.prank
to simulate the action. This encapsulation improves test readability and maintainability.- 121-125: The
writeEntryWithVerification
function combines the actions of writing an entry and requesting its verification in one step. This is a useful abstraction for tests that need to simulate this combined operation, enhancing test clarity.- 137-138: The
expectEntryDoesNotExist
function is a good example of using Foundry'svm.expectRevert
to anticipate specific revert conditions in tests. This is crucial for testing error handling paths in the contract logic.- 157-158: The test
test_setup_getDBNonce
correctly asserts that the initial DB nonce is set as expected. This is an important test to ensure that the initial state of the contract aligns with the expectations set by the new nonce management system.- 162-163: The loop in
test_setup_getEntry
effectively tests the retrieval of initial entries, ensuring that the contract's state matches the expected initial conditions. This thorough approach is commendable for validating the setup phase of the contract.- 286-296: The series of tests for
requestVerification
with reverts due to non-existent entries are comprehensive, covering a range of scenarios including next nonce, huge nonce values, and the maximum possible nonce. This thorough testing is crucial for ensuring robust error handling in the contract.- 316-334: The tests for
requestVerification
with reverts due to incorrect fee amounts are well-structured, covering both underpaid and overpaid scenarios for one module and two modules. These tests are essential for validating the contract's fee handling logic.- 339-345: The tests for
requestVerification
with reverts due to no modules specified and the same chain ID are important for ensuring the contract correctly handles these edge cases. This attention to detail in testing edge cases enhances the contract's reliability.packages/contracts-communication/test/InterchainDB.Dst.t.sol (10)
- 4-10: The import statements have been updated to include
InterchainEntryLib
. This change aligns with the PR objectives to refactor the nonce management system. Ensure thatInterchainEntryLib
is used appropriately within the test suite for operations related to the new globaldbNonce
.- 41-54: The
setUp
function has been modified to use the newgetMockEntry
function signature, which now includes adbNonce
parameter. This change is consistent with the PR's objective to transition to a global nonce system. Ensure that all test entries are correctly initialized with the intendeddbNonce
values for accurate testing.- 63-74: The functions
introduceConflictsSameWriter
andintroduceConflictsDiffWriter
have been updated to reflect the new nonce management approach. It's important to verify that these functions accurately simulate the intended conflict scenarios under the new system, especially considering the transition to a globaldbNonce
.- 80-97: The introduction of empty entries in
introduceEmptyEntries
andintroduceEqualEmptyEntries
functions is crucial for testing edge cases. Ensure that these functions correctly utilize the newgetEmptyEntry
signature and that the tests cover scenarios relevant to the global nonce management system.- 135-168: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [117-164]
The
getMockEntry
,getFakeEntry
, andgetEmptyEntry
functions have been updated to include thedbNonce
parameter. This change is essential for generating test entries that align with the new nonce management system. Ensure that the data generation functions correctly create entries with the intended nonce values and data hashes.
- 183-190: The
assertCorrectVerificationTime
andexpectConflictingEntries
helper functions are used to assert conditions and expect specific reverts. It's important to ensure that these functions are correctly implemented to accurately test the contract's behavior under various scenarios, especially with the updated nonce management system.- 202-218: The test cases, such as
test_verifyEntry_new_emitsEvent
andtest_verifyEntry_existing_diffModule_emitsEvent
, have been updated to reflect the new event parameters and the global nonce system. Ensure that the expected events are correctly emitted with the appropriate parameters, including the globaldbNonce
.- 278-296: The test cases that expect reverts, such as
test_verifyEntry_revert_conflict_sameModule_sameWriter
andtest_verifyEntry_revert_sameChainId
, are crucial for ensuring the contract behaves as expected under error conditions. Verify that these tests accurately reflect the contract's logic, especially in handling conflicting entries and same chain ID errors under the new nonce system.- 305-517: The reading entry test cases, such as
test_readEntry_existingA_existingB
andtest_readEntry_emptyA_emptyB
, have been updated to account for the new nonce management system. It's important to ensure that these tests accurately assess the contract's functionality in reading and verifying entries under various scenarios, including conflicts, empty entries, and entries verified by different modules.- 525-525: The
test_readEntry_revert_sameChainId
function tests the contract's behavior when attempting to read an entry from the same chain ID. This test is important for ensuring the contract correctly handles such cases, especially with the updated nonce management system. Verify that the expected revert is correctly triggered.
* Use dbNonce in `InterchainEntry` struct * Update InterchainDB: source chain logic * Update InterchainDB: destination chain logic * Update InterchainDB tests * Use `dbNonce` in InterchainClient * Update the rest of the tests
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
Summary by CodeRabbit
LocalEntry
structure with enhanced fields for better data management.dbWriterNonce
todbNonce
across various contracts for consistency.InterchainDB
contract, including its storage mappings and function signatures, to accommodate new data structures and logic.