mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 13:55:41 +00:00
Fix the light client protocol protobuf schema (#12732)
* Fix the light client protocol protobuf schema * Add another test * Remove unused protobuf struct * Ok you have to use the nightly rustfmt apparently
This commit is contained in:
@@ -173,10 +173,7 @@ where
|
|||||||
let block = Decode::decode(&mut request.block.as_ref())?;
|
let block = Decode::decode(&mut request.block.as_ref())?;
|
||||||
|
|
||||||
let response = match self.client.execution_proof(block, &request.method, &request.data) {
|
let response = match self.client.execution_proof(block, &request.method, &request.data) {
|
||||||
Ok((_, proof)) => {
|
Ok((_, proof)) => schema::v1::light::RemoteCallResponse { proof: Some(proof.encode()) },
|
||||||
let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
|
|
||||||
Some(schema::v1::light::response::Response::RemoteCallResponse(r))
|
|
||||||
},
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!(
|
trace!(
|
||||||
"remote call request from {} ({} at {:?}) failed with: {}",
|
"remote call request from {} ({} at {:?}) failed with: {}",
|
||||||
@@ -185,11 +182,13 @@ where
|
|||||||
request.block,
|
request.block,
|
||||||
e,
|
e,
|
||||||
);
|
);
|
||||||
None
|
schema::v1::light::RemoteCallResponse { proof: None }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(schema::v1::light::Response { response })
|
Ok(schema::v1::light::Response {
|
||||||
|
response: Some(schema::v1::light::response::Response::RemoteCallResponse(response)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_remote_read_request(
|
fn on_remote_read_request(
|
||||||
@@ -213,10 +212,7 @@ where
|
|||||||
|
|
||||||
let response =
|
let response =
|
||||||
match self.client.read_proof(block, &mut request.keys.iter().map(AsRef::as_ref)) {
|
match self.client.read_proof(block, &mut request.keys.iter().map(AsRef::as_ref)) {
|
||||||
Ok(proof) => {
|
Ok(proof) => schema::v1::light::RemoteReadResponse { proof: Some(proof.encode()) },
|
||||||
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
|
|
||||||
Some(schema::v1::light::response::Response::RemoteReadResponse(r))
|
|
||||||
},
|
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
trace!(
|
trace!(
|
||||||
"remote read request from {} ({} at {:?}) failed with: {}",
|
"remote read request from {} ({} at {:?}) failed with: {}",
|
||||||
@@ -225,11 +221,13 @@ where
|
|||||||
request.block,
|
request.block,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
None
|
schema::v1::light::RemoteReadResponse { proof: None }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(schema::v1::light::Response { response })
|
Ok(schema::v1::light::Response {
|
||||||
|
response: Some(schema::v1::light::response::Response::RemoteReadResponse(response)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_remote_read_child_request(
|
fn on_remote_read_child_request(
|
||||||
@@ -264,10 +262,7 @@ where
|
|||||||
&mut request.keys.iter().map(AsRef::as_ref),
|
&mut request.keys.iter().map(AsRef::as_ref),
|
||||||
)
|
)
|
||||||
}) {
|
}) {
|
||||||
Ok(proof) => {
|
Ok(proof) => schema::v1::light::RemoteReadResponse { proof: Some(proof.encode()) },
|
||||||
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
|
|
||||||
Some(schema::v1::light::response::Response::RemoteReadResponse(r))
|
|
||||||
},
|
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
trace!(
|
trace!(
|
||||||
"remote read child request from {} ({} {} at {:?}) failed with: {}",
|
"remote read child request from {} ({} {} at {:?}) failed with: {}",
|
||||||
@@ -277,11 +272,13 @@ where
|
|||||||
request.block,
|
request.block,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
None
|
schema::v1::light::RemoteReadResponse { proof: None }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(schema::v1::light::Response { response })
|
Ok(schema::v1::light::Response {
|
||||||
|
response: Some(schema::v1::light::response::Response::RemoteReadResponse(response)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,3 +23,47 @@ pub(crate) mod v1 {
|
|||||||
include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
|
include!(concat!(env!("OUT_DIR"), "/api.v1.light.rs"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use prost::Message as _;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_proof_encodes_correctly() {
|
||||||
|
let encoded = super::v1::light::Response {
|
||||||
|
response: Some(super::v1::light::response::Response::RemoteReadResponse(
|
||||||
|
super::v1::light::RemoteReadResponse { proof: Some(Vec::new()) },
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
.encode_to_vec();
|
||||||
|
|
||||||
|
// Make sure that the response contains one field of number 2 and wire type 2 (message),
|
||||||
|
// then another field of number 2 and wire type 2 (bytes), then a length of 0.
|
||||||
|
assert_eq!(encoded, vec![(2 << 3) | 2, 2, (2 << 3) | 2, 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_proof_encodes_correctly() {
|
||||||
|
let encoded = super::v1::light::Response {
|
||||||
|
response: Some(super::v1::light::response::Response::RemoteReadResponse(
|
||||||
|
super::v1::light::RemoteReadResponse { proof: None },
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
.encode_to_vec();
|
||||||
|
|
||||||
|
// Make sure that the response contains one field of number 2 and wire type 2 (message).
|
||||||
|
assert_eq!(encoded, vec![(2 << 3) | 2, 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn proof_encodes_correctly() {
|
||||||
|
let encoded = super::v1::light::Response {
|
||||||
|
response: Some(super::v1::light::response::Response::RemoteReadResponse(
|
||||||
|
super::v1::light::RemoteReadResponse { proof: Some(vec![1, 2, 3, 4]) },
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
.encode_to_vec();
|
||||||
|
|
||||||
|
assert_eq!(encoded, vec![(2 << 3) | 2, 6, (2 << 3) | 2, 4, 1, 2, 3, 4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
// Schema definition for light client messages.
|
// Schema definition for light client messages.
|
||||||
|
|
||||||
syntax = "proto3";
|
syntax = "proto2";
|
||||||
|
|
||||||
package api.v1.light;
|
package api.v1.light;
|
||||||
|
|
||||||
// A pair of arbitrary bytes.
|
|
||||||
message Pair {
|
|
||||||
// The first element of the pair.
|
|
||||||
bytes fst = 1;
|
|
||||||
// The second element of the pair.
|
|
||||||
bytes snd = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enumerate all possible light client request messages.
|
// Enumerate all possible light client request messages.
|
||||||
message Request {
|
message Request {
|
||||||
oneof request {
|
oneof request {
|
||||||
@@ -34,40 +26,42 @@ message Response {
|
|||||||
// Remote call request.
|
// Remote call request.
|
||||||
message RemoteCallRequest {
|
message RemoteCallRequest {
|
||||||
// Block at which to perform call.
|
// Block at which to perform call.
|
||||||
bytes block = 2;
|
required bytes block = 2;
|
||||||
// Method name.
|
// Method name.
|
||||||
string method = 3;
|
required string method = 3;
|
||||||
// Call data.
|
// Call data.
|
||||||
bytes data = 4;
|
required bytes data = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote call response.
|
// Remote call response.
|
||||||
message RemoteCallResponse {
|
message RemoteCallResponse {
|
||||||
// Execution proof.
|
// Execution proof. If missing, indicates that the remote couldn't answer, for example because
|
||||||
bytes proof = 2;
|
// the block is pruned.
|
||||||
|
optional bytes proof = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote storage read request.
|
// Remote storage read request.
|
||||||
message RemoteReadRequest {
|
message RemoteReadRequest {
|
||||||
// Block at which to perform call.
|
// Block at which to perform call.
|
||||||
bytes block = 2;
|
required bytes block = 2;
|
||||||
// Storage keys.
|
// Storage keys.
|
||||||
repeated bytes keys = 3;
|
repeated bytes keys = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote read response.
|
// Remote read response.
|
||||||
message RemoteReadResponse {
|
message RemoteReadResponse {
|
||||||
// Read proof.
|
// Read proof. If missing, indicates that the remote couldn't answer, for example because
|
||||||
bytes proof = 2;
|
// the block is pruned.
|
||||||
|
optional bytes proof = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote storage read child request.
|
// Remote storage read child request.
|
||||||
message RemoteReadChildRequest {
|
message RemoteReadChildRequest {
|
||||||
// Block at which to perform call.
|
// Block at which to perform call.
|
||||||
bytes block = 2;
|
required bytes block = 2;
|
||||||
// Child Storage key, this is relative
|
// Child Storage key, this is relative
|
||||||
// to the child type storage location.
|
// to the child type storage location.
|
||||||
bytes storage_key = 3;
|
required bytes storage_key = 3;
|
||||||
// Storage keys.
|
// Storage keys.
|
||||||
repeated bytes keys = 6;
|
repeated bytes keys = 6;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user