diff --git a/beacon_node/libp2p/src/rpc/methods.rs b/beacon_node/libp2p/src/rpc/methods.rs index 1a35763ff2..4ee73761d5 100644 --- a/beacon_node/libp2p/src/rpc/methods.rs +++ b/beacon_node/libp2p/src/rpc/methods.rs @@ -1,12 +1,13 @@ /// Available RPC methods types and ids. use ssz_derive::{Decode, Encode}; -use types::{Epoch, Hash256, Slot}; +use types::{BeaconBlockHeader, Epoch, Hash256, Slot}; #[derive(Debug)] pub enum RPCMethod { Hello, Goodbye, BeaconBlockRoots, + BeaconBlockHeaders, Unknown, } @@ -16,6 +17,7 @@ impl From for RPCMethod { 0 => RPCMethod::Hello, 1 => RPCMethod::Goodbye, 10 => RPCMethod::BeaconBlockRoots, + 11 => RPCMethod::BeaconBlockHeaders, _ => RPCMethod::Unknown, } } @@ -27,6 +29,7 @@ impl Into for RPCMethod { RPCMethod::Hello => 0, RPCMethod::Goodbye => 1, RPCMethod::BeaconBlockRoots => 10, + RPCMethod::BeaconBlockHeaders => 11, _ => 0, } } @@ -37,12 +40,14 @@ pub enum RPCRequest { Hello(HelloMessage), Goodbye(u64), BeaconBlockRoots(BeaconBlockRootsRequest), + BeaconBlockHeaders(BeaconBlockHeadersRequest), } #[derive(Debug, Clone)] pub enum RPCResponse { Hello(HelloMessage), BeaconBlockRoots(BeaconBlockRootsResponse), + BeaconBlockHeaders(BeaconBlockHeadersResponse), } /* Request/Response data structures for RPC methods */ @@ -71,7 +76,7 @@ pub struct BeaconBlockRootsRequest { count: u64, // this must be less than 32768. //TODO: Enforce this in the lower layers } -/// Response a number of beacon block roots from a peer. +/// Response containing a number of beacon block roots from a peer. #[derive(Encode, Decode, Clone, Debug)] pub struct BeaconBlockRootsResponse { /// List of requested blocks and associated slots. @@ -86,3 +91,23 @@ pub struct BlockRootSlot { /// The block slot. slot: Slot, } + +/// Request a number of beacon block headers from a peer. +#[derive(Encode, Decode, Clone, Debug)] +pub struct BeaconBlockHeadersRequest { + /// The starting header hash of the requested headers. + start_root: Hash256, + /// The starting slot of the requested headers. + start_slot: Slot, + /// The maximum number of headers than can be returned. + max_headers: u64, + /// The maximum number of slots to skip between blocks. + skip_slots: u64, +} + +/// Response containing requested block headers. +#[derive(Encode, Decode, Clone, Debug)] +pub struct BeaconBlockHeadersResponse { + /// The list of requested beacon block headers. + headers: Vec, +}