Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
261b95c
Fancy compact encode/decode impl for compact solution
kianenigma Jul 23, 2020
973bd25
Merge branch 'master' of github.com:paritytech/substrate into kiz-cod…
kianenigma Aug 3, 2020
0ff952c
Make it optional
kianenigma Aug 3, 2020
8c7b07a
Remove extra file
kianenigma Aug 3, 2020
41ad894
Update primitives/npos-elections/compact/src/lib.rs
kianenigma Aug 6, 2020
03ce657
Final fixes.
kianenigma Aug 6, 2020
82641f9
Merge branch 'kiz-codec-for-compact' of github.com:paritytech/substra…
kianenigma Aug 6, 2020
1524c5b
Merge branch 'master' of github.com:paritytech/substrate into kiz-cod…
kianenigma Aug 6, 2020
6fcb09e
getSize rpc should work for maps as well
kianenigma Aug 7, 2020
ba19fd3
Fix future types
kianenigma Aug 10, 2020
ba3eacd
Remove minimum_validator_count stale const
kianenigma Aug 10, 2020
b889970
Update client/rpc/src/state/mod.rs
kianenigma Aug 11, 2020
66586a4
"Optimize" `storage_size`
bkchr Aug 11, 2020
754098a
Remove unused import
bkchr Aug 11, 2020
85532e1
Merge branch 'kiz-rpc-for-map-len' of github.com:paritytech/substrate…
kianenigma Aug 11, 2020
11ff7ee
Update doc
kianenigma Aug 11, 2020
fcc7f0c
Merge branch 'master' of github.com:paritytech/substrate into kiz-cod…
kianenigma Aug 11, 2020
41663f4
Merge branch 'kiz-rpc-for-map-len' of github.com:paritytech/substrate…
kianenigma Aug 11, 2020
e12e6c9
Merge branch 'master' of github.com:paritytech/substrate into kiz-rpc…
kianenigma Aug 11, 2020
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
8 changes: 4 additions & 4 deletions client/rpc/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ pub trait StateBackend<Block: BlockT, Client>: Send + Sync + 'static
) -> FutureResult<Option<Block::Hash>>;

/// Returns the size of a storage entry at a block's state.
///
/// If data is available at `key`, it is returned. Else, the sum of values who's key has `key`
/// prefix is returned, i.e. all the storage (double) maps that have this prefix.
fn storage_size(
&self,
block: Option<Block::Hash>,
key: StorageKey,
) -> FutureResult<Option<u64>> {
Box::new(self.storage(block, key)
.map(|x| x.map(|x| x.0.len() as u64)))
}
) -> FutureResult<Option<u64>>;

/// Returns the runtime metadata as an opaque blob.
fn metadata(&self, block: Option<Block::Hash>) -> FutureResult<Bytes>;
Expand Down
30 changes: 30 additions & 0 deletions client/rpc/src/state/state_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,36 @@ impl<BE, Block, Client> StateBackend<Block, Client> for FullState<BE, Block, Cli
.map_err(client_err)))
}

fn storage_size(
&self,
block: Option<Block::Hash>,
key: StorageKey,
) -> FutureResult<Option<u64>> {
let block = match self.block_or_best(block) {
Ok(b) => b,
Err(e) => return Box::new(result(Err(client_err(e)))),
};

match self.client.storage(&BlockId::Hash(block), &key) {
Ok(Some(d)) => return Box::new(result(Ok(Some(d.0.len() as u64)))),
Err(e) => return Box::new(result(Err(client_err(e)))),
Ok(None) => {},
}

Box::new(result(
self.client.storage_pairs(&BlockId::Hash(block), &key)
.map(|kv| {
let item_sum = kv.iter().map(|(_, v)| v.0.len() as u64).sum::<u64>();
if item_sum > 0 {
Some(item_sum)
} else {
None
}
})
.map_err(client_err)
))
}

fn storage_hash(
&self,
block: Option<Block::Hash>,
Expand Down
8 changes: 8 additions & 0 deletions client/rpc/src/state/state_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ impl<Block, F, Client> StateBackend<Block, Client> for LightState<Block, F, Clie
Box::new(result(Err(client_err(ClientError::NotAvailableOnLightClient))))
}

fn storage_size(
&self,
_: Option<Block::Hash>,
_: StorageKey,
) -> FutureResult<Option<u64>> {
Box::new(result(Err(client_err(ClientError::NotAvailableOnLightClient))))
}

fn storage(
&self,
block: Option<Block::Hash>,
Expand Down
8 changes: 7 additions & 1 deletion client/rpc/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ fn should_return_storage() {
let client = TestClientBuilder::new()
.add_extra_storage(KEY.to_vec(), VALUE.to_vec())
.add_extra_child_storage(&child_info, KEY.to_vec(), CHILD_VALUE.to_vec())
// similar to a map with two keys
.add_extra_storage(b":map:acc1".to_vec(), vec![1, 2])
.add_extra_storage(b":map:acc2".to_vec(), vec![1, 2, 3])
.build();
let genesis_hash = client.genesis_hash();
let (client, child) = new_full(Arc::new(client), SubscriptionManager::new(Arc::new(TaskExecutor)));
Expand All @@ -72,6 +75,10 @@ fn should_return_storage() {
client.storage_size(key.clone(), None).wait().unwrap().unwrap() as usize,
VALUE.len(),
);
assert_eq!(
client.storage_size(StorageKey(b":map".to_vec()), None).wait().unwrap().unwrap() as usize,
2 + 3,
);
assert_eq!(
executor::block_on(
child.storage(prefixed_storage_key(), key, Some(genesis_hash).into())
Expand All @@ -80,7 +87,6 @@ fn should_return_storage() {
).unwrap().unwrap() as usize,
CHILD_VALUE.len(),
);

}

#[test]
Expand Down