mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 02:07:56 +00:00
Implement change trie for child trie. (#3122)
* Initial implementation, some redundancy is awkward and there is some useless computation (but there is a pending pr for that). Next are tests. * Minimal tests and fix extend child. * implement iterator for change child trie. * prune child trie. * Fix pruning test. * bump spec version. * Avoid empty child trie (could also be checked before) * tabs. * Fix child digest overriding each others. * Restore doc deleted on merge. * Check correct child value on extrinsics build. * Revert runtime version update.
This commit is contained in:
committed by
Svyatoslav Nikolsky
parent
06658e0c3c
commit
e3d0c60a31
@@ -64,6 +64,7 @@ pub trait Client<Block: BlockT>: Send + Sync {
|
||||
last: Block::Hash,
|
||||
min: Block::Hash,
|
||||
max: Block::Hash,
|
||||
storage_key: Option<&StorageKey>,
|
||||
key: &StorageKey
|
||||
) -> Result<ChangesProof<Block::Header>, Error>;
|
||||
|
||||
@@ -136,9 +137,10 @@ impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
|
||||
last: Block::Hash,
|
||||
min: Block::Hash,
|
||||
max: Block::Hash,
|
||||
key: &StorageKey
|
||||
storage_key: Option<&StorageKey>,
|
||||
key: &StorageKey,
|
||||
) -> Result<ChangesProof<Block::Header>, Error> {
|
||||
(self as &SubstrateClient<B, E, Block, RA>).key_changes_proof(first, last, min, max, key)
|
||||
(self as &SubstrateClient<B, E, Block, RA>).key_changes_proof(first, last, min, max, storage_key, key)
|
||||
}
|
||||
|
||||
fn is_descendent_of(&self, base: &Block::Hash, block: &Block::Hash) -> Result<bool, Error> {
|
||||
|
||||
@@ -226,7 +226,8 @@ impl<'a, B: BlockT> LightDispatchNetwork<B> for LightDispatchIn<'a, B> {
|
||||
last: <B as BlockT>::Hash,
|
||||
min: <B as BlockT>::Hash,
|
||||
max: <B as BlockT>::Hash,
|
||||
key: Vec<u8>
|
||||
storage_key: Option<Vec<u8>>,
|
||||
key: Vec<u8>,
|
||||
) {
|
||||
let message = message::generic::Message::RemoteChangesRequest(message::RemoteChangesRequest {
|
||||
id,
|
||||
@@ -234,6 +235,7 @@ impl<'a, B: BlockT> LightDispatchNetwork<B> for LightDispatchIn<'a, B> {
|
||||
last,
|
||||
min,
|
||||
max,
|
||||
storage_key,
|
||||
key,
|
||||
});
|
||||
|
||||
@@ -1385,24 +1387,34 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
trace!(target: "sync", "Remote changes proof request {} from {} for key {} ({}..{})",
|
||||
request.id,
|
||||
who,
|
||||
request.key.to_hex::<String>(),
|
||||
if let Some(sk) = request.storage_key.as_ref() {
|
||||
format!("{} : {}", sk.to_hex::<String>(), request.key.to_hex::<String>())
|
||||
} else {
|
||||
request.key.to_hex::<String>()
|
||||
},
|
||||
request.first,
|
||||
request.last
|
||||
);
|
||||
let storage_key = request.storage_key.map(|sk| StorageKey(sk));
|
||||
let key = StorageKey(request.key);
|
||||
let proof = match self.context_data.chain.key_changes_proof(
|
||||
request.first,
|
||||
request.last,
|
||||
request.min,
|
||||
request.max,
|
||||
&key
|
||||
storage_key.as_ref(),
|
||||
&key,
|
||||
) {
|
||||
Ok(proof) => proof,
|
||||
Err(error) => {
|
||||
trace!(target: "sync", "Remote changes proof request {} from {} for key {} ({}..{}) failed with: {}",
|
||||
request.id,
|
||||
who,
|
||||
key.0.to_hex::<String>(),
|
||||
if let Some(sk) = storage_key {
|
||||
format!("{} : {}", sk.0.to_hex::<String>(), key.0.to_hex::<String>())
|
||||
} else {
|
||||
key.0.to_hex::<String>()
|
||||
},
|
||||
request.first,
|
||||
request.last,
|
||||
error
|
||||
|
||||
@@ -84,7 +84,8 @@ pub trait LightDispatchNetwork<B: BlockT> {
|
||||
last: <B as BlockT>::Hash,
|
||||
min: <B as BlockT>::Hash,
|
||||
max: <B as BlockT>::Hash,
|
||||
key: Vec<u8>
|
||||
storage_key: Option<Vec<u8>>,
|
||||
key: Vec<u8>,
|
||||
);
|
||||
|
||||
/// Send to `who` a body request.
|
||||
@@ -629,6 +630,7 @@ impl<Block: BlockT> Request<Block> {
|
||||
data.last_block.1.clone(),
|
||||
data.tries_roots.1.clone(),
|
||||
data.max_block.1.clone(),
|
||||
data.storage_key.clone(),
|
||||
data.key.clone(),
|
||||
),
|
||||
RequestData::RemoteBody(ref data, _) =>
|
||||
@@ -785,7 +787,7 @@ pub mod tests {
|
||||
_: Vec<u8>) {}
|
||||
fn send_call_request(&mut self, _: &PeerId, _: RequestId, _: <B as BlockT>::Hash, _: String, _: Vec<u8>) {}
|
||||
fn send_changes_request(&mut self, _: &PeerId, _: RequestId, _: <B as BlockT>::Hash, _: <B as BlockT>::Hash,
|
||||
_: <B as BlockT>::Hash, _: <B as BlockT>::Hash, _: Vec<u8>) {}
|
||||
_: <B as BlockT>::Hash, _: <B as BlockT>::Hash, _: Option<Vec<u8>>, _: Vec<u8>) {}
|
||||
fn send_body_request(&mut self, _: &PeerId, _: RequestId, _: BlockAttributes, _: FromBlock<<B as BlockT>::Hash,
|
||||
<<B as BlockT>::Header as HeaderT>::Number>, _: Option<B::Hash>, _: Direction, _: Option<u32>) {}
|
||||
}
|
||||
@@ -1063,6 +1065,7 @@ pub mod tests {
|
||||
max_block: (100, Default::default()),
|
||||
tries_roots: (1, Default::default(), vec![]),
|
||||
key: vec![],
|
||||
storage_key: None,
|
||||
retry_count: None,
|
||||
}, tx));
|
||||
|
||||
|
||||
@@ -334,6 +334,8 @@ pub mod generic {
|
||||
pub min: H,
|
||||
/// Hash of the last block that we can use when querying changes.
|
||||
pub max: H,
|
||||
/// Storage child node key which changes are requested.
|
||||
pub storage_key: Option<Vec<u8>>,
|
||||
/// Storage key which changes are requested.
|
||||
pub key: Vec<u8>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user