Implement RequestBeaconBlockRoots RPC method
This commit is contained in:
parent
0e8b174770
commit
8acfb260d1
@ -6,6 +6,7 @@ use types::{Epoch, Hash256, Slot};
|
||||
pub enum RPCMethod {
|
||||
Hello,
|
||||
Goodbye,
|
||||
RequestBeaconBlockRoots,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
@ -14,6 +15,7 @@ impl From<u16> for RPCMethod {
|
||||
match method_id {
|
||||
0 => RPCMethod::Hello,
|
||||
1 => RPCMethod::Goodbye,
|
||||
10 => RPCMethod::RequestBeaconBlockRoots,
|
||||
_ => RPCMethod::Unknown,
|
||||
}
|
||||
}
|
||||
@ -24,6 +26,7 @@ impl Into<u16> for RPCMethod {
|
||||
match self {
|
||||
RPCMethod::Hello => 0,
|
||||
RPCMethod::Goodbye => 1,
|
||||
RPCMethod::RequestBeaconBlockRoots => 10,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
@ -33,19 +36,53 @@ impl Into<u16> for RPCMethod {
|
||||
pub enum RPCRequest {
|
||||
Hello(HelloMessage),
|
||||
Goodbye(u64),
|
||||
RequestBeaconBlockRoots(BeaconBlockRootsRequest),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RPCResponse {
|
||||
Hello(HelloMessage),
|
||||
RequestBeaconBlockRoots(BeaconBlockRootsResponse),
|
||||
}
|
||||
|
||||
// request/response structs for RPC methods
|
||||
/* Request/Response data structures for RPC methods */
|
||||
|
||||
/// The HELLO request/response handshake message.
|
||||
#[derive(Encode, Decode, Clone, Debug)]
|
||||
pub struct HelloMessage {
|
||||
/// The network ID of the peer.
|
||||
pub network_id: u8,
|
||||
/// The peers last finalized root.
|
||||
pub latest_finalized_root: Hash256,
|
||||
/// The peers last finalized epoch.
|
||||
pub latest_finalized_epoch: Epoch,
|
||||
/// The peers last block root.
|
||||
pub best_root: Hash256,
|
||||
/// The peers last slot.
|
||||
pub best_slot: Slot,
|
||||
}
|
||||
|
||||
/// Request a number of beacon block roots from a peer.
|
||||
#[derive(Encode, Decode, Clone, Debug)]
|
||||
pub struct BeaconBlockRootsRequest {
|
||||
/// The starting slot of the requested blocks.
|
||||
start_slot: Slot,
|
||||
/// The number of blocks from the start slot.
|
||||
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.
|
||||
#[derive(Encode, Decode, Clone, Debug)]
|
||||
pub struct BeaconBlockRootsResponse {
|
||||
/// List of requested blocks and associated slots.
|
||||
roots: Vec<BlockRootSlot>,
|
||||
}
|
||||
|
||||
/// Contains a block root and associated slot.
|
||||
#[derive(Encode, Decode, Clone, Debug)]
|
||||
pub struct BlockRootSlot {
|
||||
/// The block root.
|
||||
block_root: Hash256,
|
||||
/// The block slot.
|
||||
slot: Slot,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user