2019-03-28 23:49:43 +00:00
|
|
|
/// The Validator Client service.
|
|
|
|
///
|
|
|
|
/// Connects to a beacon node and negotiates the correct chain id.
|
|
|
|
///
|
|
|
|
/// Once connected, the service loads known validators keypairs from disk. Every slot,
|
|
|
|
/// the service pings the beacon node, asking for new duties for each of the validators.
|
|
|
|
///
|
|
|
|
/// 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
|
|
|
|
/// node.
|
2019-03-30 07:46:06 +00:00
|
|
|
use crate::attestation_producer::AttestationProducer;
|
2019-03-29 12:45:53 +00:00
|
|
|
use crate::block_producer::{BeaconBlockGrpcClient, BlockProducer};
|
2019-03-22 06:27:07 +00:00
|
|
|
use crate::config::Config as ValidatorConfig;
|
2019-03-30 07:46:06 +00:00
|
|
|
use crate::duties::{BeaconNodeDuties, DutiesManager, EpochDutiesMap};
|
2019-03-25 05:50:15 +00:00
|
|
|
use crate::error as error_chain;
|
|
|
|
use crate::error::ErrorKind;
|
2019-03-30 03:27:37 +00:00
|
|
|
use crate::signer::Signer;
|
2019-03-22 06:27:07 +00:00
|
|
|
use bls::Keypair;
|
2019-06-09 00:21:50 +00:00
|
|
|
use eth2_config::Eth2Config;
|
2019-03-22 06:27:07 +00:00
|
|
|
use grpcio::{ChannelBuilder, EnvBuilder};
|
2019-03-23 00:48:36 +00:00
|
|
|
use protos::services::Empty;
|
2019-03-22 06:27:07 +00:00
|
|
|
use protos::services_grpc::{
|
|
|
|
AttestationServiceClient, BeaconBlockServiceClient, BeaconNodeServiceClient,
|
|
|
|
ValidatorServiceClient,
|
|
|
|
};
|
2019-08-10 01:44:17 +00:00
|
|
|
use slog::{crit, error, info, warn};
|
2019-03-23 00:48:36 +00:00
|
|
|
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
use std::marker::PhantomData;
|
2019-03-22 06:27:07 +00:00
|
|
|
use std::sync::Arc;
|
2019-03-27 08:52:05 +00:00
|
|
|
use std::sync::RwLock;
|
2019-03-23 00:48:36 +00:00
|
|
|
use std::time::{Duration, Instant, SystemTime};
|
|
|
|
use tokio::prelude::*;
|
|
|
|
use tokio::runtime::Builder;
|
2019-04-03 05:23:09 +00:00
|
|
|
use tokio::timer::Interval;
|
2019-03-23 00:48:36 +00:00
|
|
|
use tokio_timer::clock::Clock;
|
2019-06-09 00:21:50 +00:00
|
|
|
use types::{ChainSpec, Epoch, EthSpec, Fork, Slot};
|
2019-03-23 00:48:36 +00:00
|
|
|
|
2019-03-31 03:26:58 +00:00
|
|
|
/// A fixed amount of time after a slot to perform operations. This gives the node time to complete
|
|
|
|
/// per-slot processes.
|
2019-08-10 01:44:17 +00:00
|
|
|
const TIME_DELAY_FROM_SLOT: Duration = Duration::from_millis(100);
|
2019-03-31 03:26:58 +00:00
|
|
|
|
2019-03-22 06:27:07 +00:00
|
|
|
/// The validator service. This is the main thread that executes and maintains validator
|
|
|
|
/// duties.
|
2019-03-29 12:45:53 +00:00
|
|
|
//TODO: Generalize the BeaconNode types to use testing
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
pub struct Service<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> {
|
2019-03-30 01:14:56 +00:00
|
|
|
/// The node's current fork version we are processing on.
|
2019-03-22 11:50:16 +00:00
|
|
|
fork: Fork,
|
2019-03-27 08:47:08 +00:00
|
|
|
/// The slot clock for this service.
|
|
|
|
slot_clock: SystemTimeSlotClock,
|
2019-03-22 13:36:48 +00:00
|
|
|
/// The current slot we are processing.
|
|
|
|
current_slot: Slot,
|
2019-06-08 11:57:25 +00:00
|
|
|
slots_per_epoch: u64,
|
2019-03-29 06:28:07 +00:00
|
|
|
/// The chain specification for this clients instance.
|
|
|
|
spec: Arc<ChainSpec>,
|
|
|
|
/// The duties manager which maintains the state of when to perform actions.
|
2019-03-30 03:27:37 +00:00
|
|
|
duties_manager: Arc<DutiesManager<B, S>>,
|
2019-03-22 12:21:26 +00:00
|
|
|
// GRPC Clients
|
|
|
|
/// The beacon block GRPC client.
|
2019-03-29 06:28:07 +00:00
|
|
|
beacon_block_client: Arc<BeaconBlockGrpcClient>,
|
2019-03-22 12:21:26 +00:00
|
|
|
/// The attester GRPC client.
|
2019-03-30 07:46:06 +00:00
|
|
|
attestation_client: Arc<AttestationServiceClient>,
|
2019-03-22 12:21:26 +00:00
|
|
|
/// The validator client logger.
|
|
|
|
log: slog::Logger,
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
_phantom: PhantomData<E>,
|
2019-03-22 11:50:16 +00:00
|
|
|
}
|
2019-03-22 06:27:07 +00:00
|
|
|
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
impl<B: BeaconNodeDuties + 'static, S: Signer + 'static, E: EthSpec> Service<B, S, E> {
|
2019-03-22 11:50:16 +00:00
|
|
|
/// Initial connection to the beacon node to determine its properties.
|
2019-03-22 12:21:26 +00:00
|
|
|
///
|
|
|
|
/// This tries to connect to a beacon node. Once connected, it initialised the gRPC clients
|
|
|
|
/// and returns an instance of the service.
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
fn initialize_service(
|
2019-06-09 00:21:50 +00:00
|
|
|
client_config: ValidatorConfig,
|
|
|
|
eth2_config: Eth2Config,
|
2019-03-30 01:14:56 +00:00
|
|
|
log: slog::Logger,
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
) -> error_chain::Result<Service<ValidatorServiceClient, Keypair, E>> {
|
2019-03-22 12:21:26 +00:00
|
|
|
// initialise the beacon node client to check for a connection
|
|
|
|
|
|
|
|
let env = Arc::new(EnvBuilder::new().build());
|
|
|
|
// Beacon node gRPC beacon node endpoints.
|
|
|
|
let beacon_node_client = {
|
2019-06-09 00:21:50 +00:00
|
|
|
let ch = ChannelBuilder::new(env.clone()).connect(&client_config.server);
|
2019-03-29 03:52:08 +00:00
|
|
|
BeaconNodeServiceClient::new(ch)
|
2019-03-22 12:21:26 +00:00
|
|
|
};
|
|
|
|
|
2019-03-28 23:49:43 +00:00
|
|
|
// retrieve node information and validate the beacon node
|
2019-03-22 11:50:16 +00:00
|
|
|
let node_info = loop {
|
2019-03-27 08:47:08 +00:00
|
|
|
match beacon_node_client.info(&Empty::new()) {
|
2019-03-22 11:50:16 +00:00
|
|
|
Err(e) => {
|
|
|
|
warn!(log, "Could not connect to node. Error: {}", e);
|
|
|
|
info!(log, "Retrying in 5 seconds...");
|
|
|
|
std::thread::sleep(Duration::from_secs(5));
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-25 04:10:26 +00:00
|
|
|
Ok(info) => {
|
2019-03-28 23:49:43 +00:00
|
|
|
// verify the node's genesis time
|
2019-03-25 04:10:26 +00:00
|
|
|
if SystemTime::now()
|
|
|
|
.duration_since(SystemTime::UNIX_EPOCH)
|
|
|
|
.unwrap()
|
2019-03-25 06:47:23 +00:00
|
|
|
.as_secs()
|
|
|
|
< info.genesis_time
|
2019-03-25 04:10:26 +00:00
|
|
|
{
|
2019-03-28 23:49:43 +00:00
|
|
|
error!(
|
2019-03-25 04:10:26 +00:00
|
|
|
log,
|
|
|
|
"Beacon Node's genesis time is in the future. No work to do.\n Exiting"
|
|
|
|
);
|
2019-03-25 05:50:15 +00:00
|
|
|
return Err("Genesis time in the future".into());
|
2019-03-25 04:10:26 +00:00
|
|
|
}
|
2019-08-10 01:44:17 +00:00
|
|
|
// verify the node's network id
|
|
|
|
if eth2_config.spec.network_id != info.network_id as u8 {
|
2019-03-28 23:49:43 +00:00
|
|
|
error!(
|
|
|
|
log,
|
|
|
|
"Beacon Node's genesis time is in the future. No work to do.\n Exiting"
|
|
|
|
);
|
2019-08-10 01:44:17 +00:00
|
|
|
return Err(format!("Beacon node has the wrong chain id. Expected chain id: {}, node's chain id: {}", eth2_config.spec.network_id, info.network_id).into());
|
2019-03-28 23:49:43 +00:00
|
|
|
}
|
2019-03-25 04:10:26 +00:00
|
|
|
break info;
|
|
|
|
}
|
2019-03-22 11:50:16 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-22 12:01:10 +00:00
|
|
|
// build requisite objects to form Self
|
|
|
|
let genesis_time = node_info.get_genesis_time();
|
2019-03-26 04:44:28 +00:00
|
|
|
let genesis_slot = Slot::from(node_info.get_genesis_slot());
|
2019-03-22 12:01:10 +00:00
|
|
|
|
2019-08-10 01:44:17 +00:00
|
|
|
info!(log,"Beacon node connected"; "Node Version" => node_info.version.clone(), "Chain ID" => node_info.network_id, "Genesis time" => genesis_time);
|
2019-03-22 11:50:16 +00:00
|
|
|
|
|
|
|
let proto_fork = node_info.get_fork();
|
|
|
|
let mut previous_version: [u8; 4] = [0; 4];
|
|
|
|
let mut current_version: [u8; 4] = [0; 4];
|
|
|
|
previous_version.copy_from_slice(&proto_fork.get_previous_version()[..4]);
|
|
|
|
current_version.copy_from_slice(&proto_fork.get_current_version()[..4]);
|
|
|
|
let fork = Fork {
|
|
|
|
previous_version,
|
|
|
|
current_version,
|
|
|
|
epoch: Epoch::from(proto_fork.get_epoch()),
|
|
|
|
};
|
|
|
|
|
2019-03-22 06:27:07 +00:00
|
|
|
// initialize the RPC clients
|
|
|
|
|
|
|
|
// Beacon node gRPC beacon block endpoints.
|
2019-03-22 12:21:26 +00:00
|
|
|
let beacon_block_client = {
|
2019-06-09 00:21:50 +00:00
|
|
|
let ch = ChannelBuilder::new(env.clone()).connect(&client_config.server);
|
2019-03-29 06:28:07 +00:00
|
|
|
let beacon_block_service_client = Arc::new(BeaconBlockServiceClient::new(ch));
|
|
|
|
// a wrapper around the service client to implement the beacon block node trait
|
|
|
|
Arc::new(BeaconBlockGrpcClient::new(beacon_block_service_client))
|
2019-03-22 06:27:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Beacon node gRPC validator endpoints.
|
2019-03-22 12:21:26 +00:00
|
|
|
let validator_client = {
|
2019-06-09 00:21:50 +00:00
|
|
|
let ch = ChannelBuilder::new(env.clone()).connect(&client_config.server);
|
2019-03-22 06:27:07 +00:00
|
|
|
Arc::new(ValidatorServiceClient::new(ch))
|
|
|
|
};
|
|
|
|
|
|
|
|
//Beacon node gRPC attester endpoints.
|
2019-03-30 07:46:06 +00:00
|
|
|
let attestation_client = {
|
2019-06-09 00:21:50 +00:00
|
|
|
let ch = ChannelBuilder::new(env.clone()).connect(&client_config.server);
|
2019-03-22 06:27:07 +00:00
|
|
|
Arc::new(AttestationServiceClient::new(ch))
|
|
|
|
};
|
|
|
|
|
2019-03-27 08:47:08 +00:00
|
|
|
// build the validator slot clock
|
2019-06-09 00:21:50 +00:00
|
|
|
let slot_clock = SystemTimeSlotClock::new(
|
|
|
|
genesis_slot,
|
|
|
|
genesis_time,
|
|
|
|
eth2_config.spec.seconds_per_slot,
|
|
|
|
);
|
2019-03-27 08:47:08 +00:00
|
|
|
|
2019-03-25 05:50:15 +00:00
|
|
|
let current_slot = slot_clock
|
|
|
|
.present_slot()
|
2019-03-30 08:58:19 +00:00
|
|
|
.map_err(ErrorKind::SlotClockError)?
|
2019-06-09 00:21:50 +00:00
|
|
|
.ok_or_else::<error_chain::Error, _>(|| {
|
|
|
|
"Genesis is not in the past. Exiting.".into()
|
|
|
|
})?;
|
2019-03-23 00:48:36 +00:00
|
|
|
|
2019-03-29 06:28:07 +00:00
|
|
|
/* Generate the duties manager */
|
|
|
|
|
2019-04-08 05:02:11 +00:00
|
|
|
// Load generated keypairs
|
2019-06-09 00:21:50 +00:00
|
|
|
let keypairs = match client_config.fetch_keys(&log) {
|
2019-04-08 05:02:11 +00:00
|
|
|
Some(kps) => Arc::new(kps),
|
2019-06-09 00:21:50 +00:00
|
|
|
None => {
|
|
|
|
return Err("Unable to locate validator key pairs, nothing to do.".into());
|
|
|
|
}
|
2019-04-08 05:02:11 +00:00
|
|
|
};
|
2019-03-29 06:28:07 +00:00
|
|
|
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
let slots_per_epoch = E::slots_per_epoch();
|
2019-06-09 00:21:50 +00:00
|
|
|
|
2019-03-29 06:28:07 +00:00
|
|
|
// TODO: keypairs are randomly generated; they should be loaded from a file or generated.
|
|
|
|
// https://github.com/sigp/lighthouse/issues/160
|
2019-04-08 05:02:11 +00:00
|
|
|
//let keypairs = Arc::new(generate_deterministic_keypairs(8));
|
2019-03-29 06:28:07 +00:00
|
|
|
|
|
|
|
// Builds a mapping of Epoch -> Map(PublicKey, EpochDuty)
|
|
|
|
// where EpochDuty contains slot numbers and attestation data that each validator needs to
|
|
|
|
// produce work on.
|
2019-06-09 00:21:50 +00:00
|
|
|
let duties_map = RwLock::new(EpochDutiesMap::new(slots_per_epoch));
|
2019-03-29 06:28:07 +00:00
|
|
|
|
|
|
|
// builds a manager which maintains the list of current duties for all known validators
|
|
|
|
// and can check when a validator needs to perform a task.
|
|
|
|
let duties_manager = Arc::new(DutiesManager {
|
|
|
|
duties_map,
|
2019-03-30 03:27:37 +00:00
|
|
|
// these are abstract objects capable of signing
|
2019-03-30 02:17:24 +00:00
|
|
|
signers: keypairs,
|
2019-03-29 06:28:07 +00:00
|
|
|
beacon_node: validator_client,
|
|
|
|
});
|
|
|
|
|
2019-06-09 00:21:50 +00:00
|
|
|
let spec = Arc::new(eth2_config.spec);
|
2019-03-30 01:14:56 +00:00
|
|
|
|
|
|
|
Ok(Service {
|
2019-03-22 12:21:26 +00:00
|
|
|
fork,
|
|
|
|
slot_clock,
|
2019-03-22 13:36:48 +00:00
|
|
|
current_slot,
|
2019-06-09 00:21:50 +00:00
|
|
|
slots_per_epoch,
|
2019-03-29 06:28:07 +00:00
|
|
|
spec,
|
|
|
|
duties_manager,
|
2019-03-22 12:21:26 +00:00
|
|
|
beacon_block_client,
|
2019-03-30 07:46:06 +00:00
|
|
|
attestation_client,
|
2019-03-22 12:21:26 +00:00
|
|
|
log,
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
_phantom: PhantomData,
|
2019-03-25 05:50:15 +00:00
|
|
|
})
|
2019-03-22 12:21:26 +00:00
|
|
|
}
|
2019-03-22 06:27:07 +00:00
|
|
|
|
2019-03-23 00:48:36 +00:00
|
|
|
/// Initialise the service then run the core thread.
|
2019-03-30 01:14:56 +00:00
|
|
|
// TODO: Improve handling of generic BeaconNode types, to stub grpcClient
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
pub fn start(
|
2019-06-09 00:21:50 +00:00
|
|
|
client_config: ValidatorConfig,
|
|
|
|
eth2_config: Eth2Config,
|
2019-06-08 11:57:25 +00:00
|
|
|
log: slog::Logger,
|
|
|
|
) -> error_chain::Result<()> {
|
2019-03-23 00:48:36 +00:00
|
|
|
// connect to the node and retrieve its properties and initialize the gRPC clients
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
let mut service = Service::<ValidatorServiceClient, Keypair, E>::initialize_service(
|
2019-06-09 00:21:50 +00:00
|
|
|
client_config,
|
|
|
|
eth2_config,
|
|
|
|
log,
|
|
|
|
)?;
|
2019-03-22 13:36:48 +00:00
|
|
|
|
2019-03-23 00:48:36 +00:00
|
|
|
// we have connected to a node and established its parameters. Spin up the core service
|
2019-03-22 06:27:07 +00:00
|
|
|
|
2019-03-22 13:36:48 +00:00
|
|
|
// set up the validator service runtime
|
2019-03-23 00:48:36 +00:00
|
|
|
let mut runtime = Builder::new()
|
|
|
|
.clock(Clock::system())
|
|
|
|
.name_prefix("validator-client-")
|
|
|
|
.build()
|
2019-03-25 05:50:15 +00:00
|
|
|
.map_err(|e| format!("Tokio runtime failed: {}", e))?;
|
2019-03-22 13:36:48 +00:00
|
|
|
|
2019-03-28 03:31:35 +00:00
|
|
|
let duration_to_next_slot = service
|
|
|
|
.slot_clock
|
|
|
|
.duration_to_next_slot()
|
|
|
|
.map_err(|e| format!("System clock error: {:?}", e))?
|
2019-06-09 00:21:50 +00:00
|
|
|
.ok_or_else::<error_chain::Error, _>(|| {
|
|
|
|
"Genesis is not in the past. Exiting.".into()
|
|
|
|
})?;
|
2019-03-28 03:31:35 +00:00
|
|
|
|
2019-03-22 13:36:48 +00:00
|
|
|
// set up the validator work interval - start at next slot and proceed every slot
|
|
|
|
let interval = {
|
|
|
|
// Set the interval to start at the next slot, and every slot after
|
2019-03-30 01:14:56 +00:00
|
|
|
let slot_duration = Duration::from_secs(service.spec.seconds_per_slot);
|
2019-03-22 13:36:48 +00:00
|
|
|
//TODO: Handle checked add correctly
|
2019-03-28 03:31:35 +00:00
|
|
|
Interval::new(Instant::now() + duration_to_next_slot, slot_duration)
|
2019-03-23 00:48:36 +00:00
|
|
|
};
|
2019-03-22 13:36:48 +00:00
|
|
|
|
2019-03-29 06:28:07 +00:00
|
|
|
/* kick off the core service */
|
2019-03-28 06:16:43 +00:00
|
|
|
runtime.block_on(
|
|
|
|
interval
|
|
|
|
.for_each(move |_| {
|
2019-03-31 03:26:58 +00:00
|
|
|
// wait for node to process
|
|
|
|
std::thread::sleep(TIME_DELAY_FROM_SLOT);
|
2019-03-29 06:28:07 +00:00
|
|
|
// if a non-fatal error occurs, proceed to the next slot.
|
|
|
|
let _ignore_error = service.per_slot_execution();
|
|
|
|
// completed a slot process
|
2019-03-28 06:16:43 +00:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.map_err(|e| format!("Service thread failed: {:?}", e)),
|
2019-03-30 01:14:56 +00:00
|
|
|
)?;
|
2019-03-29 06:28:07 +00:00
|
|
|
// validator client exited
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The execution logic that runs every slot.
|
|
|
|
// Errors are logged to output, and core execution continues unless fatal errors occur.
|
|
|
|
fn per_slot_execution(&mut self) -> error_chain::Result<()> {
|
|
|
|
/* get the new current slot and epoch */
|
|
|
|
self.update_current_slot()?;
|
|
|
|
|
|
|
|
/* check for new duties */
|
|
|
|
self.check_for_duties();
|
|
|
|
|
|
|
|
/* process any required duties for validators */
|
|
|
|
self.process_duties();
|
2019-03-26 04:59:00 +00:00
|
|
|
|
2019-03-25 05:50:15 +00:00
|
|
|
Ok(())
|
2019-03-23 00:48:36 +00:00
|
|
|
}
|
2019-03-22 12:21:26 +00:00
|
|
|
|
2019-03-29 06:28:07 +00:00
|
|
|
/// Updates the known current slot and epoch.
|
|
|
|
fn update_current_slot(&mut self) -> error_chain::Result<()> {
|
|
|
|
let current_slot = match self.slot_clock.present_slot() {
|
|
|
|
Err(e) => {
|
|
|
|
error!(self.log, "SystemTimeError {:?}", e);
|
|
|
|
return Err("Could not read system time".into());
|
|
|
|
}
|
2019-06-09 00:21:50 +00:00
|
|
|
Ok(slot) => slot.ok_or_else::<error_chain::Error, _>(|| {
|
|
|
|
"Genesis is not in the past. Exiting.".into()
|
|
|
|
})?,
|
2019-03-23 00:48:36 +00:00
|
|
|
};
|
2019-03-22 06:27:07 +00:00
|
|
|
|
2019-06-08 11:57:25 +00:00
|
|
|
let current_epoch = current_slot.epoch(self.slots_per_epoch);
|
2019-03-29 06:28:07 +00:00
|
|
|
|
2019-08-10 01:44:17 +00:00
|
|
|
// this is a non-fatal error. If the slot clock repeats, the node could
|
|
|
|
// have been slow to process the previous slot and is now duplicating tasks.
|
|
|
|
// We ignore duplicated but raise a critical error.
|
|
|
|
if current_slot <= self.current_slot {
|
|
|
|
crit!(
|
|
|
|
self.log,
|
|
|
|
"The validator tried to duplicate a slot. Likely missed the previous slot"
|
|
|
|
);
|
|
|
|
return Err("Duplicate slot".into());
|
|
|
|
}
|
2019-03-29 06:28:07 +00:00
|
|
|
self.current_slot = current_slot;
|
|
|
|
info!(self.log, "Processing"; "slot" => current_slot.as_u64(), "epoch" => current_epoch.as_u64());
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-03-22 06:27:07 +00:00
|
|
|
|
2019-03-29 06:28:07 +00:00
|
|
|
/// For all known validator keypairs, update any known duties from the beacon node.
|
|
|
|
fn check_for_duties(&mut self) {
|
|
|
|
let cloned_manager = self.duties_manager.clone();
|
|
|
|
let cloned_log = self.log.clone();
|
2019-06-08 11:57:25 +00:00
|
|
|
let current_epoch = self.current_slot.epoch(self.slots_per_epoch);
|
2019-03-29 06:28:07 +00:00
|
|
|
// spawn a new thread separate to the runtime
|
|
|
|
// TODO: Handle thread termination/timeout
|
2019-04-01 05:29:11 +00:00
|
|
|
// TODO: Add duties thread back in, with channel to process duties in duty change.
|
|
|
|
// leave sequential for now.
|
|
|
|
//std::thread::spawn(move || {
|
|
|
|
// the return value is a future which returns ready.
|
|
|
|
// built to be compatible with the tokio runtime.
|
|
|
|
let _empty = cloned_manager.run_update(current_epoch, cloned_log.clone());
|
|
|
|
//});
|
2019-03-23 00:48:36 +00:00
|
|
|
}
|
2019-03-22 06:27:07 +00:00
|
|
|
|
2019-03-29 06:28:07 +00:00
|
|
|
/// If there are any duties to process, spawn a separate thread and perform required actions.
|
|
|
|
fn process_duties(&mut self) {
|
|
|
|
if let Some(work) = self.duties_manager.get_current_work(self.current_slot) {
|
2019-03-30 03:48:43 +00:00
|
|
|
for (signer_index, work_type) in work {
|
2019-03-29 06:28:07 +00:00
|
|
|
if work_type.produce_block {
|
2019-03-30 07:46:06 +00:00
|
|
|
// we need to produce a block
|
2019-03-29 06:28:07 +00:00
|
|
|
// spawns a thread to produce a beacon block
|
2019-03-30 04:58:31 +00:00
|
|
|
let signers = self.duties_manager.signers.clone(); // this is an arc
|
2019-03-30 03:48:43 +00:00
|
|
|
let fork = self.fork.clone();
|
2019-03-30 08:58:19 +00:00
|
|
|
let slot = self.current_slot;
|
2019-03-30 03:48:43 +00:00
|
|
|
let spec = self.spec.clone();
|
|
|
|
let beacon_node = self.beacon_block_client.clone();
|
2019-03-30 04:58:31 +00:00
|
|
|
let log = self.log.clone();
|
2019-06-08 11:57:25 +00:00
|
|
|
let slots_per_epoch = self.slots_per_epoch;
|
2019-03-29 06:28:07 +00:00
|
|
|
std::thread::spawn(move || {
|
2019-03-30 04:58:31 +00:00
|
|
|
info!(log, "Producing a block"; "Validator"=> format!("{}", signers[signer_index]));
|
2019-03-30 03:48:43 +00:00
|
|
|
let signer = &signers[signer_index];
|
2019-03-30 04:58:31 +00:00
|
|
|
let mut block_producer = BlockProducer {
|
2019-03-30 03:48:43 +00:00
|
|
|
fork,
|
|
|
|
slot,
|
|
|
|
spec,
|
|
|
|
beacon_node,
|
|
|
|
signer,
|
2019-06-08 11:57:25 +00:00
|
|
|
slots_per_epoch,
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
_phantom: PhantomData::<E>,
|
2019-03-29 06:28:07 +00:00
|
|
|
};
|
2019-03-30 04:58:31 +00:00
|
|
|
block_producer.handle_produce_block(log);
|
2019-03-29 06:28:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if work_type.attestation_duty.is_some() {
|
2019-03-30 07:46:06 +00:00
|
|
|
// we need to produce an attestation
|
|
|
|
// spawns a thread to produce and sign an attestation
|
|
|
|
let signers = self.duties_manager.signers.clone(); // this is an arc
|
|
|
|
let fork = self.fork.clone();
|
|
|
|
let spec = self.spec.clone();
|
|
|
|
let beacon_node = self.attestation_client.clone();
|
|
|
|
let log = self.log.clone();
|
2019-06-08 11:57:25 +00:00
|
|
|
let slots_per_epoch = self.slots_per_epoch;
|
2019-03-30 07:46:06 +00:00
|
|
|
std::thread::spawn(move || {
|
|
|
|
info!(log, "Producing an attestation"; "Validator"=> format!("{}", signers[signer_index]));
|
|
|
|
let signer = &signers[signer_index];
|
|
|
|
let mut attestation_producer = AttestationProducer {
|
|
|
|
fork,
|
|
|
|
duty: work_type.attestation_duty.expect("Should never be none"),
|
|
|
|
spec,
|
|
|
|
beacon_node,
|
|
|
|
signer,
|
2019-06-08 11:57:25 +00:00
|
|
|
slots_per_epoch,
|
Update to frozen spec ❄️ (v0.8.1) (#444)
* types: first updates for v0.8
* state_processing: epoch processing v0.8.0
* state_processing: block processing v0.8.0
* tree_hash_derive: support generics in SignedRoot
* types v0.8: update to use ssz_types
* state_processing v0.8: use ssz_types
* ssz_types: add bitwise methods and from_elem
* types: fix v0.8 FIXMEs
* ssz_types: add bitfield shift_up
* ssz_types: iterators and DerefMut for VariableList
* types,state_processing: use VariableList
* ssz_types: fix BitVector Decode impl
Fixed a typo in the implementation of ssz::Decode for BitVector, which caused it
to be considered variable length!
* types: fix test modules for v0.8 update
* types: remove slow type-level arithmetic
* state_processing: fix tests for v0.8
* op_pool: update for v0.8
* ssz_types: Bitfield difference length-independent
Allow computing the difference of two bitfields of different lengths.
* Implement compact committee support
* epoch_processing: committee & active index roots
* state_processing: genesis state builder v0.8
* state_processing: implement v0.8.1
* Further improve tree_hash
* Strip examples, tests from cached_tree_hash
* Update TreeHash, un-impl CachedTreeHash
* Update bitfield TreeHash, un-impl CachedTreeHash
* Update FixedLenVec TreeHash, unimpl CachedTreeHash
* Update update tree_hash_derive for new TreeHash
* Fix TreeHash, un-impl CachedTreeHash for ssz_types
* Remove fixed_len_vec, ssz benches
SSZ benches relied upon fixed_len_vec -- it is easier to just delete
them and rebuild them later (when necessary)
* Remove boolean_bitfield crate
* Fix fake_crypto BLS compile errors
* Update ef_tests for new v.8 type params
* Update ef_tests submodule to v0.8.1 tag
* Make fixes to support parsing ssz ef_tests
* `compact_committee...` to `compact_committees...`
* Derive more traits for `CompactCommittee`
* Flip bitfield byte-endianness
* Fix tree_hash for bitfields
* Modify CLI output for ef_tests
* Bump ssz crate version
* Update ssz_types doc comment
* Del cached tree hash tests from ssz_static tests
* Tidy SSZ dependencies
* Rename ssz_types crate to eth2_ssz_types
* validator_client: update for v0.8
* ssz_types: update union/difference for bit order swap
* beacon_node: update for v0.8, EthSpec
* types: disable cached tree hash, update min spec
* state_processing: fix slot bug in committee update
* tests: temporarily disable fork choice harness test
See #447
* committee cache: prevent out-of-bounds access
In the case where we tried to access the committee of a shard that didn't have a committee in the
current epoch, we were accessing elements beyond the end of the shuffling vector and panicking! This
commit adds a check to make the failure safe and explicit.
* fix bug in get_indexed_attestation and simplify
There was a bug in our implementation of get_indexed_attestation whereby
incorrect "committee indices" were used to index into the custody bitfield. The
bug was only observable in the case where some bits of the custody bitfield were
set to 1. The implementation has been simplified to remove the bug, and a test
added.
* state_proc: workaround for compact committees bug
https://github.com/ethereum/eth2.0-specs/issues/1315
* v0.8: updates to make the EF tests pass
* Remove redundant max operation checks.
* Always supply both messages when checking attestation signatures -- allowing
verification of an attestation with no signatures.
* Swap the order of the fork and domain constant in `get_domain`, to match
the spec.
* rustfmt
* ef_tests: add new epoch processing tests
* Integrate v0.8 into master (compiles)
* Remove unused crates, fix clippy lints
* Replace v0.6.3 tags w/ v0.8.1
* Remove old comment
* Ensure lmd ghost tests only run in release
* Update readme
2019-07-30 02:44:51 +00:00
|
|
|
_phantom: PhantomData::<E>,
|
2019-03-30 07:46:06 +00:00
|
|
|
};
|
|
|
|
attestation_producer.handle_produce_attestation(log);
|
|
|
|
});
|
2019-03-29 06:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-22 06:27:07 +00:00
|
|
|
}
|
|
|
|
}
|