mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Apply some clippy lints (#11154)
* Apply some clippy hints * Revert clippy ci changes * Update client/cli/src/commands/generate.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/cli/src/commands/inspect_key.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/transactions.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/protocol.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Revert due to missing `or_default` function. * Fix compilation and simplify code * Undo change that corrupts benchmark. * fix clippy * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs remove leftovers! * Update client/tracing/src/logging/directives.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/fork-tree/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * added needed ref * Update frame/referenda/src/benchmarking.rs * Simplify byte-vec creation * let's just not overlap the ranges * Correction * cargo fmt * Update utils/frame/benchmarking-cli/src/shared/stats.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a990473cf9
commit
b581604aa7
@@ -57,14 +57,14 @@ impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for StorageDb<Bloc
|
||||
fn get(&self, key: &Block::Hash, prefix: Prefix) -> Result<Option<DBValue>, String> {
|
||||
let prefixed_key = prefixed_key::<HashFor<Block>>(key, prefix);
|
||||
if let Some(recorder) = &self.proof_recorder {
|
||||
if let Some(v) = recorder.get(&key) {
|
||||
return Ok(v.clone())
|
||||
if let Some(v) = recorder.get(key) {
|
||||
return Ok(v)
|
||||
}
|
||||
let backend_value = self
|
||||
.db
|
||||
.get(0, &prefixed_key)
|
||||
.map_err(|e| format!("Database backend error: {:?}", e))?;
|
||||
recorder.record(key.clone(), backend_value.clone());
|
||||
recorder.record(*key, backend_value.clone());
|
||||
Ok(backend_value)
|
||||
} else {
|
||||
self.db
|
||||
@@ -114,7 +114,7 @@ impl<B: BlockT> BenchmarkingState<B> {
|
||||
let mut state = BenchmarkingState {
|
||||
state: RefCell::new(None),
|
||||
db: Cell::new(None),
|
||||
root: Cell::new(root.clone()),
|
||||
root: Cell::new(root),
|
||||
genesis: Default::default(),
|
||||
genesis_root: Default::default(),
|
||||
record: Default::default(),
|
||||
@@ -123,7 +123,7 @@ impl<B: BlockT> BenchmarkingState<B> {
|
||||
child_key_tracker: Default::default(),
|
||||
whitelist: Default::default(),
|
||||
proof_recorder: record_proof.then(Default::default),
|
||||
proof_recorder_root: Cell::new(root.clone()),
|
||||
proof_recorder_root: Cell::new(root),
|
||||
enable_tracking,
|
||||
};
|
||||
|
||||
@@ -143,7 +143,7 @@ impl<B: BlockT> BenchmarkingState<B> {
|
||||
state_version,
|
||||
);
|
||||
state.genesis = transaction.clone().drain();
|
||||
state.genesis_root = root.clone();
|
||||
state.genesis_root = root;
|
||||
state.commit(root, transaction, Vec::new(), Vec::new())?;
|
||||
state.record.take();
|
||||
Ok(state)
|
||||
@@ -201,9 +201,7 @@ impl<B: BlockT> BenchmarkingState<B> {
|
||||
let mut main_key_tracker = self.main_key_tracker.borrow_mut();
|
||||
|
||||
let key_tracker = if let Some(childtrie) = childtrie {
|
||||
child_key_tracker
|
||||
.entry(childtrie.to_vec())
|
||||
.or_insert_with(|| LinkedHashMap::new())
|
||||
child_key_tracker.entry(childtrie.to_vec()).or_insert_with(LinkedHashMap::new)
|
||||
} else {
|
||||
&mut main_key_tracker
|
||||
};
|
||||
@@ -244,9 +242,7 @@ impl<B: BlockT> BenchmarkingState<B> {
|
||||
let mut main_key_tracker = self.main_key_tracker.borrow_mut();
|
||||
|
||||
let key_tracker = if let Some(childtrie) = childtrie {
|
||||
child_key_tracker
|
||||
.entry(childtrie.to_vec())
|
||||
.or_insert_with(|| LinkedHashMap::new())
|
||||
child_key_tracker.entry(childtrie.to_vec()).or_insert_with(LinkedHashMap::new)
|
||||
} else {
|
||||
&mut main_key_tracker
|
||||
};
|
||||
@@ -517,7 +513,7 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
|
||||
self.db.set(Some(db));
|
||||
}
|
||||
|
||||
self.root.set(self.genesis_root.clone());
|
||||
self.root.set(self.genesis_root);
|
||||
self.reopen()?;
|
||||
self.wipe_tracker();
|
||||
Ok(())
|
||||
@@ -612,18 +608,17 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
|
||||
if proof_recorder_root == Default::default() || proof_size == 1 {
|
||||
// empty trie
|
||||
proof_size
|
||||
} else if let Some(size) = proof.encoded_compact_size::<HashFor<B>>(proof_recorder_root)
|
||||
{
|
||||
size as u32
|
||||
} else {
|
||||
if let Some(size) = proof.encoded_compact_size::<HashFor<B>>(proof_recorder_root) {
|
||||
size as u32
|
||||
} else {
|
||||
panic!(
|
||||
"proof rec root {:?}, root {:?}, genesis {:?}, rec_len {:?}",
|
||||
self.proof_recorder_root.get(),
|
||||
self.root.get(),
|
||||
self.genesis_root,
|
||||
proof_size,
|
||||
);
|
||||
}
|
||||
panic!(
|
||||
"proof rec root {:?}, root {:?}, genesis {:?}, rec_len {:?}",
|
||||
self.proof_recorder_root.get(),
|
||||
self.root.get(),
|
||||
self.genesis_root,
|
||||
proof_size,
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -352,8 +352,8 @@ impl DatabaseSource {
|
||||
//
|
||||
// IIUC this is needed for polkadot to create its own dbs, so until it can use parity db
|
||||
// I would think rocksdb, but later parity-db.
|
||||
DatabaseSource::Auto { paritydb_path, .. } => Some(&paritydb_path),
|
||||
DatabaseSource::RocksDb { path, .. } | DatabaseSource::ParityDb { path } => Some(&path),
|
||||
DatabaseSource::Auto { paritydb_path, .. } => Some(paritydb_path),
|
||||
DatabaseSource::RocksDb { path, .. } | DatabaseSource::ParityDb { path } => Some(path),
|
||||
DatabaseSource::Custom(..) => None,
|
||||
}
|
||||
}
|
||||
@@ -478,7 +478,7 @@ impl<Block: BlockT> BlockchainDb<Block> {
|
||||
|
||||
if is_finalized {
|
||||
if with_state {
|
||||
meta.finalized_state = Some((hash.clone(), number));
|
||||
meta.finalized_state = Some((hash, number));
|
||||
}
|
||||
meta.finalized_number = number;
|
||||
meta.finalized_hash = hash;
|
||||
@@ -501,7 +501,7 @@ impl<Block: BlockT> sc_client_api::blockchain::HeaderBackend<Block> for Blockcha
|
||||
}
|
||||
let header =
|
||||
utils::read_header(&*self.db, columns::KEY_LOOKUP, columns::HEADER, id)?;
|
||||
cache_header(&mut cache, h.clone(), header.clone());
|
||||
cache_header(&mut cache, *h, header.clone());
|
||||
Ok(header)
|
||||
},
|
||||
BlockId::Number(_) =>
|
||||
@@ -517,7 +517,7 @@ impl<Block: BlockT> sc_client_api::blockchain::HeaderBackend<Block> for Blockcha
|
||||
genesis_hash: meta.genesis_hash,
|
||||
finalized_hash: meta.finalized_hash,
|
||||
finalized_number: meta.finalized_number,
|
||||
finalized_state: meta.finalized_state.clone(),
|
||||
finalized_state: meta.finalized_state,
|
||||
number_leaves: self.leaves.read().count(),
|
||||
block_gap: meta.block_gap,
|
||||
}
|
||||
@@ -540,10 +540,7 @@ impl<Block: BlockT> sc_client_api::blockchain::HeaderBackend<Block> for Blockcha
|
||||
|
||||
fn hash(&self, number: NumberFor<Block>) -> ClientResult<Option<Block::Hash>> {
|
||||
self.header(BlockId::Number(number))
|
||||
.and_then(|maybe_header| match maybe_header {
|
||||
Some(header) => Ok(Some(header.hash().clone())),
|
||||
None => Ok(None),
|
||||
})
|
||||
.map(|maybe_header| maybe_header.map(|header| header.hash()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,7 +618,7 @@ impl<Block: BlockT> sc_client_api::blockchain::Backend<Block> for BlockchainDb<B
|
||||
}
|
||||
|
||||
fn last_finalized(&self) -> ClientResult<Block::Hash> {
|
||||
Ok(self.meta.read().finalized_hash.clone())
|
||||
Ok(self.meta.read().finalized_hash)
|
||||
}
|
||||
|
||||
fn leaves(&self) -> ClientResult<Vec<Block::Hash>> {
|
||||
@@ -765,8 +762,8 @@ impl<Block: BlockT> BlockImportOperation<Block> {
|
||||
storage: Storage,
|
||||
state_version: StateVersion,
|
||||
) -> ClientResult<Block::Hash> {
|
||||
if storage.top.keys().any(|k| well_known_keys::is_child_storage_key(&k)) {
|
||||
return Err(sp_blockchain::Error::InvalidState.into())
|
||||
if storage.top.keys().any(|k| well_known_keys::is_child_storage_key(k)) {
|
||||
return Err(sp_blockchain::Error::InvalidState)
|
||||
}
|
||||
|
||||
let child_delta = storage.children_default.iter().map(|(_storage_key, child_content)| {
|
||||
@@ -1063,7 +1060,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
) -> ClientResult<Self> {
|
||||
let is_archive_pruning = config.state_pruning.is_archive();
|
||||
let blockchain = BlockchainDb::new(db.clone())?;
|
||||
let map_e = |e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e);
|
||||
let map_e = sp_blockchain::Error::from_state_db;
|
||||
let state_db: StateDb<_, _> = StateDb::new(
|
||||
config.state_pruning.clone(),
|
||||
!db.supports_ref_counting(),
|
||||
@@ -1087,7 +1084,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
is_archive: is_archive_pruning,
|
||||
io_stats: FrozenForDuration::new(std::time::Duration::from_secs(1)),
|
||||
state_usage: Arc::new(StateUsageStats::new()),
|
||||
keep_blocks: config.keep_blocks.clone(),
|
||||
keep_blocks: config.keep_blocks,
|
||||
genesis_state: RwLock::new(None),
|
||||
};
|
||||
|
||||
@@ -1135,7 +1132,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
(meta.best_number - best_number).saturated_into::<u64>() >
|
||||
self.canonicalization_delay
|
||||
{
|
||||
return Err(sp_blockchain::Error::SetHeadTooOld.into())
|
||||
return Err(sp_blockchain::Error::SetHeadTooOld)
|
||||
}
|
||||
|
||||
let parent_exists =
|
||||
@@ -1154,16 +1151,16 @@ impl<Block: BlockT> Backend<Block> {
|
||||
(&r.number, &r.hash)
|
||||
);
|
||||
|
||||
return Err(::sp_blockchain::Error::NotInFinalizedChain.into())
|
||||
return Err(::sp_blockchain::Error::NotInFinalizedChain)
|
||||
}
|
||||
|
||||
retracted.push(r.hash.clone());
|
||||
retracted.push(r.hash);
|
||||
utils::remove_number_to_key_mapping(transaction, columns::KEY_LOOKUP, r.number)?;
|
||||
}
|
||||
|
||||
// canonicalize: set the number lookup to map to this block's hash.
|
||||
for e in tree_route.enacted() {
|
||||
enacted.push(e.hash.clone());
|
||||
enacted.push(e.hash);
|
||||
utils::insert_number_to_key_mapping(
|
||||
transaction,
|
||||
columns::KEY_LOOKUP,
|
||||
@@ -1199,8 +1196,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
"Last finalized {:?} not parent of {:?}",
|
||||
last_finalized,
|
||||
header.hash()
|
||||
))
|
||||
.into())
|
||||
)))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1217,7 +1213,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
// TODO: ensure best chain contains this block.
|
||||
let number = *header.number();
|
||||
self.ensure_sequential_finalization(header, last_finalized)?;
|
||||
let with_state = sc_client_api::Backend::have_state_at(self, &hash, number);
|
||||
let with_state = sc_client_api::Backend::have_state_at(self, hash, number);
|
||||
|
||||
self.note_finalized(transaction, header, *hash, finalization_displaced, with_state)?;
|
||||
|
||||
@@ -1264,9 +1260,10 @@ impl<Block: BlockT> Backend<Block> {
|
||||
}
|
||||
|
||||
trace!(target: "db", "Canonicalize block #{} ({:?})", new_canonical, hash);
|
||||
let commit = self.storage.state_db.canonicalize_block(&hash).map_err(
|
||||
|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e),
|
||||
)?;
|
||||
let commit =
|
||||
self.storage.state_db.canonicalize_block(&hash).map_err(
|
||||
sp_blockchain::Error::from_state_db::<sc_state_db::Error<io::Error>>,
|
||||
)?;
|
||||
apply_state_commit(transaction, commit);
|
||||
}
|
||||
Ok(())
|
||||
@@ -1282,7 +1279,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
let mut meta_updates = Vec::with_capacity(operation.finalized_blocks.len());
|
||||
let (best_num, mut last_finalized_hash, mut last_finalized_num, mut block_gap) = {
|
||||
let meta = self.blockchain.meta.read();
|
||||
(meta.best_number, meta.finalized_hash, meta.finalized_number, meta.block_gap.clone())
|
||||
(meta.best_number, meta.finalized_hash, meta.finalized_number, meta.block_gap)
|
||||
};
|
||||
|
||||
for (block, justification) in operation.finalized_blocks {
|
||||
@@ -1297,14 +1294,14 @@ impl<Block: BlockT> Backend<Block> {
|
||||
&mut finalization_displaced_leaves,
|
||||
)?);
|
||||
last_finalized_hash = block_hash;
|
||||
last_finalized_num = block_header.number().clone();
|
||||
last_finalized_num = *block_header.number();
|
||||
}
|
||||
|
||||
let imported = if let Some(pending_block) = operation.pending_block {
|
||||
let hash = pending_block.header.hash();
|
||||
|
||||
let parent_hash = *pending_block.header.parent_hash();
|
||||
let number = pending_block.header.number().clone();
|
||||
let number = *pending_block.header.number();
|
||||
let existing_header =
|
||||
number <= best_num && self.blockchain.header(BlockId::hash(hash))?.is_some();
|
||||
|
||||
@@ -1352,7 +1349,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
// memory to bootstrap consensus. It is queried for an initial list of
|
||||
// authorities, etc.
|
||||
*self.genesis_state.write() = Some(Arc::new(DbGenesisStorage::new(
|
||||
pending_block.header.state_root().clone(),
|
||||
*pending_block.header.state_root(),
|
||||
operation.db_updates.clone(),
|
||||
)));
|
||||
}
|
||||
@@ -1411,7 +1408,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
let commit = self
|
||||
.storage
|
||||
.state_db
|
||||
.insert_block(&hash, number_u64, &pending_block.header.parent_hash(), changeset)
|
||||
.insert_block(&hash, number_u64, pending_block.header.parent_hash(), changeset)
|
||||
.map_err(|e: sc_state_db::Error<io::Error>| {
|
||||
sp_blockchain::Error::from_state_db(e)
|
||||
})?;
|
||||
@@ -1419,7 +1416,7 @@ impl<Block: BlockT> Backend<Block> {
|
||||
if number <= last_finalized_num {
|
||||
// Canonicalize in the db when re-importing existing blocks with state.
|
||||
let commit = self.storage.state_db.canonicalize_block(&hash).map_err(
|
||||
|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e),
|
||||
sp_blockchain::Error::from_state_db::<sc_state_db::Error<io::Error>>,
|
||||
)?;
|
||||
apply_state_commit(&mut transaction, commit);
|
||||
meta_updates.push(MetaUpdate {
|
||||
@@ -1549,11 +1546,8 @@ impl<Block: BlockT> Backend<Block> {
|
||||
let number = header.number();
|
||||
let hash = header.hash();
|
||||
|
||||
let (enacted, retracted) = self.set_head_with_transaction(
|
||||
&mut transaction,
|
||||
hash.clone(),
|
||||
(number.clone(), hash.clone()),
|
||||
)?;
|
||||
let (enacted, retracted) =
|
||||
self.set_head_with_transaction(&mut transaction, hash, (*number, hash))?;
|
||||
meta_updates.push(MetaUpdate {
|
||||
hash,
|
||||
number: *number,
|
||||
@@ -1616,9 +1610,9 @@ impl<Block: BlockT> Backend<Block> {
|
||||
displaced: &mut Option<FinalizationDisplaced<Block::Hash, NumberFor<Block>>>,
|
||||
with_state: bool,
|
||||
) -> ClientResult<()> {
|
||||
let f_num = f_header.number().clone();
|
||||
let f_num = *f_header.number();
|
||||
|
||||
let lookup_key = utils::number_and_hash_to_lookup_key(f_num, f_hash.clone())?;
|
||||
let lookup_key = utils::number_and_hash_to_lookup_key(f_num, f_hash)?;
|
||||
if with_state {
|
||||
transaction.set_from_vec(columns::META, meta_keys::FINALIZED_STATE, lookup_key.clone());
|
||||
}
|
||||
@@ -1631,9 +1625,10 @@ impl<Block: BlockT> Backend<Block> {
|
||||
.map(|c| f_num.saturated_into::<u64>() > c)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
let commit = self.storage.state_db.canonicalize_block(&f_hash).map_err(
|
||||
|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e),
|
||||
)?;
|
||||
let commit =
|
||||
self.storage.state_db.canonicalize_block(&f_hash).map_err(
|
||||
sp_blockchain::Error::from_state_db::<sc_state_db::Error<io::Error>>,
|
||||
)?;
|
||||
apply_state_commit(transaction, commit);
|
||||
}
|
||||
|
||||
@@ -1664,18 +1659,18 @@ impl<Block: BlockT> Backend<Block> {
|
||||
// Also discard all blocks from displaced branches
|
||||
for h in displaced.leaves() {
|
||||
let mut number = finalized;
|
||||
let mut hash = h.clone();
|
||||
let mut hash = *h;
|
||||
// Follow displaced chains back until we reach a finalized block.
|
||||
// Since leaves are discarded due to finality, they can't have parents
|
||||
// that are canonical, but not yet finalized. So we stop deleting as soon as
|
||||
// we reach canonical chain.
|
||||
while self.blockchain.hash(number)? != Some(hash.clone()) {
|
||||
let id = BlockId::<Block>::hash(hash.clone());
|
||||
while self.blockchain.hash(number)? != Some(hash) {
|
||||
let id = BlockId::<Block>::hash(hash);
|
||||
match self.blockchain.header(id)? {
|
||||
Some(header) => {
|
||||
self.prune_block(transaction, id)?;
|
||||
number = header.number().saturating_sub(One::one());
|
||||
hash = header.parent_hash().clone();
|
||||
hash = *header.parent_hash();
|
||||
},
|
||||
None => break,
|
||||
}
|
||||
@@ -1780,7 +1775,7 @@ fn apply_index_ops<Block: BlockT>(
|
||||
// Bump ref counter
|
||||
let extrinsic = extrinsic.encode();
|
||||
transaction.reference(columns::TRANSACTION, DbHash::from_slice(hash.as_ref()));
|
||||
DbExtrinsic::Indexed { hash: hash.clone(), header: extrinsic }
|
||||
DbExtrinsic::Indexed { hash: *hash, header: extrinsic }
|
||||
} else {
|
||||
match index_map.get(&(index as u32)) {
|
||||
Some((hash, size)) => {
|
||||
@@ -2063,8 +2058,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
|
||||
let update_finalized = best_number < finalized;
|
||||
|
||||
let key =
|
||||
utils::number_and_hash_to_lookup_key(best_number.clone(), &best_hash)?;
|
||||
let key = utils::number_and_hash_to_lookup_key(best_number, &best_hash)?;
|
||||
if update_finalized {
|
||||
transaction.set_from_vec(
|
||||
columns::META,
|
||||
@@ -2143,8 +2137,8 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
return Err(sp_blockchain::Error::Backend(format!("Can't remove best block {:?}", hash)))
|
||||
}
|
||||
|
||||
let hdr = self.blockchain.header_metadata(hash.clone())?;
|
||||
if !self.have_state_at(&hash, hdr.number) {
|
||||
let hdr = self.blockchain.header_metadata(*hash)?;
|
||||
if !self.have_state_at(hash, hdr.number) {
|
||||
return Err(sp_blockchain::Error::UnknownBlock(format!(
|
||||
"State already discarded for {:?}",
|
||||
hash
|
||||
@@ -2164,7 +2158,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
apply_state_commit(&mut transaction, commit);
|
||||
}
|
||||
transaction.remove(columns::KEY_LOOKUP, hash.as_ref());
|
||||
leaves.revert(hash.clone(), hdr.number);
|
||||
leaves.revert(*hash, hdr.number);
|
||||
leaves.prepare_transaction(&mut transaction, columns::META, meta_keys::LEAF_PREFIX);
|
||||
self.storage.db.commit(transaction)?;
|
||||
self.blockchain().remove_header_metadata(*hash);
|
||||
@@ -2185,8 +2179,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
};
|
||||
if is_genesis {
|
||||
if let Some(genesis_state) = &*self.genesis_state.read() {
|
||||
let root = genesis_state.root.clone();
|
||||
let db_state = DbState::<Block>::new(genesis_state.clone(), root);
|
||||
let db_state = DbState::<Block>::new(genesis_state.clone(), genesis_state.root);
|
||||
let state = RefTrackingState::new(db_state, self.storage.clone(), None);
|
||||
let caching_state = CachingState::new(state, self.shared_cache.clone(), None);
|
||||
let mut state = SyncingCachingState::new(
|
||||
@@ -2218,8 +2211,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
if let Ok(()) = self.storage.state_db.pin(&hash) {
|
||||
let root = hdr.state_root;
|
||||
let db_state = DbState::<Block>::new(self.storage.clone(), root);
|
||||
let state =
|
||||
RefTrackingState::new(db_state, self.storage.clone(), Some(hash.clone()));
|
||||
let state = RefTrackingState::new(db_state, self.storage.clone(), Some(hash));
|
||||
let caching_state =
|
||||
CachingState::new(state, self.shared_cache.clone(), Some(hash));
|
||||
Ok(SyncingCachingState::new(
|
||||
@@ -2241,7 +2233,7 @@ impl<Block: BlockT> sc_client_api::backend::Backend<Block> for Backend<Block> {
|
||||
|
||||
fn have_state_at(&self, hash: &Block::Hash, number: NumberFor<Block>) -> bool {
|
||||
if self.is_archive {
|
||||
match self.blockchain.header_metadata(hash.clone()) {
|
||||
match self.blockchain.header_metadata(*hash) {
|
||||
Ok(header) => sp_state_machine::Storage::get(
|
||||
self.storage.as_ref(),
|
||||
&header.state_root,
|
||||
|
||||
@@ -104,7 +104,7 @@ impl sp_core::offchain::OffchainStorage for LocalStorage {
|
||||
{
|
||||
drop(key_lock);
|
||||
let key_lock = locks.get_mut(&key);
|
||||
if let Some(_) = key_lock.and_then(Arc::get_mut) {
|
||||
if key_lock.and_then(Arc::get_mut).is_some() {
|
||||
locks.remove(&key);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ impl sp_core::offchain::OffchainStorage for LocalStorage {
|
||||
|
||||
/// Concatenate the prefix and key to create an offchain key in the db.
|
||||
pub(crate) fn concatenate_prefix_and_key(prefix: &[u8], key: &[u8]) -> Vec<u8> {
|
||||
prefix.iter().chain(key.into_iter()).cloned().collect()
|
||||
prefix.iter().chain(key.iter()).cloned().collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -360,9 +360,9 @@ impl<B: BlockT> CacheChanges<B> {
|
||||
// Same block comitted twice with different state changes.
|
||||
// Treat it as reenacted/retracted.
|
||||
if is_best {
|
||||
enacted.push(commit_hash.clone());
|
||||
enacted.push(*commit_hash);
|
||||
} else {
|
||||
retracted.to_mut().push(commit_hash.clone());
|
||||
retracted.to_mut().push(*commit_hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,7 +371,7 @@ impl<B: BlockT> CacheChanges<B> {
|
||||
// Propagate cache only if committing on top of the latest canonical state
|
||||
// blocks are ordered by number and only one block with a given number is marked as
|
||||
// canonical (contributed to canonical state cache)
|
||||
if let Some(_) = self.parent_hash {
|
||||
if self.parent_hash.is_some() {
|
||||
let mut local_cache = self.local_cache.write();
|
||||
if is_best {
|
||||
trace!(
|
||||
@@ -423,9 +423,9 @@ impl<B: BlockT> CacheChanges<B> {
|
||||
storage: modifications,
|
||||
child_storage: child_modifications,
|
||||
number: *number,
|
||||
hash: hash.clone(),
|
||||
hash: *hash,
|
||||
is_canon: is_best,
|
||||
parent: parent.clone(),
|
||||
parent: *parent,
|
||||
};
|
||||
let insert_at = cache
|
||||
.modifications
|
||||
@@ -564,7 +564,7 @@ impl<S: StateBackend<HashFor<B>>, B: BlockT> StateBackend<HashFor<B>> for Cachin
|
||||
let cache = self.cache.shared_cache.upgradable_read();
|
||||
if Self::is_allowed(Some(key), None, &self.cache.parent_hash, &cache.modifications) {
|
||||
let mut cache = RwLockUpgradableReadGuard::upgrade(cache);
|
||||
if let Some(entry) = cache.lru_hashes.get(key).map(|a| a.0.clone()) {
|
||||
if let Some(entry) = cache.lru_hashes.get(key).map(|a| a.0) {
|
||||
trace!("Found hash in shared cache: {:?}", HexDisplay::from(&key));
|
||||
return Ok(entry)
|
||||
}
|
||||
@@ -934,7 +934,7 @@ impl<S, B: BlockT> Drop for SyncingCachingState<S, B> {
|
||||
let _lock = self.lock.read();
|
||||
|
||||
self.state_usage.merge_sm(caching_state.usage.take());
|
||||
if let Some(hash) = caching_state.cache.parent_hash.clone() {
|
||||
if let Some(hash) = caching_state.cache.parent_hash {
|
||||
let is_best = self.meta.read().best_hash == hash;
|
||||
caching_state.cache.sync_cache(&[], &[], vec![], vec![], None, None, is_best);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
/// Version file name.
|
||||
const VERSION_FILE_NAME: &'static str = "db_version";
|
||||
const VERSION_FILE_NAME: &str = "db_version";
|
||||
|
||||
/// Current db version.
|
||||
const CURRENT_VERSION: u32 = 4;
|
||||
|
||||
@@ -201,16 +201,16 @@ fn open_database_at<Block: BlockT>(
|
||||
db_type: DatabaseType,
|
||||
) -> sp_blockchain::Result<Arc<dyn Database<DbHash>>> {
|
||||
let db: Arc<dyn Database<DbHash>> = match &source {
|
||||
DatabaseSource::ParityDb { path } => open_parity_db::<Block>(&path, db_type, true)?,
|
||||
DatabaseSource::ParityDb { path } => open_parity_db::<Block>(path, db_type, true)?,
|
||||
DatabaseSource::RocksDb { path, cache_size } =>
|
||||
open_kvdb_rocksdb::<Block>(&path, db_type, true, *cache_size)?,
|
||||
open_kvdb_rocksdb::<Block>(path, db_type, true, *cache_size)?,
|
||||
DatabaseSource::Custom(db) => db.clone(),
|
||||
DatabaseSource::Auto { paritydb_path, rocksdb_path, cache_size } => {
|
||||
// check if rocksdb exists first, if not, open paritydb
|
||||
match open_kvdb_rocksdb::<Block>(&rocksdb_path, db_type, false, *cache_size) {
|
||||
match open_kvdb_rocksdb::<Block>(rocksdb_path, db_type, false, *cache_size) {
|
||||
Ok(db) => db,
|
||||
Err(OpenDbError::NotEnabled(_)) | Err(OpenDbError::DoesNotExist) =>
|
||||
open_parity_db::<Block>(&paritydb_path, db_type, true)?,
|
||||
open_parity_db::<Block>(paritydb_path, db_type, true)?,
|
||||
Err(_) => return Err(backend_err("cannot open rocksdb. corrupted database")),
|
||||
}
|
||||
},
|
||||
@@ -234,7 +234,7 @@ type OpenDbResult = Result<Arc<dyn Database<DbHash>>, OpenDbError>;
|
||||
impl fmt::Display for OpenDbError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
OpenDbError::Internal(e) => write!(f, "{}", e.to_string()),
|
||||
OpenDbError::Internal(e) => write!(f, "{}", e),
|
||||
OpenDbError::DoesNotExist => write!(f, "Database does not exist at given location"),
|
||||
OpenDbError::NotEnabled(feat) => {
|
||||
write!(f, "`{}` feature not enabled, database can not be opened", feat)
|
||||
@@ -300,7 +300,7 @@ fn open_kvdb_rocksdb<Block: BlockT>(
|
||||
cache_size: usize,
|
||||
) -> OpenDbResult {
|
||||
// first upgrade database to required version
|
||||
match crate::upgrade::upgrade_db::<Block>(&path, db_type) {
|
||||
match crate::upgrade::upgrade_db::<Block>(path, db_type) {
|
||||
// in case of missing version file, assume that database simply does not exist at given
|
||||
// location
|
||||
Ok(_) | Err(crate::upgrade::UpgradeError::MissingDatabaseVersionFile) => (),
|
||||
@@ -363,8 +363,7 @@ pub fn check_database_type(
|
||||
return Err(sp_blockchain::Error::Backend(format!(
|
||||
"Unexpected database type. Expected: {}",
|
||||
db_type.as_str()
|
||||
))
|
||||
.into())
|
||||
)))
|
||||
},
|
||||
None => {
|
||||
let mut transaction = Transaction::new();
|
||||
@@ -425,9 +424,9 @@ pub fn read_db<Block>(
|
||||
where
|
||||
Block: BlockT,
|
||||
{
|
||||
block_id_to_lookup_key(db, col_index, id).and_then(|key| match key {
|
||||
Some(key) => Ok(db.get(col, key.as_ref())),
|
||||
None => Ok(None),
|
||||
block_id_to_lookup_key(db, col_index, id).map(|key| match key {
|
||||
Some(key) => db.get(col, key.as_ref()),
|
||||
None => None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -442,9 +441,10 @@ pub fn remove_from_db<Block>(
|
||||
where
|
||||
Block: BlockT,
|
||||
{
|
||||
block_id_to_lookup_key(db, col_index, id).and_then(|key| match key {
|
||||
Some(key) => Ok(transaction.remove(col, key.as_ref())),
|
||||
None => Ok(()),
|
||||
block_id_to_lookup_key(db, col_index, id).map(|key| {
|
||||
if let Some(key) = key {
|
||||
transaction.remove(col, key.as_ref());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ pub fn read_header<Block: BlockT>(
|
||||
match read_db(db, col_index, col, id)? {
|
||||
Some(header) => match Block::Header::decode(&mut &header[..]) {
|
||||
Ok(header) => Ok(Some(header)),
|
||||
Err(_) => return Err(sp_blockchain::Error::Backend("Error decoding header".into())),
|
||||
Err(_) => Err(sp_blockchain::Error::Backend("Error decoding header".into())),
|
||||
},
|
||||
None => Ok(None),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user