mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Update RPC. WIP
This commit is contained in:
@@ -166,13 +166,6 @@ pub struct DecodedBeaconBlockBodiesResponse {
|
|||||||
pub block_bodies: Vec<BeaconBlockBody>,
|
pub block_bodies: Vec<BeaconBlockBody>,
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Build a cleaner API for this encoding/decoding
|
|
||||||
/// This only exists to encode/decode beacon block bodies according to the wire protocol.
|
|
||||||
#[derive(Encode, Decode)]
|
|
||||||
pub struct EncodeableBeaconBlockBodiesResponse {
|
|
||||||
pub block_bodies: Vec<BeaconBlockBody>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Request values for tree hashes which yield a blocks `state_root`.
|
/// Request values for tree hashes which yield a blocks `state_root`.
|
||||||
#[derive(Encode, Decode, Clone, Debug, PartialEq)]
|
#[derive(Encode, Decode, Clone, Debug, PartialEq)]
|
||||||
pub struct BeaconChainStateRequest {
|
pub struct BeaconChainStateRequest {
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ const PROTOCOL_PREFIX: &str = "/eth/serenity/rpc/";
|
|||||||
/// The number of seconds to wait for a request once a protocol has been established before the stream is terminated.
|
/// The number of seconds to wait for a request once a protocol has been established before the stream is terminated.
|
||||||
const REQUEST_TIMEOUT: u64 = 3;
|
const REQUEST_TIMEOUT: u64 = 3;
|
||||||
|
|
||||||
/// Implementation of the `ConnectionUpgrade` for the RPC protocol.
|
|
||||||
const MAX_READ_SIZE: usize = 4_194_304; // 4M
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RPCProtocol;
|
pub struct RPCProtocol;
|
||||||
|
|
||||||
|
|||||||
@@ -254,16 +254,12 @@ impl<T: BeaconChainTypes + 'static> MessageHandler<T> {
|
|||||||
bodies_response: BeaconBlockBodiesResponse,
|
bodies_response: BeaconBlockBodiesResponse,
|
||||||
) -> Option<DecodedBeaconBlockBodiesResponse> {
|
) -> Option<DecodedBeaconBlockBodiesResponse> {
|
||||||
//TODO: Implement faster block verification before decoding entirely
|
//TODO: Implement faster block verification before decoding entirely
|
||||||
let simple_decoded_bodies =
|
|
||||||
EncodeableBeaconBlockBodiesResponse::from_ssz_bytes(&bodies_response.block_bodies);
|
|
||||||
|
|
||||||
//TODO: Potentially improve the types used here for SSZ encoding/decoding
|
|
||||||
if let Ok(simple_decoded_bodies) = simple_decoded_bodies {
|
if let Ok(simple_decoded_bodies) = simple_decoded_bodies {
|
||||||
Some(DecodedBeaconBlockBodiesResponse {
|
Some(DecodedBeaconBlockBodiesResponse {
|
||||||
block_roots: bodies_response
|
block_roots: bodies_response
|
||||||
.block_roots
|
.block_roots
|
||||||
.expect("Responses must have associated roots"),
|
.expect("Responses must have associated roots"),
|
||||||
block_bodies: simple_decoded_bodies.block_bodies,
|
block_bodies: Vec::from_ssz_bytes(&bodies_response.block_bodies).unwrap(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -503,11 +503,7 @@ impl<T: BeaconChainTypes> SimpleSync<T> {
|
|||||||
"returned" => block_bodies.len(),
|
"returned" => block_bodies.len(),
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO: Elegant ssz encoding. Either here or in the message handler
|
let bytes = block_bodes.as_ssz_bytes();
|
||||||
let bytes = {
|
|
||||||
let resp = EncodeableBeaconBlockBodiesResponse { block_bodies };
|
|
||||||
resp.as_ssz_bytes()
|
|
||||||
};
|
|
||||||
|
|
||||||
network.send_rpc_response(
|
network.send_rpc_response(
|
||||||
peer_id,
|
peer_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user