-
Notifications
You must be signed in to change notification settings - Fork 35
fix: RPC should return error on failed contract deployment instead of address #1276
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -587,7 +587,7 @@ def _process_result(self, transaction_data: dict) -> dict: | |
| return transaction_data | ||
|
|
||
| def get_transaction_by_hash( | ||
| self, transaction_hash: str, sim_config: dict | None = None | ||
| self, transaction_hash: str, sim_config: dict | None = None, hide_fields: bool = False | ||
| ) -> dict | None: | ||
| transaction = ( | ||
| self.session.query(Transactions) | ||
|
|
@@ -630,6 +630,23 @@ def get_transaction_by_hash( | |
| transaction_data = self._process_messages(transaction_data) | ||
| transaction_data = self._process_queue(transaction_data) | ||
| transaction_data = self._process_round_data(transaction_data) | ||
|
|
||
| if hide_fields: | ||
| if transaction_data[ | ||
| "type" | ||
| ] == TransactionType.DEPLOY_CONTRACT.value and not ( | ||
| transaction_data["last_round"]["result"] == 6 | ||
| and "leader_receipt" in transaction_data["consensus_data"] | ||
| and transaction_data["consensus_data"]["leader_receipt"] is not None | ||
| and len(transaction_data["consensus_data"]["leader_receipt"]) > 0 | ||
| and transaction_data["consensus_data"]["leader_receipt"][0][ | ||
| "execution_result" | ||
| ] | ||
| == ExecutionResultStatus.SUCCESS.value | ||
| ): | ||
| transaction_data["data"]["contract_address"] = None | ||
| if "contract_snapshot" in transaction_data: | ||
| del transaction_data["contract_snapshot"] | ||
|
Comment on lines
+634
to
+649
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential TypeError if
🔧 Suggested fix+ from backend.consensus.types import ConsensusResult
+
if hide_fields:
if transaction_data[
"type"
] == TransactionType.DEPLOY_CONTRACT.value and not (
- transaction_data["last_round"]["result"] == 6
- and "leader_receipt" in transaction_data["consensus_data"]
+ transaction_data["last_round"]["result"]
+ == int(ConsensusResult.MAJORITY_AGREE)
+ and transaction_data["consensus_data"] is not None
+ and "leader_receipt" in transaction_data["consensus_data"]
and transaction_data["consensus_data"]["leader_receipt"] is not None
and len(transaction_data["consensus_data"]["leader_receipt"]) > 0
and transaction_data["consensus_data"]["leader_receipt"][0][
"execution_result"
]
== ExecutionResultStatus.SUCCESS.value
):
transaction_data["data"]["contract_address"] = None
if "contract_snapshot" in transaction_data:
del transaction_data["contract_snapshot"]🤖 Prompt for AI Agents |
||
| return transaction_data | ||
|
|
||
| def get_studio_transaction_by_hash( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1048,7 +1048,7 @@ def get_transaction_by_hash( | |||||
| sim_config: dict | None = None, | ||||||
| ) -> dict: | ||||||
| transaction = transactions_processor.get_transaction_by_hash( | ||||||
| transaction_hash, sim_config | ||||||
| transaction_hash, sim_config, True | ||||||
| ) | ||||||
|
|
||||||
| if transaction is None: | ||||||
|
|
@@ -1427,7 +1427,7 @@ def get_transaction_receipt( | |||||
| event_signature = "NewTransaction(bytes32,address,address)" | ||||||
| event_signature_hash = eth_utils.keccak(text=event_signature).hex() | ||||||
|
|
||||||
| to_addr = transaction.get("to_address") | ||||||
| to_addr = transaction.get("to_address") if transaction.get("to_address") else None | ||||||
| from_addr = transaction.get("from_address") | ||||||
|
|
||||||
| logs = [ | ||||||
|
|
@@ -1457,6 +1457,19 @@ def get_transaction_receipt( | |||||
| } | ||||||
| ] | ||||||
|
|
||||||
| if ( | ||||||
| transaction["type"] == TransactionType.DEPLOY_CONTRACT.value | ||||||
| and transaction["last_round"]["result"] == 6 | ||||||
| and "leader_receipt" in transaction["consensus_data"] | ||||||
| and transaction["consensus_data"]["leader_receipt"] is not None | ||||||
| and len(transaction["consensus_data"]["leader_receipt"]) > 0 | ||||||
| and transaction["consensus_data"]["leader_receipt"][0]["execution_result"] | ||||||
| == ExecutionResultStatus.SUCCESS.value | ||||||
| ): | ||||||
| contract_address = transaction["to_address"] | ||||||
| else: | ||||||
| contract_address = None | ||||||
|
Comment on lines
+1460
to
+1471
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated logic and magic number 6; also potential TypeError if
♻️ Suggested refactor+from backend.consensus.types import ConsensusResult
+
+def _is_successful_deployment(transaction: dict) -> bool:
+ """Check if a DEPLOY_CONTRACT transaction was successfully deployed."""
+ return (
+ transaction["type"] == TransactionType.DEPLOY_CONTRACT.value
+ and transaction["last_round"]["result"] == int(ConsensusResult.MAJORITY_AGREE)
+ and transaction.get("consensus_data") is not None
+ and "leader_receipt" in transaction["consensus_data"]
+ and transaction["consensus_data"]["leader_receipt"] is not None
+ and len(transaction["consensus_data"]["leader_receipt"]) > 0
+ and transaction["consensus_data"]["leader_receipt"][0].get("execution_result")
+ == ExecutionResultStatus.SUCCESS.value
+ )
+
# In get_transaction_receipt:
- if (
- transaction["type"] == TransactionType.DEPLOY_CONTRACT.value
- and transaction["last_round"]["result"] == 6
- and "leader_receipt" in transaction["consensus_data"]
- and transaction["consensus_data"]["leader_receipt"] is not None
- and len(transaction["consensus_data"]["leader_receipt"]) > 0
- and transaction["consensus_data"]["leader_receipt"][0]["execution_result"]
- == ExecutionResultStatus.SUCCESS.value
- ):
- contract_address = transaction["to_address"]
- else:
- contract_address = None
+ contract_address = transaction["to_address"] if _is_successful_deployment(transaction) else None
|
||||||
|
|
||||||
| receipt = { | ||||||
| "transactionHash": transaction_hash, | ||||||
| "transactionIndex": hex(0), | ||||||
|
|
@@ -1466,11 +1479,7 @@ def get_transaction_receipt( | |||||
| "to": to_addr, | ||||||
| "cumulativeGasUsed": hex(transaction.get("gas_used", 8000000)), | ||||||
| "gasUsed": hex(transaction.get("gas_used", 8000000)), | ||||||
| "contractAddress": ( | ||||||
| transaction.get("contract_address") | ||||||
| if transaction.get("contract_address") | ||||||
| else None | ||||||
| ), | ||||||
| "contractAddress": contract_address, | ||||||
| "logs": logs, | ||||||
| "logsBloom": "0x" + "00" * 256, | ||||||
| "status": hex(1 if transaction.get("status", True) else 0), | ||||||
|
|
@@ -1485,7 +1494,7 @@ def get_block_by_hash( | |||||
| full_tx: bool = False, | ||||||
| ) -> dict | None: | ||||||
|
|
||||||
| transaction = transactions_processor.get_transaction_by_hash(block_hash) | ||||||
| transaction = transactions_processor.get_transaction_by_hash(block_hash, True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type error: The method signature is 🐛 Suggested fix- transaction = transactions_processor.get_transaction_by_hash(block_hash, True)
+ transaction = transactions_processor.get_transaction_by_hash(block_hash, None, True)Or use keyword argument for clarity: - transaction = transactions_processor.get_transaction_by_hash(block_hash, True)
+ transaction = transactions_processor.get_transaction_by_hash(block_hash, hide_fields=True)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| if not transaction: | ||||||
| return None | ||||||
|
|
||||||
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 Black formatting to pass CI.
The pipeline failure indicates Black reformatted this line. The parameter list on a single line likely exceeds the line length limit.
🔧 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents