mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 09:16:00 +00:00
ran cargo fmt
This commit is contained in:
@@ -146,15 +146,9 @@ impl<T: BeaconChainTypes + 'static> MessageHandler<T> {
|
|||||||
) {
|
) {
|
||||||
// an error could have occurred.
|
// an error could have occurred.
|
||||||
match error_response {
|
match error_response {
|
||||||
RPCErrorResponse::InvalidRequest(error) => {
|
RPCErrorResponse::InvalidRequest(error) => warn!(self.log, "Peer indicated invalid request";"peer_id" => format!("{:?}", peer_id), "error" => error.as_string()),
|
||||||
warn!(self.log, "Peer indicated invalid request";"peer_id" => format!("{:?}", peer_id), "error" => error.as_string())
|
RPCErrorResponse::ServerError(error) => warn!(self.log, "Peer internal server error";"peer_id" => format!("{:?}", peer_id), "error" => error.as_string()),
|
||||||
}
|
RPCErrorResponse::Unknown(error) => warn!(self.log, "Unknown peer error";"peer" => format!("{:?}", peer_id), "error" => error.as_string()),
|
||||||
RPCErrorResponse::ServerError(error) => {
|
|
||||||
warn!(self.log, "Peer internal server error";"peer_id" => format!("{:?}", peer_id), "error" => error.as_string())
|
|
||||||
}
|
|
||||||
RPCErrorResponse::Unknown(error) => {
|
|
||||||
warn!(self.log, "Unknown peer error";"peer" => format!("{:?}", peer_id), "error" => error.as_string())
|
|
||||||
}
|
|
||||||
RPCErrorResponse::Success(response) => {
|
RPCErrorResponse::Success(response) => {
|
||||||
match response {
|
match response {
|
||||||
RPCResponse::Hello(hello_message) => {
|
RPCResponse::Hello(hello_message) => {
|
||||||
@@ -207,7 +201,8 @@ impl<T: BeaconChainTypes + 'static> MessageHandler<T> {
|
|||||||
match gossip_message {
|
match gossip_message {
|
||||||
PubsubMessage::Block(message) => match self.decode_gossip_block(message) {
|
PubsubMessage::Block(message) => match self.decode_gossip_block(message) {
|
||||||
Ok(block) => {
|
Ok(block) => {
|
||||||
self.message_processor.on_block_gossip(peer_id.clone(), block.clone());
|
self.message_processor
|
||||||
|
.on_block_gossip(peer_id.clone(), block.clone());
|
||||||
if self.message_processor.should_forward_block(block) {
|
if self.message_processor.should_forward_block(block) {
|
||||||
self.propagate_message(id, peer_id.clone());
|
self.propagate_message(id, peer_id.clone());
|
||||||
}
|
}
|
||||||
@@ -218,8 +213,12 @@ impl<T: BeaconChainTypes + 'static> MessageHandler<T> {
|
|||||||
},
|
},
|
||||||
PubsubMessage::Attestation(message) => match self.decode_gossip_attestation(message) {
|
PubsubMessage::Attestation(message) => match self.decode_gossip_attestation(message) {
|
||||||
Ok(attestation) => {
|
Ok(attestation) => {
|
||||||
self.message_processor.on_attestation_gossip(peer_id.clone(), attestation.clone());
|
self.message_processor
|
||||||
if self.message_processor.should_forward_attestation(attestation) {
|
.on_attestation_gossip(peer_id.clone(), attestation.clone());
|
||||||
|
if self
|
||||||
|
.message_processor
|
||||||
|
.should_forward_attestation(attestation)
|
||||||
|
{
|
||||||
self.propagate_message(id, peer_id);
|
self.propagate_message(id, peer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,23 @@ use crate::service::NetworkMessage;
|
|||||||
use beacon_chain::{
|
use beacon_chain::{
|
||||||
AttestationProcessingOutcome, BeaconChain, BeaconChainTypes, BlockProcessingOutcome,
|
AttestationProcessingOutcome, BeaconChain, BeaconChainTypes, BlockProcessingOutcome,
|
||||||
};
|
};
|
||||||
|
use bls::SignatureSet;
|
||||||
use eth2_libp2p::rpc::methods::*;
|
use eth2_libp2p::rpc::methods::*;
|
||||||
use eth2_libp2p::rpc::{RPCEvent, RPCRequest, RPCResponse, RequestId};
|
use eth2_libp2p::rpc::{RPCEvent, RPCRequest, RPCResponse, RequestId};
|
||||||
use eth2_libp2p::PeerId;
|
use eth2_libp2p::PeerId;
|
||||||
use slog::{debug, error, info, o, trace, warn};
|
use slog::{debug, error, info, o, trace, warn};
|
||||||
use ssz::Encode;
|
use ssz::Encode;
|
||||||
|
use state_processing::{
|
||||||
|
common::get_indexed_attestation,
|
||||||
|
per_block_processing::signature_sets::indexed_attestation_signature_set, per_slot_processing,
|
||||||
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use store::Store;
|
use store::Store;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
use tree_hash::SignedRoot;
|
use tree_hash::SignedRoot;
|
||||||
use types::{Attestation, BeaconBlock, Epoch, EthSpec, Hash256, Slot, BeaconState, RelativeEpoch, Domain};
|
use types::{
|
||||||
use bls::SignatureSet;
|
Attestation, BeaconBlock, BeaconState, Domain, Epoch, EthSpec, Hash256, RelativeEpoch, Slot,
|
||||||
use state_processing::{per_slot_processing, common::get_indexed_attestation, per_block_processing::signature_sets::indexed_attestation_signature_set};
|
};
|
||||||
|
|
||||||
//TODO: Put a maximum limit on the number of block that can be requested.
|
//TODO: Put a maximum limit on the number of block that can be requested.
|
||||||
//TODO: Rate limit requests
|
//TODO: Rate limit requests
|
||||||
@@ -433,11 +438,11 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
pub fn should_forward_block(&mut self, block: BeaconBlock<T::EthSpec>) -> bool {
|
pub fn should_forward_block(&mut self, block: BeaconBlock<T::EthSpec>) -> bool {
|
||||||
// Retrieve the parent block used to generate the signature.
|
// Retrieve the parent block used to generate the signature.
|
||||||
// This will eventually return false if this operation fails or returns an empty option.
|
// This will eventually return false if this operation fails or returns an empty option.
|
||||||
let parent_block_opt = if let Ok(Some(parent_block)) = self
|
let parent_block_opt = if let Ok(Some(parent_block)) =
|
||||||
.chain
|
self.chain
|
||||||
.store
|
.store
|
||||||
.get::<BeaconBlock<T::EthSpec>>(&block.parent_root) {
|
.get::<BeaconBlock<T::EthSpec>>(&block.parent_root)
|
||||||
|
{
|
||||||
// Check if the parent block's state root is equal to the current state, if it is, then
|
// Check if the parent block's state root is equal to the current state, if it is, then
|
||||||
// we can validate the block using the state in our chain head. This saves us from
|
// we can validate the block using the state in our chain head. This saves us from
|
||||||
// having to make an unecessary database read.
|
// having to make an unecessary database read.
|
||||||
@@ -453,7 +458,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
// should never be the case though.
|
// should never be the case though.
|
||||||
match state_res {
|
match state_res {
|
||||||
Ok(Some(state)) => Some((parent_block, state)),
|
Ok(Some(state)) => Some((parent_block, state)),
|
||||||
_ => None
|
_ => None,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -466,7 +471,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
let relative_epoch = if let Ok(relative_epoch) = RelativeEpoch::from_slot(
|
let relative_epoch = if let Ok(relative_epoch) = RelativeEpoch::from_slot(
|
||||||
parent_block.slot,
|
parent_block.slot,
|
||||||
block.slot,
|
block.slot,
|
||||||
T::EthSpec::slots_per_epoch()
|
T::EthSpec::slots_per_epoch(),
|
||||||
) {
|
) {
|
||||||
relative_epoch
|
relative_epoch
|
||||||
} else {
|
} else {
|
||||||
@@ -489,7 +494,10 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
|
|
||||||
// Compute the committee cache so we can check the proposer.
|
// Compute the committee cache so we can check the proposer.
|
||||||
// TODO: Downvote peer
|
// TODO: Downvote peer
|
||||||
if state.build_committee_cache(RelativeEpoch::Current, &self.chain.spec).is_err() {
|
if state
|
||||||
|
.build_committee_cache(RelativeEpoch::Current, &self.chain.spec)
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,17 +507,14 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
|
|
||||||
// Compute the proposer for the block's slot.
|
// Compute the proposer for the block's slot.
|
||||||
let proposer_result = state
|
let proposer_result = state
|
||||||
.get_beacon_proposer_index(
|
.get_beacon_proposer_index(block.slot, relative_epoch, &self.chain.spec)
|
||||||
block.slot,
|
.map(|i| state.validators.get(i));
|
||||||
relative_epoch,
|
|
||||||
&self.chain.spec
|
|
||||||
).map( |i| state.validators.get(i));
|
|
||||||
|
|
||||||
// Generate the domain that should have been used to create the signature.
|
// Generate the domain that should have been used to create the signature.
|
||||||
let domain = self.chain.spec.get_domain(
|
let domain = self.chain.spec.get_domain(
|
||||||
block.slot.epoch(T::EthSpec::slots_per_epoch()),
|
block.slot.epoch(T::EthSpec::slots_per_epoch()),
|
||||||
Domain::BeaconProposer,
|
Domain::BeaconProposer,
|
||||||
&state.fork
|
&state.fork,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify the signature if we were able to get a proposer, otherwise, we eventually
|
// Verify the signature if we were able to get a proposer, otherwise, we eventually
|
||||||
@@ -519,7 +524,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
&block.signature,
|
&block.signature,
|
||||||
&proposer.pubkey,
|
&proposer.pubkey,
|
||||||
block.signed_root(),
|
block.signed_root(),
|
||||||
domain
|
domain,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Downvote if the signature is invalid.
|
// TODO: Downvote if the signature is invalid.
|
||||||
@@ -577,7 +582,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
&head_state,
|
&head_state,
|
||||||
&indexed_attestation.signature,
|
&indexed_attestation.signature,
|
||||||
&indexed_attestation,
|
&indexed_attestation,
|
||||||
&self.chain.spec
|
&self.chain.spec,
|
||||||
) {
|
) {
|
||||||
// An invalid signature here does not necessarily mean the attestation is invalid.
|
// An invalid signature here does not necessarily mean the attestation is invalid.
|
||||||
// It could be the case that our state has a different validator registry.
|
// It could be the case that our state has a different validator registry.
|
||||||
@@ -595,7 +600,11 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
.get::<BeaconBlock<T::EthSpec>>(&attestation.data.beacon_block_root)
|
.get::<BeaconBlock<T::EthSpec>>(&attestation.data.beacon_block_root)
|
||||||
{
|
{
|
||||||
// Retrieve the block's state.
|
// Retrieve the block's state.
|
||||||
if let Ok(Some(state)) = self.chain.store.get::<BeaconState<T::EthSpec>>(&block.state_root) {
|
if let Ok(Some(state)) = self
|
||||||
|
.chain
|
||||||
|
.store
|
||||||
|
.get::<BeaconState<T::EthSpec>>(&block.state_root)
|
||||||
|
{
|
||||||
// Convert the attestation to an indexed attestation.
|
// Convert the attestation to an indexed attestation.
|
||||||
if let Ok(indexed_attestation) = get_indexed_attestation(&state, &attestation) {
|
if let Ok(indexed_attestation) = get_indexed_attestation(&state, &attestation) {
|
||||||
// Check if the signature is valid against the state we got from the database.
|
// Check if the signature is valid against the state we got from the database.
|
||||||
@@ -603,7 +612,7 @@ impl<T: BeaconChainTypes> MessageProcessor<T> {
|
|||||||
&state,
|
&state,
|
||||||
&indexed_attestation.signature,
|
&indexed_attestation.signature,
|
||||||
&indexed_attestation,
|
&indexed_attestation,
|
||||||
&self.chain.spec
|
&self.chain.spec,
|
||||||
) {
|
) {
|
||||||
// TODO: Maybe downvote peer if the signature is invalid.
|
// TODO: Maybe downvote peer if the signature is invalid.
|
||||||
return signature.is_valid();
|
return signature.is_valid();
|
||||||
|
|||||||
Reference in New Issue
Block a user