-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Implement getSlot RPC method #33
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
16 commits
Select commit
Hold shift + click to select a range
abd6762
XC-292: Add num_subnet_nodes and mode to install args
lpahlavi 02d1534
XC-292: Add getSlot implementation
lpahlavi 4d399c6
XC-292: Formatting
lpahlavi 3322e2a
XC-292: Candid
lpahlavi 6f4ccaf
XC-292: Newlines
lpahlavi 786c2e9
XC-292: Fix integration tests
lpahlavi c9c04b5
XC-292: Formatting
lpahlavi 2e81c2b
XC-292: Formatting
lpahlavi c67f9f1
Merge branch 'main' into lpahlavi/XC-292-get-slot
lpahlavi 5076487
Revert "Merge branch 'main' into lpahlavi/XC-292-get-slot"
lpahlavi 619dfee
XC-292: Address review feedback
lpahlavi 7467f16
XC-292: Formatting
lpahlavi c7b3f5e
XC-292: Remove unnecessary annotations
lpahlavi c5eae49
XC-292: Address review feedback
lpahlavi d65b4b9
XC-292: Use derive_more::From
lpahlavi 9d88674
XC-292: Formatting
lpahlavi 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| use crate::{ | ||
| rpc_client::{MultiCallError, SolRpcClient}, | ||
| types::MultiRpcResult, | ||
| }; | ||
| use sol_rpc_types::{GetSlotParams, RpcConfig, RpcResult, RpcSources}; | ||
| use solana_clock::Slot; | ||
|
|
||
| fn process_result<T>(result: Result<T, MultiCallError<T>>) -> MultiRpcResult<T> { | ||
| match result { | ||
| Ok(value) => MultiRpcResult::Consistent(Ok(value)), | ||
| Err(err) => match err { | ||
| MultiCallError::ConsistentError(err) => MultiRpcResult::Consistent(Err(err)), | ||
| MultiCallError::InconsistentResults(multi_call_results) => { | ||
| let results = multi_call_results.into_vec(); | ||
| results.iter().for_each(|(_service, _service_result)| { | ||
| // TODO XC-296: Add metrics for inconsistent providers | ||
| }); | ||
| MultiRpcResult::Inconsistent(results) | ||
| } | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /// Adapt the `EthRpcClient` to the `Candid` interface used by the EVM-RPC canister. | ||
| pub struct CandidRpcClient { | ||
| client: SolRpcClient, | ||
| } | ||
|
|
||
| impl CandidRpcClient { | ||
| pub fn new(source: RpcSources, config: Option<RpcConfig>) -> RpcResult<Self> { | ||
| Ok(Self { | ||
| client: SolRpcClient::new(source, config)?, | ||
| }) | ||
| } | ||
|
|
||
| pub async fn get_slot(&self, params: GetSlotParams) -> MultiRpcResult<Slot> { | ||
| process_result(self.client.get_slot(params).await) | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use canhttp::{ | ||
| http::{ | ||
| json::{JsonRequestConversionError, JsonResponseConversionError}, | ||
| FilterNonSuccessfulHttpResponseError, HttpRequestConversionError, | ||
| HttpResponseConversionError, | ||
| }, | ||
| CyclesAccountingError, HttpsOutcallError, IcError, | ||
| }; | ||
| use derive_more::From; | ||
| use sol_rpc_types::{HttpOutcallError, ProviderError, RpcError}; | ||
| use thiserror::Error; | ||
|
|
||
| #[derive(Clone, Debug, Error, From)] | ||
| pub enum HttpClientError { | ||
| #[error("IC error: {0}")] | ||
| IcError(IcError), | ||
| #[error("unknown error (most likely sign of a bug): {0}")] | ||
| NotHandledError(String), | ||
| #[error("cycles accounting error: {0}")] | ||
| CyclesAccountingError(CyclesAccountingError), | ||
| #[error("HTTP response was not successful: {0}")] | ||
| UnsuccessfulHttpResponse(FilterNonSuccessfulHttpResponseError<Vec<u8>>), | ||
| #[error("Error converting response to JSON: {0}")] | ||
| InvalidJsonResponse(JsonResponseConversionError), | ||
| } | ||
|
|
||
| impl From<HttpRequestConversionError> for HttpClientError { | ||
| fn from(value: HttpRequestConversionError) -> Self { | ||
| HttpClientError::NotHandledError(value.to_string()) | ||
| } | ||
| } | ||
|
|
||
| impl From<HttpResponseConversionError> for HttpClientError { | ||
| fn from(value: HttpResponseConversionError) -> Self { | ||
| // Replica should return valid http::Response | ||
| HttpClientError::NotHandledError(value.to_string()) | ||
| } | ||
| } | ||
|
|
||
| impl From<JsonRequestConversionError> for HttpClientError { | ||
| fn from(value: JsonRequestConversionError) -> Self { | ||
| HttpClientError::NotHandledError(value.to_string()) | ||
| } | ||
| } | ||
|
|
||
| impl From<HttpClientError> for RpcError { | ||
| fn from(error: HttpClientError) -> Self { | ||
| match error { | ||
| HttpClientError::IcError(IcError { code, message }) => { | ||
| RpcError::HttpOutcallError(HttpOutcallError::IcError { code, message }) | ||
| } | ||
| HttpClientError::NotHandledError(e) => RpcError::ValidationError(e), | ||
| HttpClientError::CyclesAccountingError( | ||
| CyclesAccountingError::InsufficientCyclesError { expected, received }, | ||
| ) => RpcError::ProviderError(ProviderError::TooFewCycles { expected, received }), | ||
| HttpClientError::InvalidJsonResponse( | ||
| JsonResponseConversionError::InvalidJsonResponse { | ||
| status, | ||
| body, | ||
| parsing_error, | ||
| }, | ||
| ) => RpcError::HttpOutcallError(HttpOutcallError::InvalidHttpJsonRpcResponse { | ||
| status, | ||
| body, | ||
| parsing_error: Some(parsing_error), | ||
| }), | ||
| HttpClientError::UnsuccessfulHttpResponse( | ||
| FilterNonSuccessfulHttpResponseError::UnsuccessfulResponse(response), | ||
| ) => RpcError::HttpOutcallError(HttpOutcallError::InvalidHttpJsonRpcResponse { | ||
| status: response.status().as_u16(), | ||
| body: String::from_utf8_lossy(response.body()).to_string(), | ||
| parsing_error: None, | ||
| }), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl HttpsOutcallError for HttpClientError { | ||
| fn is_response_too_large(&self) -> bool { | ||
| match self { | ||
| HttpClientError::IcError(e) => e.is_response_too_large(), | ||
| HttpClientError::NotHandledError(_) | ||
| | HttpClientError::CyclesAccountingError(_) | ||
| | HttpClientError::UnsuccessfulHttpResponse(_) | ||
| | HttpClientError::InvalidJsonResponse(_) => false, | ||
| } | ||
| } | ||
| } |
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.