-
Notifications
You must be signed in to change notification settings - Fork 5
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
CI: enhance CI to check storage layout backwards compatibility #111
Conversation
WalkthroughA new Python script, Changes
Possibly related PRs
Poem
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (6)
.github/workflows/forge-ci.yml (3)
162-170
: LGTM: Effective setup for target branch comparison.The steps to checkout the target branch and generate layout files are well-structured and align with the PR's objective. The focus on ExocoreGateway is consistent with the PR description.
Consider adding a comment explaining why only ExocoreGateway is being inspected here, as it might not be immediately clear to other developers why other contracts aren't included at this stage.
184-189
: LGTM: Proper setup of Python environment.The Python setup and pandas installation are correctly configured with specific versions, which is excellent for ensuring reproducibility across different environments.
Consider adding a
requirements.txt
file for managing Python dependencies. This would allow for easier management of multiple dependencies in the future and is a common best practice in Python projects.
Line range hint
190-204
: LGTM: Comprehensive comparison process with informative failure messaging.The addition of separate comparison steps for different contracts and the update to the failure comment provide a more thorough and informative CI process. This directly supports the PR's objective of enhancing storage layout compatibility checks.
Consider parameterizing the script calls to make it easier to add or modify contract comparisons in the future. For example:
- name: Run comparison scripts run: | for contract in Bootstrap ClientChainGateway ExocoreGateway; do python .github/workflows/compare_storage_layout.py $contract done python .github/workflows/compare_deployed_storage_layout.pyThis approach would make the workflow more maintainable and extensible.
.github/workflows/compare_storage_layout.py (2)
46-46
: Rename unused loop variableindex
The variable
index
is not used within the loop body. To indicate that it's intentionally unused, rename it to_
.Apply this diff:
-for index, row in old_layout.iterrows(): +for _, row in old_layout.iterrows():🧰 Tools
🪛 Ruff
46-46: Loop control variable
index
not used within loop bodyRename unused
index
to_index
(B007)
55-55
: Remove unnecessaryf
prefix in print statementThe string
"No mismatches found"
does not contain any placeholders, so thef
prefix is unnecessary.Apply this diff:
- print(f"No mismatches found") + print("No mismatches found")🧰 Tools
🪛 Ruff
55-55: f-string without any placeholders
Remove extraneous
f
prefix(F541)
.github/workflows/compare_deployed_storage_layout.py (1)
26-26
: Correct the print statement for clarityIn the message, "finish executing" should be "Finished executing" to improve readability.
Apply this change:
- print(f"finish executing: cast storage {address} --rpc-url ...") + print(f"Finished executing: cast storage {address} --rpc-url ...")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- .github/workflows/compare_deployed_storage_layout.py (1 hunks)
- .github/workflows/compare_storage_layout.py (1 hunks)
- .github/workflows/forge-ci.yml (3 hunks)
- .gitignore (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .gitignore
🧰 Additional context used
🪛 Ruff
.github/workflows/compare_storage_layout.py
9-9: Statement ends with an unnecessary semicolon
Remove unnecessary semicolon
(E703)
46-46: Loop control variable
index
not used within loop bodyRename unused
index
to_index
(B007)
55-55: f-string without any placeholders
Remove extraneous
f
prefix(F541)
🔇 Additional comments (3)
.github/workflows/forge-ci.yml (3)
140-142
: LGTM: Secure addition of API keys as environment variables.The addition of ALCHEMY_API_KEY and ETHERSCAN_API_KEY as environment variables, sourced from GitHub secrets, is a secure way to provide necessary API access for the CI process. This change supports the PR's objective of enhancing the storage layout compatibility check.
171-183
: LGTM: Efficient caching strategy for layout files.The implementation of caching and restoring the target branch layout file is a smart optimization. It ensures that the layout file is preserved across checkout operations and can be quickly accessed for comparison, potentially speeding up the CI process.
Line range hint
140-204
: Overall assessment: Excellent enhancements to the CI workflowThe changes to this workflow file significantly improve the process of checking storage layout compatibility. Key improvements include:
- Secure handling of API keys
- Efficient caching of layout files
- Comprehensive comparison across different contracts
- Informative failure messaging
These enhancements align perfectly with the PR objectives and will contribute to maintaining backwards compatibility for contract upgrades.
While the implementation is solid, consider the minor suggestions provided in previous comments to further improve maintainability and clarity.
def parse_output(contract_name, lines): | ||
# Clean up the output and create a dataframe | ||
data = [] | ||
separator_line = len(lines); |
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.
Remove unnecessary semicolon
There's an unnecessary semicolon at the end of the line. In Python, semicolons are not required at the end of statements.
Apply this diff to remove the semicolon:
- separator_line = len(lines);
+ separator_line = len(lines)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
separator_line = len(lines); | |
separator_line = len(lines) |
🧰 Tools
🪛 Ruff
9-9: Statement ends with an unnecessary semicolon
Remove unnecessary semicolon
(E703)
if i > separator_line and line.startswith('|'): | ||
parts = [part.strip() for part in line.split('|')[1:-1]] # Remove empty first and last elements | ||
data.append(parts[:6]) # Keep Name, Type, Slot, Offset, Bytes, Contract | ||
elif line.startswith('|') and 'Name' in line: | ||
separator_line = i + 1 | ||
|
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.
Fix the loop condition to correctly parse the output
The current loop condition may prevent the parsing logic from working as intended. Since separator_line
is initialized to len(lines)
, the condition i > separator_line
will always be False
because i
ranges from 0
to len(lines) - 1
. This means the loop might skip processing the necessary lines, resulting in data
being empty.
Consider initializing separator_line
to -1
so that the condition i > separator_line
becomes True
after the header line is identified.
Apply this diff to adjust the initialization:
- separator_line = len(lines)
+ separator_line = -1
Alternatively, adjust the condition in the loop to correctly process the lines after the header.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if i > separator_line and line.startswith('|'): | |
parts = [part.strip() for part in line.split('|')[1:-1]] # Remove empty first and last elements | |
data.append(parts[:6]) # Keep Name, Type, Slot, Offset, Bytes, Contract | |
elif line.startswith('|') and 'Name' in line: | |
separator_line = i + 1 | |
if i > separator_line and line.startswith('|'): | |
parts = [part.strip() for part in line.split('|')[1:-1]] # Remove empty first and last elements | |
data.append(parts[:6]) # Keep Name, Type, Slot, Offset, Bytes, Contract | |
elif line.startswith('|') and 'Name' in line: | |
separator_line = i + 1 | |
separator_line = -1 |
print(f"Skipping {contract_name} as it's not deployed.") | ||
return pd.DataFrame() | ||
|
||
result = subprocess.run(['cast', 'storage', address, '--rpc-url', rpc_url, '--etherscan-api-key', etherscan_api_key], capture_output=True, text=True) |
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.
🛠️ Refactor suggestion
Check for the 'cast' command before execution
If the cast
command is not installed or not in the system's PATH, the script will raise a FileNotFoundError
. To handle this gracefully, check if cast
is available before attempting to run it, and provide a clear error message if it isn't.
Add this check before line 25:
import shutil
if not shutil.which('cast'):
raise EnvironmentError("'cast' command not found. Please install Foundry to proceed.")
|
||
# then we load the layout file of ExocoreGateway on target branch and compare it with the current layout | ||
print("Checking ExocoreGateway...") | ||
target_branch_layout = load_and_parse_layout('ExocoreGateway', 'ExocoreGateway_target.txt') |
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.
Ensure correct file path for 'ExocoreGateway_target.txt'
The script expects ExocoreGateway_target.txt
to be in the current working directory, which may not always be the case. To prevent file not found errors, use a path relative to the script's location.
Apply this change:
+ script_dir = os.path.dirname(os.path.abspath(__file__))
+ layout_path = os.path.join(script_dir, 'ExocoreGateway_target.txt')
- target_branch_layout = load_and_parse_layout('ExocoreGateway', 'ExocoreGateway_target.txt')
+ target_branch_layout = load_and_parse_layout('ExocoreGateway', layout_path)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
target_branch_layout = load_and_parse_layout('ExocoreGateway', 'ExocoreGateway_target.txt') | |
script_dir = os.path.dirname(os.path.abspath(__file__)) | |
layout_path = os.path.join(script_dir, 'ExocoreGateway_target.txt') | |
target_branch_layout = load_and_parse_layout('ExocoreGateway', layout_path) |
exit(1) | ||
else: | ||
print("Storage layout is compatible with all deployed contracts.") | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
exit(1) |
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.
Use sys.exit()
instead of exit()
for script termination
The built-in exit()
function is meant for interactive shells and may not work as expected in scripts. Using sys.exit()
ensures proper termination of the script in all environments.
Apply this change:
+import sys
print(f" {mismatch}")
- exit(1)
+ sys.exit(1)
else:
print("Storage layout is compatible with all deployed contracts.")
except Exception as e:
print(f"Error: {e}")
- exit(1)
+ sys.exit(1)
Committable suggestion was skipped due to low confidence.
with open('script/deployedContracts.json', 'r') as f: | ||
data = json.load(f) |
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.
Use absolute paths to ensure file accessibility
The script assumes that script/deployedContracts.json
is in the current working directory. This can lead to issues if the script is executed from a different directory. To make the script more robust, use an absolute path relative to the script's location.
Apply this change:
+script_dir = os.path.dirname(os.path.abspath(__file__))
def get_deployed_addresses():
- with open('script/deployedContracts.json', 'r') as f:
+ file_path = os.path.join(script_dir, 'script', 'deployedContracts.json')
+ with open(file_path, 'r') as f:
data = json.load(f)
Committable suggestion was skipped due to low confidence.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
.github/workflows/forge-ci.yml (4)
167-180
: LGTM: Efficient caching strategy for layout files.The caching and restoring steps are well-implemented, ensuring that the layout file from the target branch is preserved and available for comparison. This approach optimizes the workflow by avoiding unnecessary regeneration of files.
Consider using a more specific cache key that includes the target branch name, such as:
key: ${{ runner.os }}-exocore-target-${{ github.event.pull_request.base.ref }}-${{ github.sha }}This would allow for better cache isolation between different target branches.
187-190
: LGTM: Comprehensive comparison strategy implemented.The addition of separate comparison scripts for Bootstrap/ClientChainGateway and deployed contracts aligns well with the PR objectives. This approach allows for more detailed and specific comparisons.
Consider adding error handling or result logging for each script execution. This could be achieved by capturing the output and exit code of each script, which could then be used for more detailed reporting or conditional execution of subsequent steps. For example:
- name: Run comparison scripts run: | python .github/workflows/compare_storage_layout.py COMPARE_RESULT=$? python .github/workflows/compare_deployed_storage_layout.py DEPLOY_COMPARE_RESULT=$? if [ $COMPARE_RESULT -ne 0 ] || [ $DEPLOY_COMPARE_RESULT -ne 0 ]; then echo "One or more comparisons failed" exit 1 fi
191-193
: LGTM: Secure handling of API keys implemented.The addition of
ALCHEMY_API_KEY
andETHERSCAN_API_KEY
as environment variables, sourced from GitHub secrets, is a secure way to provide necessary access for the deployed contracts comparison script.To further enhance security, consider implementing API key rotation or using GitHub's OIDC (OpenID Connect) feature for more dynamic and secure credential management. This could involve setting up a workflow that periodically rotates these keys or using temporary, session-based tokens.
Example of using OIDC for AWS (similar approach can be adapted for other providers):
- name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role aws-region: us-east-2This approach eliminates the need to store long-lived credentials in GitHub secrets.
204-204
: LGTM: Improved failure message provides better context.The updated failure message offers more specific information about potential causes of the storage layout compatibility check failure. This will help developers quickly identify and address issues.
Consider adding a link to the workflow run in the failure message. This would make it easier for developers to access the logs directly. You can use the
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
context to generate the link. For example:body: 'Storage layout compatibility check failed. This could be due to a mismatch between Bootstrap and ClientChainGateway, or incompatibility with deployed contracts on Sepolia. Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- .github/workflows/forge-ci.yml (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
.github/workflows/forge-ci.yml (1)
159-167
: LGTM: Proper setup for storage layout comparison.The added steps correctly checkout the target branch and generate the layout file for
ExocoreGateway
. This setup is crucial for accurate storage layout comparison between branches.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
.github/workflows/forge-ci.yml (3)
144-147
: Consider removing the debug step in the futureThe "Debug Secrets" step is useful for initial setup and troubleshooting, as it safely verifies the presence of secrets without exposing their values. However, consider removing this step once the workflow is confirmed to be working correctly in production.
166-187
: LGTM: Efficient branch comparison setupThe changes to check out the target branch, generate the ExocoreGateway layout file, and cache it for later comparison are well-implemented. This process effectively supports the PR objective of ensuring backwards compatibility of storage layout.
Consider parameterizing the file path 'src/core/ExocoreGateway.sol' to make the workflow more resilient to potential file structure changes in the future.
208-208
: Improved failure message, but could be more actionableThe updated failure message provides more specific information about potential causes of the storage layout compatibility check failure. This is a good improvement that aligns with the enhanced comparison process.
Consider making the message even more actionable by suggesting next steps for the developer. For example:
body: 'Storage layout compatibility check failed. This could be due to a mismatch between Bootstrap and ClientChainGateway, or incompatibility with deployed contracts on Sepolia. Please check the logs for details. To resolve, review the changes in the storage variables and ensure they maintain backwards compatibility. If you need assistance, consult the upgradeability guidelines in the project documentation.'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- .github/workflows/forge-ci.yml (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
.github/workflows/forge-ci.yml (2)
140-142
: LGTM: Environment variables added securelyThe addition of
ALCHEMY_API_KEY
andETHERSCAN_API_KEY
as environment variables using GitHub secrets is a good practice. This change aligns with the PR objective of enhancing CI to check storage layout compatibility, likely by interacting with deployed contracts.
194-197
: LGTM: Enhanced comparison processThe separation of comparison steps for different contracts (Bootstrap, ClientChainGateway, and deployed contracts) improves clarity and control. This change aligns well with the PR objective of ensuring compatibility with already deployed contracts.
However, the content of the new script 'compare_deployed_storage_layout.py' is not provided in this diff. Please include this file in the PR for a comprehensive review of the new functionality.
To verify the existence and basic structure of the new script, run:
✅ Verification successful
LGTM: Verified comparison script
The
compare_deployed_storage_layout.py
script effectively retrieves and compares the storage layouts of deployed contracts against the current branch. The implementation includes appropriate error handling and covers all relevant contracts.No issues found.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if the new script exists and show its structure if [ -f ".github/workflows/compare_deployed_storage_layout.py" ]; then echo "File exists. Here's its structure:" grep -n "^def " .github/workflows/compare_deployed_storage_layout.py else echo "File .github/workflows/compare_deployed_storage_layout.py does not exist." fiLength of output: 380
Script:
#!/bin/bash # Display the entire content of the new comparison script for thorough review cat .github/workflows/compare_deployed_storage_layout.pyLength of output: 3740
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
.github/workflows/forge-ci.yml (2)
162-174
: LGTM: Efficient target branch comparison setup.The new steps for checking out the target branch, generating the
ExocoreGateway
layout file, and caching it are well-structured and efficient. This setup ensures accurate comparison between the PR and the target branch.Consider adding a comment in the workflow file explaining the purpose of these steps for better maintainability.
Line range hint
140-204
: Summary: CI enhancements align well with PR objectives.The changes to the
forge-ci.yml
workflow file effectively enhance the CI process to check storage layout backwards compatibility:
- Addition of necessary API keys as secure environment variables.
- Implementation of a more robust comparison process, including checks against the target branch and deployed contracts.
- Improved error messaging for better developer feedback.
These enhancements align well with the PR objectives of ensuring backwards compatibility for contract storage layouts, which is crucial for the upgradeability of deployed contracts.
Consider documenting the overall CI process, including the purpose of each script and how they work together to ensure backwards compatibility. This documentation would be valuable for future maintenance and onboarding of new team members.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- .github/workflows/forge-ci.yml (3 hunks)
🧰 Additional context used
🔇 Additional comments (4)
.github/workflows/forge-ci.yml (4)
140-142
: LGTM: Environment variables added securely.The addition of
ALCHEMY_API_KEY
andETHERSCAN_API_KEY
as environment variables, referencing GitHub Actions secrets, is a good practice for securely handling API keys.
175-183
: LGTM: Proper restoration of PR context and cached data.The steps to check out back to the PR branch and restore the cached layout file from the target branch are correct and ensure that the comparison is made between the appropriate versions.
204-204
: LGTM: Improved failure message.The updated failure message for storage layout mismatches is more informative. It now includes specific mentions of potential issues with Bootstrap, ClientChainGateway, and deployed contracts on Sepolia, which will help developers quickly identify and address problems.
190-193
: LGTM: Enhanced comparison process.The split of the comparison process into two steps (for Bootstrap/ClientChainGateway and for deployed contracts) is a good improvement. It allows for more granular control and aligns with the PR objectives of ensuring backwards compatibility.
Could you provide more information about the new
compare_deployed_storage_layout.py
script? It would be helpful to understand its specific functionality and how it compares deployed contracts.✅ Verification successful
: The
compare_deployed_storage_layout.py
script effectively automates the verification of storage layouts for deployed contracts, ensuring backward compatibility and enhancing the CI workflow.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Retrieve the content of the new comparison script. cat .github/workflows/compare_deployed_storage_layout.pyLength of output: 3740
this PR is originated from forked repo and can not access repo secrets, so I open #112 to replace this one |
Description
Since we have decided to freeze the contract storage layout, to make deployed contracts upgradeable, we need to keep backwards compatibility for contract storage layout, so that these deployed contracts would be upgradeable in the next release.
By comparing storage layout against deployed contracts, we ensure future pull requests would not break the upgradeability for most of the contracts(client chain contracts). For
ExocoreGateway
, we can compare against the main branch to make it sincecast storage
does not work with Exocore chain for now.Summary by CodeRabbit
New Features
Bug Fixes
Chores
.gitignore
to exclude sensitive information, including.secrets
.