-
Notifications
You must be signed in to change notification settings - Fork 25
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
Improve the HTTP server response + type usage common.hash
instead of String
.
#65
Conversation
common.hash
instead of String
.
return | ||
} | ||
|
||
if (txHash != common.Hash{}) && (err != nil) { // If the transaction hash is not empty and the error is not nil we return the transaction hash. |
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.
Hi,
Just notice you have forgotten the case where the txHash
is not set while no error is returned. Although this case cannot be returned by the FetchAndExecute
function with the current implementation, it might be better to handle every possible case right now to avoid errors in the future. For example, you could return a generic http error.
if (txHash == common.hash{}) && (err == nil) {
response := Response{
Message: "🛑 Unknown error, transaction hash does not exist 🛑",
Status: http.StatusInternalServerError,
}
json.NewEncoder(w).Encode(response)
return
}
What do you think ?
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.
Thanks @nodauf, for the suggestion as you mentioned this is not used for now, but still worth it to apply right now to avoid any mistakes in the future!
I have applied the suggestion in the latest commit :)
op-defender/psp_executor/defender.go
Outdated
Message: "🛑" + err.Error() + "🛑", | ||
Status: http.StatusInternalServerError, | ||
} | ||
json.NewEncoder(w).Encode(response) |
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.
json.NewEncoder(w).Encode(response) | |
if err := json.NewEncoder(w).Encode(response); err != nil { | |
http.Error(w, "Failed to encode response", http.StatusInternalServerError) | |
return | |
} |
op-defender/psp_executor/defender.go
Outdated
Message: "🚧 Transaction Executed 🚧, but the SuperchainConfig is not *pause*. An error occured: " + err.Error() + ". The TxHash: " + txHash.Hex(), | ||
Status: http.StatusInternalServerError, | ||
} | ||
json.NewEncoder(w).Encode(response) |
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.
json.NewEncoder(w).Encode(response) | |
if err := json.NewEncoder(w).Encode(response); err != nil { | |
http.Error(w, "Failed to encode response", http.StatusInternalServerError) | |
return | |
} |
op-defender/psp_executor/defender.go
Outdated
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
response := Response{ | ||
Message: "PSP executed successfully", | ||
Message: "PSP executed successfully ✅ Transaction hash: " + txHash.Hex() + "🎉", | ||
Status: http.StatusOK, | ||
} | ||
json.NewEncoder(w).Encode(response) |
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.
json.NewEncoder(w).Encode(response) | |
if err := json.NewEncoder(w).Encode(response); err != nil { | |
http.Error(w, "Failed to encode response", http.StatusInternalServerError) | |
return | |
} |
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.
suggested few changes
Description
This PR Improve the HTTP server response + type usage
common.hash
instead ofString
. This now return theTxHash
to help the triagger to quickly make sure the transaction is valid on chain.This also introduce an error if the super-chain is not pause after the transaction has been executed without any error.
And also return an error if the superchain is paused before doing the pause.
Tests
Fix the tests with the new signatures.
Additional context
This is part of the https://github.com/ethereum-optimism/security-pod/issues/148