Set GRPC block to be just SSZ
This commit is contained in:
parent
33d0f29221
commit
d4fecd8a84
@ -9,8 +9,10 @@ use protos::services::{
|
|||||||
PublishBeaconBlockRequest, PublishBeaconBlockResponse,
|
PublishBeaconBlockRequest, PublishBeaconBlockResponse,
|
||||||
};
|
};
|
||||||
use protos::services_grpc::BeaconBlockService;
|
use protos::services_grpc::BeaconBlockService;
|
||||||
|
use slog::debug;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use types::{Hash256, Slot};
|
use ssz::{Decodable, TreeHash};
|
||||||
|
use types::{BeaconBlock, Hash256, Slot};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BeaconBlockServiceInstance {
|
pub struct BeaconBlockServiceInstance {
|
||||||
@ -30,8 +32,7 @@ impl BeaconBlockService for BeaconBlockServiceInstance {
|
|||||||
|
|
||||||
// TODO: build a legit block.
|
// TODO: build a legit block.
|
||||||
let mut block = BeaconBlockProto::new();
|
let mut block = BeaconBlockProto::new();
|
||||||
block.set_slot(req.get_slot());
|
block.set_ssz(b"cats".to_vec());
|
||||||
block.set_block_root(b"cats".to_vec());
|
|
||||||
|
|
||||||
let mut resp = ProduceBeaconBlockResponse::new();
|
let mut resp = ProduceBeaconBlockResponse::new();
|
||||||
resp.set_block(block);
|
resp.set_block(block);
|
||||||
@ -49,17 +50,21 @@ impl BeaconBlockService for BeaconBlockServiceInstance {
|
|||||||
req: PublishBeaconBlockRequest,
|
req: PublishBeaconBlockRequest,
|
||||||
sink: UnarySink<PublishBeaconBlockResponse>,
|
sink: UnarySink<PublishBeaconBlockResponse>,
|
||||||
) {
|
) {
|
||||||
|
debug!(self.log, "PublishBeaconBlock");
|
||||||
|
|
||||||
let block = req.get_block();
|
let block = req.get_block();
|
||||||
let block_root = Hash256::from_slice(block.get_block_root());
|
|
||||||
let block_slot = BlockRootSlot {
|
match BeaconBlock::ssz_decode(block.get_ssz(), 0) {
|
||||||
block_root,
|
Ok((block, _i)) => {
|
||||||
slot: Slot::from(block.get_slot()),
|
let block_root = Hash256::from_slice(&block.hash_tree_root()[..]);
|
||||||
};
|
|
||||||
println!("publishing block with root {:?}", block_root);
|
|
||||||
|
|
||||||
// TODO: Obtain topics from the network service properly.
|
// TODO: Obtain topics from the network service properly.
|
||||||
let topic = types::TopicBuilder::new("beacon_chain".to_string()).build();
|
let topic = types::TopicBuilder::new("beacon_chain".to_string()).build();
|
||||||
let message = PubsubMessage::Block(block_slot);
|
let message = PubsubMessage::Block(BlockRootSlot {
|
||||||
|
block_root,
|
||||||
|
slot: block.slot,
|
||||||
|
});
|
||||||
|
|
||||||
println!("Sending beacon block to gossipsub");
|
println!("Sending beacon block to gossipsub");
|
||||||
self.network_chan.send(NetworkMessage::Publish {
|
self.network_chan.send(NetworkMessage::Publish {
|
||||||
topics: vec![topic],
|
topics: vec![topic],
|
||||||
@ -75,4 +80,9 @@ impl BeaconBlockService for BeaconBlockServiceInstance {
|
|||||||
.map_err(move |e| println!("failed to reply {:?}: {:?}", req, e));
|
.map_err(move |e| println!("failed to reply {:?}: {:?}", req, e));
|
||||||
ctx.spawn(f)
|
ctx.spawn(f)
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,7 @@ message PublishBeaconBlockResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message BeaconBlock {
|
message BeaconBlock {
|
||||||
uint64 slot = 1;
|
bytes ssz = 1;
|
||||||
bytes block_root = 2;
|
|
||||||
bytes randao_reveal = 3;
|
|
||||||
bytes signature = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5,7 +5,7 @@ use protos::services::{
|
|||||||
use protos::services_grpc::BeaconBlockServiceClient;
|
use protos::services_grpc::BeaconBlockServiceClient;
|
||||||
use ssz::{ssz_encode, Decodable};
|
use ssz::{ssz_encode, Decodable};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, BeaconBlockBody, Eth1Data, Hash256, Signature, Slot};
|
use types::{BeaconBlock, Signature, Slot};
|
||||||
|
|
||||||
/// A newtype designed to wrap the gRPC-generated service so the `BeaconNode` trait may be
|
/// A newtype designed to wrap the gRPC-generated service so the `BeaconNode` trait may be
|
||||||
/// implemented upon it.
|
/// implemented upon it.
|
||||||
@ -40,33 +40,12 @@ impl BeaconNode for BeaconBlockGrpcClient {
|
|||||||
|
|
||||||
if reply.has_block() {
|
if reply.has_block() {
|
||||||
let block = reply.get_block();
|
let block = reply.get_block();
|
||||||
|
let ssz = block.get_ssz();
|
||||||
|
|
||||||
let (signature, _) = Signature::ssz_decode(block.get_signature(), 0)
|
let (block, _i) =
|
||||||
.map_err(|_| BeaconNodeError::DecodeFailure)?;
|
BeaconBlock::ssz_decode(&ssz, 0).map_err(|_| BeaconNodeError::DecodeFailure)?;
|
||||||
|
|
||||||
let (randao_reveal, _) = Signature::ssz_decode(block.get_randao_reveal(), 0)
|
Ok(Some(block))
|
||||||
.map_err(|_| BeaconNodeError::DecodeFailure)?;
|
|
||||||
|
|
||||||
// TODO: this conversion is incomplete; fix it.
|
|
||||||
Ok(Some(BeaconBlock {
|
|
||||||
slot: Slot::new(block.get_slot()),
|
|
||||||
previous_block_root: Hash256::zero(),
|
|
||||||
state_root: Hash256::zero(),
|
|
||||||
signature,
|
|
||||||
body: BeaconBlockBody {
|
|
||||||
randao_reveal,
|
|
||||||
eth1_data: Eth1Data {
|
|
||||||
deposit_root: Hash256::zero(),
|
|
||||||
block_hash: Hash256::zero(),
|
|
||||||
},
|
|
||||||
proposer_slashings: vec![],
|
|
||||||
attester_slashings: vec![],
|
|
||||||
attestations: vec![],
|
|
||||||
deposits: vec![],
|
|
||||||
voluntary_exits: vec![],
|
|
||||||
transfers: vec![],
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
@ -79,12 +58,11 @@ impl BeaconNode for BeaconBlockGrpcClient {
|
|||||||
fn publish_beacon_block(&self, block: BeaconBlock) -> Result<PublishOutcome, BeaconNodeError> {
|
fn publish_beacon_block(&self, block: BeaconBlock) -> Result<PublishOutcome, BeaconNodeError> {
|
||||||
let mut req = PublishBeaconBlockRequest::new();
|
let mut req = PublishBeaconBlockRequest::new();
|
||||||
|
|
||||||
|
let ssz = ssz_encode(&block);
|
||||||
|
|
||||||
// TODO: this conversion is incomplete; fix it.
|
// TODO: this conversion is incomplete; fix it.
|
||||||
let mut grpc_block = GrpcBeaconBlock::new();
|
let mut grpc_block = GrpcBeaconBlock::new();
|
||||||
grpc_block.set_slot(block.slot.as_u64());
|
grpc_block.set_ssz(ssz);
|
||||||
grpc_block.set_block_root(vec![0]);
|
|
||||||
grpc_block.set_randao_reveal(ssz_encode(&block.body.randao_reveal));
|
|
||||||
grpc_block.set_signature(ssz_encode(&block.signature));
|
|
||||||
|
|
||||||
req.set_block(grpc_block);
|
req.set_block(grpc_block);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user