mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
feat(light client): fetch block body from remote (#2527)
* feat(on_demand): block body request * fix(light block req): no justific + one block * fix(bad rebase) * feat(protocol): add messages for `remote_body` * fix(on demand body): remove needless `take()` * fix(network): remove messages for `on_demand_body` * fix(grumbles): use `hash` in `remote_body_requests` As long as we can't compute `ordered_trie_root(body)` just compare that request.header.hash() == response.header.hash() * fix(grumbles): `hdr.ext_root == trie_root(body)` * fix(grumbles): propogate `Err` in `fn body()` * fix(grumbles): Vec<Block::Extrinsic> * fix(grumbles): util_fn for `not_impl` in tests * fix(on remote body): tests `fetch` and `on_demand` * docs(resolve todos)
This commit is contained in:
committed by
DemiMarie-parity
parent
55937d1f08
commit
009898f309
@@ -324,6 +324,10 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Future for Protocol<B,
|
||||
}
|
||||
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
fn is_on_demand_response(&self, who: &PeerId, response_id: message::RequestId) -> bool {
|
||||
self.on_demand.as_ref().map_or(false, |od| od.is_on_demand_response(&who, response_id))
|
||||
}
|
||||
|
||||
fn handle_response(
|
||||
&mut self,
|
||||
who: PeerId,
|
||||
@@ -365,10 +369,15 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
GenericMessage::Status(s) => self.on_status_message(who, s),
|
||||
GenericMessage::BlockRequest(r) => self.on_block_request(who, r),
|
||||
GenericMessage::BlockResponse(r) => {
|
||||
if let Some(request) = self.handle_response(who.clone(), &r) {
|
||||
let outcome = self.on_block_response(who.clone(), request, r);
|
||||
self.update_peer_info(&who);
|
||||
return outcome
|
||||
// Note, this is safe because only `ordinary bodies` and `remote bodies` are received in this matter.
|
||||
if self.is_on_demand_response(&who, r.id) {
|
||||
self.on_remote_body_response(who, r);
|
||||
} else {
|
||||
if let Some(request) = self.handle_response(who.clone(), &r) {
|
||||
let outcome = self.on_block_response(who.clone(), request, r);
|
||||
self.update_peer_info(&who);
|
||||
return outcome
|
||||
}
|
||||
}
|
||||
},
|
||||
GenericMessage::BlockAnnounce(announce) => {
|
||||
@@ -1202,6 +1211,12 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
CustomMessageOutcome::None
|
||||
}
|
||||
}
|
||||
|
||||
fn on_remote_body_response(&self, peer: PeerId, response: message::BlockResponse<B>) {
|
||||
self.on_demand
|
||||
.as_ref()
|
||||
.map(|od| od.on_remote_body_response(peer, response));
|
||||
}
|
||||
}
|
||||
|
||||
/// Outcome of an incoming custom message.
|
||||
|
||||
Reference in New Issue
Block a user