Skip to content

Commit ae58255

Browse files
authored
Merge pull request #143 from koushiro/rename-error
Rename `Error` to `ArchiveError`
2 parents fc108fa + 047e0d0 commit ae58255

File tree

11 files changed

+48
-45
lines changed

11 files changed

+48
-45
lines changed

substrate-archive-backend/src/frontend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use sp_api::ConstructRuntimeApi;
3030
use sp_core::traits::SpawnNamed;
3131
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
3232

33-
use substrate_archive_common::{Error as ArchiveError, ReadOnlyDB};
33+
use substrate_archive_common::{ArchiveError, ReadOnlyDB};
3434

3535
pub use self::client::{Client, GetMetadata, GetRuntimeVersion};
3636
use crate::{read_only_backend::ReadOnlyBackend, RuntimeApiCollection};

substrate-archive-backend/src/frontend/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use sp_runtime::{
3535
traits::{Block as BlockT, Header as HeaderT, One},
3636
};
3737

38-
use substrate_archive_common::{Error, ReadOnlyDB, Result};
38+
use substrate_archive_common::{ArchiveError, ReadOnlyDB, Result};
3939

4040
use crate::read_only_backend::{ReadOnlyBackend, TrieState};
4141

@@ -78,7 +78,7 @@ where
7878
}
7979

8080
pub fn runtime_version_at(&self, id: &BlockId<Block>) -> Result<RuntimeVersion> {
81-
self.executor.runtime_version(id).map_err(Error::from)
81+
self.executor.runtime_version(id).map_err(ArchiveError::from)
8282
}
8383

8484
/// get the backend for this client instance

substrate-archive-backend/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
3232
#[cfg(feature = "logging")]
3333
pub use substrate_archive_common::util::init_logger;
3434

