-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add childstate_getStorageEntries
RPC
#9459
Changes from 1 commit
d2ad280
993a877
ab725c8
3a3c1ae
a23ed69
fa146dc
d73a745
0cbe5eb
cd4c158
3199a10
a1b6eed
83251ad
58fe359
f3e3ce3
d618704
d840015
5813b43
a001771
19f5d24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,10 @@ use futures::{future, StreamExt as _, TryStreamExt as _}; | |
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId}; | ||
use log::warn; | ||
use rpc::{ | ||
futures::{future::result, stream, Future, Sink, Stream}, | ||
futures::{ | ||
future::{join_all, result}, | ||
stream, Future, Sink, Stream, | ||
}, | ||
Result as RpcResult, | ||
}; | ||
use std::{ | ||
|
@@ -358,6 +361,22 @@ where | |
)) | ||
} | ||
|
||
fn storages( | ||
&self, | ||
block: Option<Block::Hash>, | ||
keys: Vec<StorageKey>, | ||
) -> FutureResult<Vec<Option<StorageData>>> { | ||
let block = match self.block_or_best(block) { | ||
Ok(b) => b, | ||
Err(e) => return Box::new(result(Err(client_err(e)))), | ||
}; | ||
let client = self.client.clone(); | ||
Box::new(join_all( | ||
keys.into_iter() | ||
.map(move |key| client.storage(&BlockId::Hash(block), &key).map_err(client_err)), | ||
)) | ||
bkchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
fn storage_size( | ||
&self, | ||
block: Option<Block::Hash>, | ||
|
@@ -722,6 +741,30 @@ where | |
)) | ||
} | ||
|
||
fn storages( | ||
&self, | ||
block: Option<Block::Hash>, | ||
storage_key: PrefixedStorageKey, | ||
keys: Vec<StorageKey>, | ||
) -> FutureResult<Vec<Option<StorageData>>> { | ||
let block = match self.block_or_best(block) { | ||
Ok(b) => b, | ||
Err(e) => return Box::new(result(Err(client_err(e)))), | ||
}; | ||
let client = self.client.clone(); | ||
Box::new( | ||
join_all(keys.into_iter().map(move |key| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
let child_info = match ChildType::from_prefixed_key(&storage_key) { | ||
Some((ChildType::ParentKeyId, storage_key)) => | ||
ChildInfo::new_default(storage_key), | ||
None => return Err(sp_blockchain::Error::InvalidChildStorageKey), | ||
}; | ||
client.child_storage(&BlockId::Hash(block), &child_info, &key) | ||
})) | ||
.map_err(client_err), | ||
) | ||
} | ||
|
||
fn storage_hash( | ||
&self, | ||
block: Option<Block::Hash>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ use log::warn; | |
use parking_lot::Mutex; | ||
use rpc::{ | ||
futures::{ | ||
future::{result, Future}, | ||
future::{join_all, result, Future}, | ||
stream::Stream, | ||
Sink, | ||
}, | ||
|
@@ -245,6 +245,26 @@ where | |
) | ||
} | ||
|
||
fn storages( | ||
&self, | ||
block: Option<Block::Hash>, | ||
keys: Vec<StorageKey>, | ||
) -> FutureResult<Vec<Option<StorageData>>> { | ||
let remote_blockchain = self.remote_blockchain.clone(); | ||
let fetcher = self.fetcher.clone(); | ||
let block = self.block_or_best(block); | ||
Box::new(join_all(keys.into_iter().map(move |key| { | ||
storage(&*remote_blockchain, fetcher.clone(), block, vec![key.0.clone()]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should request all keys in one request and not one request per key. |
||
.boxed() | ||
.compat() | ||
.map(move |mut values| { | ||
values | ||
.remove(&key) | ||
.expect("successful request has entries for all requested keys; qed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least it's the claim that was made in the |
||
}) | ||
}))) | ||
} | ||
|
||
fn storage_hash( | ||
&self, | ||
block: Option<Block::Hash>, | ||
|
@@ -563,6 +583,52 @@ where | |
Box::new(child_storage.boxed().compat()) | ||
} | ||
|
||
fn storages( | ||
&self, | ||
block: Option<Block::Hash>, | ||
storage_key: PrefixedStorageKey, | ||
keys: Vec<StorageKey>, | ||
) -> FutureResult<Vec<Option<StorageData>>> { | ||
let block = self.block_or_best(block); | ||
let fetcher = self.fetcher.clone(); | ||
let remote_blockchain = self.remote_blockchain.clone(); | ||
Box::new(join_all(keys.into_iter().map(move |key| { | ||
let storage_key = storage_key.clone(); | ||
let fetcher2 = fetcher.clone(); | ||
let child_storage = | ||
resolve_header(&*remote_blockchain, &*fetcher, block).then(move |result| { | ||
match result { | ||
Ok(header) => Either::Left( | ||
fetcher2 | ||
.remote_read_child(RemoteReadChildRequest { | ||
block, | ||
header, | ||
storage_key, | ||
keys: vec![key.0.clone()], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again you are only requesting one key after another. |
||
retry_count: Default::default(), | ||
}) | ||
.then(move |result| { | ||
ready( | ||
result | ||
.map(|mut data| { | ||
data.remove(&key.0) | ||
.expect( | ||
"successful result has entry for all keys; qed", | ||
) | ||
.map(StorageData) | ||
}) | ||
.map_err(client_err), | ||
) | ||
}), | ||
), | ||
Err(error) => Either::Right(ready(Err(error))), | ||
} | ||
}); | ||
|
||
Box::new(child_storage.boxed().compat()) | ||
}))) | ||
} | ||
|
||
fn storage_hash( | ||
&self, | ||
block: Option<Block::Hash>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storage_entries
maybe?storages
sounds weird.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's better.
Another question is if we should deprecate
storage
because of the overlapping functionality?