Skip to content
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

Merged
merged 7 commits into from
Sep 16, 2024

Conversation

Ethnical
Copy link
Collaborator

@Ethnical Ethnical commented Sep 13, 2024

Description

This PR Improve the HTTP server response + type usage common.hash instead of String. This now return the TxHash to help the triagger to quickly make sure the transaction is valid on chain.

b17dbabef0aeedc2ff6c4d1b4efdda793c78b6ca0071609094fa9052603fb8cb
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.
5d9d34a44d669815dbf6aef9e7f52d09dbe88ead5eb7b691d4d8aef91e79ea8c

Tests
Fix the tests with the new signatures.
Additional context

This is part of the https://github.com/ethereum-optimism/security-pod/issues/148

@Ethnical Ethnical requested a review from a team as a code owner September 13, 2024 21:51
@Ethnical Ethnical changed the title Improve the HTTP server response + type usage common.hash instead of string. Improve the HTTP server response + type usage common.hash instead of String. Sep 13, 2024
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.
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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 :)

Message: "🛑" + err.Error() + "🛑",
Status: http.StatusInternalServerError,
}
json.NewEncoder(w).Encode(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json.NewEncoder(w).Encode(response)
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
return
}

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json.NewEncoder(w).Encode(response)
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
return
}

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json.NewEncoder(w).Encode(response)
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
return
}

Copy link
Contributor

@raffaele-oplabs raffaele-oplabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested few changes

@Ethnical Ethnical merged commit 1eacd78 into main Sep 16, 2024
7 checks passed
@Ethnical Ethnical deleted the ethni/return-http-error branch September 16, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants