Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions client/cli/src/frontier_db_cmd/mapping_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
.client
.runtime_api()
.current_transaction_statuses(*substrate_block_hash)
.map_err(|e| format!("{:?}", e))?
.map_err(|e| format!("{e:?}"))?
{
statuses
.iter()
Expand All @@ -114,7 +114,7 @@ where
// Given ethereum block hash, get substrate block hash.
(Column::Block, MappingKey::EthBlockOrTransactionHash(ethereum_block_hash)) => {
let value = self.backend.mapping().block_hash(ethereum_block_hash)?;
println!("{:?}", value);
println!("{value:?}");
}
// Given ethereum transaction hash, get transaction metadata.
(
Expand All @@ -125,7 +125,7 @@ where
.backend
.mapping()
.transaction_metadata(ethereum_transaction_hash)?;
println!("{:?}", value);
println!("{value:?}");
}
_ => return Err(self.key_column_error(key, value)),
},
Expand All @@ -145,7 +145,7 @@ where
.client
.runtime_api()
.current_transaction_statuses(*substrate_block_hash)
.map_err(|e| format!("{:?}", e))?
.map_err(|e| format!("{e:?}"))?
{
statuses
.iter()
Expand Down
6 changes: 3 additions & 3 deletions client/cli/src/frontier_db_cmd/meta_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl FromStr for MetaKey {
match input {
x if x == tips => Ok(MetaKey::Tips),
y if y == schema => Ok(MetaKey::Schema),
_ => Err(format!("`{:?}` is not a meta column static key", input).into()),
_ => Err(format!("`{input:?}` is not a meta column static key").into()),
}
}
}
Expand Down Expand Up @@ -99,12 +99,12 @@ impl<'a, B: BlockT, C: HeaderBackend<B>> MetaDb<'a, B, C> {
// Read meta column, static tips key.
MetaKey::Tips => {
let value = self.backend.meta().current_syncing_tips()?;
println!("{:?}", value);
println!("{value:?}");
}
// Read meta column, static schema cache key.
MetaKey::Schema => {
let value = self.backend.meta().ethereum_schema()?;
println!("{:?}", value);
println!("{value:?}");
}
},
Operation::Update => match (key, value) {
Expand Down
2 changes: 2 additions & 0 deletions client/cli/src/frontier_db_cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![allow(clippy::result_large_err)]

mod mapping_db;
mod meta_db;
#[cfg(test)]
Expand Down
14 changes: 7 additions & 7 deletions client/cli/src/frontier_db_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ fn commitment_create() {
// Run the command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
assert!(cmd(
format!("{:?}", ethereum_block_hash),
format!("{ethereum_block_hash:?}"),
Some(test_value_path.clone()),
Operation::Create,
Column::Block
Expand All @@ -596,7 +596,7 @@ fn commitment_create() {

// Expect a second command run to fail, as the key is not empty anymore.
assert!(cmd(
format!("{:?}", ethereum_block_hash),
format!("{ethereum_block_hash:?}"),
Some(test_value_path),
Operation::Create,
Column::Block
Expand Down Expand Up @@ -655,7 +655,7 @@ fn commitment_update() {
// Run the command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
assert!(cmd(
format!("{:?}", ethereum_block_hash),
format!("{ethereum_block_hash:?}"),
Some(test_value_path),
Operation::Create,
Column::Block
Expand Down Expand Up @@ -703,7 +703,7 @@ fn commitment_update() {
// Run the command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
assert!(cmd(
format!("{:?}", ethereum_block_hash),
format!("{ethereum_block_hash:?}"),
Some(test_value_path),
Operation::Update,
Column::Block
Expand Down Expand Up @@ -780,7 +780,7 @@ fn mapping_read_works() {
// Create command using some ethereum block hash as key.
let ethereum_block_hash = H256::default();
assert!(cmd(
format!("{:?}", ethereum_block_hash),
format!("{ethereum_block_hash:?}"),
Some(test_value_path),
Operation::Create,
Column::Block,
Expand All @@ -790,7 +790,7 @@ fn mapping_read_works() {

// Read block command.
assert!(cmd(
format!("{:?}", ethereum_block_hash),
format!("{ethereum_block_hash:?}"),
None,
Operation::Read,
Column::Block
Expand All @@ -800,7 +800,7 @@ fn mapping_read_works() {

// Read transaction command.
assert!(cmd(
format!("{:?}", t1_hash),
format!("{t1_hash:?}"),
None,
Operation::Read,
Column::Transaction
Expand Down
15 changes: 4 additions & 11 deletions client/cli/src/frontier_db_cmd/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,20 @@ pub trait FrontierDbMessage {
key: K,
value: &V,
) -> sc_cli::Error {
format!(
"Key `{:?}` and Value `{:?}` are not compatible with this operation",
key, value
)
.into()
format!("Key `{key:?}` and Value `{value:?}` are not compatible with this operation").into()
}

fn key_column_error<K: core::fmt::Debug, V: core::fmt::Debug>(
&self,
key: K,
value: &V,
) -> sc_cli::Error {
format!(
"Key `{:?}` and Column `{:?}` are not compatible with this operation",
key, value
)
.into()
format!("Key `{key:?}` and Column `{value:?}` are not compatible with this operation")
.into()
}

fn key_not_empty_error<K: core::fmt::Debug>(&self, key: K) -> sc_cli::Error {
format!("Operation not allowed for non-empty Key `{:?}`", key).into()
format!("Operation not allowed for non-empty Key `{key:?}`").into()
}

#[cfg(not(test))]
Expand Down
4 changes: 2 additions & 2 deletions client/db/src/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub struct MappingDb<Block> {
impl<Block: BlockT> MappingDb<Block> {
pub fn is_synced(&self, block_hash: &Block::Hash) -> Result<bool, String> {
match self.db.get(columns::SYNCED_MAPPING, &block_hash.encode()) {
Some(raw) => Ok(bool::decode(&mut &raw[..]).map_err(|e| format!("{:?}", e))?),
Some(raw) => Ok(bool::decode(&mut &raw[..]).map_err(|e| format!("{e:?}"))?),
None => Ok(false),
}
}
Expand All @@ -274,7 +274,7 @@ impl<Block: BlockT> MappingDb<Block> {
.get(columns::BLOCK_MAPPING, &ethereum_block_hash.encode())
{
Some(raw) => Ok(Some(
Vec::<Block::Hash>::decode(&mut &raw[..]).map_err(|e| format!("{:?}", e))?,
Vec::<Block::Hash>::decode(&mut &raw[..]).map_err(|e| format!("{e:?}"))?,
)),
None => Ok(None),
}
Expand Down
2 changes: 1 addition & 1 deletion client/db/src/kv/parity_db_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn handle_err<T>(result: parity_db::Result<T>) -> T {
match result {
Ok(r) => r,
Err(e) => {
panic!("Critical database error: {:?}", e);
panic!("Critical database error: {e:?}");
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions client/db/src/kv/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@ impl fmt::Display for UpgradeError {
)
}
UpgradeError::UnsupportedVersion(version) => {
write!(f, "Database version no longer supported: {}", version)
write!(f, "Database version no longer supported: {version}")
}
UpgradeError::FutureDatabaseVersion(version) => {
write!(
f,
"Database version comes from future version of the client: {}",
version
"Database version comes from future version of the client: {version}"
)
}
UpgradeError::Io(err) => write!(f, "Io error: {}", err),
UpgradeError::Io(err) => write!(f, "Io error: {err}"),
}
}
}
Expand Down Expand Up @@ -131,7 +130,7 @@ pub(crate) fn current_version(path: &Path) -> UpgradeResult<u32> {
Err(ref err) if err.kind() == ErrorKind::NotFound => {
fs::create_dir_all(path)?;
let mut file = fs::File::create(version_file_path(path))?;
file.write_all(format!("{}", CURRENT_VERSION).as_bytes())?;
file.write_all(format!("{CURRENT_VERSION}").as_bytes())?;
Ok(CURRENT_VERSION)
}
Err(_) => Err(UpgradeError::UnknownDatabaseVersion),
Expand All @@ -150,7 +149,7 @@ pub(crate) fn current_version(path: &Path) -> UpgradeResult<u32> {
pub(crate) fn update_version(path: &Path) -> io::Result<()> {
fs::create_dir_all(path)?;
let mut file = fs::File::create(version_file_path(path))?;
file.write_all(format!("{}", CURRENT_VERSION).as_bytes())?;
file.write_all(format!("{CURRENT_VERSION}").as_bytes())?;
Ok(())
}

Expand Down Expand Up @@ -211,7 +210,7 @@ pub(crate) fn migrate_1_to_2_rocks_db<Block: BlockT, C: HeaderBackend<Block>>(
}
}
db.write(transaction)
.map_err(|_| io::Error::new(ErrorKind::Other, "Failed to commit on migrate_1_to_2"))?;
.map_err(|_| io::Error::other("Failed to commit on migrate_1_to_2"))?;
log::debug!(
target: "fc-db-upgrade",
"🔨 Success {}, error {}.",
Expand Down Expand Up @@ -265,7 +264,7 @@ pub(crate) fn migrate_1_to_2_parity_db<Block: BlockT, C: HeaderBackend<Block>>(
for ethereum_hash in ethereum_hashes {
let mut maybe_error = true;
if let Some(substrate_hash) = db.get(super::columns::BLOCK_MAPPING as u8, ethereum_hash).map_err(|_|
io::Error::new(ErrorKind::Other, "Key does not exist")
io::Error::other("Key does not exist")
)? {
// Only update version1 data
let decoded = Vec::<Block::Hash>::decode(&mut &substrate_hash[..]);
Expand All @@ -289,15 +288,15 @@ pub(crate) fn migrate_1_to_2_parity_db<Block: BlockT, C: HeaderBackend<Block>>(
}
}
db.commit(transaction)
.map_err(|_| io::Error::new(ErrorKind::Other, "Failed to commit on migrate_1_to_2"))?;
.map_err(|_| io::Error::other("Failed to commit on migrate_1_to_2"))?;
Ok(())
};

let mut db_cfg = parity_db::Options::with_columns(db_path, V2_NUM_COLUMNS as u8);
db_cfg.columns[super::columns::BLOCK_MAPPING as usize].btree_index = true;

let db = parity_db::Db::open_or_create(&db_cfg)
.map_err(|_| io::Error::new(ErrorKind::Other, "Failed to open db"))?;
.map_err(|_| io::Error::other("Failed to open db"))?;

// Get all the block hashes we need to update
let ethereum_hashes: Vec<_> = match db.iter(super::columns::BLOCK_MAPPING as u8) {
Expand Down
4 changes: 2 additions & 2 deletions client/db/src/kv/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn open_kvdb_rocksdb<Block: BlockT, C: HeaderBackend<Block>>(
let mut db_config = kvdb_rocksdb::DatabaseConfig::with_columns(super::columns::NUM_COLUMNS);
db_config.create_if_missing = create;

let db = kvdb_rocksdb::Database::open(&db_config, path).map_err(|err| format!("{}", err))?;
let db = kvdb_rocksdb::Database::open(&db_config, path).map_err(|err| format!("{err}"))?;
// write database version only after the database is successfully opened
#[cfg(not(test))]
super::upgrade::update_version(path).map_err(|_| "Cannot update db version".to_string())?;
Expand Down Expand Up @@ -102,7 +102,7 @@ fn open_parity_db<Block: BlockT, C: HeaderBackend<Block>>(
let mut config = parity_db::Options::with_columns(path, super::columns::NUM_COLUMNS as u8);
config.columns[super::columns::BLOCK_MAPPING as usize].btree_index = true;

let db = parity_db::Db::open_or_create(&config).map_err(|err| format!("{}", err))?;
let db = parity_db::Db::open_or_create(&config).map_err(|err| format!("{err}"))?;
// write database version only after the database is successfully opened
#[cfg(not(test))]
super::upgrade::update_version(path).map_err(|_| "Cannot update db version".to_string())?;
Expand Down
10 changes: 5 additions & 5 deletions client/db/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ impl<Block: BlockT<Hash = H256>> fc_api::Backend<Block> for Backend<Block> {
.fetch_one(self.pool())
.await
.map(|row| H256::from_slice(&row.get::<Vec<u8>, _>(0)[..]))
.map_err(|e| format!("Failed to fetch oldest block hash: {}", e))
.map_err(|e| format!("Failed to fetch oldest block hash: {e}"))
}

async fn latest_block_hash(&self) -> Result<Block::Hash, String> {
Expand All @@ -836,7 +836,7 @@ impl<Block: BlockT<Hash = H256>> fc_api::Backend<Block> for Backend<Block> {
.fetch_one(self.pool())
.await
.map(|row| H256::from_slice(&row.get::<Vec<u8>, _>(0)[..]))
.map_err(|e| format!("Failed to fetch best hash: {}", e))
.map_err(|e| format!("Failed to fetch best hash: {e}"))
}
}

Expand Down Expand Up @@ -880,11 +880,11 @@ impl<Block: BlockT<Hash = H256>> fc_api::LogIndexerBackend<Block> for Backend<Bl
.pool()
.acquire()
.await
.map_err(|err| format!("failed acquiring sqlite connection: {}", err))?;
.map_err(|err| format!("failed acquiring sqlite connection: {err}"))?;
let log_key2 = log_key.clone();
conn.lock_handle()
.await
.map_err(|err| format!("{:?}", err))?
.map_err(|err| format!("{err:?}"))?
.set_progress_handler(self.num_ops_timeout, move || {
log::debug!(target: "frontier-sql", "Sqlite progress_handler triggered for {log_key2}");
false
Expand Down Expand Up @@ -930,7 +930,7 @@ impl<Block: BlockT<Hash = H256>> fc_api::LogIndexerBackend<Block> for Backend<Bl
drop(rows);
conn.lock_handle()
.await
.map_err(|err| format!("{:?}", err))?
.map_err(|err| format!("{err:?}"))?
.remove_progress_handler();

if let Some(err) = maybe_err {
Expand Down
Loading
Loading