Adds attestation producer to the validation client
This commit is contained in:
parent
d8fd7c8803
commit
e1befe9d3a
@ -8,15 +8,13 @@
|
|||||||
/// When a validator needs to either produce a block or sign an attestation, it requests the
|
/// When a validator needs to either produce a block or sign an attestation, it requests the
|
||||||
/// data from the beacon node and performs the signing before publishing the block to the beacon
|
/// data from the beacon node and performs the signing before publishing the block to the beacon
|
||||||
/// node.
|
/// node.
|
||||||
//use crate::attester_service::{AttestationGrpcClient, AttesterService};
|
use crate::attestation_producer::AttestationProducer;
|
||||||
use crate::block_producer::{BeaconBlockGrpcClient, BlockProducer};
|
use crate::block_producer::{BeaconBlockGrpcClient, BlockProducer};
|
||||||
use crate::config::Config as ValidatorConfig;
|
use crate::config::Config as ValidatorConfig;
|
||||||
use crate::duties::{BeaconNodeDuties, DutiesManager, EpochDutiesMap, UpdateOutcome};
|
use crate::duties::{BeaconNodeDuties, DutiesManager, EpochDutiesMap};
|
||||||
use crate::error as error_chain;
|
use crate::error as error_chain;
|
||||||
use crate::error::ErrorKind;
|
use crate::error::ErrorKind;
|
||||||
use crate::signer::Signer;
|
use crate::signer::Signer;
|
||||||
use attester::test_utils::EpochMap;
|
|
||||||
use attester::{test_utils::LocalSigner as AttesterLocalSigner, Attester};
|
|
||||||
use bls::Keypair;
|
use bls::Keypair;
|
||||||
use grpcio::{ChannelBuilder, EnvBuilder};
|
use grpcio::{ChannelBuilder, EnvBuilder};
|
||||||
use protos::services::Empty;
|
use protos::services::Empty;
|
||||||
@ -24,11 +22,10 @@ use protos::services_grpc::{
|
|||||||
AttestationServiceClient, BeaconBlockServiceClient, BeaconNodeServiceClient,
|
AttestationServiceClient, BeaconBlockServiceClient, BeaconNodeServiceClient,
|
||||||
ValidatorServiceClient,
|
ValidatorServiceClient,
|
||||||
};
|
};
|
||||||
use slog::{debug, error, info, warn};
|
use slog::{error, info, warn};
|
||||||
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use std::thread;
|
|
||||||
use std::time::{Duration, Instant, SystemTime};
|
use std::time::{Duration, Instant, SystemTime};
|
||||||
use tokio::prelude::*;
|
use tokio::prelude::*;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
@ -55,7 +52,7 @@ pub struct Service<B: BeaconNodeDuties + 'static, S: Signer + 'static> {
|
|||||||
/// The beacon block GRPC client.
|
/// The beacon block GRPC client.
|
||||||
beacon_block_client: Arc<BeaconBlockGrpcClient>,
|
beacon_block_client: Arc<BeaconBlockGrpcClient>,
|
||||||
/// The attester GRPC client.
|
/// The attester GRPC client.
|
||||||
attester_client: Arc<AttestationServiceClient>,
|
attestation_client: Arc<AttestationServiceClient>,
|
||||||
/// The validator client logger.
|
/// The validator client logger.
|
||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
}
|
}
|
||||||
@ -148,7 +145,7 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static> Service<B, S> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Beacon node gRPC attester endpoints.
|
//Beacon node gRPC attester endpoints.
|
||||||
let attester_client = {
|
let attestation_client = {
|
||||||
let ch = ChannelBuilder::new(env.clone()).connect(&config.server);
|
let ch = ChannelBuilder::new(env.clone()).connect(&config.server);
|
||||||
Arc::new(AttestationServiceClient::new(ch))
|
Arc::new(AttestationServiceClient::new(ch))
|
||||||
};
|
};
|
||||||
@ -194,7 +191,7 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static> Service<B, S> {
|
|||||||
spec,
|
spec,
|
||||||
duties_manager,
|
duties_manager,
|
||||||
beacon_block_client,
|
beacon_block_client,
|
||||||
attester_client,
|
attestation_client,
|
||||||
log,
|
log,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -301,6 +298,7 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static> Service<B, S> {
|
|||||||
if let Some(work) = self.duties_manager.get_current_work(self.current_slot) {
|
if let Some(work) = self.duties_manager.get_current_work(self.current_slot) {
|
||||||
for (signer_index, work_type) in work {
|
for (signer_index, work_type) in work {
|
||||||
if work_type.produce_block {
|
if work_type.produce_block {
|
||||||
|
// we need to produce a block
|
||||||
// spawns a thread to produce a beacon block
|
// spawns a thread to produce a beacon block
|
||||||
let signers = self.duties_manager.signers.clone(); // this is an arc
|
let signers = self.duties_manager.signers.clone(); // this is an arc
|
||||||
let fork = self.fork.clone();
|
let fork = self.fork.clone();
|
||||||
@ -320,26 +318,27 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static> Service<B, S> {
|
|||||||
};
|
};
|
||||||
block_producer.handle_produce_block(log);
|
block_producer.handle_produce_block(log);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Produce a beacon block in a new thread
|
|
||||||
}
|
}
|
||||||
if work_type.attestation_duty.is_some() {
|
if work_type.attestation_duty.is_some() {
|
||||||
// available AttestationDuty info
|
// we need to produce an attestation
|
||||||
/*
|
// spawns a thread to produce and sign an attestation
|
||||||
let attestation_duty =
|
let signers = self.duties_manager.signers.clone(); // this is an arc
|
||||||
work_type.attestation_duty.expect("Cannot be None");
|
let fork = self.fork.clone();
|
||||||
let attester_grpc_client = Arc::new(AttestationGrpcClient::new(
|
let spec = self.spec.clone();
|
||||||
service.attester_client.clone(),
|
let beacon_node = self.attestation_client.clone();
|
||||||
));
|
let log = self.log.clone();
|
||||||
let signer = Arc::new(AttesterLocalSigner::new(keypair.clone()));
|
std::thread::spawn(move || {
|
||||||
let attester = Attester::new(attester_grpc_client, signer);
|
info!(log, "Producing an attestation"; "Validator"=> format!("{}", signers[signer_index]));
|
||||||
let mut attester_service = AttesterService {
|
let signer = &signers[signer_index];
|
||||||
attester,
|
let mut attestation_producer = AttestationProducer {
|
||||||
poll_interval_millis: POLL_INTERVAL_MILLIS,
|
fork,
|
||||||
log: log.clone(),
|
duty: work_type.attestation_duty.expect("Should never be none"),
|
||||||
|
spec,
|
||||||
|
beacon_node,
|
||||||
|
signer,
|
||||||
};
|
};
|
||||||
attester_service.run();
|
attestation_producer.handle_produce_attestation(log);
|
||||||
*/
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user