35-
use self::{
36-
frontend::{GetMetadata, GetRuntimeVersion},
37-
};
35+
use self::frontend::{GetMetadata, GetRuntimeVersion};
3836
// re-exports
3937
pub use self::{
4038
block_exec::BlockExecutor,

substrate-archive-backend/src/runtime_version_cache.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sp_state_machine::BasicExternalities;
3333
use sp_storage::well_known_keys;
3434
use sp_version::RuntimeVersion;
3535

36-
use substrate_archive_common::{types::Block, util, Error, ReadOnlyDB, Result};
36+
use substrate_archive_common::{types::Block, util, ArchiveError, ReadOnlyDB, Result};
3737

3838
use crate::read_only_backend::ReadOnlyBackend;
3939

@@ -84,8 +84,10 @@ impl<B: BlockT, D: ReadOnlyDB + 'static> RuntimeVersionCache<B, D> {
8484
pub fn get(&self, hash: B::Hash) -> Result<Option<RuntimeVersion>> {
8585
// Getting code from the backend is the slowest part of this. Takes an average of
8686
// 6ms
87-
let code =
88-
self.backend.storage(hash, well_known_keys::CODE).ok_or_else(|| Error::from("storage does not exist"))?;
87+
let code = self
88+
.backend
89+
.storage(hash, well_known_keys::CODE)
90+
.ok_or_else(|| ArchiveError::from("storage does not exist"))?;
8991

9092
let code_hash = util::make_hash(&code);
9193
if self.versions.load().contains_key(&code_hash) {
@@ -95,7 +97,7 @@ impl<B: BlockT, D: ReadOnlyDB + 'static> RuntimeVersionCache<B, D> {
9597
let mut ext: BasicExternalities = BasicExternalities::default();
9698
ext.register_extension(CallInWasmExt::new(self.exec.clone()));
9799
let v: RuntimeVersion = ext.execute_with(|| {
98-
let ver = sp_io::misc::runtime_version(&code).ok_or(Error::WasmExecutionError)?;
100+
let ver = sp_io::misc::runtime_version(&code).ok_or(ArchiveError::WasmExecutionError)?;
99101
decode_version(ver.as_slice())
100102
})?;
101103
log::debug!("Registered New Runtime Version: {:?}", v);
@@ -141,15 +143,18 @@ impl<B: BlockT, D: ReadOnlyDB + 'static> RuntimeVersionCache<B, D> {
141143
if blocks.is_empty() {
142144
return Ok(());
143145
} else if blocks.len() == 1 {
144-
let version = self.get(blocks[0].block.header().hash())?.ok_or_else(|| Error::from("Version not found"))?;
146+
let version =
147+
self.get(blocks[0].block.header().hash())?.ok_or_else(|| ArchiveError::from("Version not found"))?;
145148
versions.push(VersionRange::new(&blocks[0], &blocks[0], version));
146149
return Ok(());
147150
}
148151

149-
let first =
150-
self.get(blocks.first().unwrap().block.header().hash())?.ok_or_else(|| Error::from("Version not found"))?;
151-
let last =
152-
self.get(blocks.last().unwrap().block.header().hash())?.ok_or_else(|| Error::from("Version not found"))?;
152+
let first = self
153+
.get(blocks.first().unwrap().block.header().hash())?
154+
.ok_or_else(|| ArchiveError::from("Version not found"))?;
155+
let last = self
156+
.get(blocks.last().unwrap().block.header().hash())?
157+
.ok_or_else(|| ArchiveError::from("Version not found"))?;
153158

154159
if first.spec_version != last.spec_version && blocks.len() > 2 {
155160
let half = blocks.len() / 2;

substrate-archive-backend/src/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use sp_runtime::{
2626
traits::{Block as BlockT, Header as HeaderT, UniqueSaturatedFrom, UniqueSaturatedInto, Zero},
2727
};
2828

29-
use substrate_archive_common::{Error, ReadOnlyDB, Result};
29+
use substrate_archive_common::{ArchiveError, ReadOnlyDB, Result};
3030

3131
pub type NumberIndexKey = [u8; 4];
3232

@@ -82,7 +82,7 @@ pub fn read_header<Block: BlockT, D: ReadOnlyDB>(
8282
match read_db(db, col_index, col, id)? {
8383
Some(header) => match Block::Header::decode(&mut &header[..]) {
8484
Ok(header) => Ok(Some(header)),
85-
Err(_) => Err(Error::from("Error decoding header")),
85+
Err(_) => Err(ArchiveError::from("Error decoding header")),
8686
},
8787
None => Ok(None),
8888
}
@@ -115,7 +115,7 @@ where
115115
/// In the current database schema, this kind of key is only used for
116116
/// lookups into an index, NOT for storing header data or others
117117
pub fn number_index_key<N: TryInto<u32>>(n: N) -> Result<NumberIndexKey> {
118-
let n = n.try_into().map_err(|_| Error::from("Block num cannot be converted to u32"))?;
118+
let n = n.try_into().map_err(|_| ArchiveError::from("Block num cannot be converted to u32"))?;
119119

120120
Ok([(n >> 24) as u8, ((n >> 16) & 0xff) as u8, ((n >> 8) & 0xff) as u8, (n & 0xff) as u8])
121121
}

substrate-archive-common/src/error.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
use std::{env, io};
1717
use thiserror::Error;
1818

19-
pub type Result<T, E = Error> = std::result::Result<T, E>;
19+
pub type Result<T, E = ArchiveError> = std::result::Result<T, E>;
2020

2121
/// Substrate Archive Error Enum
2222
#[derive(Error, Debug)]
23-
pub enum Error {
23+
pub enum ArchiveError {
2424
#[error("Io Error")]
2525
Io(#[from] io::Error),
2626
#[error("environment variable for `DATABASE_URL` not found")]
@@ -67,34 +67,34 @@ pub enum Error {
6767
Bincode(#[from] Box<bincode::ErrorKind>),
6868
}
6969

70-
impl From<&str> for Error {
71-
fn from(e: &str) -> Error {
72-
Error::Msg(e.to_string())
70+
impl From<&str> for ArchiveError {
71+
fn from(e: &str) -> ArchiveError {
72+
ArchiveError::Msg(e.to_string())
7373
}
7474
}
7575

76-
impl From<String> for Error {
77-
fn from(e: String) -> Error {
78-
Error::Msg(e)
76+
impl From<String> for ArchiveError {
77+
fn from(e: String) -> ArchiveError {
78+
ArchiveError::Msg(e)
7979
}
8080
}
8181

8282
// this conversion is required for our Error type to be
8383
// Send + Sync
84-
impl From<sp_blockchain::Error> for Error {
85-
fn from(e: sp_blockchain::Error) -> Error {
86-
Error::Blockchain(e.to_string())
84+
impl From<sp_blockchain::Error> for ArchiveError {
85+
fn from(e: sp_blockchain::Error) -> ArchiveError {
86+
ArchiveError::Blockchain(e.to_string())
8787
}
8888
}
8989

90-
impl From<xtra::Disconnected> for Error {
91-
fn from(_: xtra::Disconnected) -> Error {
92-
Error::Disconnected
90+
impl From<xtra::Disconnected> for ArchiveError {
91+
fn from(_: xtra::Disconnected) -> ArchiveError {
92+
ArchiveError::Disconnected
9393
}
9494
}
9595

96-
impl<T> From<flume::SendError<T>> for Error {
97-
fn from(_: flume::SendError<T>) -> Error {
98-
Error::Channel
96+
impl<T> From<flume::SendError<T>> for ArchiveError {
97+
fn from(_: flume::SendError<T>) -> ArchiveError {
98+
ArchiveError::Channel
9999
}
100100
}

substrate-archive-common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ pub mod types;
2222
pub mod util;
2323

2424
pub use self::database::{KeyValuePair, ReadOnlyDB, NUM_COLUMNS};
25-
pub use self::error::{Error, Result};
25+
pub use self::error::{ArchiveError, Result};

substrate-archive-common/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::path::{Path, PathBuf};
2323
#[cfg(feature = "logging")]
2424
use fern::colors::{Color, ColoredLevelConfig};
2525

26-
use crate::error::Error as ArchiveError;
26+
use crate::error::ArchiveError;
2727

2828
#[cfg(feature = "logging")]
2929
pub fn init_logger(std: log::LevelFilter, file: log::LevelFilter) -> Result<(), ArchiveError> {

substrate-archive/src/actors/workers/blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use substrate_archive_backend::{ReadOnlyBackend, RuntimeVersionCache};
2525
use substrate_archive_common::{
2626
msg,
2727
types::{BatchBlock, Block},
28-
Error, ReadOnlyDB, Result,
28+
ArchiveError, ReadOnlyDB, Result,
2929
};
3030

3131
use crate::{
@@ -200,7 +200,7 @@ where
200200
async fn handle(&mut self, _: ReIndex, ctx: &mut Context<Self>) {
201201
match self.re_index().await {
202202
// stop if disconnected from the metadata actor
203-
Err(Error::Disconnected) => ctx.stop(),
203+
Err(ArchiveError::Disconnected) => ctx.stop(),
204204
Ok(()) => {}
205205
Err(e) => log::error!("{}", e.to_string()),
206206
}

substrate-archive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use substrate_archive_common::util::init_logger;
3838
pub use sc_executor::native_executor_instance;
3939
pub use sp_blockchain::Error as BlockchainError;
4040
pub use sp_runtime::MultiSignature;
41-
pub use substrate_archive_common::Error;
41+
pub use substrate_archive_common::ArchiveError;
4242
pub mod chain_traits {
4343
//! Traits defining functions on the client needed for indexing
4444
pub use sc_client_api::client::BlockBackend;

0 commit comments

Comments
 (0)