mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Merge branch 'v0.3.0-staging' into v3-master
This commit is contained in:
@@ -5,7 +5,7 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dev-dependencies]
|
||||
sloggers = "1.0.0"
|
||||
sloggers = "1.0.1"
|
||||
genesis = { path = "../genesis" }
|
||||
lazy_static = "1.4.0"
|
||||
matches = "0.1.8"
|
||||
@@ -17,7 +17,6 @@ beacon_chain = { path = "../beacon_chain" }
|
||||
store = { path = "../store" }
|
||||
eth2_libp2p = { path = "../eth2_libp2p" }
|
||||
hashset_delay = { path = "../../common/hashset_delay" }
|
||||
rest_types = { path = "../../common/rest_types" }
|
||||
types = { path = "../../consensus/types" }
|
||||
state_processing = { path = "../../consensus/state_processing" }
|
||||
slot_clock = { path = "../../common/slot_clock" }
|
||||
@@ -25,18 +24,19 @@ slog = { version = "2.5.2", features = ["max_level_trace"] }
|
||||
hex = "0.4.2"
|
||||
eth2_ssz = "0.1.2"
|
||||
eth2_ssz_types = { path = "../../consensus/ssz_types" }
|
||||
tree_hash = "0.1.0"
|
||||
tree_hash = "0.1.1"
|
||||
futures = "0.3.5"
|
||||
error-chain = "0.12.2"
|
||||
error-chain = "0.12.4"
|
||||
tokio = { version = "0.2.22", features = ["full"] }
|
||||
parking_lot = "0.11.0"
|
||||
smallvec = "1.4.1"
|
||||
smallvec = "1.4.2"
|
||||
rand = "0.7.3"
|
||||
fnv = "1.0.6"
|
||||
rlp = "0.4.5"
|
||||
fnv = "1.0.7"
|
||||
rlp = "0.4.6"
|
||||
lazy_static = "1.4.0"
|
||||
lighthouse_metrics = { path = "../../common/lighthouse_metrics" }
|
||||
environment = { path = "../../lighthouse/environment" }
|
||||
task_executor = { path = "../../common/task_executor" }
|
||||
igd = "0.11.1"
|
||||
itertools = "0.9.0"
|
||||
num_cpus = "1.13.0"
|
||||
|
||||
@@ -15,9 +15,8 @@ use slog::{debug, error, o, trace, warn};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2_libp2p::SubnetDiscovery;
|
||||
use hashset_delay::HashSetDelay;
|
||||
use rest_types::ValidatorSubscription;
|
||||
use slot_clock::SlotClock;
|
||||
use types::{Attestation, EthSpec, Slot, SubnetId};
|
||||
use types::{Attestation, EthSpec, Slot, SubnetId, ValidatorSubscription};
|
||||
|
||||
use crate::metrics;
|
||||
|
||||
@@ -196,14 +195,9 @@ impl<T: BeaconChainTypes> AttestationService<T> {
|
||||
slot: subscription.slot,
|
||||
};
|
||||
|
||||
// determine if the validator is an aggregator. If so, we subscribe to the subnet and
|
||||
// Determine if the validator is an aggregator. If so, we subscribe to the subnet and
|
||||
// if successful add the validator to a mapping of known aggregators for that exact
|
||||
// subnet.
|
||||
// NOTE: There is a chance that a fork occurs between now and when the validator needs
|
||||
// to aggregate attestations. If this happens, the signature will no longer be valid
|
||||
// and it could be likely the validator no longer needs to aggregate. More
|
||||
// sophisticated logic should be added using known future forks.
|
||||
// TODO: Implement
|
||||
|
||||
if subscription.is_aggregator {
|
||||
metrics::inc_counter(&metrics::SUBNET_SUBSCRIPTION_AGGREGATOR_REQUESTS);
|
||||
@@ -287,8 +281,6 @@ impl<T: BeaconChainTypes> AttestationService<T> {
|
||||
min_ttl,
|
||||
})
|
||||
} else {
|
||||
// TODO: Send the time frame needed to have a peer connected, so that we can
|
||||
// maintain peers for a least this duration.
|
||||
// We may want to check the global PeerInfo to see estimated timeouts for each
|
||||
// peer before they can be removed.
|
||||
warn!(self.log,
|
||||
|
||||
@@ -37,12 +37,12 @@
|
||||
|
||||
use crate::{metrics, service::NetworkMessage, sync::SyncMessage};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError};
|
||||
use environment::TaskExecutor;
|
||||
use eth2_libp2p::{MessageId, NetworkGlobals, PeerId};
|
||||
use slog::{crit, debug, error, trace, warn, Logger};
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::time::{Duration, Instant};
|
||||
use task_executor::TaskExecutor;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use types::{
|
||||
Attestation, AttesterSlashing, EthSpec, Hash256, ProposerSlashing, SignedAggregateAndProof,
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<T: BeaconChainTypes> Worker<T> {
|
||||
|
||||
let attestation = match self
|
||||
.chain
|
||||
.verify_unaggregated_attestation_for_gossip(attestation, subnet_id)
|
||||
.verify_unaggregated_attestation_for_gossip(attestation, Some(subnet_id))
|
||||
{
|
||||
Ok(attestation) => attestation,
|
||||
Err(e) => {
|
||||
|
||||
@@ -3,15 +3,14 @@ use std::sync::Arc;
|
||||
use store::{DBColumn, Error as StoreError, HotColdDB, ItemStore, StoreItem};
|
||||
use types::{EthSpec, Hash256};
|
||||
|
||||
/// 32-byte key for accessing the `DhtEnrs`.
|
||||
pub const DHT_DB_KEY: &str = "PERSISTEDDHTPERSISTEDDHTPERSISTE";
|
||||
/// 32-byte key for accessing the `DhtEnrs`. All zero because `DhtEnrs` has its own column.
|
||||
pub const DHT_DB_KEY: Hash256 = Hash256::zero();
|
||||
|
||||
pub fn load_dht<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
|
||||
store: Arc<HotColdDB<E, Hot, Cold>>,
|
||||
) -> Vec<Enr> {
|
||||
// Load DHT from store
|
||||
let key = Hash256::from_slice(&DHT_DB_KEY.as_bytes());
|
||||
match store.get_item(&key) {
|
||||
match store.get_item(&DHT_DB_KEY) {
|
||||
Ok(Some(p)) => {
|
||||
let p: PersistedDht = p;
|
||||
p.enrs
|
||||
@@ -25,9 +24,7 @@ pub fn persist_dht<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
|
||||
store: Arc<HotColdDB<E, Hot, Cold>>,
|
||||
enrs: Vec<Enr>,
|
||||
) -> Result<(), store::Error> {
|
||||
let key = Hash256::from_slice(&DHT_DB_KEY.as_bytes());
|
||||
store.put_item(&key, &PersistedDht { enrs })?;
|
||||
Ok(())
|
||||
store.put_item(&DHT_DB_KEY, &PersistedDht { enrs })
|
||||
}
|
||||
|
||||
/// Wrapper around DHT for persistence to disk.
|
||||
@@ -61,7 +58,7 @@ mod tests {
|
||||
use std::str::FromStr;
|
||||
use store::config::StoreConfig;
|
||||
use store::{HotColdDB, MemoryStore};
|
||||
use types::{ChainSpec, Hash256, MinimalEthSpec};
|
||||
use types::{ChainSpec, MinimalEthSpec};
|
||||
#[test]
|
||||
fn test_persisted_dht() {
|
||||
let log = NullLoggerBuilder.build().unwrap();
|
||||
@@ -71,11 +68,10 @@ mod tests {
|
||||
MemoryStore<MinimalEthSpec>,
|
||||
> = HotColdDB::open_ephemeral(StoreConfig::default(), ChainSpec::minimal(), log).unwrap();
|
||||
let enrs = vec![Enr::from_str("enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8").unwrap()];
|
||||
let key = Hash256::from_slice(&DHT_DB_KEY.as_bytes());
|
||||
store
|
||||
.put_item(&key, &PersistedDht { enrs: enrs.clone() })
|
||||
.put_item(&DHT_DB_KEY, &PersistedDht { enrs: enrs.clone() })
|
||||
.unwrap();
|
||||
let dht: PersistedDht = store.get_item(&key).unwrap().unwrap();
|
||||
let dht: PersistedDht = store.get_item(&DHT_DB_KEY).unwrap().unwrap();
|
||||
assert_eq!(dht.enrs, enrs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
executor: environment::TaskExecutor,
|
||||
executor: task_executor::TaskExecutor,
|
||||
log: slog::Logger,
|
||||
) -> error::Result<mpsc::UnboundedSender<RouterMessage<T::EthSpec>>> {
|
||||
let message_handler_log = log.new(o!("service"=> "router"));
|
||||
|
||||
@@ -41,7 +41,7 @@ pub struct Processor<T: BeaconChainTypes> {
|
||||
impl<T: BeaconChainTypes> Processor<T> {
|
||||
/// Instantiate a `Processor` instance
|
||||
pub fn new(
|
||||
executor: environment::TaskExecutor,
|
||||
executor: task_executor::TaskExecutor,
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
|
||||
@@ -15,13 +15,12 @@ use eth2_libp2p::{
|
||||
};
|
||||
use eth2_libp2p::{MessageAcceptance, Service as LibP2PService};
|
||||
use futures::prelude::*;
|
||||
use rest_types::ValidatorSubscription;
|
||||
use slog::{debug, error, info, o, trace, warn};
|
||||
use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration};
|
||||
use store::HotColdDB;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::time::Delay;
|
||||
use types::EthSpec;
|
||||
use types::{EthSpec, ValidatorSubscription};
|
||||
|
||||
mod tests;
|
||||
|
||||
@@ -52,7 +51,7 @@ pub enum NetworkMessage<T: EthSpec> {
|
||||
},
|
||||
/// Respond to a peer's request with an error.
|
||||
SendError {
|
||||
// TODO: note that this is never used, we just say goodbye without nicely closing the
|
||||
// NOTE: Currently this is never used, we just say goodbye without nicely closing the
|
||||
// stream assigned to the request
|
||||
peer_id: PeerId,
|
||||
error: RPCResponseErrorCode,
|
||||
@@ -122,7 +121,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
pub async fn start(
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
config: &NetworkConfig,
|
||||
executor: environment::TaskExecutor,
|
||||
executor: task_executor::TaskExecutor,
|
||||
) -> error::Result<(
|
||||
Arc<NetworkGlobals<T::EthSpec>>,
|
||||
mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
@@ -164,7 +163,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
"Loading peers into the routing table"; "peers" => enrs_to_load.len()
|
||||
);
|
||||
for enr in enrs_to_load {
|
||||
libp2p.swarm.add_enr(enr.clone()); //TODO change?
|
||||
libp2p.swarm.add_enr(enr.clone());
|
||||
}
|
||||
|
||||
// launch derived network services
|
||||
@@ -208,7 +207,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
|
||||
}
|
||||
|
||||
fn spawn_service<T: BeaconChainTypes>(
|
||||
executor: environment::TaskExecutor,
|
||||
executor: task_executor::TaskExecutor,
|
||||
mut service: NetworkService<T>,
|
||||
) -> error::Result<()> {
|
||||
let mut exit_rx = executor.exit();
|
||||
@@ -350,7 +349,6 @@ fn spawn_service<T: BeaconChainTypes>(
|
||||
// process any attestation service events
|
||||
Some(attestation_service_message) = service.attestation_service.next() => {
|
||||
match attestation_service_message {
|
||||
// TODO: Implement
|
||||
AttServiceMessage::Subscribe(subnet_id) => {
|
||||
service.libp2p.swarm.subscribe_to_subnet(subnet_id);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ mod tests {
|
||||
|
||||
let (signal, exit) = exit_future::signal();
|
||||
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
|
||||
let executor = environment::TaskExecutor::new(
|
||||
let executor = task_executor::TaskExecutor::new(
|
||||
runtime.handle().clone(),
|
||||
exit,
|
||||
log.clone(),
|
||||
|
||||
@@ -119,7 +119,6 @@ pub enum SyncMessage<T: EthSpec> {
|
||||
}
|
||||
|
||||
/// The result of processing a multiple blocks (a chain segment).
|
||||
// TODO: When correct batch error handling occurs, we will include an error type.
|
||||
#[derive(Debug)]
|
||||
pub enum BatchProcessResult {
|
||||
/// The batch was completed successfully. It carries whether the sent batch contained blocks.
|
||||
@@ -205,7 +204,7 @@ impl SingleBlockRequest {
|
||||
/// chain. This allows the chain to be
|
||||
/// dropped during the syncing process which will gracefully end the `SyncManager`.
|
||||
pub fn spawn<T: BeaconChainTypes>(
|
||||
executor: environment::TaskExecutor,
|
||||
executor: task_executor::TaskExecutor,
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
@@ -629,7 +628,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
|
||||
self.update_sync_state();
|
||||
}
|
||||
|
||||
// TODO: Group these functions into one.
|
||||
// TODO: Group these functions into one for cleaner code.
|
||||
/// Updates the syncing state of a peer to be synced.
|
||||
fn synced_peer(&mut self, peer_id: &PeerId, sync_info: PeerSyncInfo) {
|
||||
if let Some(peer_info) = self.network_globals.peers.write().peer_info_mut(peer_id) {
|
||||
@@ -792,7 +791,6 @@ impl<T: BeaconChainTypes> SyncManager<T> {
|
||||
|
||||
// This currently can be a host of errors. We permit this due to the partial
|
||||
// ambiguity.
|
||||
// TODO: Refine the error types and score the peer appropriately.
|
||||
self.network.report_peer(
|
||||
parent_request.last_submitted_peer,
|
||||
PeerAction::MidToleranceError,
|
||||
|
||||
@@ -613,9 +613,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
|
||||
BatchState::Failed | BatchState::Poisoned | BatchState::AwaitingDownload => {
|
||||
unreachable!("batch indicates inconsistent chain state while advancing chain")
|
||||
}
|
||||
BatchState::AwaitingProcessing(..) => {
|
||||
// TODO: can we be sure the old attempts are wrong?
|
||||
}
|
||||
BatchState::AwaitingProcessing(..) => {}
|
||||
BatchState::Processing(_) => {
|
||||
assert_eq!(
|
||||
id,
|
||||
@@ -651,9 +649,6 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
|
||||
/// These events occur when a peer has successfully responded with blocks, but the blocks we
|
||||
/// have received are incorrect or invalid. This indicates the peer has not performed as
|
||||
/// intended and can result in downvoting a peer.
|
||||
// TODO: Batches could have been partially downloaded due to RPC size-limit restrictions. We
|
||||
// need to add logic for partial batch downloads. Potentially, if another peer returns the same
|
||||
// batch, we try a partial download.
|
||||
fn handle_invalid_batch(
|
||||
&mut self,
|
||||
network: &mut SyncNetworkContext<T::EthSpec>,
|
||||
|
||||
@@ -220,7 +220,10 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
if let Some(removed_chain) = removed_chain {
|
||||
debug!(self.log, "Chain removed after block response"; "sync_type" => ?sync_type, "chain_id" => chain_id);
|
||||
removed_chain.status_peers(network);
|
||||
// TODO: update & update_sync_state?
|
||||
// update the state of the collection
|
||||
self.chains.update(network);
|
||||
// update the global state and inform the user
|
||||
self.chains.update_sync_state(network);
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
@@ -319,7 +322,10 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
.call_all(|chain| chain.remove_peer(peer_id, network))
|
||||
{
|
||||
debug!(self.log, "Chain removed after removing peer"; "sync_type" => ?sync_type, "chain" => removed_chain.get_id());
|
||||
// TODO: anything else to do?
|
||||
// update the state of the collection
|
||||
self.chains.update(network);
|
||||
// update the global state and inform the user
|
||||
self.chains.update_sync_state(network);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +349,10 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
if let Some(removed_chain) = removed_chain {
|
||||
debug!(self.log, "Chain removed on rpc error"; "sync_type" => ?sync_type, "chain" => removed_chain.get_id());
|
||||
removed_chain.status_peers(network);
|
||||
// TODO: update & update_sync_state?
|
||||
// update the state of the collection
|
||||
self.chains.update(network);
|
||||
// update the global state and inform the user
|
||||
self.chains.update_sync_state(network);
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
|
||||
Reference in New Issue
Block a user