started implementing BeaconNode for AttestationGrpcClient; included correct epoch_map for instantiation of Attester (lighthouse-255)
This commit is contained in:
parent
c269cb40c4
commit
d8099ae00c
@ -2,6 +2,7 @@ use protos::services_grpc::AttestationServiceClient;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use attester::{BeaconNode, BeaconNodeError, PublishOutcome};
|
use attester::{BeaconNode, BeaconNodeError, PublishOutcome};
|
||||||
|
use protos::services::ProduceAttestationDataRequest;
|
||||||
use types::{AttestationData, FreeAttestation, Slot};
|
use types::{AttestationData, FreeAttestation, Slot};
|
||||||
|
|
||||||
pub struct AttestationGrpcClient {
|
pub struct AttestationGrpcClient {
|
||||||
@ -20,6 +21,16 @@ impl BeaconNode for AttestationGrpcClient {
|
|||||||
slot: Slot,
|
slot: Slot,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
) -> Result<Option<AttestationData>, BeaconNodeError> {
|
) -> Result<Option<AttestationData>, BeaconNodeError> {
|
||||||
|
let mut req = ProduceAttestationDataRequest::new();
|
||||||
|
req.set_slot(slot.as_u64());
|
||||||
|
req.set_shard(shard);
|
||||||
|
|
||||||
|
let reply = self
|
||||||
|
.client
|
||||||
|
.produce_attestation_data(&req)
|
||||||
|
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
||||||
|
|
||||||
|
// TODO: return correct AttestationData
|
||||||
Err(BeaconNodeError::DecodeFailure)
|
Err(BeaconNodeError::DecodeFailure)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +38,7 @@ impl BeaconNode for AttestationGrpcClient {
|
|||||||
&self,
|
&self,
|
||||||
free_attestation: FreeAttestation,
|
free_attestation: FreeAttestation,
|
||||||
) -> Result<PublishOutcome, BeaconNodeError> {
|
) -> Result<PublishOutcome, BeaconNodeError> {
|
||||||
|
// TODO: return correct PublishOutcome
|
||||||
Err(BeaconNodeError::DecodeFailure)
|
Err(BeaconNodeError::DecodeFailure)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use self::block_producer_service::{BeaconBlockGrpcClient, BlockProducerService};
|
|||||||
use self::duties::{DutiesManager, DutiesManagerService, EpochDutiesMap};
|
use self::duties::{DutiesManager, DutiesManagerService, EpochDutiesMap};
|
||||||
use crate::attester_service::{AttestationGrpcClient, AttesterService};
|
use crate::attester_service::{AttestationGrpcClient, AttesterService};
|
||||||
use crate::config::ClientConfig;
|
use crate::config::ClientConfig;
|
||||||
|
use attester::test_utils::EpochMap;
|
||||||
use attester::{test_utils::LocalSigner as AttesterLocalSigner, Attester};
|
use attester::{test_utils::LocalSigner as AttesterLocalSigner, Attester};
|
||||||
use block_proposer::{test_utils::LocalSigner as BlockProposerLocalSigner, BlockProducer};
|
use block_proposer::{test_utils::LocalSigner as BlockProposerLocalSigner, BlockProducer};
|
||||||
use bls::Keypair;
|
use bls::Keypair;
|
||||||
@ -19,7 +20,6 @@ use types::ChainSpec;
|
|||||||
|
|
||||||
mod attester_service;
|
mod attester_service;
|
||||||
mod block_producer_service;
|
mod block_producer_service;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod duties;
|
mod duties;
|
||||||
|
|
||||||
@ -143,6 +143,7 @@ fn main() {
|
|||||||
for keypair in keypairs {
|
for keypair in keypairs {
|
||||||
info!(log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
info!(log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
||||||
let duties_map = Arc::new(EpochDutiesMap::new(spec.slots_per_epoch));
|
let duties_map = Arc::new(EpochDutiesMap::new(spec.slots_per_epoch));
|
||||||
|
let epoch_map_for_attester = Arc::new(EpochMap::new(spec.slots_per_epoch));
|
||||||
|
|
||||||
// Spawn a new thread to maintain the validator's `EpochDuties`.
|
// Spawn a new thread to maintain the validator's `EpochDuties`.
|
||||||
let duties_manager_thread = {
|
let duties_manager_thread = {
|
||||||
@ -191,15 +192,15 @@ fn main() {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
// Spawn a new thread for attestation for the validator.
|
// Spawn a new thread for attestation for the validator.
|
||||||
let attester_thread = {
|
let attester_thread = {
|
||||||
let signer = Arc::new(AttesterLocalSigner::new(keypair.clone()));
|
let signer = Arc::new(AttesterLocalSigner::new(keypair.clone()));
|
||||||
let duties_map = duties_map.clone();
|
let epoch_map = epoch_map_for_attester.clone();
|
||||||
let slot_clock = slot_clock.clone();
|
let slot_clock = slot_clock.clone();
|
||||||
let log = log.clone();
|
let log = log.clone();
|
||||||
let client = Arc::new(AttestationGrpcClient::new(attester_grpc_client.clone()));
|
let client = Arc::new(AttestationGrpcClient::new(attester_grpc_client.clone()));
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let attester = Attester::new(duties_map, slot_clock, client, signer);
|
let attester = Attester::new(epoch_map, slot_clock, client, signer);
|
||||||
let mut attester_service = AttesterService {
|
let mut attester_service = AttesterService {
|
||||||
attester,
|
attester,
|
||||||
poll_interval_millis,
|
poll_interval_millis,
|
||||||
@ -210,13 +211,14 @@ fn main() {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
threads.push((duties_manager_thread, producer_thread));
|
threads.push((duties_manager_thread, producer_thread, attester_thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Naively wait for all the threads to complete.
|
// Naively wait for all the threads to complete.
|
||||||
for tuple in threads {
|
for tuple in threads {
|
||||||
let (manager, producer) = tuple;
|
let (manager, producer, attester) = tuple;
|
||||||
let _ = producer.join();
|
let _ = producer.join();
|
||||||
let _ = manager.join();
|
let _ = manager.join();
|
||||||
|
let _ = attester.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user