-
Notifications
You must be signed in to change notification settings - Fork 519
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
archive: Implement height, hashByHeight and call #1582
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d259a73
archive: Implement finalized height
lexnv 62a1fa0
archive/tests: Test archive_unstable_finalizedHeight
lexnv c7129d8
archive: Implement archive_unstable_hashByHeight
lexnv 92f4a1b
archive/tests: Test archive_hash_by_height
lexnv c9ad16d
archive: Implement archive_unstable_call
lexnv 1d3d63d
archive: Simplify call and add tests
lexnv e4f1796
archive: Iterate blocks from leaves to finalized
lexnv c8d2ed3
archive: Map invalid params
lexnv fca587f
Update substrate/client/rpc-spec-v2/src/archive/archive.rs
lexnv 3811cd2
archive: Use u64 instead of u32
lexnv 21a2048
rpc-spec: Introduce method response struct
lexnv 5e08f51
archive/tests: Adjust tests to the new format
lexnv File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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,66 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! Error helpers for `archive` RPC module. | ||
|
||
use jsonrpsee::{ | ||
core::Error as RpcError, | ||
types::error::{CallError, ErrorObject}, | ||
}; | ||
|
||
/// ChainHead RPC errors. | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
/// Invalid parameter provided to the RPC method. | ||
#[error("Invalid parameter: {0}")] | ||
InvalidParam(String), | ||
/// Runtime call failed. | ||
#[error("Runtime call: {0}")] | ||
RuntimeCall(String), | ||
/// Failed to fetch leaves. | ||
#[error("Failed to fetch leaves of the chain: {0}")] | ||
FetchLeaves(String), | ||
} | ||
|
||
// Base code for all `archive` errors. | ||
const BASE_ERROR: i32 = 3000; | ||
/// Invalid parameter error. | ||
const INVALID_PARAM_ERROR: i32 = BASE_ERROR + 1; | ||
/// Runtime call error. | ||
const RUNTIME_CALL_ERROR: i32 = BASE_ERROR + 2; | ||
/// Failed to fetch leaves. | ||
const FETCH_LEAVES_ERROR: i32 = BASE_ERROR + 3; | ||
|
||
impl From<Error> for ErrorObject<'static> { | ||
fn from(e: Error) -> Self { | ||
let msg = e.to_string(); | ||
|
||
match e { | ||
Error::InvalidParam(_) => ErrorObject::owned(INVALID_PARAM_ERROR, msg, None::<()>), | ||
Error::RuntimeCall(_) => ErrorObject::owned(RUNTIME_CALL_ERROR, msg, None::<()>), | ||
Error::FetchLeaves(_) => ErrorObject::owned(FETCH_LEAVES_ERROR, msg, None::<()>), | ||
} | ||
.into() | ||
} | ||
} | ||
|
||
impl From<Error> for RpcError { | ||
fn from(e: Error) -> Self { | ||
CallError::Custom(e.into()).into() | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -27,5 +27,6 @@ mod tests; | |
|
||
pub mod api; | ||
pub mod archive; | ||
pub mod error; | ||
|
||
pub use api::ArchiveApiServer; |
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.
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 wonder if it's makes sense to throw an error or something if the block number is bigger than u32::MAX instead of truncating....
It might be impossible not sure...
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 assume it'd take a few hundred years to hit, but yeah I'd be inlined to at least panic rather than saturate since the latter is hiding some issue :)
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 changed this to u64 to be extra safe here :D