mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Merges in validator client branch
This commit is contained in:
@@ -479,7 +479,7 @@ where
|
||||
}
|
||||
|
||||
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
||||
pub fn produce_attestation(&self, shard: u64) -> Result<AttestationData, Error> {
|
||||
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
||||
trace!("BeaconChain::produce_attestation: shard: {}", shard);
|
||||
let source_epoch = self.state.read().current_justified_epoch;
|
||||
let source_root = *self.state.read().get_block_root(
|
||||
|
||||
@@ -50,12 +50,12 @@ impl<T: ClientDB, U: SlotClock, F: ForkChoice> DirectBeaconNode<T, U, F> {
|
||||
}
|
||||
|
||||
impl<T: ClientDB, U: SlotClock, F: ForkChoice> AttesterBeaconNode for DirectBeaconNode<T, U, F> {
|
||||
fn produce_attestation(
|
||||
fn produce_attestation_data(
|
||||
&self,
|
||||
_slot: Slot,
|
||||
shard: u64,
|
||||
) -> Result<Option<AttestationData>, NodeError> {
|
||||
match self.beacon_chain.produce_attestation(shard) {
|
||||
match self.beacon_chain.produce_attestation_data(shard) {
|
||||
Ok(attestation_data) => Ok(Some(attestation_data)),
|
||||
Err(e) => Err(NodeError::RemoteFailure(format!("{:?}", e))),
|
||||
}
|
||||
|
||||
@@ -1,45 +1,63 @@
|
||||
use crate::beacon_chain::BeaconChain;
|
||||
use futures::Future;
|
||||
use grpcio::{RpcContext, UnarySink};
|
||||
use grpcio::{RpcContext, UnarySink, RpcStatus, RpcStatusCode};
|
||||
use protos::services::{
|
||||
Attestation as AttestationProto, ProduceAttestation, ProduceAttestationResponse,
|
||||
ProduceAttestationRequest, PublishAttestationResponse, PublishAttestationRequest,
|
||||
AttestationData as AttestationDataProto, ProduceAttestationData, ProduceAttestationDataResponse,
|
||||
ProduceAttestationDataRequest, PublishAttestationResponse, PublishAttestationRequest,
|
||||
PublishAttestation
|
||||
};
|
||||
use protos::services_grpc::BeaconBlockService;
|
||||
use slog::Logger;
|
||||
use slog::{Logger, info, warn, error};
|
||||
|
||||
const TEST_SHARD_PHASE_ZERO: u8 = 0;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AttestationServiceInstance {
|
||||
pub chain: Arc<BeaconChain>,
|
||||
pub log: Logger,
|
||||
}
|
||||
|
||||
impl AttestationService for AttestationServiceInstance {
|
||||
/// Produce a `BeaconBlock` for signing by a validator.
|
||||
fn produce_attestation(
|
||||
/// Produce the `AttestationData` for signing by a validator.
|
||||
fn produce_attestation_data(
|
||||
&mut self,
|
||||
ctx: RpcContext,
|
||||
req: ProduceAttestationRequest,
|
||||
sink: UnarySink<ProduceAttestationResponse>,
|
||||
req: ProduceAttestationDataRequest,
|
||||
sink: UnarySink<ProduceAttestationDataResponse>,
|
||||
) {
|
||||
println!("producing attestation at slot {}", req.get_slot());
|
||||
info!(&self.log, "Attempting to produce attestation at slot {}", req.get_slot());
|
||||
|
||||
// TODO: build a legit block.
|
||||
let mut attestation = AttestationProto::new();
|
||||
attestation.set_slot(req.get_slot());
|
||||
// TODO Set the shard to something legit.
|
||||
attestation.set_shard(0);
|
||||
attestation.set_block_root(b"cats".to_vec());
|
||||
// get the chain spec & state
|
||||
let spec = self.chain.get_spec();
|
||||
let state = self.chain.get_state();
|
||||
|
||||
let mut resp = ProduceAttestationResponse::new();
|
||||
resp.set_attestation_data(attestation);
|
||||
let slot_requested = req.get_slot();
|
||||
|
||||
// Start by performing some checks
|
||||
// Check that the the AttestionData is for the current slot (otherwise it will not be valid)
|
||||
if slot_requested != state.slot {
|
||||
let f = sink
|
||||
.fail(RpcStatus::new(
|
||||
RpcStatusCode::OutOfRange,
|
||||
"AttestationData request for a slot that is not the current slot."
|
||||
))
|
||||
.map_err(move |e| error!(&self.log, "Failed to reply with failure {:?}: {:?}", req, e));
|
||||
}
|
||||
|
||||
// Then get the AttestationData from the beacon chain (for shard 0 for now)
|
||||
let attestation_data = self.chain.produce_attestation_data(TEST_SHARD_PHASE_ZERO);
|
||||
|
||||
let mut resp = ProduceAttestationDataResponse::new();
|
||||
resp.set_attestation_data(attestation_data);
|
||||
|
||||
let f = sink
|
||||
.success(resp)
|
||||
.map_err(move |e| println!("failed to reply {:?}: {:?}", req, e));
|
||||
.map_err(move |e| error!("Failed to reply with success {:?}: {:?}", req, e));
|
||||
ctx.spawn(f)
|
||||
}
|
||||
|
||||
/// Accept some fully-formed `BeaconBlock`, process and publish it.
|
||||
/// Accept some fully-formed `FreeAttestation` from the validator,
|
||||
/// store it, and aggregate it into an `Attestation`.
|
||||
fn publish_attestation(
|
||||
&mut self,
|
||||
ctx: RpcContext,
|
||||
|
||||
Reference in New Issue
Block a user