BlockId removal: refactor: StorageProvider (#12510)

* BlockId removal: refactor: StorageProvider

It changes the arguments of `Backend::StorageProvider` trait from:
block: `BlockId<Block>` to: hash: `&Block::Hash`

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update client/api/src/backend.rs

Co-authored-by: Dmitrii Markin <dmitry@markin.tech>

* GrandpaBlockImport::current_set_id reworked

* ExportStateCmd reworked

* trigger CI job

* trigger CI job

Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Dmitrii Markin <dmitry@markin.tech>
This commit is contained in:
Michal Kucharczyk
2022-10-18 14:52:04 +02:00
committed by GitHub
parent 2f341fcf15
commit b16135f602
12 changed files with 112 additions and 120 deletions
+14 -22
View File
@@ -145,10 +145,9 @@ where
) -> Result<()> {
for block_hash in &range.hashes {
let mut block_changes = StorageChangeSet { block: *block_hash, changes: Vec::new() };
let id = BlockId::hash(*block_hash);
for key in keys {
let (has_changed, data) = {
let curr_data = self.client.storage(&id, key).map_err(client_err)?;
let curr_data = self.client.storage(block_hash, key).map_err(client_err)?;
match last_values.get(key) {
Some(prev_data) => (curr_data != *prev_data, curr_data),
None => (true, curr_data),
@@ -214,7 +213,7 @@ where
prefix: StorageKey,
) -> std::result::Result<Vec<StorageKey>, Error> {
self.block_or_best(block)
.and_then(|block| self.client.storage_keys(&BlockId::Hash(block), &prefix))
.and_then(|block| self.client.storage_keys(&block, &prefix))
.map_err(client_err)
}
@@ -224,7 +223,7 @@ where
prefix: StorageKey,
) -> std::result::Result<Vec<(StorageKey, StorageData)>, Error> {
self.block_or_best(block)
.and_then(|block| self.client.storage_pairs(&BlockId::Hash(block), &prefix))
.and_then(|block| self.client.storage_pairs(&block, &prefix))
.map_err(client_err)
}
@@ -237,11 +236,7 @@ where
) -> std::result::Result<Vec<StorageKey>, Error> {
self.block_or_best(block)
.and_then(|block| {
self.client.storage_keys_iter(
&BlockId::Hash(block),
prefix.as_ref(),
start_key.as_ref(),
)
self.client.storage_keys_iter(&block, prefix.as_ref(), start_key.as_ref())
})
.map(|iter| iter.take(count as usize).collect())
.map_err(client_err)
@@ -253,7 +248,7 @@ where
key: StorageKey,
) -> std::result::Result<Option<StorageData>, Error> {
self.block_or_best(block)
.and_then(|block| self.client.storage(&BlockId::Hash(block), &key))
.and_then(|block| self.client.storage(&block, &key))
.map_err(client_err)
}
@@ -267,14 +262,14 @@ where
Err(e) => return Err(client_err(e)),
};
match self.client.storage(&BlockId::Hash(block), &key) {
match self.client.storage(&block, &key) {
Ok(Some(d)) => return Ok(Some(d.0.len() as u64)),
Err(e) => return Err(client_err(e)),
Ok(None) => {},
}
self.client
.storage_pairs(&BlockId::Hash(block), &key)
.storage_pairs(&block, &key)
.map(|kv| {
let item_sum = kv.iter().map(|(_, v)| v.0.len() as u64).sum::<u64>();
if item_sum > 0 {
@@ -292,7 +287,7 @@ where
key: StorageKey,
) -> std::result::Result<Option<Block::Hash>, Error> {
self.block_or_best(block)
.and_then(|block| self.client.storage_hash(&BlockId::Hash(block), &key))
.and_then(|block| self.client.storage_hash(&block, &key))
.map_err(client_err)
}
@@ -418,7 +413,7 @@ where
let changes = keys
.into_iter()
.map(|key| {
let v = self.client.storage(&BlockId::Hash(block), &key).ok().flatten();
let v = self.client.storage(&block, &key).ok().flatten();
(key, v)
})
.collect();
@@ -522,7 +517,7 @@ where
ChildInfo::new_default(storage_key),
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
};
self.client.child_storage_keys(&BlockId::Hash(block), &child_info, &prefix)
self.client.child_storage_keys(&block, &child_info, &prefix)
})
.map_err(client_err)
}
@@ -543,7 +538,7 @@ where
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
};
self.client.child_storage_keys_iter(
&BlockId::Hash(block),
&block,
child_info,
prefix.as_ref(),
start_key.as_ref(),
@@ -566,7 +561,7 @@ where
ChildInfo::new_default(storage_key),
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
};
self.client.child_storage(&BlockId::Hash(block), &child_info, &key)
self.client.child_storage(&block, &child_info, &key)
})
.map_err(client_err)
}
@@ -589,10 +584,7 @@ where
keys.into_iter()
.map(move |key| {
client
.clone()
.child_storage(&BlockId::Hash(block), &child_info, &key)
.map_err(client_err)
client.clone().child_storage(&block, &child_info, &key).map_err(client_err)
})
.collect()
}
@@ -610,7 +602,7 @@ where
ChildInfo::new_default(storage_key),
None => return Err(sp_blockchain::Error::InvalidChildStorageKey),
};
self.client.child_storage_hash(&BlockId::Hash(block), &child_info, &key)
self.client.child_storage_hash(&block, &child_info, &key)
})
.map_err(client_err)
}