-
Notifications
You must be signed in to change notification settings - Fork 742
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
(fix): HTTP error handling in VC API #4606
Conversation
@michaelsproul, since this PR got merged, shall I update to use the function |
I think it's OK to duplicate the definition for now. Or we could move |
@protocolwhisper looks like there are a few CI failures, would you mind taking a look? |
This reverts commit 24fa06b.
@michaelsproul @jimmygchen Hello! I'm currently facing an issue. I've made changes to the function as follows: pub async fn blocking_signed_json_task<S, F, T>(signer: S, func: F) -> Response<Body>
where
S: Fn(&[u8]) -> String,
F: FnOnce() -> Result<T, Rejection> + Send + 'static,
T: Reply + Send + 'static,
{
// Get the Result from the blocking task
let result = warp_utils::task::blocking_task(func).await;
// Convert the result using your convert_rejection function
let mut response = convert_rejection(result).await;
// Process the response for the signature
let body: &Vec<u8> = response.body(); // NOTE: Ensure `body` method exists and returns a Vec<u8>
let signature = signer(body);
let header_value = HeaderValue::from_str(&signature).expect("hash can be encoded as header");
response.headers_mut().append("Signature", header_value);
response
} |
validator_client/src/http_api/mod.rs
Outdated
/// | ||
/// This function should *always* be used to convert rejections into responses. This prevents warp | ||
/// from trying to backtrack in strange ways. See: https://github.com/sigp/lighthouse/issues/3404 | ||
pub async fn convert_with_header<T: Reply>(res: Result<T, warp::Rejection>) -> resp { |
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.
It seems like this function isn't used anywhere and can be removed? (There are some compilation errors as well)
validator_client/src/http_api/mod.rs
Outdated
response | ||
}) | ||
let result = warp_utils::task::blocking_task(func).await; | ||
let conversion = convert_rejection(result).await; // It handles the rejection |
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.
I'm not following the logic here, convert_rejection
isn't available in the scope, perhaps you're trying to call the convert_with_header
you defined above?
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.
Right, I’ve already modified it but haven’t uploaded the last commit. I’m using ‘convert_with_header’ instead of ‘convert_rejection
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.
I've made significant progress. I'll check tomorrow to see if only the .then
is causing the failure, and then I'll modify the handlers that call blocking_signed_task
:)
@protocolwhisper I think it's best to go through the compiler errors - the explanations are usually pretty clear, there are a few easy ones to fix, e.g. method not found, variable not found, I'd suggest to fix those first if you're not sure where to start. I've pointed out 2 of these in the above comments, let us know if there's any specific error that you're struggling to resolve. |
@michaelsproul @jimmygchen I've updated the latest PR with the necessary changes and it now passes the tests for the module. Let me know your feedback :) . |
Hello 👋🏽, can I get your comments on this PR? I’d like to make changes since the function’s signature has been modified. @michaelsproul @jimmygchen |
Hi @protocolwhisper, thanks for the update! It looks like @michaelsproul has triggered a CI run, and there are some CI failures possibly related to the changes, would you mind taking a look please?
|
Gotcha, I corrected the lint but since we changed the signature from |
This reverts commit f05c3fb.
Feel free to ignore the test failure, it seems to be related to an issue we discovered earlier today, which is now being addressed in #4868. I'll re-run the fail jobs now. |
validator_client/src/http_api/mod.rs
Outdated
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.
This is bit isn't really doing what the function is advertised to do; I think it probably falls under the responsibility of the blocking_signed_json_task
function instead as it describes here:
lighthouse/validator_client/src/http_api/mod.rs
Lines 1277 to 1280 in f77a5a0
/// Executes `func` in blocking tokio task (i.e., where long-running tasks are permitted). | |
/// JSON-encodes the return value of `func`, using the `signer` function to produce a signature of | |
/// those bytes. | |
pub async fn blocking_signed_json_task<S, F, T>(signer: S, func: F) -> Response<Vec<u8>> |
Is it possible to move this block there to keep the convert_rejection
only do what it's supposed to do?
Convert a warp
Rejection
into aResponse
.
If it's too much of an issue, we could consider renaming this function to something like convert_into_json_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.
Hi @protocolwhisper
Thanks for the updates, I've added a few more comments. Let me know if you have any questions.
Hi @jimmygchen |
Heyy , can I get any comments about this? |
Sorry @protocolwhisper but we've decided to delete the response signing altogether, so this change has been rolled into the PR that implements that: #5529 |
Got it, I'll close this issue then |
@protocolwhisper Sorry this one didn't work out, thanks for your help though! 🙏 |
Issue Addressed
Closes #4597
Proposed Changes
Updated Handler Return Types: Handlers now return
Response
directlyRefactored blocking_signed_json_task function
Additional Info
No