mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +00:00
Child trie api changes BREAKING (#4857)
Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -58,7 +58,7 @@ use sc_client::light::fetcher;
|
||||
use sc_client_api::StorageProof;
|
||||
use sc_peerset::ReputationChange;
|
||||
use sp_core::{
|
||||
storage::{ChildInfo, StorageKey},
|
||||
storage::{ChildInfo, ChildType,StorageKey, PrefixedStorageKey},
|
||||
hexdisplay::HexDisplay,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
@@ -617,35 +617,27 @@ where
|
||||
|
||||
let block = Decode::decode(&mut request.block.as_ref())?;
|
||||
|
||||
let proof =
|
||||
if let Some(info) = ChildInfo::resolve_child_info(request.child_type, &request.child_info[..]) {
|
||||
match self.chain.read_child_proof(
|
||||
&BlockId::Hash(block),
|
||||
&request.storage_key,
|
||||
info,
|
||||
&mut request.keys.iter().map(AsRef::as_ref)
|
||||
) {
|
||||
Ok(proof) => proof,
|
||||
Err(error) => {
|
||||
log::trace!("remote read child request from {} ({} {} at {:?}) failed with: {}",
|
||||
peer,
|
||||
HexDisplay::from(&request.storage_key),
|
||||
fmt_keys(request.keys.first(), request.keys.last()),
|
||||
request.block,
|
||||
error);
|
||||
StorageProof::empty()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let prefixed_key = PrefixedStorageKey::new_ref(&request.storage_key);
|
||||
let child_info = match ChildType::from_prefixed_key(prefixed_key) {
|
||||
Some((ChildType::ParentKeyId, storage_key)) => Ok(ChildInfo::new_default(storage_key)),
|
||||
None => Err("Invalid child storage key".into()),
|
||||
};
|
||||
let proof = match child_info.and_then(|child_info| self.chain.read_child_proof(
|
||||
&BlockId::Hash(block),
|
||||
&child_info,
|
||||
&mut request.keys.iter().map(AsRef::as_ref)
|
||||
)) {
|
||||
Ok(proof) => proof,
|
||||
Err(error) => {
|
||||
log::trace!("remote read child request from {} ({} {} at {:?}) failed with: {}",
|
||||
peer,
|
||||
HexDisplay::from(&request.storage_key),
|
||||
fmt_keys(request.keys.first(), request.keys.last()),
|
||||
request.block,
|
||||
"invalid child info and type"
|
||||
);
|
||||
error);
|
||||
StorageProof::empty()
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
let response = {
|
||||
let r = api::v1::light::RemoteReadResponse { proof: proof.encode() };
|
||||
@@ -704,23 +696,18 @@ where
|
||||
let min = Decode::decode(&mut request.min.as_ref())?;
|
||||
let max = Decode::decode(&mut request.max.as_ref())?;
|
||||
let key = StorageKey(request.key.clone());
|
||||
let storage_key =
|
||||
if request.storage_key.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(StorageKey(request.storage_key.clone()))
|
||||
};
|
||||
let storage_key = if request.storage_key.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(PrefixedStorageKey::new_ref(&request.storage_key))
|
||||
};
|
||||
|
||||
let proof = match self.chain.key_changes_proof(first, last, min, max, storage_key.as_ref(), &key) {
|
||||
let proof = match self.chain.key_changes_proof(first, last, min, max, storage_key, &key) {
|
||||
Ok(proof) => proof,
|
||||
Err(error) => {
|
||||
log::trace!("remote changes proof request from {} for key {} ({:?}..{:?}) failed with: {}",
|
||||
peer,
|
||||
if let Some(sk) = storage_key {
|
||||
format!("{} : {}", HexDisplay::from(&sk.0), HexDisplay::from(&key.0))
|
||||
} else {
|
||||
HexDisplay::from(&key.0).to_string()
|
||||
},
|
||||
format!("{} : {}", HexDisplay::from(&request.storage_key), HexDisplay::from(&key.0)),
|
||||
request.first,
|
||||
request.last,
|
||||
error);
|
||||
@@ -1092,9 +1079,7 @@ fn serialize_request<B: Block>(request: &Request<B>) -> Result<Vec<u8>, prost::E
|
||||
Request::ReadChild { request, .. } => {
|
||||
let r = api::v1::light::RemoteReadChildRequest {
|
||||
block: request.block.encode(),
|
||||
storage_key: request.storage_key.clone(),
|
||||
child_type: request.child_type.clone(),
|
||||
child_info: request.child_info.clone(),
|
||||
storage_key: request.storage_key.clone().into_inner(),
|
||||
keys: request.keys.clone(),
|
||||
};
|
||||
api::v1::light::request::Request::RemoteReadChildRequest(r)
|
||||
@@ -1113,7 +1098,8 @@ fn serialize_request<B: Block>(request: &Request<B>) -> Result<Vec<u8>, prost::E
|
||||
last: request.last_block.1.encode(),
|
||||
min: request.tries_roots.1.encode(),
|
||||
max: request.max_block.1.encode(),
|
||||
storage_key: request.storage_key.clone().unwrap_or_default(),
|
||||
storage_key: request.storage_key.clone().map(|s| s.into_inner())
|
||||
.unwrap_or_default(),
|
||||
key: request.key.clone(),
|
||||
};
|
||||
api::v1::light::request::Request::RemoteChangesRequest(r)
|
||||
@@ -1343,8 +1329,6 @@ mod tests {
|
||||
use super::{Event, LightClientHandler, Request, Response, OutboundProtocol, PeerStatus};
|
||||
use void::Void;
|
||||
|
||||
const CHILD_INFO: ChildInfo<'static> = ChildInfo::new_default(b"foobarbaz");
|
||||
|
||||
type Block = sp_runtime::generic::Block<Header<u64, BlakeTwo256>, substrate_test_runtime::Extrinsic>;
|
||||
type Handler = LightClientHandler<Block>;
|
||||
type Swarm = libp2p::swarm::Swarm<Handler>;
|
||||
@@ -1894,15 +1878,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn receives_remote_read_child_response() {
|
||||
let info = CHILD_INFO.info();
|
||||
let mut chan = oneshot::channel();
|
||||
let child_info = ChildInfo::new_default(&b":child_storage:default:sub"[..]);
|
||||
let request = fetcher::RemoteReadChildRequest {
|
||||
header: dummy_header(),
|
||||
block: Default::default(),
|
||||
storage_key: b":child_storage:sub".to_vec(),
|
||||
storage_key: child_info.prefixed_storage_key(),
|
||||
keys: vec![b":key".to_vec()],
|
||||
child_info: info.0.to_vec(),
|
||||
child_type: info.1,
|
||||
retry_count: None,
|
||||
};
|
||||
issue_request(Request::ReadChild { request, sender: chan.0 });
|
||||
@@ -1997,15 +1979,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn send_receive_read_child() {
|
||||
let info = CHILD_INFO.info();
|
||||
let chan = oneshot::channel();
|
||||
let child_info = ChildInfo::new_default(&b":child_storage:default:sub"[..]);
|
||||
let request = fetcher::RemoteReadChildRequest {
|
||||
header: dummy_header(),
|
||||
block: Default::default(),
|
||||
storage_key: b":child_storage:sub".to_vec(),
|
||||
storage_key: child_info.prefixed_storage_key(),
|
||||
keys: vec![b":key".to_vec()],
|
||||
child_info: info.0.to_vec(),
|
||||
child_type: info.1,
|
||||
retry_count: None,
|
||||
};
|
||||
send_receive(Request::ReadChild { request, sender: chan.0 });
|
||||
|
||||
@@ -477,11 +477,6 @@ pub mod generic {
|
||||
pub block: H,
|
||||
/// Child Storage key.
|
||||
pub storage_key: Vec<u8>,
|
||||
/// Child trie source information.
|
||||
pub child_info: Vec<u8>,
|
||||
/// Child type, its required to resolve `child_info`
|
||||
/// content and choose child implementation.
|
||||
pub child_type: u32,
|
||||
/// Storage key.
|
||||
pub keys: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
@@ -67,13 +67,9 @@ message RemoteReadResponse {
|
||||
message RemoteReadChildRequest {
|
||||
// Block at which to perform call.
|
||||
bytes block = 2;
|
||||
// Child Storage key.
|
||||
// Child Storage key, this is relative
|
||||
// to the child type storage location.
|
||||
bytes storage_key = 3;
|
||||
// Child trie source information.
|
||||
bytes child_info = 4;
|
||||
/// Child type, its required to resolve `child_info`
|
||||
/// content and choose child implementation.
|
||||
uint32 child_type = 5;
|
||||
// Storage keys.
|
||||
repeated bytes keys = 6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user