added protos specification for Attester and created first draft for attestation_grpc_client (lighthouse-255)
This commit is contained in:
		
							parent
							
								
									e02bc82b6a
								
							
						
					
					
						commit
						2215aa4b46
					
				| @ -23,6 +23,11 @@ service ValidatorService { | ||||
| 	rpc ValidatorIndex(PublicKey) returns (IndexResponse); | ||||
| } | ||||
| 
 | ||||
| service AttestationService { | ||||
| 	rpc ProduceAttestationData (ProduceAttestationDataRequest) returns (ProduceAttestationDataResponse); | ||||
| 	rpc PublishAttestationData (PublishAttestationDataRequest) returns (PublishAttestationDataResponse); | ||||
| } | ||||
| 
 | ||||
| message BeaconBlock { | ||||
| 	uint64 slot = 1; | ||||
| 	bytes block_root = 2; | ||||
| @ -30,6 +35,30 @@ message BeaconBlock { | ||||
| 	bytes signature = 4; | ||||
| } | ||||
| 
 | ||||
| message Crosslink { | ||||
| 	uint64 epoch = 1; | ||||
| 	bytes crosslink_data_root = 2; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| message AttestationData { | ||||
| 	uint64 slot = 1; | ||||
| 	uint64 shard = 2; | ||||
| 	bytes beacon_block_root = 3; | ||||
| 	bytes epoch_boundary_root = 4; | ||||
| 	bytes crosslink_data_root = 5; | ||||
| 	Crosslink latest_crosslink = 6; | ||||
| 	uint64 justified_epoch = 7; | ||||
| 	bytes justified_block_root = 8; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| message FreeAttestation { | ||||
| 	AttestationData attestation_data = 1; | ||||
| 	bytes signature = 2; | ||||
| 	uint64 validator_index = 3; | ||||
| } | ||||
| 
 | ||||
| // Validator requests an unsigned proposal. | ||||
| message ProduceBeaconBlockRequest { | ||||
|     uint64 slot = 1; | ||||
| @ -51,6 +80,24 @@ message PublishBeaconBlockResponse { | ||||
|     bytes msg = 2; | ||||
| } | ||||
| 
 | ||||
| message ProduceAttestationDataRequest { | ||||
| 	uint64 slot = 1; | ||||
| 	uint64 shard = 2; | ||||
| } | ||||
| 
 | ||||
| message ProduceAttestationDataResponse { | ||||
| 	AttestationData attestation_data = 1; | ||||
| } | ||||
| 
 | ||||
| message PublishAttestationDataRequest { | ||||
| 	FreeAttestation free_attestation = 1; | ||||
| } | ||||
| 
 | ||||
| message PublishAttestationDataResponse { | ||||
| 	bool success = 1; | ||||
| 	bytes msg = 2; | ||||
| } | ||||
| 
 | ||||
| // A validators duties for some epoch. | ||||
| // TODO: add shard duties. | ||||
| message ValidatorAssignment { | ||||
|  | ||||
| @ -0,0 +1,32 @@ | ||||
| use protos::services_grpc::AttestationServiceClient; | ||||
| use std::sync::Arc; | ||||
| 
 | ||||
| use attester::{BeaconNode, BeaconNodeError, PublishOutcome}; | ||||
| use types::{AttestationData, FreeAttestation, Slot}; | ||||
| 
 | ||||
| pub struct AttestationGrpcClient { | ||||
|     client: Arc<AttestationServiceClient>, | ||||
| } | ||||
| 
 | ||||
| impl AttestationGrpcClient { | ||||
|     pub fn new(client: Arc<AttestationServiceClient>) -> Self { | ||||
|         Self { client } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl BeaconNode for AttestationGrpcClient { | ||||
|     fn produce_attestation_data( | ||||
|         &self, | ||||
|         slot: Slot, | ||||
|         shard: u64, | ||||
|     ) -> Result<Option<AttestationData>, BeaconNodeError> { | ||||
|         Err(BeaconNodeError::DecodeFailure) | ||||
|     } | ||||
| 
 | ||||
|     fn publish_attestation_data( | ||||
|         &self, | ||||
|         free_attestation: FreeAttestation, | ||||
|     ) -> Result<PublishOutcome, BeaconNodeError> { | ||||
|         Err(BeaconNodeError::DecodeFailure) | ||||
|     } | ||||
| } | ||||
| @ -1,8 +1,11 @@ | ||||
| mod attestation_grpc_client; | ||||
| use attester::{Attester, BeaconNode, DutiesReader, PollOutcome as AttesterPollOutcome, Signer}; | ||||
| use slog::Logger; | ||||
| use slog::{error, info, warn, Logger}; | ||||
| use slot_clock::SlotClock; | ||||
| use std::time::Duration; | ||||
| 
 | ||||
| pub use self::attestation_grpc_client::AttestationGrpcClient; | ||||
| 
 | ||||
| pub struct AttesterService<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> { | ||||
|     pub attester: Attester<T, U, V, W>, | ||||
|     pub poll_interval_millis: u64, | ||||
|  | ||||
| @ -1,13 +1,15 @@ | ||||
| use self::block_producer_service::{BeaconBlockGrpcClient, BlockProducerService}; | ||||
| use self::duties::{DutiesManager, DutiesManagerService, EpochDutiesMap}; | ||||
| use crate::attester_service::AttesterService; | ||||
| use crate::attester_service::{AttestationGrpcClient, AttesterService}; | ||||
| use crate::config::ClientConfig; | ||||
| use attester::{test_utils::LocalSigner as AttesterLocalSigner, Attester}; | ||||
| use block_proposer::{test_utils::LocalSigner as BlockProposerLocalSigner, BlockProducer}; | ||||
| use bls::Keypair; | ||||
| use clap::{App, Arg}; | ||||
| use grpcio::{ChannelBuilder, EnvBuilder}; | ||||
| use protos::services_grpc::{BeaconBlockServiceClient, ValidatorServiceClient}; | ||||
| use protos::services_grpc::{ | ||||
|     AttestationServiceClient, BeaconBlockServiceClient, ValidatorServiceClient, | ||||
| }; | ||||
| use slog::{error, info, o, Drain}; | ||||
| use slot_clock::SystemTimeSlotClock; | ||||
| use std::path::PathBuf; | ||||
| @ -106,6 +108,13 @@ fn main() { | ||||
|         Arc::new(ValidatorServiceClient::new(ch)) | ||||
|     }; | ||||
| 
 | ||||
|     //Beacon node gRPC attester endpoints.
 | ||||
|     let attester_grpc_client = { | ||||
|         let env = Arc::new(EnvBuilder::new().build()); | ||||
|         let ch = ChannelBuilder::new(env).connect(&config.server); | ||||
|         Arc::new(AttestationServiceClient::new(ch)) | ||||
|     }; | ||||
| 
 | ||||
|     // Spec
 | ||||
|     let spec = Arc::new(config.spec.clone()); | ||||
| 
 | ||||
| @ -182,15 +191,13 @@ fn main() { | ||||
|             }) | ||||
|         }; | ||||
| 
 | ||||
|         //Spawn a new thread for attestation for the validator.
 | ||||
|         //        Spawn a new thread for attestation for the validator.
 | ||||
|         let attester_thread = { | ||||
|             let signer = Arc::new(AttesterLocalSigner::new(keypair.clone())); | ||||
|             let duties_map = duties_map.clone(); | ||||
|             let slot_clock = slot_clock.clone(); | ||||
|             let log = log.clone(); | ||||
|             //TODO: this is wrong, I assume this has to be AttesterGrpcClient, which has to be defined analogous
 | ||||
|             // to beacon_block_grpc_client.rs
 | ||||
|             let client = Arc::new(BeaconBlockGrpcClient::new(beacon_block_grpc_client.clone())); | ||||
|             let client = Arc::new(AttestationGrpcClient::new(attester_grpc_client.clone())); | ||||
|             thread::spawn(move || { | ||||
|                 let attester = Attester::new(duties_map, slot_clock, client, signer); | ||||
|                 let mut attester_service = AttesterService { | ||||
| @ -199,7 +206,7 @@ fn main() { | ||||
|                     log, | ||||
|                 }; | ||||
| 
 | ||||
|                 block_producer_service.run(); | ||||
|                 attester_service.run(); | ||||
|             }) | ||||
|         }; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user