mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 22:01:04 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
@@ -14,18 +14,12 @@
|
||||
//! A `RocksDB` instance for storing parachain data; availability data, and approvals.
|
||||
|
||||
#[cfg(feature = "full-node")]
|
||||
use {
|
||||
std::io,
|
||||
std::path::PathBuf,
|
||||
std::sync::Arc,
|
||||
|
||||
kvdb::KeyValueDB,
|
||||
};
|
||||
use {kvdb::KeyValueDB, std::io, std::path::PathBuf, std::sync::Arc};
|
||||
|
||||
#[cfg(feature = "full-node")]
|
||||
mod upgrade;
|
||||
|
||||
#[cfg(any(test,feature = "full-node"))]
|
||||
#[cfg(any(test, feature = "full-node"))]
|
||||
pub(crate) mod columns {
|
||||
pub mod v0 {
|
||||
pub const NUM_COLUMNS: u32 = 3;
|
||||
@@ -40,7 +34,7 @@ pub(crate) mod columns {
|
||||
}
|
||||
|
||||
/// Columns used by different subsystems.
|
||||
#[cfg(any(test,feature = "full-node"))]
|
||||
#[cfg(any(test, feature = "full-node"))]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ColumnsConfig {
|
||||
/// The column used by the av-store for data.
|
||||
@@ -56,7 +50,7 @@ pub struct ColumnsConfig {
|
||||
}
|
||||
|
||||
/// The real columns used by the parachains DB.
|
||||
#[cfg(any(test,feature = "full-node"))]
|
||||
#[cfg(any(test, feature = "full-node"))]
|
||||
pub const REAL_COLUMNS: ColumnsConfig = ColumnsConfig {
|
||||
col_availability_data: columns::COL_AVAILABILITY_DATA,
|
||||
col_availability_meta: columns::COL_AVAILABILITY_META,
|
||||
@@ -78,11 +72,7 @@ pub struct CacheSizes {
|
||||
|
||||
impl Default for CacheSizes {
|
||||
fn default() -> Self {
|
||||
CacheSizes {
|
||||
availability_data: 25,
|
||||
availability_meta: 1,
|
||||
approval_data: 5,
|
||||
}
|
||||
CacheSizes { availability_data: 25, availability_meta: 1, approval_data: 5 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,26 +83,26 @@ pub(crate) fn other_io_error(err: String) -> io::Error {
|
||||
|
||||
/// Open the database on disk, creating it if it doesn't exist.
|
||||
#[cfg(feature = "full-node")]
|
||||
pub fn open_creating(
|
||||
root: PathBuf,
|
||||
cache_sizes: CacheSizes,
|
||||
) -> io::Result<Arc<dyn KeyValueDB>> {
|
||||
use kvdb_rocksdb::{DatabaseConfig, Database};
|
||||
pub fn open_creating(root: PathBuf, cache_sizes: CacheSizes) -> io::Result<Arc<dyn KeyValueDB>> {
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
|
||||
let path = root.join("parachains").join("db");
|
||||
|
||||
let mut db_config = DatabaseConfig::with_columns(columns::NUM_COLUMNS);
|
||||
|
||||
let _ = db_config.memory_budget
|
||||
let _ = db_config
|
||||
.memory_budget
|
||||
.insert(columns::COL_AVAILABILITY_DATA, cache_sizes.availability_data);
|
||||
let _ = db_config.memory_budget
|
||||
let _ = db_config
|
||||
.memory_budget
|
||||
.insert(columns::COL_AVAILABILITY_META, cache_sizes.availability_meta);
|
||||
let _ = db_config.memory_budget
|
||||
let _ = db_config
|
||||
.memory_budget
|
||||
.insert(columns::COL_APPROVAL_DATA, cache_sizes.approval_data);
|
||||
|
||||
let path_str = path.to_str().ok_or_else(|| other_io_error(
|
||||
format!("Bad database path: {:?}", path),
|
||||
))?;
|
||||
let path_str = path
|
||||
.to_str()
|
||||
.ok_or_else(|| other_io_error(format!("Bad database path: {:?}", path)))?;
|
||||
|
||||
std::fs::create_dir_all(&path_str)?;
|
||||
upgrade::try_upgrade_db(&path)?;
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
|
||||
//! Migration code for the parachain's DB.
|
||||
|
||||
|
||||
#![cfg(feature = "full-node")]
|
||||
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
fs, io,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
type Version = u32;
|
||||
|
||||
@@ -36,10 +36,7 @@ pub enum Error {
|
||||
#[error("The version file format is incorrect")]
|
||||
CorruptedVersionFile,
|
||||
#[error("Future version (expected {current:?}, found {got:?})")]
|
||||
FutureVersion {
|
||||
current: Version,
|
||||
got: Version,
|
||||
},
|
||||
FutureVersion { current: Version, got: Version },
|
||||
}
|
||||
|
||||
impl From<Error> for io::Error {
|
||||
@@ -58,10 +55,7 @@ pub fn try_upgrade_db(db_path: &Path) -> Result<(), Error> {
|
||||
match current_version(db_path)? {
|
||||
0 => migrate_from_version_0_to_1(db_path)?,
|
||||
CURRENT_VERSION => (),
|
||||
v => return Err(Error::FutureVersion {
|
||||
current: CURRENT_VERSION,
|
||||
got: v,
|
||||
}),
|
||||
v => return Err(Error::FutureVersion { current: CURRENT_VERSION, got: v }),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,13 +86,13 @@ fn version_file_path(path: &Path) -> PathBuf {
|
||||
file_path
|
||||
}
|
||||
|
||||
|
||||
/// Migration from version 0 to version 1:
|
||||
/// * the number of columns has changed from 3 to 5;
|
||||
fn migrate_from_version_0_to_1(path: &Path) -> Result<(), Error> {
|
||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
|
||||
let db_path = path.to_str()
|
||||
let db_path = path
|
||||
.to_str()
|
||||
.ok_or_else(|| super::other_io_error("Invalid database path".into()))?;
|
||||
let db_cfg = DatabaseConfig::with_columns(super::columns::v0::NUM_COLUMNS);
|
||||
let db = Database::open(&db_cfg, db_path)?;
|
||||
|
||||
Reference in New Issue
Block a user