-
Notifications
You must be signed in to change notification settings - Fork 74
FIX - Web3py refactor #1248
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
base: staging/product-ia
Are you sure you want to change the base?
FIX - Web3py refactor #1248
Conversation
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.
Pull Request Overview
This PR refactors the Web3.py documentation to transition from PolkaVM-specific implementations to standard EVM compatibility. The changes include removing PolkaVM-specific warnings, updating bytecode file formats, and enhancing the deployment script with better error handling and logging.
Key Changes
- Removed PolkaVM warning banner and updated bytecode references from
.polkavmto.binformat - Enhanced deployment script with retry logic, timeout configuration, and comprehensive logging
- Transitioned from async to synchronous implementation in the deploy function
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| smart-contracts/libraries/web3-py.md | Updated documentation to remove PolkaVM references and change bytecode format from .polkavm to .bin |
| .snippets/code/smart-contracts/libraries/web3-py/deploy.py | Refactored deployment script: removed async/await, added retry logic, improved error handling, and switched to text-based bytecode reading |
| llms-full.jsonl | Updated AI training data to reflect documentation changes |
| .ai/pages/smart-contracts-libraries-web3-py.md | Updated AI-readable version with embedded code examples |
| .ai/site-index.json | Updated site metadata including character counts, word counts, and content hashes |
| .ai/categories/tooling.md | Updated tooling category documentation with new deployment script |
| .ai/categories/smart-contracts.md | Updated smart contracts category documentation with new deployment script |
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| with open(f"{contract_name}.bin", 'r') as file: | ||
| bytecode = file.read().strip() | ||
| return bytecode if bytecode.startswith('0x') else f"0x{bytecode}" |
Copilot
AI
Nov 18, 2025
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.
[nitpick] The bytecode file reading mode was changed from binary ('rb') to text mode ('r'). While this works for .bin files that contain hex-encoded text, the subsequent .strip() call and conditional prefix check suggest this is the intended approach.
However, for standard Solidity compiler output, .bin files typically contain only the hex bytecode without the 0x prefix. Consider documenting this expectation or handling both cases more robustly by checking if the file contains binary data vs hex text.
| with open(f"{contract_name}.bin", 'r') as file: | |
| bytecode = file.read().strip() | |
| return bytecode if bytecode.startswith('0x') else f"0x{bytecode}" | |
| with open(f"{contract_name}.bin", 'rb') as file: | |
| content = file.read().strip() | |
| # Try to decode as ASCII hex text | |
| try: | |
| text = content.decode('utf-8').strip() | |
| if text.startswith('0x'): | |
| hex_str = text[2:] | |
| else: | |
| hex_str = text | |
| # Validate hex string | |
| int(hex_str, 16) | |
| return f"0x{hex_str}" | |
| except (UnicodeDecodeError, ValueError): | |
| # If not ASCII hex, treat as raw binary | |
| return f"0x{content.hex()}" |
| def deploy_with_retry(config, max_retries=3): | ||
| """Deploy with retry logic for RPC errors""" | ||
| for attempt in range(max_retries): | ||
| try: | ||
| return deploy(config) | ||
| except Exception as error: | ||
| error_str = str(error) | ||
| if "500" in error_str or "Internal Server Error" in error_str or "Connection" in error_str: | ||
| if attempt < max_retries - 1: | ||
| wait_time = (attempt + 1) * 3 | ||
| print(f"RPC error, retrying in {wait_time} seconds... (attempt {attempt + 1}/{max_retries})") | ||
| time.sleep(wait_time) | ||
| continue | ||
| raise error |
Copilot
AI
Nov 18, 2025
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.
The retry logic catches errors based on string matching for "500", "Internal Server Error", or "Connection" in the error message. This approach is fragile and may not catch all relevant RPC errors or may incorrectly retry non-transient errors.
Consider checking for specific exception types (e.g., requests.exceptions.ConnectionError, requests.exceptions.Timeout) or using the HTTP status code from the response object if available, rather than relying on string matching.
|
|
||
| ```python title="connect_to_provider.py" | ||
| ```python title="fetch_last_block.py" | ||
| --8<-- "code/smart-contracts/libraries/web3-py/connect_to_provider.py" |
Copilot
AI
Nov 18, 2025
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.
The code block title was changed to "fetch_last_block.py" but the included file path on line 50 still references "connect_to_provider.py". This creates a mismatch between the displayed title and the actual file being included.
Either update line 50 to --8<-- "code/smart-contracts/libraries/web3-py/fetch_last_block.py" or revert line 49 to use "connect_to_provider.py" as the title.
| --8<-- "code/smart-contracts/libraries/web3-py/connect_to_provider.py" | |
| --8<-- "code/smart-contracts/libraries/web3-py/fetch_last_block.py" |
| raise error | ||
|
|
||
| async def deploy(config): | ||
| def deploy_with_retry(config, max_retries=3): |
Copilot
AI
Nov 18, 2025
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.
Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.
π Description
Provide a clear and concise description of your changes.
π Review Preference
Choose one:
π€ AI-Ready Docs
If content changed, regenerate AI files:
python3 scripts/generate_llms.pyβ Checklist