Initial work towards v0.2.0 (#924)
* Remove ping protocol
* Initial renaming of network services
* Correct rebasing relative to latest master
* Start updating types
* Adds HashMapDelay struct to utils
* Initial network restructure
* Network restructure. Adds new types for v0.2.0
* Removes build artefacts
* Shift validation to beacon chain
* Temporarily remove gossip validation
This is to be updated to match current optimisation efforts.
* Adds AggregateAndProof
* Begin rebuilding pubsub encoding/decoding
* Signature hacking
* Shift gossipsup decoding into eth2_libp2p
* Existing EF tests passing with fake_crypto
* Shifts block encoding/decoding into RPC
* Delete outdated API spec
* All release tests passing bar genesis state parsing
* Update and test YamlConfig
* Update to spec v0.10 compatible BLS
* Updates to BLS EF tests
* Add EF test for AggregateVerify
And delete unused hash2curve tests for uncompressed points
* Update EF tests to v0.10.1
* Use optional block root correctly in block proc
* Use genesis fork in deposit domain. All tests pass
* Fast aggregate verify test
* Update REST API docs
* Fix unused import
* Bump spec tags to v0.10.1
* Add `seconds_per_eth1_block` to chainspec
* Update to timestamp based eth1 voting scheme
* Return None from `get_votes_to_consider` if block cache is empty
* Handle overflows in `is_candidate_block`
* Revert to failing tests
* Fix eth1 data sets test
* Choose default vote according to spec
* Fix collect_valid_votes tests
* Fix `get_votes_to_consider` to choose all eligible blocks
* Uncomment winning_vote tests
* Add comments; remove unused code
* Reduce seconds_per_eth1_block for simulation
* Addressed review comments
* Add test for default vote case
* Fix logs
* Remove unused functions
* Meter default eth1 votes
* Fix comments
* Progress on attestation service
* Address review comments; remove unused dependency
* Initial work on removing libp2p lock
* Add LRU caches to store (rollup)
* Update attestation validation for DB changes (WIP)
* Initial version of should_forward_block
* Scaffold
* Progress on attestation validation
Also, consolidate prod+testing slot clocks so that they share much
of the same implementation and can both handle sub-slot time changes.
* Removes lock from libp2p service
* Completed network lock removal
* Finish(?) attestation processing
* Correct network termination future
* Add slot check to block check
* Correct fmt issues
* Remove Drop implementation for network service
* Add first attempt at attestation proc. re-write
* Add version 2 of attestation processing
* Minor fixes
* Add validator pubkey cache
* Make get_indexed_attestation take a committee
* Link signature processing into new attn verification
* First working version
* Ensure pubkey cache is updated
* Add more metrics, slight optimizations
* Clone committee cache during attestation processing
* Update shuffling cache during block processing
* Remove old commented-out code
* Fix shuffling cache insert bug
* Used indexed attestation in fork choice
* Restructure attn processing, add metrics
* Add more detailed metrics
* Tidy, fix failing tests
* Fix failing tests, tidy
* Address reviewers suggestions
* Disable/delete two outdated tests
* Modification of validator for subscriptions
* Add slot signing to validator client
* Further progress on validation subscription
* Adds necessary validator subscription functionality
* Add new Pubkeys struct to signature_sets
* Refactor with functional approach
* Update beacon chain
* Clean up validator <-> beacon node http types
* Add aggregator status to ValidatorDuty
* Impl Clone for manual slot clock
* Fix minor errors
* Further progress validator client subscription
* Initial subscription and aggregation handling
* Remove decompressed member from pubkey bytes
* Progress to modifying val client for attestation aggregation
* First draft of validator client upgrade for aggregate attestations
* Add hashmap for indices lookup
* Add state cache, remove store cache
* Only build the head committee cache
* Removes lock on a network channel
* Partially implement beacon node subscription http api
* Correct compilation issues
* Change `get_attesting_indices` to use Vec
* Fix failing test
* Partial implementation of timer
* Adds timer, removes exit_future, http api to op pool
* Partial multiple aggregate attestation handling
* Permits bulk messages accross gossipsub network channel
* Correct compile issues
* Improve gosispsub messaging and correct rest api helpers
* Added global gossipsub subscriptions
* Update validator subscriptions data structs
* Tidy
* Re-structure validator subscriptions
* Initial handling of subscriptions
* Re-structure network service
* Add pubkey cache persistence file
* Add more comments
* Integrate persistence file into builder
* Add pubkey cache tests
* Add HashSetDelay and introduce into attestation service
* Handles validator subscriptions
* Add data_dir to beacon chain builder
* Remove Option in pubkey cache persistence file
* Ensure consistency between datadir/data_dir
* Fix failing network test
* Peer subnet discovery gets queued for future subscriptions
* Reorganise attestation service functions
* Initial wiring of attestation service
* First draft of attestation service timing logic
* Correct minor typos
* Tidy
* Fix todos
* Improve tests
* Add PeerInfo to connected peers mapping
* Fix compile error
* Fix compile error from merge
* Split up block processing metrics
* Tidy
* Refactor get_pubkey_from_state
* Remove commented-out code
* Rename state_cache -> checkpoint_cache
* Rename Checkpoint -> Snapshot
* Tidy, add comments
* Tidy up find_head function
* Change some checkpoint -> snapshot
* Add tests
* Expose max_len
* Remove dead code
* Tidy
* Fix bug
* Add sync-speed metric
* Add first attempt at VerifiableBlock
* Start integrating into beacon chain
* Integrate VerifiableBlock
* Rename VerifableBlock -> PartialBlockVerification
* Add start of typed methods
* Add progress
* Add further progress
* Rename structs
* Add full block verification to block_processing.rs
* Further beacon chain integration
* Update checks for gossip
* Add todo
* Start adding segement verification
* Add passing chain segement test
* Initial integration with batch sync
* Minor changes
* Tidy, add more error checking
* Start adding chain_segment tests
* Finish invalid signature tests
* Include single and gossip verified blocks in tests
* Add gossip verification tests
* Start adding docs
* Finish adding comments to block_processing.rs
* Rename block_processing.rs -> block_verification
* Start removing old block processing code
* Fixes beacon_chain compilation
* Fix project-wide compile errors
* Remove old code
* Correct code to pass all tests
* Fix bug with beacon proposer index
* Fix shim for BlockProcessingError
* Only process one epoch at a time
* Fix loop in chain segment processing
* Correct tests from master merge
* Add caching for state.eth1_data_votes
* Add BeaconChain::validator_pubkey
* Revert "Add caching for state.eth1_data_votes"
This reverts commit cd73dcd6434fb8d8e6bf30c5356355598ea7b78e.
Co-authored-by: Grant Wuerker <gwuerker@gmail.com>
Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Co-authored-by: Michael Sproul <micsproul@gmail.com>
Co-authored-by: pawan <pawandhananjay@gmail.com>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
2020-03-17 06:24:44 +00:00
|
|
|
use crate::metrics;
|
2019-12-06 07:44:38 +00:00
|
|
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
Initial work towards v0.2.0 (#924)
* Remove ping protocol
* Initial renaming of network services
* Correct rebasing relative to latest master
* Start updating types
* Adds HashMapDelay struct to utils
* Initial network restructure
* Network restructure. Adds new types for v0.2.0
* Removes build artefacts
* Shift validation to beacon chain
* Temporarily remove gossip validation
This is to be updated to match current optimisation efforts.
* Adds AggregateAndProof
* Begin rebuilding pubsub encoding/decoding
* Signature hacking
* Shift gossipsup decoding into eth2_libp2p
* Existing EF tests passing with fake_crypto
* Shifts block encoding/decoding into RPC
* Delete outdated API spec
* All release tests passing bar genesis state parsing
* Update and test YamlConfig
* Update to spec v0.10 compatible BLS
* Updates to BLS EF tests
* Add EF test for AggregateVerify
And delete unused hash2curve tests for uncompressed points
* Update EF tests to v0.10.1
* Use optional block root correctly in block proc
* Use genesis fork in deposit domain. All tests pass
* Fast aggregate verify test
* Update REST API docs
* Fix unused import
* Bump spec tags to v0.10.1
* Add `seconds_per_eth1_block` to chainspec
* Update to timestamp based eth1 voting scheme
* Return None from `get_votes_to_consider` if block cache is empty
* Handle overflows in `is_candidate_block`
* Revert to failing tests
* Fix eth1 data sets test
* Choose default vote according to spec
* Fix collect_valid_votes tests
* Fix `get_votes_to_consider` to choose all eligible blocks
* Uncomment winning_vote tests
* Add comments; remove unused code
* Reduce seconds_per_eth1_block for simulation
* Addressed review comments
* Add test for default vote case
* Fix logs
* Remove unused functions
* Meter default eth1 votes
* Fix comments
* Progress on attestation service
* Address review comments; remove unused dependency
* Initial work on removing libp2p lock
* Add LRU caches to store (rollup)
* Update attestation validation for DB changes (WIP)
* Initial version of should_forward_block
* Scaffold
* Progress on attestation validation
Also, consolidate prod+testing slot clocks so that they share much
of the same implementation and can both handle sub-slot time changes.
* Removes lock from libp2p service
* Completed network lock removal
* Finish(?) attestation processing
* Correct network termination future
* Add slot check to block check
* Correct fmt issues
* Remove Drop implementation for network service
* Add first attempt at attestation proc. re-write
* Add version 2 of attestation processing
* Minor fixes
* Add validator pubkey cache
* Make get_indexed_attestation take a committee
* Link signature processing into new attn verification
* First working version
* Ensure pubkey cache is updated
* Add more metrics, slight optimizations
* Clone committee cache during attestation processing
* Update shuffling cache during block processing
* Remove old commented-out code
* Fix shuffling cache insert bug
* Used indexed attestation in fork choice
* Restructure attn processing, add metrics
* Add more detailed metrics
* Tidy, fix failing tests
* Fix failing tests, tidy
* Address reviewers suggestions
* Disable/delete two outdated tests
* Modification of validator for subscriptions
* Add slot signing to validator client
* Further progress on validation subscription
* Adds necessary validator subscription functionality
* Add new Pubkeys struct to signature_sets
* Refactor with functional approach
* Update beacon chain
* Clean up validator <-> beacon node http types
* Add aggregator status to ValidatorDuty
* Impl Clone for manual slot clock
* Fix minor errors
* Further progress validator client subscription
* Initial subscription and aggregation handling
* Remove decompressed member from pubkey bytes
* Progress to modifying val client for attestation aggregation
* First draft of validator client upgrade for aggregate attestations
* Add hashmap for indices lookup
* Add state cache, remove store cache
* Only build the head committee cache
* Removes lock on a network channel
* Partially implement beacon node subscription http api
* Correct compilation issues
* Change `get_attesting_indices` to use Vec
* Fix failing test
* Partial implementation of timer
* Adds timer, removes exit_future, http api to op pool
* Partial multiple aggregate attestation handling
* Permits bulk messages accross gossipsub network channel
* Correct compile issues
* Improve gosispsub messaging and correct rest api helpers
* Added global gossipsub subscriptions
* Update validator subscriptions data structs
* Tidy
* Re-structure validator subscriptions
* Initial handling of subscriptions
* Re-structure network service
* Add pubkey cache persistence file
* Add more comments
* Integrate persistence file into builder
* Add pubkey cache tests
* Add HashSetDelay and introduce into attestation service
* Handles validator subscriptions
* Add data_dir to beacon chain builder
* Remove Option in pubkey cache persistence file
* Ensure consistency between datadir/data_dir
* Fix failing network test
* Peer subnet discovery gets queued for future subscriptions
* Reorganise attestation service functions
* Initial wiring of attestation service
* First draft of attestation service timing logic
* Correct minor typos
* Tidy
* Fix todos
* Improve tests
* Add PeerInfo to connected peers mapping
* Fix compile error
* Fix compile error from merge
* Split up block processing metrics
* Tidy
* Refactor get_pubkey_from_state
* Remove commented-out code
* Rename state_cache -> checkpoint_cache
* Rename Checkpoint -> Snapshot
* Tidy, add comments
* Tidy up find_head function
* Change some checkpoint -> snapshot
* Add tests
* Expose max_len
* Remove dead code
* Tidy
* Fix bug
* Add sync-speed metric
* Add first attempt at VerifiableBlock
* Start integrating into beacon chain
* Integrate VerifiableBlock
* Rename VerifableBlock -> PartialBlockVerification
* Add start of typed methods
* Add progress
* Add further progress
* Rename structs
* Add full block verification to block_processing.rs
* Further beacon chain integration
* Update checks for gossip
* Add todo
* Start adding segement verification
* Add passing chain segement test
* Initial integration with batch sync
* Minor changes
* Tidy, add more error checking
* Start adding chain_segment tests
* Finish invalid signature tests
* Include single and gossip verified blocks in tests
* Add gossip verification tests
* Start adding docs
* Finish adding comments to block_processing.rs
* Rename block_processing.rs -> block_verification
* Start removing old block processing code
* Fixes beacon_chain compilation
* Fix project-wide compile errors
* Remove old code
* Correct code to pass all tests
* Fix bug with beacon proposer index
* Fix shim for BlockProcessingError
* Only process one epoch at a time
* Fix loop in chain segment processing
* Correct tests from master merge
* Add caching for state.eth1_data_votes
* Add BeaconChain::validator_pubkey
* Revert "Add caching for state.eth1_data_votes"
This reverts commit cd73dcd6434fb8d8e6bf30c5356355598ea7b78e.
Co-authored-by: Grant Wuerker <gwuerker@gmail.com>
Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Co-authored-by: Michael Sproul <micsproul@gmail.com>
Co-authored-by: pawan <pawandhananjay@gmail.com>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
2020-03-17 06:24:44 +00:00
|
|
|
use eth2_libp2p::NetworkGlobals;
|
2019-12-06 07:44:38 +00:00
|
|
|
use parking_lot::Mutex;
|
2020-11-30 20:29:17 +00:00
|
|
|
use slog::{debug, error, info, warn, Logger};
|
2019-12-06 07:44:38 +00:00
|
|
|
use slot_clock::SlotClock;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::{Duration, Instant};
|
2020-11-28 05:30:57 +00:00
|
|
|
use tokio::time::sleep;
|
2019-12-06 07:44:38 +00:00
|
|
|
use types::{EthSpec, Slot};
|
|
|
|
|
|
|
|
/// Create a warning log whenever the peer count is at or below this value.
|
|
|
|
pub const WARN_PEER_COUNT: usize = 1;
|
|
|
|
|
2020-05-26 03:25:52 +00:00
|
|
|
const DAYS_PER_WEEK: i64 = 7;
|
|
|
|
const HOURS_PER_DAY: i64 = 24;
|
|
|
|
const MINUTES_PER_HOUR: i64 = 60;
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2019-12-09 06:23:43 +00:00
|
|
|
/// The number of historical observations that should be used to determine the average sync time.
|
|
|
|
const SPEEDO_OBSERVATIONS: usize = 4;
|
|
|
|
|
2019-12-06 07:44:38 +00:00
|
|
|
/// Spawns a notifier service which periodically logs information about the node.
|
|
|
|
pub fn spawn_notifier<T: BeaconChainTypes>(
|
2020-10-05 07:45:54 +00:00
|
|
|
executor: task_executor::TaskExecutor,
|
2019-12-06 07:44:38 +00:00
|
|
|
beacon_chain: Arc<BeaconChain<T>>,
|
Initial work towards v0.2.0 (#924)
* Remove ping protocol
* Initial renaming of network services
* Correct rebasing relative to latest master
* Start updating types
* Adds HashMapDelay struct to utils
* Initial network restructure
* Network restructure. Adds new types for v0.2.0
* Removes build artefacts
* Shift validation to beacon chain
* Temporarily remove gossip validation
This is to be updated to match current optimisation efforts.
* Adds AggregateAndProof
* Begin rebuilding pubsub encoding/decoding
* Signature hacking
* Shift gossipsup decoding into eth2_libp2p
* Existing EF tests passing with fake_crypto
* Shifts block encoding/decoding into RPC
* Delete outdated API spec
* All release tests passing bar genesis state parsing
* Update and test YamlConfig
* Update to spec v0.10 compatible BLS
* Updates to BLS EF tests
* Add EF test for AggregateVerify
And delete unused hash2curve tests for uncompressed points
* Update EF tests to v0.10.1
* Use optional block root correctly in block proc
* Use genesis fork in deposit domain. All tests pass
* Fast aggregate verify test
* Update REST API docs
* Fix unused import
* Bump spec tags to v0.10.1
* Add `seconds_per_eth1_block` to chainspec
* Update to timestamp based eth1 voting scheme
* Return None from `get_votes_to_consider` if block cache is empty
* Handle overflows in `is_candidate_block`
* Revert to failing tests
* Fix eth1 data sets test
* Choose default vote according to spec
* Fix collect_valid_votes tests
* Fix `get_votes_to_consider` to choose all eligible blocks
* Uncomment winning_vote tests
* Add comments; remove unused code
* Reduce seconds_per_eth1_block for simulation
* Addressed review comments
* Add test for default vote case
* Fix logs
* Remove unused functions
* Meter default eth1 votes
* Fix comments
* Progress on attestation service
* Address review comments; remove unused dependency
* Initial work on removing libp2p lock
* Add LRU caches to store (rollup)
* Update attestation validation for DB changes (WIP)
* Initial version of should_forward_block
* Scaffold
* Progress on attestation validation
Also, consolidate prod+testing slot clocks so that they share much
of the same implementation and can both handle sub-slot time changes.
* Removes lock from libp2p service
* Completed network lock removal
* Finish(?) attestation processing
* Correct network termination future
* Add slot check to block check
* Correct fmt issues
* Remove Drop implementation for network service
* Add first attempt at attestation proc. re-write
* Add version 2 of attestation processing
* Minor fixes
* Add validator pubkey cache
* Make get_indexed_attestation take a committee
* Link signature processing into new attn verification
* First working version
* Ensure pubkey cache is updated
* Add more metrics, slight optimizations
* Clone committee cache during attestation processing
* Update shuffling cache during block processing
* Remove old commented-out code
* Fix shuffling cache insert bug
* Used indexed attestation in fork choice
* Restructure attn processing, add metrics
* Add more detailed metrics
* Tidy, fix failing tests
* Fix failing tests, tidy
* Address reviewers suggestions
* Disable/delete two outdated tests
* Modification of validator for subscriptions
* Add slot signing to validator client
* Further progress on validation subscription
* Adds necessary validator subscription functionality
* Add new Pubkeys struct to signature_sets
* Refactor with functional approach
* Update beacon chain
* Clean up validator <-> beacon node http types
* Add aggregator status to ValidatorDuty
* Impl Clone for manual slot clock
* Fix minor errors
* Further progress validator client subscription
* Initial subscription and aggregation handling
* Remove decompressed member from pubkey bytes
* Progress to modifying val client for attestation aggregation
* First draft of validator client upgrade for aggregate attestations
* Add hashmap for indices lookup
* Add state cache, remove store cache
* Only build the head committee cache
* Removes lock on a network channel
* Partially implement beacon node subscription http api
* Correct compilation issues
* Change `get_attesting_indices` to use Vec
* Fix failing test
* Partial implementation of timer
* Adds timer, removes exit_future, http api to op pool
* Partial multiple aggregate attestation handling
* Permits bulk messages accross gossipsub network channel
* Correct compile issues
* Improve gosispsub messaging and correct rest api helpers
* Added global gossipsub subscriptions
* Update validator subscriptions data structs
* Tidy
* Re-structure validator subscriptions
* Initial handling of subscriptions
* Re-structure network service
* Add pubkey cache persistence file
* Add more comments
* Integrate persistence file into builder
* Add pubkey cache tests
* Add HashSetDelay and introduce into attestation service
* Handles validator subscriptions
* Add data_dir to beacon chain builder
* Remove Option in pubkey cache persistence file
* Ensure consistency between datadir/data_dir
* Fix failing network test
* Peer subnet discovery gets queued for future subscriptions
* Reorganise attestation service functions
* Initial wiring of attestation service
* First draft of attestation service timing logic
* Correct minor typos
* Tidy
* Fix todos
* Improve tests
* Add PeerInfo to connected peers mapping
* Fix compile error
* Fix compile error from merge
* Split up block processing metrics
* Tidy
* Refactor get_pubkey_from_state
* Remove commented-out code
* Rename state_cache -> checkpoint_cache
* Rename Checkpoint -> Snapshot
* Tidy, add comments
* Tidy up find_head function
* Change some checkpoint -> snapshot
* Add tests
* Expose max_len
* Remove dead code
* Tidy
* Fix bug
* Add sync-speed metric
* Add first attempt at VerifiableBlock
* Start integrating into beacon chain
* Integrate VerifiableBlock
* Rename VerifableBlock -> PartialBlockVerification
* Add start of typed methods
* Add progress
* Add further progress
* Rename structs
* Add full block verification to block_processing.rs
* Further beacon chain integration
* Update checks for gossip
* Add todo
* Start adding segement verification
* Add passing chain segement test
* Initial integration with batch sync
* Minor changes
* Tidy, add more error checking
* Start adding chain_segment tests
* Finish invalid signature tests
* Include single and gossip verified blocks in tests
* Add gossip verification tests
* Start adding docs
* Finish adding comments to block_processing.rs
* Rename block_processing.rs -> block_verification
* Start removing old block processing code
* Fixes beacon_chain compilation
* Fix project-wide compile errors
* Remove old code
* Correct code to pass all tests
* Fix bug with beacon proposer index
* Fix shim for BlockProcessingError
* Only process one epoch at a time
* Fix loop in chain segment processing
* Correct tests from master merge
* Add caching for state.eth1_data_votes
* Add BeaconChain::validator_pubkey
* Revert "Add caching for state.eth1_data_votes"
This reverts commit cd73dcd6434fb8d8e6bf30c5356355598ea7b78e.
Co-authored-by: Grant Wuerker <gwuerker@gmail.com>
Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Co-authored-by: Michael Sproul <micsproul@gmail.com>
Co-authored-by: pawan <pawandhananjay@gmail.com>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
2020-03-17 06:24:44 +00:00
|
|
|
network: Arc<NetworkGlobals<T::EthSpec>>,
|
2021-01-19 09:39:51 +00:00
|
|
|
seconds_per_slot: u64,
|
2020-06-04 11:48:05 +00:00
|
|
|
) -> Result<(), String> {
|
2021-01-19 09:39:51 +00:00
|
|
|
let slot_duration = Duration::from_secs(seconds_per_slot);
|
2019-12-06 07:44:38 +00:00
|
|
|
let duration_to_next_slot = beacon_chain
|
|
|
|
.slot_clock
|
|
|
|
.duration_to_next_slot()
|
2020-12-03 01:10:26 +00:00
|
|
|
.ok_or("slot_notifier unable to determine time to next slot")?;
|
2019-12-06 07:44:38 +00:00
|
|
|
|
|
|
|
// Run this half way through each slot.
|
2020-05-17 11:16:48 +00:00
|
|
|
let start_instant = tokio::time::Instant::now() + duration_to_next_slot + (slot_duration / 2);
|
2019-12-06 07:44:38 +00:00
|
|
|
|
|
|
|
// Run this each slot.
|
|
|
|
let interval_duration = slot_duration;
|
|
|
|
|
2019-12-09 06:23:43 +00:00
|
|
|
let speedo = Mutex::new(Speedo::default());
|
2020-06-04 11:48:05 +00:00
|
|
|
let log = executor.log().clone();
|
2020-05-17 11:16:48 +00:00
|
|
|
let mut interval = tokio::time::interval_at(start_instant, interval_duration);
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-05-17 11:16:48 +00:00
|
|
|
let interval_future = async move {
|
2020-05-26 03:25:52 +00:00
|
|
|
// Perform pre-genesis logging.
|
|
|
|
loop {
|
|
|
|
match beacon_chain.slot_clock.duration_to_next_slot() {
|
|
|
|
// If the duration to the next slot is greater than the slot duration, then we are
|
|
|
|
// waiting for genesis.
|
|
|
|
Some(next_slot) if next_slot > slot_duration => {
|
|
|
|
info!(
|
|
|
|
log,
|
|
|
|
"Waiting for genesis";
|
|
|
|
"peers" => peer_count_pretty(network.connected_peers()),
|
|
|
|
"wait_time" => estimated_time_pretty(Some(next_slot.as_secs() as f64)),
|
|
|
|
);
|
2020-11-30 20:29:17 +00:00
|
|
|
eth1_logging(&beacon_chain, &log);
|
2020-11-28 05:30:57 +00:00
|
|
|
sleep(slot_duration).await;
|
2020-05-26 03:25:52 +00:00
|
|
|
}
|
|
|
|
_ => break,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform post-genesis logging.
|
2021-02-10 23:29:49 +00:00
|
|
|
loop {
|
|
|
|
interval.tick().await;
|
2020-02-19 11:12:25 +00:00
|
|
|
let connected_peer_count = network.connected_peers();
|
2020-04-19 10:45:25 +00:00
|
|
|
let sync_state = network.sync_state();
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2021-02-10 23:29:49 +00:00
|
|
|
let head_info = match beacon_chain.head_info() {
|
|
|
|
Ok(head_info) => head_info,
|
|
|
|
Err(e) => {
|
|
|
|
error!(log, "Failed to get beacon chain head info"; "error" => format!("{:?}", e));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-02-04 01:43:04 +00:00
|
|
|
let head_slot = head_info.slot;
|
2021-05-26 05:58:41 +00:00
|
|
|
|
|
|
|
metrics::set_gauge(&metrics::NOTIFIER_HEAD_SLOT, head_slot.as_u64() as i64);
|
|
|
|
|
2021-02-10 23:29:49 +00:00
|
|
|
let current_slot = match beacon_chain.slot() {
|
|
|
|
Ok(slot) => slot,
|
|
|
|
Err(e) => {
|
|
|
|
error!(
|
|
|
|
log,
|
|
|
|
"Unable to read current slot";
|
|
|
|
"error" => format!("{:?}", e)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-06 07:44:38 +00:00
|
|
|
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
|
2020-02-04 01:43:04 +00:00
|
|
|
let finalized_epoch = head_info.finalized_checkpoint.epoch;
|
|
|
|
let finalized_root = head_info.finalized_checkpoint.root;
|
|
|
|
let head_root = head_info.block_root;
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2019-12-09 06:23:43 +00:00
|
|
|
let mut speedo = speedo.lock();
|
|
|
|
speedo.observe(head_slot, Instant::now());
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-05-17 11:16:48 +00:00
|
|
|
metrics::set_gauge(
|
|
|
|
&metrics::SYNC_SLOTS_PER_SECOND,
|
2020-12-03 01:10:26 +00:00
|
|
|
speedo.slots_per_second().unwrap_or(0_f64) as i64,
|
2020-05-17 11:16:48 +00:00
|
|
|
);
|
Initial work towards v0.2.0 (#924)
* Remove ping protocol
* Initial renaming of network services
* Correct rebasing relative to latest master
* Start updating types
* Adds HashMapDelay struct to utils
* Initial network restructure
* Network restructure. Adds new types for v0.2.0
* Removes build artefacts
* Shift validation to beacon chain
* Temporarily remove gossip validation
This is to be updated to match current optimisation efforts.
* Adds AggregateAndProof
* Begin rebuilding pubsub encoding/decoding
* Signature hacking
* Shift gossipsup decoding into eth2_libp2p
* Existing EF tests passing with fake_crypto
* Shifts block encoding/decoding into RPC
* Delete outdated API spec
* All release tests passing bar genesis state parsing
* Update and test YamlConfig
* Update to spec v0.10 compatible BLS
* Updates to BLS EF tests
* Add EF test for AggregateVerify
And delete unused hash2curve tests for uncompressed points
* Update EF tests to v0.10.1
* Use optional block root correctly in block proc
* Use genesis fork in deposit domain. All tests pass
* Fast aggregate verify test
* Update REST API docs
* Fix unused import
* Bump spec tags to v0.10.1
* Add `seconds_per_eth1_block` to chainspec
* Update to timestamp based eth1 voting scheme
* Return None from `get_votes_to_consider` if block cache is empty
* Handle overflows in `is_candidate_block`
* Revert to failing tests
* Fix eth1 data sets test
* Choose default vote according to spec
* Fix collect_valid_votes tests
* Fix `get_votes_to_consider` to choose all eligible blocks
* Uncomment winning_vote tests
* Add comments; remove unused code
* Reduce seconds_per_eth1_block for simulation
* Addressed review comments
* Add test for default vote case
* Fix logs
* Remove unused functions
* Meter default eth1 votes
* Fix comments
* Progress on attestation service
* Address review comments; remove unused dependency
* Initial work on removing libp2p lock
* Add LRU caches to store (rollup)
* Update attestation validation for DB changes (WIP)
* Initial version of should_forward_block
* Scaffold
* Progress on attestation validation
Also, consolidate prod+testing slot clocks so that they share much
of the same implementation and can both handle sub-slot time changes.
* Removes lock from libp2p service
* Completed network lock removal
* Finish(?) attestation processing
* Correct network termination future
* Add slot check to block check
* Correct fmt issues
* Remove Drop implementation for network service
* Add first attempt at attestation proc. re-write
* Add version 2 of attestation processing
* Minor fixes
* Add validator pubkey cache
* Make get_indexed_attestation take a committee
* Link signature processing into new attn verification
* First working version
* Ensure pubkey cache is updated
* Add more metrics, slight optimizations
* Clone committee cache during attestation processing
* Update shuffling cache during block processing
* Remove old commented-out code
* Fix shuffling cache insert bug
* Used indexed attestation in fork choice
* Restructure attn processing, add metrics
* Add more detailed metrics
* Tidy, fix failing tests
* Fix failing tests, tidy
* Address reviewers suggestions
* Disable/delete two outdated tests
* Modification of validator for subscriptions
* Add slot signing to validator client
* Further progress on validation subscription
* Adds necessary validator subscription functionality
* Add new Pubkeys struct to signature_sets
* Refactor with functional approach
* Update beacon chain
* Clean up validator <-> beacon node http types
* Add aggregator status to ValidatorDuty
* Impl Clone for manual slot clock
* Fix minor errors
* Further progress validator client subscription
* Initial subscription and aggregation handling
* Remove decompressed member from pubkey bytes
* Progress to modifying val client for attestation aggregation
* First draft of validator client upgrade for aggregate attestations
* Add hashmap for indices lookup
* Add state cache, remove store cache
* Only build the head committee cache
* Removes lock on a network channel
* Partially implement beacon node subscription http api
* Correct compilation issues
* Change `get_attesting_indices` to use Vec
* Fix failing test
* Partial implementation of timer
* Adds timer, removes exit_future, http api to op pool
* Partial multiple aggregate attestation handling
* Permits bulk messages accross gossipsub network channel
* Correct compile issues
* Improve gosispsub messaging and correct rest api helpers
* Added global gossipsub subscriptions
* Update validator subscriptions data structs
* Tidy
* Re-structure validator subscriptions
* Initial handling of subscriptions
* Re-structure network service
* Add pubkey cache persistence file
* Add more comments
* Integrate persistence file into builder
* Add pubkey cache tests
* Add HashSetDelay and introduce into attestation service
* Handles validator subscriptions
* Add data_dir to beacon chain builder
* Remove Option in pubkey cache persistence file
* Ensure consistency between datadir/data_dir
* Fix failing network test
* Peer subnet discovery gets queued for future subscriptions
* Reorganise attestation service functions
* Initial wiring of attestation service
* First draft of attestation service timing logic
* Correct minor typos
* Tidy
* Fix todos
* Improve tests
* Add PeerInfo to connected peers mapping
* Fix compile error
* Fix compile error from merge
* Split up block processing metrics
* Tidy
* Refactor get_pubkey_from_state
* Remove commented-out code
* Rename state_cache -> checkpoint_cache
* Rename Checkpoint -> Snapshot
* Tidy, add comments
* Tidy up find_head function
* Change some checkpoint -> snapshot
* Add tests
* Expose max_len
* Remove dead code
* Tidy
* Fix bug
* Add sync-speed metric
* Add first attempt at VerifiableBlock
* Start integrating into beacon chain
* Integrate VerifiableBlock
* Rename VerifableBlock -> PartialBlockVerification
* Add start of typed methods
* Add progress
* Add further progress
* Rename structs
* Add full block verification to block_processing.rs
* Further beacon chain integration
* Update checks for gossip
* Add todo
* Start adding segement verification
* Add passing chain segement test
* Initial integration with batch sync
* Minor changes
* Tidy, add more error checking
* Start adding chain_segment tests
* Finish invalid signature tests
* Include single and gossip verified blocks in tests
* Add gossip verification tests
* Start adding docs
* Finish adding comments to block_processing.rs
* Rename block_processing.rs -> block_verification
* Start removing old block processing code
* Fixes beacon_chain compilation
* Fix project-wide compile errors
* Remove old code
* Correct code to pass all tests
* Fix bug with beacon proposer index
* Fix shim for BlockProcessingError
* Only process one epoch at a time
* Fix loop in chain segment processing
* Correct tests from master merge
* Add caching for state.eth1_data_votes
* Add BeaconChain::validator_pubkey
* Revert "Add caching for state.eth1_data_votes"
This reverts commit cd73dcd6434fb8d8e6bf30c5356355598ea7b78e.
Co-authored-by: Grant Wuerker <gwuerker@gmail.com>
Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Co-authored-by: Michael Sproul <micsproul@gmail.com>
Co-authored-by: pawan <pawandhananjay@gmail.com>
Co-authored-by: Paul Hauner <paul@paulhauner.com>
2020-03-17 06:24:44 +00:00
|
|
|
|
2019-12-06 07:44:38 +00:00
|
|
|
// The next two lines take advantage of saturating subtraction on `Slot`.
|
|
|
|
let head_distance = current_slot - head_slot;
|
|
|
|
|
|
|
|
if connected_peer_count <= WARN_PEER_COUNT {
|
2019-12-06 23:11:31 +00:00
|
|
|
warn!(log, "Low peer count"; "peer_count" => peer_count_pretty(connected_peer_count));
|
2019-12-06 07:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug!(
|
|
|
|
log,
|
|
|
|
"Slot timer";
|
2019-12-06 23:11:31 +00:00
|
|
|
"peers" => peer_count_pretty(connected_peer_count),
|
2019-12-06 07:44:38 +00:00
|
|
|
"finalized_root" => format!("{}", finalized_root),
|
|
|
|
"finalized_epoch" => finalized_epoch,
|
|
|
|
"head_block" => format!("{}", head_root),
|
|
|
|
"head_slot" => head_slot,
|
|
|
|
"current_slot" => current_slot,
|
2020-05-17 11:16:48 +00:00
|
|
|
"sync_state" =>format!("{}", sync_state)
|
2019-12-06 07:44:38 +00:00
|
|
|
);
|
|
|
|
|
2020-04-19 10:45:25 +00:00
|
|
|
// Log if we are syncing
|
|
|
|
if sync_state.is_syncing() {
|
2021-05-26 05:58:41 +00:00
|
|
|
metrics::set_gauge(&metrics::IS_SYNCED, 0);
|
2019-12-06 07:44:38 +00:00
|
|
|
let distance = format!(
|
|
|
|
"{} slots ({})",
|
|
|
|
head_distance.as_u64(),
|
|
|
|
slot_distance_pretty(head_distance, slot_duration)
|
|
|
|
);
|
2020-08-18 08:11:39 +00:00
|
|
|
|
|
|
|
let speed = speedo.slots_per_second();
|
|
|
|
let display_speed = speed.map_or(false, |speed| speed != 0.0);
|
|
|
|
|
|
|
|
if display_speed {
|
|
|
|
info!(
|
|
|
|
log,
|
|
|
|
"Syncing";
|
|
|
|
"peers" => peer_count_pretty(connected_peer_count),
|
|
|
|
"distance" => distance,
|
|
|
|
"speed" => sync_speed_pretty(speed),
|
|
|
|
"est_time" => estimated_time_pretty(speedo.estimated_time_till_slot(current_slot)),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
info!(
|
|
|
|
log,
|
|
|
|
"Syncing";
|
|
|
|
"peers" => peer_count_pretty(connected_peer_count),
|
|
|
|
"distance" => distance,
|
|
|
|
"est_time" => estimated_time_pretty(speedo.estimated_time_till_slot(current_slot)),
|
|
|
|
);
|
|
|
|
}
|
2020-07-23 14:18:00 +00:00
|
|
|
} else if sync_state.is_synced() {
|
2021-05-26 05:58:41 +00:00
|
|
|
metrics::set_gauge(&metrics::IS_SYNCED, 1);
|
2020-07-23 14:18:00 +00:00
|
|
|
let block_info = if current_slot > head_slot {
|
|
|
|
" … empty".to_string()
|
2020-04-19 10:45:25 +00:00
|
|
|
} else {
|
2020-07-23 14:18:00 +00:00
|
|
|
head_root.to_string()
|
|
|
|
};
|
|
|
|
info!(
|
|
|
|
log,
|
|
|
|
"Synced";
|
|
|
|
"peers" => peer_count_pretty(connected_peer_count),
|
|
|
|
"finalized_root" => format!("{}", finalized_root),
|
|
|
|
"finalized_epoch" => finalized_epoch,
|
|
|
|
"epoch" => current_epoch,
|
|
|
|
"block" => block_info,
|
|
|
|
"slot" => current_slot,
|
|
|
|
);
|
|
|
|
} else {
|
2021-05-26 05:58:41 +00:00
|
|
|
metrics::set_gauge(&metrics::IS_SYNCED, 0);
|
2020-07-23 14:18:00 +00:00
|
|
|
info!(
|
|
|
|
log,
|
|
|
|
"Searching for peers";
|
|
|
|
"peers" => peer_count_pretty(connected_peer_count),
|
|
|
|
"finalized_root" => format!("{}", finalized_root),
|
|
|
|
"finalized_epoch" => finalized_epoch,
|
|
|
|
"head_slot" => head_slot,
|
|
|
|
"current_slot" => current_slot,
|
|
|
|
);
|
2019-12-06 07:44:38 +00:00
|
|
|
}
|
2020-11-21 00:26:15 +00:00
|
|
|
|
2020-11-30 20:29:17 +00:00
|
|
|
eth1_logging(&beacon_chain, &log);
|
2020-05-17 11:16:48 +00:00
|
|
|
}
|
|
|
|
};
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-05-17 11:16:48 +00:00
|
|
|
// run the notifier on the current executor
|
2021-02-10 23:29:49 +00:00
|
|
|
executor.spawn(interval_future, "notifier");
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-06-04 11:48:05 +00:00
|
|
|
Ok(())
|
2019-12-06 07:44:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 20:29:17 +00:00
|
|
|
fn eth1_logging<T: BeaconChainTypes>(beacon_chain: &BeaconChain<T>, log: &Logger) {
|
|
|
|
let current_slot_opt = beacon_chain.slot().ok();
|
|
|
|
|
|
|
|
if let Ok(head_info) = beacon_chain.head_info() {
|
|
|
|
// Perform some logging about the eth1 chain
|
|
|
|
if let Some(eth1_chain) = beacon_chain.eth1_chain.as_ref() {
|
|
|
|
if let Some(status) =
|
|
|
|
eth1_chain.sync_status(head_info.genesis_time, current_slot_opt, &beacon_chain.spec)
|
|
|
|
{
|
|
|
|
debug!(
|
|
|
|
log,
|
|
|
|
"Eth1 cache sync status";
|
|
|
|
"eth1_head_block" => status.head_block_number,
|
|
|
|
"latest_cached_block_number" => status.latest_cached_block_number,
|
|
|
|
"latest_cached_timestamp" => status.latest_cached_block_timestamp,
|
|
|
|
"voting_target_timestamp" => status.voting_target_timestamp,
|
|
|
|
"ready" => status.lighthouse_is_cached_and_ready
|
|
|
|
);
|
|
|
|
|
|
|
|
if !status.lighthouse_is_cached_and_ready {
|
|
|
|
let voting_target_timestamp = status.voting_target_timestamp;
|
|
|
|
|
|
|
|
let distance = status
|
|
|
|
.latest_cached_block_timestamp
|
|
|
|
.map(|latest| {
|
|
|
|
voting_target_timestamp.saturating_sub(latest)
|
|
|
|
/ beacon_chain.spec.seconds_per_eth1_block
|
|
|
|
})
|
|
|
|
.map(|distance| distance.to_string())
|
|
|
|
.unwrap_or_else(|| "initializing deposits".to_string());
|
|
|
|
|
|
|
|
warn!(
|
|
|
|
log,
|
|
|
|
"Syncing eth1 block cache";
|
|
|
|
"est_blocks_remaining" => distance,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error!(
|
|
|
|
log,
|
|
|
|
"Unable to determine eth1 sync status";
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error!(
|
|
|
|
log,
|
|
|
|
"Unable to get head info";
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 23:11:31 +00:00
|
|
|
/// Returns the peer count, returning something helpful if it's `usize::max_value` (effectively a
|
|
|
|
/// `None` value).
|
|
|
|
fn peer_count_pretty(peer_count: usize) -> String {
|
|
|
|
if peer_count == usize::max_value() {
|
|
|
|
String::from("--")
|
|
|
|
} else {
|
|
|
|
format!("{}", peer_count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 06:23:43 +00:00
|
|
|
/// Returns a nicely formatted string describing the rate of slot imports per second.
|
|
|
|
fn sync_speed_pretty(slots_per_second: Option<f64>) -> String {
|
|
|
|
if let Some(slots_per_second) = slots_per_second {
|
|
|
|
format!("{:.2} slots/sec", slots_per_second)
|
|
|
|
} else {
|
|
|
|
"--".into()
|
2019-12-06 07:44:38 +00:00
|
|
|
}
|
2019-12-09 06:23:43 +00:00
|
|
|
}
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2019-12-09 06:23:43 +00:00
|
|
|
/// Returns a nicely formatted string how long will we reach the target slot.
|
|
|
|
fn estimated_time_pretty(seconds_till_slot: Option<f64>) -> String {
|
|
|
|
if let Some(seconds_till_slot) = seconds_till_slot {
|
|
|
|
seconds_pretty(seconds_till_slot)
|
2019-12-06 07:44:38 +00:00
|
|
|
} else {
|
2019-12-09 06:23:43 +00:00
|
|
|
"--".into()
|
2019-12-06 07:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a nicely formatted string describing the `slot_span` in terms of weeks, days, hours
|
|
|
|
/// and/or minutes.
|
|
|
|
fn slot_distance_pretty(slot_span: Slot, slot_duration: Duration) -> String {
|
|
|
|
if slot_duration == Duration::from_secs(0) {
|
|
|
|
return String::from("Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
let secs = (slot_duration * slot_span.as_u64() as u32).as_secs();
|
2019-12-09 06:23:43 +00:00
|
|
|
seconds_pretty(secs as f64)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a nicely formatted string describing the `slot_span` in terms of weeks, days, hours
|
|
|
|
/// and/or minutes.
|
|
|
|
fn seconds_pretty(secs: f64) -> String {
|
|
|
|
if secs <= 0.0 {
|
|
|
|
return "--".into();
|
|
|
|
}
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-05-26 03:25:52 +00:00
|
|
|
let d = time::Duration::seconds_f64(secs);
|
|
|
|
|
|
|
|
let weeks = d.whole_weeks();
|
|
|
|
let days = d.whole_days();
|
|
|
|
let hours = d.whole_hours();
|
|
|
|
let minutes = d.whole_minutes();
|
|
|
|
|
2020-08-18 08:11:39 +00:00
|
|
|
let week_string = if weeks == 1 { "week" } else { "weeks" };
|
|
|
|
let day_string = if days == 1 { "day" } else { "days" };
|
|
|
|
let hour_string = if hours == 1 { "hr" } else { "hrs" };
|
|
|
|
let min_string = if minutes == 1 { "min" } else { "mins" };
|
|
|
|
|
2020-05-26 03:25:52 +00:00
|
|
|
if weeks > 0 {
|
2020-08-18 08:11:39 +00:00
|
|
|
format!(
|
|
|
|
"{:.0} {} {:.0} {}",
|
|
|
|
weeks,
|
|
|
|
week_string,
|
|
|
|
days % DAYS_PER_WEEK,
|
|
|
|
day_string
|
|
|
|
)
|
2020-05-26 03:25:52 +00:00
|
|
|
} else if days > 0 {
|
2020-08-18 08:11:39 +00:00
|
|
|
format!(
|
|
|
|
"{:.0} {} {:.0} {}",
|
|
|
|
days,
|
|
|
|
day_string,
|
|
|
|
hours % HOURS_PER_DAY,
|
|
|
|
hour_string
|
|
|
|
)
|
2020-05-26 03:25:52 +00:00
|
|
|
} else if hours > 0 {
|
2020-08-18 08:11:39 +00:00
|
|
|
format!(
|
|
|
|
"{:.0} {} {:.0} {}",
|
|
|
|
hours,
|
|
|
|
hour_string,
|
|
|
|
minutes % MINUTES_PER_HOUR,
|
|
|
|
min_string
|
|
|
|
)
|
2019-12-06 07:44:38 +00:00
|
|
|
} else {
|
2020-08-18 08:11:39 +00:00
|
|
|
format!("{:.0} {}", minutes, min_string)
|
2019-12-09 06:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// "Speedo" is Australian for speedometer. This struct observes syncing times.
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct Speedo(Vec<(Slot, Instant)>);
|
|
|
|
|
|
|
|
impl Speedo {
|
|
|
|
/// Observe that we were at some `slot` at the given `instant`.
|
|
|
|
pub fn observe(&mut self, slot: Slot, instant: Instant) {
|
|
|
|
if self.0.len() > SPEEDO_OBSERVATIONS {
|
|
|
|
self.0.remove(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.0.push((slot, instant));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the average of the speeds between each observation.
|
|
|
|
///
|
|
|
|
/// Does not gracefully handle slots that are above `u32::max_value()`.
|
|
|
|
pub fn slots_per_second(&self) -> Option<f64> {
|
|
|
|
let speeds = self
|
|
|
|
.0
|
|
|
|
.windows(2)
|
|
|
|
.filter_map(|windows| {
|
|
|
|
let (slot_a, instant_a) = windows[0];
|
|
|
|
let (slot_b, instant_b) = windows[1];
|
|
|
|
|
|
|
|
// Taking advantage of saturating subtraction on `Slot`.
|
|
|
|
let distance = f64::from((slot_b - slot_a).as_u64() as u32);
|
|
|
|
|
|
|
|
let seconds = f64::from((instant_b - instant_a).as_millis() as u32) / 1_000.0;
|
|
|
|
|
|
|
|
if seconds > 0.0 {
|
|
|
|
Some(distance / seconds)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect::<Vec<f64>>();
|
|
|
|
|
|
|
|
let count = speeds.len();
|
|
|
|
let sum: f64 = speeds.iter().sum();
|
|
|
|
|
|
|
|
if count > 0 {
|
|
|
|
Some(sum / f64::from(count as u32))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the time we should reach the given `slot`, judging by the latest observation and
|
|
|
|
/// historical average syncing time.
|
|
|
|
///
|
|
|
|
/// Returns `None` if the slot is prior to our latest observed slot or we have not made any
|
|
|
|
/// observations.
|
|
|
|
pub fn estimated_time_till_slot(&self, target_slot: Slot) -> Option<f64> {
|
|
|
|
let (prev_slot, _) = self.0.last()?;
|
|
|
|
let slots_per_second = self.slots_per_second()?;
|
|
|
|
|
2019-12-11 00:02:54 +00:00
|
|
|
if target_slot > *prev_slot && slots_per_second > 0.0 {
|
2019-12-09 06:23:43 +00:00
|
|
|
let distance = (target_slot - *prev_slot).as_u64() as f64;
|
|
|
|
Some(distance / slots_per_second)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2019-12-06 07:44:38 +00:00
|
|
|
}
|
|
|
|
}
|