-
Notifications
You must be signed in to change notification settings - Fork 68
Improve error handling for HTTP status code 0 errors #199
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ec12868
Improve error handling for HTTP status code 0 errors
devin-ai-integration[bot] 0e65e29
Add unit test for HTTP error handling and fix error message capitaliz…
devin-ai-integration[bot] a6c0b17
Fix unused import in vm_runner_rest_test.go
devin-ai-integration[bot] b30532f
Updated the testing instructions in README.md
chrisli30 1e2ed7d
Fixed test errors from TestRestRequestErrorHandling
chrisli30 c18765f
Added Paymaster contract address to docs/contract.md
chrisli30 4876da1
Added fixes for TestContractWriteSimpleReturn case
chrisli30 9555d28
Updated error message in operator/operator.go
chrisli30 c00cbc5
Added missing txReceipt fields to vm_runner_contract_write.go and tes…
chrisli30 2cfbb48
Updated vm_runner_rest.go to handle status 0
chrisli30 1ada19c
Revert the capitalization of Errorf messages
chrisli30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package taskengine | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"strings" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
|
||
"github.com/AvaProtocol/ap-avs/core/chainio/aa" | ||
|
@@ -77,11 +80,11 @@ func (r *ContractWriteProcessor) Execute(stepID string, node *avsproto.ContractW | |
log.WriteString("\nsend userops to bundler rpc\n") | ||
|
||
total, _ := r.vm.db.GetCounter(ContractWriteCounterKey(r.owner), 0) | ||
|
||
var paymasterRequest *preset.VerifyingPaymasterRequest | ||
// TODO: move to config | ||
if total < 10 { | ||
paymasterRequest = preset.GetVerifyingPaymasterRequestForDuration(r.smartWalletConfig.PaymasterAddress, 15 * time.Minute) | ||
paymasterRequest = preset.GetVerifyingPaymasterRequestForDuration(r.smartWalletConfig.PaymasterAddress, 15*time.Minute) | ||
} | ||
|
||
userOp, txReceipt, err := preset.SendUserOp( | ||
|
@@ -97,17 +100,6 @@ func (r *ContractWriteProcessor) Execute(stepID string, node *avsproto.ContractW | |
} | ||
r.vm.db.IncCounter(ContractWriteCounterKey(r.owner), 0) | ||
|
||
var bloom []byte | ||
if txReceipt != nil { | ||
bloom, _ = txReceipt.Bloom.MarshalText() | ||
} | ||
|
||
blobGasPrice := uint64(0) | ||
|
||
if txReceipt != nil && txReceipt.BlobGasPrice != nil { | ||
blobGasPrice = uint64(txReceipt.BlobGasPrice.Int64()) | ||
} | ||
|
||
outputData := &avsproto.Execution_Step_ContractWrite{ | ||
ContractWrite: &avsproto.ContractWriteNode_Output{ | ||
UserOp: &avsproto.Evm_UserOp{ | ||
|
@@ -123,31 +115,63 @@ func (r *ContractWriteProcessor) Execute(stepID string, node *avsproto.ContractW | |
PaymasterAndData: common.Bytes2Hex(userOp.PaymasterAndData), | ||
Signature: common.Bytes2Hex(userOp.Signature), | ||
}, | ||
|
||
TxReceipt: &avsproto.Evm_TransactionReceipt{ | ||
Hash: txReceipt.TxHash.Hex(), | ||
BlockHash: txReceipt.BlockHash.Hex(), | ||
BlockNumber: uint64(txReceipt.BlockNumber.Int64()), | ||
// TODO: Need to fetch this, it isn't available | ||
//From: txReceipt.From.Hex(), | ||
chrisli30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//To: txReceipt.To.Hex(), | ||
GasUsed: txReceipt.GasUsed, | ||
GasPrice: uint64(txReceipt.EffectiveGasPrice.Int64()), | ||
CumulativeGasUsed: txReceipt.CumulativeGasUsed, | ||
// Fee: txReceipt.Fee, | ||
ContractAddress: txReceipt.ContractAddress.Hex(), | ||
Index: uint64(txReceipt.TransactionIndex), | ||
// TODO: convert raw log | ||
//Logs: txReceipt.Logs, | ||
chrisli30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
LogsBloom: common.Bytes2Hex(bloom), | ||
Root: common.Bytes2Hex(txReceipt.PostState), | ||
Status: uint32(txReceipt.Status), | ||
Type: uint32(txReceipt.Type), | ||
BlobGasPrice: blobGasPrice, | ||
BlobGasUsed: uint64(txReceipt.BlobGasUsed), | ||
}, | ||
}, | ||
} | ||
|
||
// Only add TxReceipt if it exists | ||
if txReceipt != nil { | ||
var bloom []byte | ||
bloom, _ = txReceipt.Bloom.MarshalText() | ||
|
||
blobGasPrice := uint64(0) | ||
if txReceipt.BlobGasPrice != nil { | ||
blobGasPrice = uint64(txReceipt.BlobGasPrice.Int64()) | ||
} | ||
|
||
// Get the transaction to access From and To fields | ||
tx, _, err := r.client.TransactionByHash(context.Background(), txReceipt.TxHash) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get transaction: %w", err) | ||
} | ||
|
||
// Get the sender address using the newer method | ||
signer := types.LatestSignerForChainID(tx.ChainId()) | ||
from, err := types.Sender(signer, tx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get sender from transaction: %w", err) | ||
} | ||
|
||
outputData.ContractWrite.TxReceipt = &avsproto.Evm_TransactionReceipt{ | ||
Hash: txReceipt.TxHash.Hex(), | ||
BlockHash: txReceipt.BlockHash.Hex(), | ||
BlockNumber: uint64(txReceipt.BlockNumber.Int64()), | ||
From: from.Hex(), | ||
To: tx.To().Hex(), | ||
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. These missing fields are updated, and verified in |
||
GasUsed: txReceipt.GasUsed, | ||
GasPrice: uint64(txReceipt.EffectiveGasPrice.Int64()), | ||
CumulativeGasUsed: txReceipt.CumulativeGasUsed, | ||
Fee: uint64(txReceipt.GasUsed * txReceipt.EffectiveGasPrice.Uint64()), | ||
ContractAddress: txReceipt.ContractAddress.Hex(), | ||
Index: uint64(txReceipt.TransactionIndex), | ||
Logs: make([]string, len(txReceipt.Logs)), | ||
LogsBloom: common.Bytes2Hex(bloom), | ||
Root: common.Bytes2Hex(txReceipt.PostState), | ||
Status: uint32(txReceipt.Status), | ||
Type: uint32(txReceipt.Type), | ||
BlobGasPrice: blobGasPrice, | ||
BlobGasUsed: uint64(txReceipt.BlobGasUsed), | ||
} | ||
|
||
// Convert logs to JSON strings for storage in the protobuf message | ||
for i, log := range txReceipt.Logs { | ||
logBytes, err := json.Marshal(log) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal log: %w", err) | ||
} | ||
outputData.ContractWrite.TxReceipt.Logs[i] = string(logBytes) | ||
} | ||
} | ||
chrisli30 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
s.OutputData = outputData | ||
r.SetOutputVarForStep(stepID, map[string]any{ | ||
"userOp": outputData.ContractWrite.UserOp, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.