mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 13:54:44 +00:00
Split out validator index gRPC call
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use super::traits::{BeaconNode, BeaconNodeError};
|
||||
use super::EpochDuties;
|
||||
use protos::services::ValidatorAssignmentRequest;
|
||||
use protos::services::{
|
||||
IndexResponse, ProposeBlockSlotRequest, ProposeBlockSlotResponse, PublicKey as IndexRequest,
|
||||
};
|
||||
use protos::services_grpc::ValidatorServiceClient;
|
||||
use ssz::ssz_encode;
|
||||
use types::PublicKey;
|
||||
@@ -11,30 +13,33 @@ impl BeaconNode for ValidatorServiceClient {
|
||||
epoch: u64,
|
||||
public_key: &PublicKey,
|
||||
) -> Result<Option<EpochDuties>, BeaconNodeError> {
|
||||
let mut req = ValidatorAssignmentRequest::new();
|
||||
// Lookup the validator index for the supplied public key.
|
||||
let validator_index = {
|
||||
let mut req = IndexRequest::new();
|
||||
req.set_public_key(ssz_encode(public_key).to_vec());
|
||||
let resp = self
|
||||
.validator_index(&req)
|
||||
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
||||
resp.get_index()
|
||||
};
|
||||
|
||||
let mut req = ProposeBlockSlotRequest::new();
|
||||
req.set_validator_index(validator_index);
|
||||
req.set_epoch(epoch);
|
||||
req.set_public_key(ssz_encode(public_key).to_vec());
|
||||
|
||||
let reply = self
|
||||
.validator_assignment(&req)
|
||||
.propose_block_slot(&req)
|
||||
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
||||
|
||||
if reply.has_validator_assignment() {
|
||||
let assignment = reply.get_validator_assignment();
|
||||
|
||||
let block_production_slot = if assignment.has_block_production_slot() {
|
||||
Some(assignment.get_block_production_slot())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let duties = EpochDuties {
|
||||
block_production_slot,
|
||||
};
|
||||
|
||||
Ok(Some(duties))
|
||||
let block_production_slot = if reply.has_slot() {
|
||||
Some(reply.get_slot())
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
Ok(Some(EpochDuties {
|
||||
validator_index,
|
||||
block_production_slot,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user