2019-02-14 01:09:18 +00:00
|
|
|
use crate::checkpoint::CheckPoint;
|
2019-03-07 01:53:15 +00:00
|
|
|
use crate::errors::{BeaconChainError as Error, BlockProductionError};
|
2019-09-03 05:52:25 +00:00
|
|
|
use crate::eth1_chain::{Eth1Chain, Eth1ChainBackend};
|
2019-09-14 19:41:35 +00:00
|
|
|
use crate::events::{EventHandler, EventKind};
|
2019-06-15 18:03:29 +00:00
|
|
|
use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
use crate::head_tracker::HeadTracker;
|
2019-08-19 11:02:34 +00:00
|
|
|
use crate::metrics;
|
2020-03-06 05:09:41 +00:00
|
|
|
use crate::persisted_beacon_chain::PersistedBeaconChain;
|
2020-03-05 06:19:35 +00:00
|
|
|
use crate::shuffling_cache::ShufflingCache;
|
2020-01-06 06:30:37 +00:00
|
|
|
use crate::timeout_rw_lock::TimeoutRwLock;
|
2020-03-05 06:19:35 +00:00
|
|
|
use crate::validator_pubkey_cache::ValidatorPubkeyCache;
|
2019-06-18 07:55:18 +00:00
|
|
|
use operation_pool::{OperationPool, PersistedOperationPool};
|
2019-11-27 07:37:09 +00:00
|
|
|
use slog::{debug, error, info, trace, warn, Logger};
|
2019-02-14 01:09:18 +00:00
|
|
|
use slot_clock::SlotClock;
|
2019-09-09 00:55:15 +00:00
|
|
|
use ssz::Encode;
|
2020-03-05 06:19:35 +00:00
|
|
|
use state_processing::per_block_processing::errors::{
|
|
|
|
AttestationValidationError, AttesterSlashingValidationError, ExitValidationError,
|
|
|
|
ProposerSlashingValidationError,
|
2019-03-29 07:54:01 +00:00
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
use state_processing::{
|
2020-03-05 06:19:35 +00:00
|
|
|
common::get_indexed_attestation, per_block_processing, per_slot_processing,
|
|
|
|
signature_sets::indexed_attestation_signature_set_from_pubkeys, BlockProcessingError,
|
|
|
|
BlockSignatureStrategy,
|
2019-02-14 01:09:18 +00:00
|
|
|
};
|
2020-03-04 06:10:22 +00:00
|
|
|
use std::borrow::Cow;
|
2020-01-21 07:38:56 +00:00
|
|
|
use std::cmp::Ordering;
|
2019-09-09 00:55:15 +00:00
|
|
|
use std::fs;
|
|
|
|
use std::io::prelude::*;
|
2019-02-14 01:09:18 +00:00
|
|
|
use std::sync::Arc;
|
2019-11-27 07:37:09 +00:00
|
|
|
use std::time::{Duration, Instant};
|
2019-11-26 23:54:46 +00:00
|
|
|
use store::iter::{
|
|
|
|
BlockRootsIterator, ReverseBlockRootIterator, ReverseStateRootIterator, StateRootsIterator,
|
|
|
|
};
|
2020-02-10 00:30:21 +00:00
|
|
|
use store::{Error as DBError, Migrate, StateBatch, Store};
|
2019-06-03 06:13:51 +00:00
|
|
|
use tree_hash::TreeHash;
|
2019-03-17 07:10:20 +00:00
|
|
|
use types::*;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-06-18 17:01:58 +00:00
|
|
|
// Text included in blocks.
|
|
|
|
// Must be 32-bytes or panic.
|
|
|
|
//
|
|
|
|
// |-------must be this long------|
|
2020-01-10 05:01:37 +00:00
|
|
|
pub const GRAFFITI: &str = "sigp/lighthouse-0.1.1-prerelease";
|
2019-06-18 17:01:58 +00:00
|
|
|
|
2019-09-09 01:57:48 +00:00
|
|
|
/// If true, everytime a block is processed the pre-state, post-state and block are written to SSZ
|
|
|
|
/// files in the temp directory.
|
|
|
|
///
|
|
|
|
/// Only useful for testing.
|
2019-09-23 12:20:47 +00:00
|
|
|
const WRITE_BLOCK_PROCESSING_SSZ: bool = cfg!(feature = "write_ssz_files");
|
2019-09-09 01:57:48 +00:00
|
|
|
|
2019-12-12 06:05:07 +00:00
|
|
|
/// Maximum block slot number. Block with slots bigger than this constant will NOT be processed.
|
|
|
|
const MAXIMUM_BLOCK_SLOT_NUMBER: u64 = 4_294_967_296; // 2^32
|
|
|
|
|
2020-01-06 06:30:37 +00:00
|
|
|
/// The time-out before failure during an operation to take a read/write RwLock on the canonical
|
|
|
|
/// head.
|
|
|
|
const HEAD_LOCK_TIMEOUT: Duration = Duration::from_secs(1);
|
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
/// The time-out before failure during an operation to take a read/write RwLock on the
|
|
|
|
/// attestation cache.
|
|
|
|
const ATTESTATION_CACHE_LOCK_TIMEOUT: Duration = Duration::from_secs(1);
|
|
|
|
|
|
|
|
/// The time-out before failure during an operation to take a read/write RwLock on the
|
|
|
|
/// validator pubkey cache.
|
|
|
|
const VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT: Duration = Duration::from_secs(1);
|
|
|
|
|
2020-03-06 05:09:41 +00:00
|
|
|
pub const BEACON_CHAIN_DB_KEY: [u8; 32] = [0; 32];
|
|
|
|
pub const OP_POOL_DB_KEY: [u8; 32] = [0; 32];
|
|
|
|
pub const ETH1_CACHE_DB_KEY: [u8; 32] = [0; 32];
|
|
|
|
pub const FORK_CHOICE_DB_KEY: [u8; 32] = [0; 32];
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
2019-06-13 03:54:16 +00:00
|
|
|
pub enum BlockProcessingOutcome {
|
|
|
|
/// Block was valid and imported into the block graph.
|
2019-06-20 08:46:03 +00:00
|
|
|
Processed { block_root: Hash256 },
|
2020-01-29 04:05:00 +00:00
|
|
|
/// The parent block was unknown.
|
|
|
|
ParentUnknown {
|
|
|
|
parent: Hash256,
|
|
|
|
reference_location: &'static str,
|
|
|
|
},
|
2019-02-14 01:09:18 +00:00
|
|
|
/// The block slot is greater than the present slot.
|
2019-03-24 05:35:07 +00:00
|
|
|
FutureSlot {
|
|
|
|
present_slot: Slot,
|
|
|
|
block_slot: Slot,
|
|
|
|
},
|
2019-02-14 01:09:18 +00:00
|
|
|
/// The block state_root does not match the generated state.
|
2019-09-03 04:18:45 +00:00
|
|
|
StateRootMismatch { block: Hash256, local: Hash256 },
|
2019-06-13 03:54:16 +00:00
|
|
|
/// The block was a genesis block, these blocks cannot be re-imported.
|
|
|
|
GenesisBlock,
|
|
|
|
/// The slot is finalized, no need to import.
|
2019-09-03 04:18:45 +00:00
|
|
|
WouldRevertFinalizedSlot {
|
|
|
|
block_slot: Slot,
|
|
|
|
finalized_slot: Slot,
|
|
|
|
},
|
2019-06-13 03:54:16 +00:00
|
|
|
/// Block is already known, no need to re-import.
|
|
|
|
BlockIsAlreadyKnown,
|
2019-12-12 06:05:07 +00:00
|
|
|
/// The block slot exceeds the MAXIMUM_BLOCK_SLOT_NUMBER.
|
|
|
|
BlockSlotLimitReached,
|
2019-02-14 01:09:18 +00:00
|
|
|
/// The block could not be applied to the state, it is invalid.
|
|
|
|
PerBlockProcessingError(BlockProcessingError),
|
|
|
|
}
|
|
|
|
|
2019-08-14 00:55:24 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum AttestationProcessingOutcome {
|
|
|
|
Processed,
|
2019-11-25 04:48:24 +00:00
|
|
|
EmptyAggregationBitfield,
|
2019-08-14 00:55:24 +00:00
|
|
|
UnknownHeadBlock {
|
|
|
|
beacon_block_root: Hash256,
|
|
|
|
},
|
|
|
|
/// The attestation is attesting to a state that is later than itself. (Viz., attesting to the
|
|
|
|
/// future).
|
2020-03-05 06:19:35 +00:00
|
|
|
AttestsToFutureBlock {
|
|
|
|
block: Slot,
|
2019-08-14 00:55:24 +00:00
|
|
|
attestation: Slot,
|
|
|
|
},
|
|
|
|
/// The slot is finalized, no need to import.
|
|
|
|
FinalizedSlot {
|
2020-03-05 06:19:35 +00:00
|
|
|
attestation: Slot,
|
|
|
|
finalized: Slot,
|
|
|
|
},
|
|
|
|
FutureEpoch {
|
|
|
|
attestation_epoch: Epoch,
|
|
|
|
current_epoch: Epoch,
|
|
|
|
},
|
|
|
|
PastEpoch {
|
|
|
|
attestation_epoch: Epoch,
|
|
|
|
current_epoch: Epoch,
|
|
|
|
},
|
|
|
|
BadTargetEpoch,
|
|
|
|
UnknownTargetRoot(Hash256),
|
|
|
|
InvalidSignature,
|
|
|
|
NoCommitteeForSlotAndIndex {
|
|
|
|
slot: Slot,
|
|
|
|
index: CommitteeIndex,
|
2019-08-14 00:55:24 +00:00
|
|
|
},
|
|
|
|
Invalid(AttestationValidationError),
|
|
|
|
}
|
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
/// Defines how a `BeaconState` should be "skipped" through skip-slots.
|
|
|
|
pub enum StateSkipConfig {
|
|
|
|
/// Calculate the state root during each skip slot, producing a fully-valid `BeaconState`.
|
|
|
|
WithStateRoots,
|
|
|
|
/// Don't calculate the state root at each slot, instead just use the zero hash. This is orders
|
|
|
|
/// of magnitude faster, however it produces a partially invalid state.
|
|
|
|
///
|
|
|
|
/// This state is useful for operations that don't use the state roots; e.g., for calculating
|
|
|
|
/// the shuffling.
|
|
|
|
WithoutStateRoots,
|
|
|
|
}
|
|
|
|
|
2019-12-09 03:20:25 +00:00
|
|
|
pub struct HeadInfo {
|
|
|
|
pub slot: Slot,
|
|
|
|
pub block_root: Hash256,
|
|
|
|
pub state_root: Hash256,
|
2020-03-04 06:10:22 +00:00
|
|
|
pub current_justified_checkpoint: types::Checkpoint,
|
2019-12-09 03:20:25 +00:00
|
|
|
pub finalized_checkpoint: types::Checkpoint,
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fork: Fork,
|
2019-12-09 03:20:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-23 05:53:53 +00:00
|
|
|
pub trait BeaconChainTypes: Send + Sync + 'static {
|
2019-12-06 07:52:11 +00:00
|
|
|
type Store: store::Store<Self::EthSpec>;
|
2019-11-26 23:54:46 +00:00
|
|
|
type StoreMigrator: store::Migrate<Self::Store, Self::EthSpec>;
|
2019-05-25 10:51:15 +00:00
|
|
|
type SlotClock: slot_clock::SlotClock;
|
2020-01-19 20:52:59 +00:00
|
|
|
type Eth1Chain: Eth1ChainBackend<Self::EthSpec, Self::Store>;
|
2019-05-25 10:51:15 +00:00
|
|
|
type EthSpec: types::EthSpec;
|
2019-09-14 19:41:35 +00:00
|
|
|
type EventHandler: EventHandler<Self::EthSpec>;
|
2019-05-25 10:51:15 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 07:32:20 +00:00
|
|
|
/// Represents the "Beacon Chain" component of Ethereum 2.0. Allows import of blocks and block
|
|
|
|
/// operations and chooses a canonical head.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub struct BeaconChain<T: BeaconChainTypes> {
|
2019-06-08 11:57:25 +00:00
|
|
|
pub spec: ChainSpec,
|
2019-05-31 07:32:20 +00:00
|
|
|
/// Persistent storage for blocks, states, etc. Typically an on-disk store, such as LevelDB.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub store: Arc<T::Store>,
|
2019-11-26 23:54:46 +00:00
|
|
|
/// Database migrator for running background maintenance on the store.
|
|
|
|
pub store_migrator: T::StoreMigrator,
|
2019-05-31 07:32:20 +00:00
|
|
|
/// Reports the current slot, typically based upon the system clock.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub slot_clock: T::SlotClock,
|
2019-05-31 07:32:20 +00:00
|
|
|
/// Stores all operations (e.g., `Attestation`, `Deposit`, etc) that are candidates for
|
|
|
|
/// inclusion in a block.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub op_pool: OperationPool<T::EthSpec>,
|
2019-09-03 05:52:25 +00:00
|
|
|
/// Provides information from the Ethereum 1 (PoW) chain.
|
2020-01-19 20:52:59 +00:00
|
|
|
pub eth1_chain: Option<Eth1Chain<T::Eth1Chain, T::EthSpec, T::Store>>,
|
2019-07-26 19:26:06 +00:00
|
|
|
/// Stores a "snapshot" of the chain at the time the head-of-the-chain block was received.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub(crate) canonical_head: TimeoutRwLock<CheckPoint<T::EthSpec>>,
|
2019-06-01 05:02:19 +00:00
|
|
|
/// The root of the genesis block.
|
2019-07-29 02:08:52 +00:00
|
|
|
pub genesis_block_root: Hash256,
|
2019-05-31 07:32:20 +00:00
|
|
|
/// A state-machine that is updated with information from the network and chooses a canonical
|
|
|
|
/// head block.
|
2019-06-15 19:05:34 +00:00
|
|
|
pub fork_choice: ForkChoice<T>,
|
2019-09-14 19:41:35 +00:00
|
|
|
/// A handler for events generated by the beacon chain.
|
|
|
|
pub event_handler: T::EventHandler,
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
/// Used to track the heads of the beacon chain.
|
|
|
|
pub(crate) head_tracker: HeadTracker,
|
2020-03-05 06:19:35 +00:00
|
|
|
/// Caches the shuffling for a given epoch and state root.
|
|
|
|
pub(crate) shuffling_cache: TimeoutRwLock<ShufflingCache>,
|
|
|
|
/// Caches a map of `validator_index -> validator_pubkey`.
|
|
|
|
pub(crate) validator_pubkey_cache: TimeoutRwLock<ValidatorPubkeyCache>,
|
2019-07-29 03:45:45 +00:00
|
|
|
/// Logging to CLI, etc.
|
Eth1 Integration (#542)
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Initial commit. web3 api working.
* Tidied up lib. Add function for fetching logs.
* Refactor with `Eth1DataFetcher` trait
* Add parsing for deposit contract logs and get_eth1_data function
* Add `get_eth1_votes` function
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Fix merge issue
* Refactor with `Config` struct. Remote `ContractConfig`
* Rename eth1_chain crate to eth1
* Rename files and read abi file using `fs::read`
* Move eth1 to lib
* Remove unnecessary mutability constraint
* Add `Web3Backend` for returning actual eth1 data
* Refactor `get_eth1_votes` to return a Result
* Delete `eth1_chain` crate
* Return `Result` from `get_deposits`
* Fix range of deposits to return to beacon chain
* Add `get_block_height_by_hash` trait function
* Add naive method for getting `previous_eth1_distance`
* Add eth1 config params to main config
* Add instructions for setting up eth1 testing environment
* Add build script to fetch deposit contract abi
* Contract ABI is part of compiled binary
* Fix minor bugs
* Move docs to lib
* Add timeout to config
* Remove print statements
* Change warn to error
* Fix typos
* Removed prints in test and get timeout value from config
* Fixed error types
* Added logging to web3_fetcher
* Refactor for modified web3 api
* Fix minor stuff
* Add build script
* Tidy, hide eth1 integration tests behind flag
* Add http crate
* Add first stages of eth1_test_rig
* Fix deposits on test rig
* Fix bug with deposit count method
* Add block hash getter to http eth1
* Clean eth1 http crate and tests
* Add script to start ganache
* Adds deposit tree to eth1-http
* Extend deposit tree tests
* Tidy tests in eth1-http
* Add more detail to get block request
* Add block cache to eth1-http
* Rename deposit tree to deposit cache
* Add inital updating to eth1-http
* Tidy updater
* Fix compile bugs in tests
* Adds an Eth1DataCache builder
* Reorg eth1-http files
* Add (failing) tests for eth1 updater
* Rename files, fix bug in eth1-http
* Ensure that ganache timestamps are increasing
* Fix bugs with getting eth1data ancestors
* Improve eth1 testing, fix bugs
* Add truncate method to block cache
* Add pruning to block cache update process
* Add tests for block pruning
* Allow for dropping an expired cache.
* Add more comments
* Add first compiling version of deposit updater
* Add common fn for getting range of required blocks
* Add passing deposit update test
* Improve tests
* Fix block pruning bug
* Add tests for running two updates at once
* Add updater services to eth1
* Add deposit collection to beacon chain
* Add incomplete builder experiments
* Add first working version of beacon chain builder
* Update test harness to new beacon chain type
* Rename builder file, tidy
* Add first working client builder
* Progress further on client builder
* Update becaon node binary to use client builder
* Ensure release tests compile
* Remove old eth1 crate
* Add first pass of new lighthouse binary
* Fix websocket server startup
* Remove old binary code from beacon_node crate
* Add first working beacon node tests
* Add genesis crate, new eth1 cache_2
* Add Serivce to Eth1Cache
* Refactor with general eth1 improvements
* Add passing genesis test
* Tidy, add comments
* Add more comments to eth1 service
* Add further eth1 progress
* Fix some bugs with genesis
* Fix eth1 bugs, make eth1 linking more efficient
* Shift logic in genesis service
* Add more comments to genesis service
* Add gzip, max request values, timeouts to http
* Update testnet parameters to suit goerli testnet
* Add ability to vary Fork, fix custom spec
* Be more explicit about deposit fork version
* Start adding beacon chain eth1 option
* Add more flexibility to prod client
* Further runtime refactoring
* Allow for starting from store
* Add bootstrapping to client config
* Add remote_beacon_node crate
* Update eth1 service for more configurability
* Update eth1 tests to use less runtimes
* Patch issues with tests using too many files
* Move dummy eth1 backend flag
* Ensure all tests pass
* Add ganache-cli to Dockerfile
* Use a special docker hub image for testing
* Appease clippy
* Move validator client into lighthouse binary
* Allow starting with dummy eth1 backend
* Improve logging
* Fix dummy eth1 backend from cli
* Add extra testnet command
* Ensure consistent spec in beacon node
* Update eth1 rig to work on goerli
* Tidy lcli, start adding support for yaml config
* Add incomplete YamlConfig struct
* Remove efforts at YamlConfig
* Add incomplete eth1 voting. Blocked on spec issues
* Add (untested) first pass at eth1 vote algo
* Add tests for winning vote
* Add more tests for eth1 chain
* Add more eth1 voting tests
* Added more eth1 voting testing
* Change test name
* Add more tests to eth1 chain
* Tidy eth1 generics, add more tests
* Improve comments
* Tidy beacon_node tests
* Tidy, rename JsonRpc.. to Caching..
* Tidy voting logic
* Tidy builder docs
* Add comments, tidy eth1
* Add more comments to eth1
* Fix bug with winning_vote
* Add doc comments to the `ClientBuilder`
* Remove commented-out code
* Improve `ClientBuilder` docs
* Add comments to client config
* Add decoding test for `ClientConfig`
* Remove unused `DepositSet` struct
* Tidy `block_cache`
* Remove commented out lines
* Remove unused code in `eth1` crate
* Remove old validator binary `main.rs`
* Tidy, fix tests compile error
* Add initial tests for get_deposits
* Remove dead code in eth1_test_rig
* Update TestingDepositBuilder
* Add testing for getting eth1 deposits
* Fix duplicate rand dep
* Remove dead code
* Remove accidentally-added files
* Fix comment in eth1_genesis_service
* Add .gitignore for eth1_test_rig
* Fix bug in eth1_genesis_service
* Remove dead code from eth2_config
* Fix tabs/spaces in root Cargo.toml
* Tidy eth1 crate
* Allow for re-use of eth1 service after genesis
* Update docs for new CLI
* Change README gif
* Tidy eth1 http module
* Tidy eth1 service
* Tidy environment crate
* Remove unused file
* Tidy, add comments
* Remove commented-out code
* Address majority of Michael's comments
* Address other PR comments
* Add link to issue alongside TODO
2019-11-15 03:47:51 +00:00
|
|
|
pub(crate) log: Logger,
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
Eth1 Integration (#542)
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Initial commit. web3 api working.
* Tidied up lib. Add function for fetching logs.
* Refactor with `Eth1DataFetcher` trait
* Add parsing for deposit contract logs and get_eth1_data function
* Add `get_eth1_votes` function
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Fix merge issue
* Refactor with `Config` struct. Remote `ContractConfig`
* Rename eth1_chain crate to eth1
* Rename files and read abi file using `fs::read`
* Move eth1 to lib
* Remove unnecessary mutability constraint
* Add `Web3Backend` for returning actual eth1 data
* Refactor `get_eth1_votes` to return a Result
* Delete `eth1_chain` crate
* Return `Result` from `get_deposits`
* Fix range of deposits to return to beacon chain
* Add `get_block_height_by_hash` trait function
* Add naive method for getting `previous_eth1_distance`
* Add eth1 config params to main config
* Add instructions for setting up eth1 testing environment
* Add build script to fetch deposit contract abi
* Contract ABI is part of compiled binary
* Fix minor bugs
* Move docs to lib
* Add timeout to config
* Remove print statements
* Change warn to error
* Fix typos
* Removed prints in test and get timeout value from config
* Fixed error types
* Added logging to web3_fetcher
* Refactor for modified web3 api
* Fix minor stuff
* Add build script
* Tidy, hide eth1 integration tests behind flag
* Add http crate
* Add first stages of eth1_test_rig
* Fix deposits on test rig
* Fix bug with deposit count method
* Add block hash getter to http eth1
* Clean eth1 http crate and tests
* Add script to start ganache
* Adds deposit tree to eth1-http
* Extend deposit tree tests
* Tidy tests in eth1-http
* Add more detail to get block request
* Add block cache to eth1-http
* Rename deposit tree to deposit cache
* Add inital updating to eth1-http
* Tidy updater
* Fix compile bugs in tests
* Adds an Eth1DataCache builder
* Reorg eth1-http files
* Add (failing) tests for eth1 updater
* Rename files, fix bug in eth1-http
* Ensure that ganache timestamps are increasing
* Fix bugs with getting eth1data ancestors
* Improve eth1 testing, fix bugs
* Add truncate method to block cache
* Add pruning to block cache update process
* Add tests for block pruning
* Allow for dropping an expired cache.
* Add more comments
* Add first compiling version of deposit updater
* Add common fn for getting range of required blocks
* Add passing deposit update test
* Improve tests
* Fix block pruning bug
* Add tests for running two updates at once
* Add updater services to eth1
* Add deposit collection to beacon chain
* Add incomplete builder experiments
* Add first working version of beacon chain builder
* Update test harness to new beacon chain type
* Rename builder file, tidy
* Add first working client builder
* Progress further on client builder
* Update becaon node binary to use client builder
* Ensure release tests compile
* Remove old eth1 crate
* Add first pass of new lighthouse binary
* Fix websocket server startup
* Remove old binary code from beacon_node crate
* Add first working beacon node tests
* Add genesis crate, new eth1 cache_2
* Add Serivce to Eth1Cache
* Refactor with general eth1 improvements
* Add passing genesis test
* Tidy, add comments
* Add more comments to eth1 service
* Add further eth1 progress
* Fix some bugs with genesis
* Fix eth1 bugs, make eth1 linking more efficient
* Shift logic in genesis service
* Add more comments to genesis service
* Add gzip, max request values, timeouts to http
* Update testnet parameters to suit goerli testnet
* Add ability to vary Fork, fix custom spec
* Be more explicit about deposit fork version
* Start adding beacon chain eth1 option
* Add more flexibility to prod client
* Further runtime refactoring
* Allow for starting from store
* Add bootstrapping to client config
* Add remote_beacon_node crate
* Update eth1 service for more configurability
* Update eth1 tests to use less runtimes
* Patch issues with tests using too many files
* Move dummy eth1 backend flag
* Ensure all tests pass
* Add ganache-cli to Dockerfile
* Use a special docker hub image for testing
* Appease clippy
* Move validator client into lighthouse binary
* Allow starting with dummy eth1 backend
* Improve logging
* Fix dummy eth1 backend from cli
* Add extra testnet command
* Ensure consistent spec in beacon node
* Update eth1 rig to work on goerli
* Tidy lcli, start adding support for yaml config
* Add incomplete YamlConfig struct
* Remove efforts at YamlConfig
* Add incomplete eth1 voting. Blocked on spec issues
* Add (untested) first pass at eth1 vote algo
* Add tests for winning vote
* Add more tests for eth1 chain
* Add more eth1 voting tests
* Added more eth1 voting testing
* Change test name
* Add more tests to eth1 chain
* Tidy eth1 generics, add more tests
* Improve comments
* Tidy beacon_node tests
* Tidy, rename JsonRpc.. to Caching..
* Tidy voting logic
* Tidy builder docs
* Add comments, tidy eth1
* Add more comments to eth1
* Fix bug with winning_vote
* Add doc comments to the `ClientBuilder`
* Remove commented-out code
* Improve `ClientBuilder` docs
* Add comments to client config
* Add decoding test for `ClientConfig`
* Remove unused `DepositSet` struct
* Tidy `block_cache`
* Remove commented out lines
* Remove unused code in `eth1` crate
* Remove old validator binary `main.rs`
* Tidy, fix tests compile error
* Add initial tests for get_deposits
* Remove dead code in eth1_test_rig
* Update TestingDepositBuilder
* Add testing for getting eth1 deposits
* Fix duplicate rand dep
* Remove dead code
* Remove accidentally-added files
* Fix comment in eth1_genesis_service
* Add .gitignore for eth1_test_rig
* Fix bug in eth1_genesis_service
* Remove dead code from eth2_config
* Fix tabs/spaces in root Cargo.toml
* Tidy eth1 crate
* Allow for re-use of eth1 service after genesis
* Update docs for new CLI
* Change README gif
* Tidy eth1 http module
* Tidy eth1 service
* Tidy environment crate
* Remove unused file
* Tidy, add comments
* Remove commented-out code
* Address majority of Michael's comments
* Address other PR comments
* Add link to issue alongside TODO
2019-11-15 03:47:51 +00:00
|
|
|
type BeaconBlockAndState<T> = (BeaconBlock<T>, BeaconState<T>);
|
2019-09-30 03:58:45 +00:00
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
impl<T: BeaconChainTypes> BeaconChain<T> {
|
2020-03-06 05:09:41 +00:00
|
|
|
/// Persists the core `BeaconChain` components (including the head block) and the fork choice.
|
|
|
|
///
|
|
|
|
/// ## Notes:
|
|
|
|
///
|
|
|
|
/// In this function we first obtain the head, persist fork choice, then persist the head. We
|
|
|
|
/// do it in this order to ensure that the persisted head is always from a time prior to fork
|
|
|
|
/// choice.
|
|
|
|
///
|
|
|
|
/// We want to ensure that the head never out dates the fork choice to avoid having references
|
|
|
|
/// to blocks that do not exist in fork choice.
|
|
|
|
pub fn persist_head_and_fork_choice(&self) -> Result<(), Error> {
|
|
|
|
let canonical_head_block_root = self
|
|
|
|
.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?
|
|
|
|
.beacon_block_root;
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
|
2020-03-06 05:09:41 +00:00
|
|
|
let persisted_head = PersistedBeaconChain {
|
|
|
|
canonical_head_block_root,
|
2019-06-01 05:02:19 +00:00
|
|
|
genesis_block_root: self.genesis_block_root,
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
ssz_head_tracker: self.head_tracker.to_ssz_container(),
|
2019-05-27 06:13:32 +00:00
|
|
|
};
|
|
|
|
|
2020-03-06 05:09:41 +00:00
|
|
|
let fork_choice_timer = metrics::start_timer(&metrics::PERSIST_FORK_CHOICE);
|
|
|
|
|
|
|
|
self.store.put(
|
|
|
|
&Hash256::from_slice(&FORK_CHOICE_DB_KEY),
|
|
|
|
&self.fork_choice.as_ssz_container(),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
metrics::stop_timer(fork_choice_timer);
|
|
|
|
let head_timer = metrics::start_timer(&metrics::PERSIST_HEAD);
|
|
|
|
|
|
|
|
self.store
|
|
|
|
.put(&Hash256::from_slice(&BEACON_CHAIN_DB_KEY), &persisted_head)?;
|
|
|
|
|
|
|
|
metrics::stop_timer(head_timer);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Persists `self.op_pool` to disk.
|
|
|
|
///
|
|
|
|
/// ## Notes
|
|
|
|
///
|
|
|
|
/// This operation is typically slow and causes a lot of allocations. It should be used
|
|
|
|
/// sparingly.
|
|
|
|
pub fn persist_op_pool(&self) -> Result<(), Error> {
|
|
|
|
let timer = metrics::start_timer(&metrics::PERSIST_OP_POOL);
|
|
|
|
|
|
|
|
self.store.put(
|
|
|
|
&Hash256::from_slice(&OP_POOL_DB_KEY),
|
|
|
|
&PersistedOperationPool::from_operation_pool(&self.op_pool),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
metrics::stop_timer(timer);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Persists `self.eth1_chain` and its caches to disk.
|
|
|
|
pub fn persist_eth1_cache(&self) -> Result<(), Error> {
|
|
|
|
let timer = metrics::start_timer(&metrics::PERSIST_OP_POOL);
|
|
|
|
|
|
|
|
if let Some(eth1_chain) = self.eth1_chain.as_ref() {
|
|
|
|
self.store.put(
|
|
|
|
&Hash256::from_slice(Ð1_CACHE_DB_KEY),
|
|
|
|
ð1_chain.as_ssz_container(),
|
|
|
|
)?;
|
|
|
|
}
|
2019-05-27 06:13:32 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(timer);
|
|
|
|
|
2019-05-27 06:13:32 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-08-29 04:26:30 +00:00
|
|
|
/// Returns the slot _right now_ according to `self.slot_clock`. Returns `Err` if the slot is
|
|
|
|
/// unavailable.
|
2019-08-29 03:25:55 +00:00
|
|
|
///
|
|
|
|
/// The slot might be unavailable due to an error with the system clock, or if the present time
|
|
|
|
/// is before genesis (i.e., a negative slot).
|
2019-08-29 04:26:30 +00:00
|
|
|
pub fn slot(&self) -> Result<Slot, Error> {
|
|
|
|
self.slot_clock.now().ok_or_else(|| Error::UnableToReadSlot)
|
2019-08-29 03:25:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 09:14:52 +00:00
|
|
|
/// Returns the epoch _right now_ according to `self.slot_clock`. Returns `Err` if the epoch is
|
|
|
|
/// unavailable.
|
|
|
|
///
|
|
|
|
/// The epoch might be unavailable due to an error with the system clock, or if the present time
|
|
|
|
/// is before genesis (i.e., a negative epoch).
|
|
|
|
pub fn epoch(&self) -> Result<Epoch, Error> {
|
|
|
|
self.slot()
|
|
|
|
.map(|slot| slot.epoch(T::EthSpec::slots_per_epoch()))
|
|
|
|
}
|
|
|
|
|
2019-08-08 02:28:10 +00:00
|
|
|
/// Iterates across all `(block_root, slot)` pairs from the head of the chain (inclusive) to
|
|
|
|
/// the earliest reachable ancestor (may or may not be genesis).
|
2019-06-05 03:33:32 +00:00
|
|
|
///
|
2019-08-08 02:28:10 +00:00
|
|
|
/// ## Notes
|
2019-06-05 03:33:32 +00:00
|
|
|
///
|
2019-08-08 02:28:10 +00:00
|
|
|
/// `slot` always decreases by `1`.
|
|
|
|
/// - Skipped slots contain the root of the closest prior
|
|
|
|
/// non-skipped slot (identical to the way they are stored in `state.block_roots`) .
|
|
|
|
/// - Iterator returns `(Hash256, Slot)`.
|
|
|
|
/// - As this iterator starts at the `head` of the chain (viz., the best block), the first slot
|
|
|
|
/// returned may be earlier than the wall-clock slot.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn rev_iter_block_roots(
|
|
|
|
&self,
|
|
|
|
) -> Result<ReverseBlockRootIterator<T::EthSpec, T::Store>, Error> {
|
|
|
|
let head = self.head()?;
|
2019-08-08 02:28:10 +00:00
|
|
|
|
2019-09-11 02:42:07 +00:00
|
|
|
let iter = BlockRootsIterator::owned(self.store.clone(), head.beacon_state);
|
2019-08-08 02:28:10 +00:00
|
|
|
|
2020-01-06 06:30:37 +00:00
|
|
|
Ok(ReverseBlockRootIterator::new(
|
2020-02-10 23:19:36 +00:00
|
|
|
(head.beacon_block_root, head.beacon_block.slot()),
|
2020-01-06 06:30:37 +00:00
|
|
|
iter,
|
|
|
|
))
|
2019-07-16 07:28:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 07:50:21 +00:00
|
|
|
pub fn forwards_iter_block_roots(
|
|
|
|
&self,
|
|
|
|
start_slot: Slot,
|
2020-01-06 06:30:37 +00:00
|
|
|
) -> Result<<T::Store as Store<T::EthSpec>>::ForwardsBlockRootsIterator, Error> {
|
|
|
|
let local_head = self.head()?;
|
|
|
|
|
|
|
|
Ok(T::Store::forwards_block_roots_iterator(
|
2019-12-09 07:50:21 +00:00
|
|
|
self.store.clone(),
|
|
|
|
start_slot,
|
|
|
|
local_head.beacon_state,
|
|
|
|
local_head.beacon_block_root,
|
|
|
|
&self.spec,
|
2020-01-06 06:30:37 +00:00
|
|
|
))
|
2019-12-09 07:50:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 00:47:30 +00:00
|
|
|
/// Traverse backwards from `block_root` to find the block roots of its ancestors.
|
|
|
|
///
|
|
|
|
/// ## Notes
|
|
|
|
///
|
|
|
|
/// `slot` always decreases by `1`.
|
|
|
|
/// - Skipped slots contain the root of the closest prior
|
|
|
|
/// non-skipped slot (identical to the way they are stored in `state.block_roots`) .
|
|
|
|
/// - Iterator returns `(Hash256, Slot)`.
|
|
|
|
/// - The provided `block_root` is included as the first item in the iterator.
|
|
|
|
pub fn rev_iter_block_roots_from(
|
|
|
|
&self,
|
|
|
|
block_root: Hash256,
|
|
|
|
) -> Result<ReverseBlockRootIterator<T::EthSpec, T::Store>, Error> {
|
|
|
|
let block = self
|
2020-02-10 00:30:21 +00:00
|
|
|
.get_block(&block_root)?
|
2019-11-21 00:47:30 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconBlock(block_root))?;
|
|
|
|
let state = self
|
2020-02-10 23:19:36 +00:00
|
|
|
.get_state(&block.state_root(), Some(block.slot()))?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconState(block.state_root()))?;
|
2019-11-21 00:47:30 +00:00
|
|
|
let iter = BlockRootsIterator::owned(self.store.clone(), state);
|
|
|
|
Ok(ReverseBlockRootIterator::new(
|
2020-02-10 23:19:36 +00:00
|
|
|
(block_root, block.slot()),
|
2019-11-21 00:47:30 +00:00
|
|
|
iter,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Traverse backwards from `block_root` to find the root of the ancestor block at `slot`.
|
|
|
|
pub fn get_ancestor_block_root(
|
|
|
|
&self,
|
|
|
|
block_root: Hash256,
|
|
|
|
slot: Slot,
|
|
|
|
) -> Result<Option<Hash256>, Error> {
|
|
|
|
Ok(self
|
|
|
|
.rev_iter_block_roots_from(block_root)?
|
|
|
|
.find(|(_, ancestor_slot)| *ancestor_slot == slot)
|
|
|
|
.map(|(ancestor_block_root, _)| ancestor_block_root))
|
|
|
|
}
|
|
|
|
|
2019-08-08 02:28:10 +00:00
|
|
|
/// Iterates across all `(state_root, slot)` pairs from the head of the chain (inclusive) to
|
|
|
|
/// the earliest reachable ancestor (may or may not be genesis).
|
2019-07-16 07:28:15 +00:00
|
|
|
///
|
2019-08-08 02:28:10 +00:00
|
|
|
/// ## Notes
|
2019-07-16 07:28:15 +00:00
|
|
|
///
|
2019-08-08 02:28:10 +00:00
|
|
|
/// `slot` always decreases by `1`.
|
|
|
|
/// - Iterator returns `(Hash256, Slot)`.
|
|
|
|
/// - As this iterator starts at the `head` of the chain (viz., the best block), the first slot
|
|
|
|
/// returned may be earlier than the wall-clock slot.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn rev_iter_state_roots(
|
|
|
|
&self,
|
|
|
|
) -> Result<ReverseStateRootIterator<T::EthSpec, T::Store>, Error> {
|
|
|
|
let head = self.head()?;
|
2019-09-11 02:42:07 +00:00
|
|
|
let slot = head.beacon_state.slot;
|
2019-08-05 06:25:21 +00:00
|
|
|
|
2019-09-11 02:42:07 +00:00
|
|
|
let iter = StateRootsIterator::owned(self.store.clone(), head.beacon_state);
|
2019-08-08 02:28:10 +00:00
|
|
|
|
2020-01-06 06:30:37 +00:00
|
|
|
Ok(ReverseStateRootIterator::new(
|
|
|
|
(head.beacon_state_root, slot),
|
|
|
|
iter,
|
|
|
|
))
|
2019-06-05 03:33:32 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 04:48:24 +00:00
|
|
|
/// Returns the block at the given slot, if any. Only returns blocks in the canonical chain.
|
|
|
|
///
|
|
|
|
/// ## Errors
|
|
|
|
///
|
|
|
|
/// May return a database error.
|
2020-02-10 23:19:36 +00:00
|
|
|
pub fn block_at_slot(
|
|
|
|
&self,
|
|
|
|
slot: Slot,
|
|
|
|
) -> Result<Option<SignedBeaconBlock<T::EthSpec>>, Error> {
|
2019-11-25 04:48:24 +00:00
|
|
|
let root = self
|
2020-01-06 06:30:37 +00:00
|
|
|
.rev_iter_block_roots()?
|
2019-11-25 04:48:24 +00:00
|
|
|
.find(|(_, this_slot)| *this_slot == slot)
|
|
|
|
.map(|(root, _)| root);
|
|
|
|
|
|
|
|
if let Some(block_root) = root {
|
|
|
|
Ok(self.store.get(&block_root)?)
|
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:23:44 +00:00
|
|
|
/// Returns the block at the given root, if any.
|
|
|
|
///
|
|
|
|
/// ## Errors
|
|
|
|
///
|
|
|
|
/// May return a database error.
|
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 get_block(
|
|
|
|
&self,
|
|
|
|
block_root: &Hash256,
|
2020-02-10 23:19:36 +00:00
|
|
|
) -> Result<Option<SignedBeaconBlock<T::EthSpec>>, Error> {
|
2020-02-10 00:30:21 +00:00
|
|
|
Ok(self.store.get_block(block_root)?)
|
2019-03-23 02:23:44 +00:00
|
|
|
}
|
|
|
|
|
2019-12-19 00:45:28 +00:00
|
|
|
/// Returns the state at the given root, if any.
|
|
|
|
///
|
|
|
|
/// ## Errors
|
|
|
|
///
|
|
|
|
/// May return a database error.
|
|
|
|
pub fn get_state(
|
|
|
|
&self,
|
|
|
|
state_root: &Hash256,
|
|
|
|
slot: Option<Slot>,
|
|
|
|
) -> Result<Option<BeaconState<T::EthSpec>>, Error> {
|
|
|
|
Ok(self.store.get_state(state_root, slot)?)
|
|
|
|
}
|
|
|
|
|
2019-12-09 03:20:25 +00:00
|
|
|
/// Returns the state at the given root, if any.
|
|
|
|
///
|
|
|
|
/// The return state does not contain any caches other than the committee caches. This method
|
2020-02-10 00:30:21 +00:00
|
|
|
/// is much faster than `Self::get_state` because it does not clone the tree hash cache
|
|
|
|
/// when the state is found in the cache.
|
2019-12-09 03:20:25 +00:00
|
|
|
///
|
|
|
|
/// ## Errors
|
|
|
|
///
|
|
|
|
/// May return a database error.
|
2020-01-08 02:58:01 +00:00
|
|
|
pub fn get_state_caching_only_with_committee_caches(
|
2019-12-09 03:20:25 +00:00
|
|
|
&self,
|
|
|
|
state_root: &Hash256,
|
|
|
|
slot: Option<Slot>,
|
|
|
|
) -> Result<Option<BeaconState<T::EthSpec>>, Error> {
|
2020-02-10 00:30:21 +00:00
|
|
|
Ok(self.store.get_state_with(
|
|
|
|
state_root,
|
|
|
|
slot,
|
|
|
|
types::beacon_state::CloneConfig::committee_caches_only(),
|
|
|
|
)?)
|
2019-12-09 03:20:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 02:42:07 +00:00
|
|
|
/// Returns a `Checkpoint` representing the head block and state. Contains the "best block";
|
|
|
|
/// the head of the canonical `BeaconChain`.
|
2019-05-31 07:32:20 +00:00
|
|
|
///
|
|
|
|
/// It is important to note that the `beacon_state` returned may not match the present slot. It
|
|
|
|
/// is the state as it was when the head block was received, which could be some slots prior to
|
|
|
|
/// now.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn head(&self) -> Result<CheckPoint<T::EthSpec>, Error> {
|
|
|
|
self.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)
|
2020-02-04 01:43:04 +00:00
|
|
|
.map(|v| v.clone_with_only_committee_caches())
|
2019-05-31 07:32:20 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 03:20:25 +00:00
|
|
|
/// Returns info representing the head block and state.
|
|
|
|
///
|
|
|
|
/// A summarized version of `Self::head` that involves less cloning.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn head_info(&self) -> Result<HeadInfo, Error> {
|
|
|
|
let head = self
|
|
|
|
.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?;
|
2019-12-09 03:20:25 +00:00
|
|
|
|
2020-01-06 06:30:37 +00:00
|
|
|
Ok(HeadInfo {
|
2020-02-10 23:19:36 +00:00
|
|
|
slot: head.beacon_block.slot(),
|
2019-12-09 03:20:25 +00:00
|
|
|
block_root: head.beacon_block_root,
|
|
|
|
state_root: head.beacon_state_root,
|
2020-03-04 06:10:22 +00:00
|
|
|
current_justified_checkpoint: head.beacon_state.current_justified_checkpoint.clone(),
|
2019-12-09 03:20:25 +00:00
|
|
|
finalized_checkpoint: head.beacon_state.finalized_checkpoint.clone(),
|
2020-01-06 06:30:37 +00:00
|
|
|
fork: head.beacon_state.fork.clone(),
|
|
|
|
})
|
2019-12-09 03:20:25 +00:00
|
|
|
}
|
|
|
|
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
/// Returns the current heads of the `BeaconChain`. For the canonical head, see `Self::head`.
|
|
|
|
///
|
|
|
|
/// Returns `(block_root, block_slot)`.
|
|
|
|
pub fn heads(&self) -> Vec<(Hash256, Slot)> {
|
|
|
|
self.head_tracker.heads()
|
|
|
|
}
|
|
|
|
|
2019-08-29 09:14:52 +00:00
|
|
|
/// Returns the `BeaconState` at the given slot.
|
|
|
|
///
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
/// Returns `None` when the state is not found in the database or there is an error skipping
|
|
|
|
/// to a future state.
|
2020-03-04 06:10:22 +00:00
|
|
|
pub fn state_at_slot(
|
|
|
|
&self,
|
|
|
|
slot: Slot,
|
|
|
|
config: StateSkipConfig,
|
|
|
|
) -> Result<BeaconState<T::EthSpec>, Error> {
|
2020-01-06 06:30:37 +00:00
|
|
|
let head_state = self.head()?.beacon_state;
|
2019-08-29 09:14:52 +00:00
|
|
|
|
2020-01-21 07:38:56 +00:00
|
|
|
match slot.cmp(&head_state.slot) {
|
|
|
|
Ordering::Equal => Ok(head_state),
|
|
|
|
Ordering::Greater => {
|
|
|
|
if slot > head_state.slot + T::EthSpec::slots_per_epoch() {
|
|
|
|
warn!(
|
|
|
|
self.log,
|
|
|
|
"Skipping more than an epoch";
|
|
|
|
"head_slot" => head_state.slot,
|
|
|
|
"request_slot" => slot
|
|
|
|
)
|
2019-11-27 07:37:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 07:38:56 +00:00
|
|
|
let start_slot = head_state.slot;
|
|
|
|
let task_start = Instant::now();
|
|
|
|
let max_task_runtime = Duration::from_millis(self.spec.milliseconds_per_slot);
|
|
|
|
|
|
|
|
let head_state_slot = head_state.slot;
|
|
|
|
let mut state = head_state;
|
2020-03-04 06:10:22 +00:00
|
|
|
|
|
|
|
let skip_state_root = match config {
|
|
|
|
StateSkipConfig::WithStateRoots => None,
|
|
|
|
StateSkipConfig::WithoutStateRoots => Some(Hash256::zero()),
|
|
|
|
};
|
|
|
|
|
2020-01-21 07:38:56 +00:00
|
|
|
while state.slot < slot {
|
|
|
|
// Do not allow and forward state skip that takes longer than the maximum task duration.
|
|
|
|
//
|
|
|
|
// This is a protection against nodes doing too much work when they're not synced
|
|
|
|
// to a chain.
|
|
|
|
if task_start + max_task_runtime < Instant::now() {
|
|
|
|
return Err(Error::StateSkipTooLarge {
|
|
|
|
start_slot,
|
|
|
|
requested_slot: slot,
|
|
|
|
max_task_runtime,
|
|
|
|
});
|
2019-08-29 09:14:52 +00:00
|
|
|
}
|
2020-01-21 07:38:56 +00:00
|
|
|
|
|
|
|
// Note: supplying some `state_root` when it is known would be a cheap and easy
|
|
|
|
// optimization.
|
2020-03-04 06:10:22 +00:00
|
|
|
match per_slot_processing(&mut state, skip_state_root, &self.spec) {
|
2020-01-21 07:38:56 +00:00
|
|
|
Ok(()) => (),
|
|
|
|
Err(e) => {
|
|
|
|
warn!(
|
|
|
|
self.log,
|
|
|
|
"Unable to load state at slot";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
"head_slot" => head_state_slot,
|
|
|
|
"requested_slot" => slot
|
|
|
|
);
|
|
|
|
return Err(Error::NoStateForSlot(slot));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
Ok(state)
|
|
|
|
}
|
|
|
|
Ordering::Less => {
|
|
|
|
let state_root = self
|
|
|
|
.rev_iter_state_roots()?
|
|
|
|
.take_while(|(_root, current_slot)| *current_slot >= slot)
|
|
|
|
.find(|(_root, current_slot)| *current_slot == slot)
|
|
|
|
.map(|(root, _slot)| root)
|
|
|
|
.ok_or_else(|| Error::NoStateForSlot(slot))?;
|
|
|
|
|
|
|
|
Ok(self
|
2020-02-10 00:30:21 +00:00
|
|
|
.get_state(&state_root, Some(slot))?
|
2020-01-21 07:38:56 +00:00
|
|
|
.ok_or_else(|| Error::NoStateForSlot(slot))?)
|
2019-06-20 00:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-31 02:40:12 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 09:14:52 +00:00
|
|
|
/// Returns the `BeaconState` the current slot (viz., `self.slot()`).
|
2019-03-31 02:40:12 +00:00
|
|
|
///
|
2019-08-29 09:14:52 +00:00
|
|
|
/// - A reference to the head state (note: this keeps a read lock on the head, try to use
|
|
|
|
/// sparingly).
|
|
|
|
/// - The head state, but with skipped slots (for states later than the head).
|
|
|
|
///
|
|
|
|
/// Returns `None` when there is an error skipping to a future state or the slot clock cannot
|
|
|
|
/// be read.
|
2019-09-11 02:42:07 +00:00
|
|
|
pub fn wall_clock_state(&self) -> Result<BeaconState<T::EthSpec>, Error> {
|
2020-03-04 06:10:22 +00:00
|
|
|
self.state_at_slot(self.slot()?, StateSkipConfig::WithStateRoots)
|
2019-08-29 09:14:52 +00:00
|
|
|
}
|
2019-03-24 05:35:07 +00:00
|
|
|
|
2019-08-29 09:14:52 +00:00
|
|
|
/// Returns the slot of the highest block in the canonical chain.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn best_slot(&self) -> Result<Slot, Error> {
|
|
|
|
self.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
2020-02-10 23:19:36 +00:00
|
|
|
.map(|head| head.beacon_block.slot())
|
2020-01-06 06:30:37 +00:00
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)
|
2019-03-24 05:35:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Returns the validator index (if any) for the given public key.
|
|
|
|
///
|
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
|
|
|
/// Information is retrieved from the present `beacon_state.validators`.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn validator_index(&self, pubkey: &PublicKeyBytes) -> Result<Option<usize>, Error> {
|
|
|
|
for (i, validator) in self.head()?.beacon_state.validators.iter().enumerate() {
|
2019-02-14 01:09:18 +00:00
|
|
|
if validator.pubkey == *pubkey {
|
2020-01-06 06:30:37 +00:00
|
|
|
return Ok(Some(i));
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-06 06:30:37 +00:00
|
|
|
Ok(None)
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 14:34:41 +00:00
|
|
|
/// Returns the block canonical root of the current canonical chain at a given slot.
|
|
|
|
///
|
|
|
|
/// Returns None if a block doesn't exist at the slot.
|
2020-01-06 06:30:37 +00:00
|
|
|
pub fn root_at_slot(&self, target_slot: Slot) -> Result<Option<Hash256>, Error> {
|
|
|
|
Ok(self
|
|
|
|
.rev_iter_block_roots()?
|
2019-09-02 14:34:41 +00:00
|
|
|
.find(|(_root, slot)| *slot == target_slot)
|
2020-01-06 06:30:37 +00:00
|
|
|
.map(|(root, _slot)| root))
|
2019-09-02 14:34:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Returns the block proposer for a given slot.
|
|
|
|
///
|
2019-06-20 00:59:19 +00:00
|
|
|
/// Information is read from the present `beacon_state` shuffling, only information from the
|
|
|
|
/// present epoch is available.
|
|
|
|
pub fn block_proposer(&self, slot: Slot) -> Result<usize, Error> {
|
2019-08-29 09:14:52 +00:00
|
|
|
let epoch = |slot: Slot| slot.epoch(T::EthSpec::slots_per_epoch());
|
2020-01-06 06:30:37 +00:00
|
|
|
let head_state = &self.head()?.beacon_state;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-08-29 14:24:46 +00:00
|
|
|
let mut state = if epoch(slot) == epoch(head_state.slot) {
|
2020-01-21 07:38:56 +00:00
|
|
|
self.head()?.beacon_state
|
2019-08-29 09:14:52 +00:00
|
|
|
} else {
|
2020-03-04 06:10:22 +00:00
|
|
|
// The block proposer shuffling is not affected by the state roots, so we don't need to
|
|
|
|
// calculate them.
|
|
|
|
self.state_at_slot(slot, StateSkipConfig::WithoutStateRoots)?
|
2019-08-29 09:14:52 +00:00
|
|
|
};
|
|
|
|
|
2019-09-11 02:42:07 +00:00
|
|
|
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
|
2019-08-29 14:24:46 +00:00
|
|
|
|
2019-09-02 23:50:15 +00:00
|
|
|
if epoch(state.slot) != epoch(slot) {
|
2019-08-30 01:04:15 +00:00
|
|
|
return Err(Error::InvariantViolated(format!(
|
|
|
|
"Epochs in consistent in proposer lookup: state: {}, requested: {}",
|
2019-09-02 23:50:15 +00:00
|
|
|
epoch(state.slot),
|
2019-08-30 01:04:15 +00:00
|
|
|
epoch(slot)
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2019-08-29 09:14:52 +00:00
|
|
|
state
|
2019-11-21 00:47:30 +00:00
|
|
|
.get_beacon_proposer_index(slot, &self.spec)
|
2019-08-29 09:14:52 +00:00
|
|
|
.map_err(Into::into)
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 04:48:24 +00:00
|
|
|
/// Produce an `Attestation` that is valid for the given `slot` and `index`.
|
|
|
|
///
|
|
|
|
/// Always attests to the canonical chain.
|
|
|
|
pub fn produce_attestation(
|
|
|
|
&self,
|
|
|
|
slot: Slot,
|
|
|
|
index: CommitteeIndex,
|
|
|
|
) -> Result<Attestation<T::EthSpec>, Error> {
|
2020-03-04 06:10:22 +00:00
|
|
|
// Note: we're taking a lock on the head. The work involved here should be trivial enough
|
|
|
|
// that the lock should not be held for long.
|
|
|
|
let head = self
|
|
|
|
.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?;
|
2019-11-25 04:48:24 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
if slot >= head.beacon_block.slot() {
|
|
|
|
self.produce_attestation_for_block(
|
|
|
|
slot,
|
|
|
|
index,
|
|
|
|
head.beacon_block_root,
|
|
|
|
Cow::Borrowed(&head.beacon_state),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
// Note: this method will fail if `slot` is more than `state.block_roots.len()` slots
|
|
|
|
// prior to the head.
|
|
|
|
//
|
|
|
|
// This seems reasonable, producing an attestation at a slot so far
|
|
|
|
// in the past seems useless, definitely in mainnet spec. In minimal spec, when the
|
|
|
|
// block roots only contain two epochs of history, it's possible that you will fail to
|
|
|
|
// produce an attestation that would be valid to be included in a block. Given that
|
|
|
|
// minimal is only for testing, I think this is fine.
|
|
|
|
//
|
|
|
|
// It is important to note that what's _not_ allowed here is attesting to a slot in the
|
|
|
|
// past. You can still attest to a block an arbitrary distance in the past, just not as
|
|
|
|
// if you are in a slot in the past.
|
|
|
|
let beacon_block_root = *head.beacon_state.get_block_root(slot)?;
|
|
|
|
let state_root = *head.beacon_state.get_state_root(slot)?;
|
2019-11-25 04:48:24 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
// Avoid holding a lock on the head whilst doing database reads. Good boi functions
|
|
|
|
// don't hog locks.
|
|
|
|
drop(head);
|
2019-11-25 04:48:24 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
let mut state = self
|
|
|
|
.get_state_caching_only_with_committee_caches(&state_root, Some(slot))?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconState(state_root))?;
|
2019-11-25 04:48:24 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
|
2019-08-29 09:14:52 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
self.produce_attestation_for_block(slot, index, beacon_block_root, Cow::Owned(state))
|
|
|
|
}
|
2019-06-20 08:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Produce an `AttestationData` that attests to the chain denoted by `block_root` and `state`.
|
2019-06-21 01:37:02 +00:00
|
|
|
///
|
|
|
|
/// Permits attesting to any arbitrary chain. Generally, the `produce_attestation_data`
|
|
|
|
/// function should be used as it attests to the canonical chain.
|
2020-03-04 06:10:22 +00:00
|
|
|
pub fn produce_attestation_for_block(
|
2019-06-20 08:46:03 +00:00
|
|
|
&self,
|
2020-03-04 06:10:22 +00:00
|
|
|
slot: Slot,
|
2019-11-21 00:47:30 +00:00
|
|
|
index: CommitteeIndex,
|
2020-03-04 06:10:22 +00:00
|
|
|
beacon_block_root: Hash256,
|
|
|
|
mut state: Cow<BeaconState<T::EthSpec>>,
|
|
|
|
) -> Result<Attestation<T::EthSpec>, Error> {
|
|
|
|
let epoch = slot.epoch(T::EthSpec::slots_per_epoch());
|
|
|
|
|
|
|
|
if state.slot > slot {
|
|
|
|
return Err(Error::CannotAttestToFutureState);
|
|
|
|
} else if state.current_epoch() + 1 < epoch {
|
|
|
|
let mut_state = state.to_mut();
|
|
|
|
while mut_state.current_epoch() + 1 < epoch {
|
|
|
|
// Note: here we provide `Hash256::zero()` as the root of the current state. This
|
|
|
|
// has the effect of setting the values of all historic state roots to the zero
|
|
|
|
// hash. This is an optimization, we don't need the state roots so why calculate
|
|
|
|
// them?
|
|
|
|
per_slot_processing(mut_state, Some(Hash256::zero()), &self.spec)?;
|
|
|
|
}
|
|
|
|
mut_state.build_committee_cache(RelativeEpoch::Next, &self.spec)?;
|
|
|
|
}
|
2019-06-20 08:46:03 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
let committee_len = state.get_beacon_committee(slot, index)?.committee.len();
|
2019-06-20 08:46:03 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
let target_slot = epoch.start_slot(T::EthSpec::slots_per_epoch());
|
|
|
|
let target_root = if state.slot <= target_slot {
|
|
|
|
beacon_block_root
|
2019-06-20 08:46:03 +00:00
|
|
|
} else {
|
2020-03-04 06:10:22 +00:00
|
|
|
*state.get_block_root(target_slot)?
|
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
|
|
|
};
|
2019-06-20 08:46:03 +00:00
|
|
|
|
2020-03-04 06:10:22 +00:00
|
|
|
Ok(Attestation {
|
|
|
|
aggregation_bits: BitList::with_capacity(committee_len)?,
|
|
|
|
data: AttestationData {
|
|
|
|
slot,
|
|
|
|
index,
|
|
|
|
beacon_block_root: beacon_block_root,
|
|
|
|
source: state.current_justified_checkpoint.clone(),
|
|
|
|
target: Checkpoint {
|
|
|
|
epoch,
|
|
|
|
root: target_root,
|
|
|
|
},
|
|
|
|
},
|
2020-03-29 22:29:29 +00:00
|
|
|
signature: AggregateSignature::empty_signature(),
|
2019-06-20 08:46:03 +00:00
|
|
|
})
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 00:55:24 +00:00
|
|
|
/// Accept a new, potentially invalid attestation from the network.
|
2019-03-29 07:40:50 +00:00
|
|
|
///
|
2019-08-14 00:55:24 +00:00
|
|
|
/// If valid, the attestation is added to `self.op_pool` and `self.fork_choice`.
|
|
|
|
///
|
|
|
|
/// Returns an `Ok(AttestationProcessingOutcome)` if the chain was able to make a determination
|
|
|
|
/// about the `attestation` (whether it was invalid or not). Returns an `Err` if there was an
|
|
|
|
/// error during this process and no determination was able to be made.
|
|
|
|
///
|
|
|
|
/// ## Notes
|
|
|
|
///
|
|
|
|
/// - Whilst the `attestation` is added to fork choice, the head is not updated. That must be
|
|
|
|
/// done separately.
|
2019-03-29 07:54:01 +00:00
|
|
|
pub fn process_attestation(
|
|
|
|
&self,
|
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
|
|
|
attestation: Attestation<T::EthSpec>,
|
2019-09-14 19:41:35 +00:00
|
|
|
) -> Result<AttestationProcessingOutcome, Error> {
|
2020-03-05 06:19:35 +00:00
|
|
|
metrics::inc_counter(&metrics::ATTESTATION_PROCESSING_REQUESTS);
|
|
|
|
let timer = metrics::start_timer(&metrics::ATTESTATION_PROCESSING_TIMES);
|
|
|
|
|
2019-09-14 19:41:35 +00:00
|
|
|
let outcome = self.process_attestation_internal(attestation.clone());
|
|
|
|
|
|
|
|
match &outcome {
|
|
|
|
Ok(outcome) => match outcome {
|
|
|
|
AttestationProcessingOutcome::Processed => {
|
2020-03-05 06:19:35 +00:00
|
|
|
metrics::inc_counter(&metrics::ATTESTATION_PROCESSING_SUCCESSES);
|
2019-09-14 19:41:35 +00:00
|
|
|
trace!(
|
|
|
|
self.log,
|
|
|
|
"Beacon attestation imported";
|
|
|
|
"target_epoch" => attestation.data.target.epoch,
|
2019-11-21 00:47:30 +00:00
|
|
|
"index" => attestation.data.index,
|
2019-09-14 19:41:35 +00:00
|
|
|
);
|
|
|
|
let _ = self
|
|
|
|
.event_handler
|
|
|
|
.register(EventKind::BeaconAttestationImported {
|
|
|
|
attestation: Box::new(attestation),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
other => {
|
2019-11-29 11:25:36 +00:00
|
|
|
trace!(
|
2019-09-14 19:41:35 +00:00
|
|
|
self.log,
|
|
|
|
"Beacon attestation rejected";
|
|
|
|
"reason" => format!("{:?}", other),
|
|
|
|
);
|
|
|
|
let _ = self
|
|
|
|
.event_handler
|
|
|
|
.register(EventKind::BeaconAttestationRejected {
|
|
|
|
reason: format!("Invalid attestation: {:?}", other),
|
|
|
|
attestation: Box::new(attestation),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
error!(
|
|
|
|
self.log,
|
|
|
|
"Beacon attestation processing error";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
);
|
|
|
|
let _ = self
|
|
|
|
.event_handler
|
|
|
|
.register(EventKind::BeaconAttestationRejected {
|
|
|
|
reason: format!("Internal error: {:?}", e),
|
|
|
|
attestation: Box::new(attestation),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
metrics::stop_timer(timer);
|
2019-09-14 19:41:35 +00:00
|
|
|
outcome
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn process_attestation_internal(
|
|
|
|
&self,
|
|
|
|
attestation: Attestation<T::EthSpec>,
|
2019-08-14 00:55:24 +00:00
|
|
|
) -> Result<AttestationProcessingOutcome, Error> {
|
2020-03-05 06:19:35 +00:00
|
|
|
let initial_validation_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_INITIAL_VALIDATION_TIMES);
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
// There is no point in processing an attestation with an empty bitfield. Reject
|
|
|
|
// it immediately.
|
2019-11-25 04:48:24 +00:00
|
|
|
if attestation.aggregation_bits.num_set_bits() == 0 {
|
|
|
|
return Ok(AttestationProcessingOutcome::EmptyAggregationBitfield);
|
|
|
|
}
|
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let attestation_epoch = attestation.data.slot.epoch(T::EthSpec::slots_per_epoch());
|
|
|
|
let epoch_now = self.epoch()?;
|
|
|
|
let target = attestation.data.target.clone();
|
|
|
|
|
|
|
|
// Attestation must be from the current or previous epoch.
|
|
|
|
if attestation_epoch > epoch_now {
|
|
|
|
return Ok(AttestationProcessingOutcome::FutureEpoch {
|
|
|
|
attestation_epoch,
|
|
|
|
current_epoch: epoch_now,
|
|
|
|
});
|
|
|
|
} else if attestation_epoch + 1 < epoch_now {
|
|
|
|
return Ok(AttestationProcessingOutcome::PastEpoch {
|
|
|
|
attestation_epoch,
|
|
|
|
current_epoch: epoch_now,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if target.epoch != attestation.data.slot.epoch(T::EthSpec::slots_per_epoch()) {
|
|
|
|
return Ok(AttestationProcessingOutcome::BadTargetEpoch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attestation target must be for a known block.
|
2019-08-14 00:55:24 +00:00
|
|
|
//
|
2020-03-05 06:19:35 +00:00
|
|
|
// We use fork choice to find the target root, which means that we reject any attestation
|
|
|
|
// that has a `target.root` earlier than our latest finalized root. There's no point in
|
|
|
|
// processing an attestation that does not include our latest finalized block in its chain.
|
|
|
|
//
|
|
|
|
// We do not delay consideration for later, we simply drop the attestation.
|
|
|
|
let (target_block_slot, target_block_state_root) = if let Some((slot, state_root)) =
|
|
|
|
self.fork_choice.block_slot_and_state_root(&target.root)
|
2019-08-14 00:55:24 +00:00
|
|
|
{
|
2020-03-05 06:19:35 +00:00
|
|
|
(slot, state_root)
|
|
|
|
} else {
|
|
|
|
return Ok(AttestationProcessingOutcome::UnknownTargetRoot(target.root));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load the slot and state root for `attestation.data.beacon_block_root`.
|
|
|
|
//
|
|
|
|
// This indirectly checks to see if the `attestation.data.beacon_block_root` is in our fork
|
|
|
|
// choice. Any known, non-finalized block should be in fork choice, so this check
|
|
|
|
// immediately filters out attestations that attest to a block that has not been processed.
|
|
|
|
//
|
|
|
|
// Attestations must be for a known block. If the block is unknown, we simply drop the
|
|
|
|
// attestation and do not delay consideration for later.
|
|
|
|
let block_slot = if let Some((slot, _state_root)) = self
|
|
|
|
.fork_choice
|
|
|
|
.block_slot_and_state_root(&attestation.data.beacon_block_root)
|
|
|
|
{
|
|
|
|
slot
|
|
|
|
} else {
|
|
|
|
return Ok(AttestationProcessingOutcome::UnknownHeadBlock {
|
|
|
|
beacon_block_root: attestation.data.beacon_block_root,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: currently we do not check the FFG source/target. This is what the spec dictates
|
|
|
|
// but it seems wrong.
|
|
|
|
//
|
|
|
|
// I have opened an issue on the specs repo for this:
|
|
|
|
//
|
|
|
|
// https://github.com/ethereum/eth2.0-specs/issues/1636
|
|
|
|
//
|
|
|
|
// We should revisit this code once that issue has been resolved.
|
|
|
|
|
|
|
|
// Attestations must not be for blocks in the future. If this is the case, the attestation
|
|
|
|
// should not be considered.
|
|
|
|
if block_slot > attestation.data.slot {
|
|
|
|
return Ok(AttestationProcessingOutcome::AttestsToFutureBlock {
|
|
|
|
block: block_slot,
|
|
|
|
attestation: attestation.data.slot,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics::stop_timer(initial_validation_timer);
|
|
|
|
|
|
|
|
let cache_wait_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_SHUFFLING_CACHE_WAIT_TIMES);
|
|
|
|
|
|
|
|
let mut shuffling_cache = self
|
|
|
|
.shuffling_cache
|
|
|
|
.try_write_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::AttestationCacheLockTimeout)?;
|
|
|
|
|
|
|
|
metrics::stop_timer(cache_wait_timer);
|
|
|
|
|
|
|
|
let indexed_attestation =
|
|
|
|
if let Some(committee_cache) = shuffling_cache.get(attestation_epoch, target.root) {
|
|
|
|
if let Some(committee) = committee_cache
|
|
|
|
.get_beacon_committee(attestation.data.slot, attestation.data.index)
|
|
|
|
{
|
|
|
|
let indexed_attestation =
|
|
|
|
get_indexed_attestation(committee.committee, &attestation)?;
|
|
|
|
|
|
|
|
// Drop the shuffling cache to avoid holding the lock for any longer than
|
|
|
|
// required.
|
|
|
|
drop(shuffling_cache);
|
|
|
|
|
|
|
|
indexed_attestation
|
|
|
|
} else {
|
|
|
|
return Ok(AttestationProcessingOutcome::NoCommitteeForSlotAndIndex {
|
|
|
|
slot: attestation.data.slot,
|
|
|
|
index: attestation.data.index,
|
|
|
|
});
|
|
|
|
}
|
2020-01-08 02:58:01 +00:00
|
|
|
} else {
|
2020-03-05 06:19:35 +00:00
|
|
|
// Drop the shuffling cache to avoid holding the lock for any longer than
|
|
|
|
// required.
|
|
|
|
drop(shuffling_cache);
|
|
|
|
|
|
|
|
debug!(
|
|
|
|
self.log,
|
|
|
|
"Attestation processing cache miss";
|
|
|
|
"attn_epoch" => attestation_epoch.as_u64(),
|
|
|
|
"head_block_epoch" => block_slot.epoch(T::EthSpec::slots_per_epoch()).as_u64(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let state_read_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_STATE_READ_TIMES);
|
|
|
|
|
2020-01-08 02:58:01 +00:00
|
|
|
let mut state = self
|
2020-03-04 06:10:22 +00:00
|
|
|
.get_state_caching_only_with_committee_caches(
|
2020-03-05 06:19:35 +00:00
|
|
|
&target_block_state_root,
|
|
|
|
Some(target_block_slot),
|
2020-03-04 06:10:22 +00:00
|
|
|
)?
|
2020-03-05 06:19:35 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconState(target_block_state_root))?;
|
|
|
|
|
|
|
|
metrics::stop_timer(state_read_timer);
|
|
|
|
let state_skip_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_STATE_SKIP_TIMES);
|
|
|
|
|
|
|
|
while state.current_epoch() + 1 < attestation_epoch {
|
|
|
|
// Here we tell `per_slot_processing` to skip hashing the state and just
|
|
|
|
// use the zero hash instead.
|
|
|
|
//
|
|
|
|
// The state roots are not useful for the shuffling, so there's no need to
|
|
|
|
// compute them.
|
|
|
|
per_slot_processing(&mut state, Some(Hash256::zero()), &self.spec)?
|
2020-01-08 02:58:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
metrics::stop_timer(state_skip_timer);
|
|
|
|
let committee_building_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_COMMITTEE_BUILDING_TIMES);
|
2019-08-14 00:55:24 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let relative_epoch =
|
|
|
|
RelativeEpoch::from_epoch(state.current_epoch(), attestation_epoch)
|
|
|
|
.map_err(Error::IncorrectStateForAttestation)?;
|
2019-08-14 00:55:24 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
state.build_committee_cache(relative_epoch, &self.spec)?;
|
2019-12-06 07:44:38 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let committee_cache = state.committee_cache(relative_epoch)?;
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
self.shuffling_cache
|
|
|
|
.try_write_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::AttestationCacheLockTimeout)?
|
|
|
|
.insert(attestation_epoch, target.root, committee_cache);
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
metrics::stop_timer(committee_building_timer);
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
if let Some(committee) = committee_cache
|
|
|
|
.get_beacon_committee(attestation.data.slot, attestation.data.index)
|
|
|
|
{
|
|
|
|
get_indexed_attestation(committee.committee, &attestation)?
|
|
|
|
} else {
|
|
|
|
return Ok(AttestationProcessingOutcome::NoCommitteeForSlotAndIndex {
|
|
|
|
slot: attestation.data.slot,
|
|
|
|
index: attestation.data.index,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2019-08-14 00:55:24 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let signature_setup_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_SIGNATURE_SETUP_TIMES);
|
|
|
|
|
|
|
|
let pubkey_cache = self
|
|
|
|
.validator_pubkey_cache
|
|
|
|
.try_read_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::ValidatorPubkeyCacheLockTimeout)?;
|
|
|
|
|
|
|
|
let pubkeys = indexed_attestation
|
|
|
|
.attesting_indices
|
|
|
|
.iter()
|
|
|
|
.map(|i| {
|
|
|
|
pubkey_cache
|
|
|
|
.get(*i as usize)
|
|
|
|
.ok_or_else(|| Error::ValidatorPubkeyCacheIncomplete(*i as usize))
|
|
|
|
})
|
|
|
|
.collect::<Result<Vec<&PublicKey>, Error>>()?;
|
2019-05-29 07:52:43 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let fork = self
|
|
|
|
.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)
|
|
|
|
.map(|head| head.beacon_state.fork.clone())?;
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let signature_set = indexed_attestation_signature_set_from_pubkeys(
|
|
|
|
pubkeys,
|
|
|
|
&attestation.signature,
|
|
|
|
&indexed_attestation,
|
|
|
|
&fork,
|
|
|
|
&self.spec,
|
|
|
|
)
|
|
|
|
.map_err(Error::SignatureSetError)?;
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
metrics::stop_timer(signature_setup_timer);
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
let signature_verification_timer =
|
|
|
|
metrics::start_timer(&metrics::ATTESTATION_PROCESSING_SIGNATURE_TIMES);
|
|
|
|
|
|
|
|
let signature_is_valid = signature_set.is_valid();
|
|
|
|
|
|
|
|
metrics::stop_timer(signature_verification_timer);
|
|
|
|
|
|
|
|
if signature_is_valid {
|
|
|
|
// Provide the attestation to fork choice, updating the validator latest messages but
|
|
|
|
// _without_ finding and updating the head.
|
|
|
|
if let Err(e) = self
|
|
|
|
.fork_choice
|
|
|
|
.process_indexed_attestation(&indexed_attestation)
|
2019-08-27 01:19:50 +00:00
|
|
|
{
|
2020-03-05 06:19:35 +00:00
|
|
|
error!(
|
|
|
|
self.log,
|
|
|
|
"Add attestation to fork choice failed";
|
|
|
|
"beacon_block_root" => format!("{}", attestation.data.beacon_block_root),
|
|
|
|
"error" => format!("{:?}", e)
|
|
|
|
);
|
|
|
|
return Err(e.into());
|
2019-08-27 01:19:50 +00:00
|
|
|
}
|
2019-06-15 22:19:08 +00:00
|
|
|
|
2019-08-14 00:55:24 +00:00
|
|
|
// Provide the valid attestation to op pool, which may choose to retain the
|
|
|
|
// attestation for inclusion in a future block.
|
2020-03-02 03:04:49 +00:00
|
|
|
if self.eth1_chain.is_some() {
|
|
|
|
self.op_pool
|
2020-03-05 06:19:35 +00:00
|
|
|
.insert_attestation(attestation, &fork, &self.spec)?;
|
2020-03-02 03:04:49 +00:00
|
|
|
};
|
2019-08-14 00:55:24 +00:00
|
|
|
|
|
|
|
Ok(AttestationProcessingOutcome::Processed)
|
2020-03-05 06:19:35 +00:00
|
|
|
} else {
|
|
|
|
Ok(AttestationProcessingOutcome::InvalidSignature)
|
2019-08-19 11:02:34 +00:00
|
|
|
}
|
2019-03-29 07:40:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:20:59 +00:00
|
|
|
/// Accept some exit and queue it for inclusion in an appropriate block.
|
2020-02-10 23:19:36 +00:00
|
|
|
pub fn process_voluntary_exit(
|
|
|
|
&self,
|
|
|
|
exit: SignedVoluntaryExit,
|
|
|
|
) -> Result<(), ExitValidationError> {
|
2019-09-11 02:42:07 +00:00
|
|
|
match self.wall_clock_state() {
|
2020-03-02 03:04:49 +00:00
|
|
|
Ok(state) => {
|
|
|
|
if self.eth1_chain.is_some() {
|
|
|
|
self.op_pool.insert_voluntary_exit(exit, &state, &self.spec)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2019-08-29 09:14:52 +00:00
|
|
|
Err(e) => {
|
|
|
|
error!(
|
|
|
|
&self.log,
|
|
|
|
"Unable to process voluntary exit";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
"reason" => "no state"
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2019-03-04 01:20:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 00:54:51 +00:00
|
|
|
/// Accept some proposer slashing and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_proposer_slashing(
|
2019-03-29 07:54:01 +00:00
|
|
|
&self,
|
|
|
|
proposer_slashing: ProposerSlashing,
|
|
|
|
) -> Result<(), ProposerSlashingValidationError> {
|
2019-09-11 02:42:07 +00:00
|
|
|
match self.wall_clock_state() {
|
2019-08-29 09:14:52 +00:00
|
|
|
Ok(state) => {
|
2020-03-02 03:04:49 +00:00
|
|
|
if self.eth1_chain.is_some() {
|
|
|
|
self.op_pool
|
|
|
|
.insert_proposer_slashing(proposer_slashing, &state, &self.spec)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-08-29 09:14:52 +00:00
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!(
|
|
|
|
&self.log,
|
|
|
|
"Unable to process proposer slashing";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
"reason" => "no state"
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 00:23:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 00:54:51 +00:00
|
|
|
/// Accept some attester slashing and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_attester_slashing(
|
2019-03-29 07:54:01 +00:00
|
|
|
&self,
|
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
|
|
|
attester_slashing: AttesterSlashing<T::EthSpec>,
|
2019-03-29 07:54:01 +00:00
|
|
|
) -> Result<(), AttesterSlashingValidationError> {
|
2019-09-11 02:42:07 +00:00
|
|
|
match self.wall_clock_state() {
|
2019-08-29 09:14:52 +00:00
|
|
|
Ok(state) => {
|
2020-03-02 03:04:49 +00:00
|
|
|
if self.eth1_chain.is_some() {
|
|
|
|
self.op_pool
|
|
|
|
.insert_attester_slashing(attester_slashing, &state, &self.spec)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-08-29 09:14:52 +00:00
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!(
|
|
|
|
&self.log,
|
|
|
|
"Unable to process attester slashing";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
"reason" => "no state"
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 00:23:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Accept some block and attempt to add it to block DAG.
|
|
|
|
///
|
|
|
|
/// Will accept blocks from prior slots, however it will reject any block from a future slot.
|
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 process_block(
|
|
|
|
&self,
|
2020-02-10 23:19:36 +00:00
|
|
|
block: SignedBeaconBlock<T::EthSpec>,
|
2019-09-14 19:41:35 +00:00
|
|
|
) -> Result<BlockProcessingOutcome, Error> {
|
|
|
|
let outcome = self.process_block_internal(block.clone());
|
|
|
|
|
|
|
|
match &outcome {
|
|
|
|
Ok(outcome) => match outcome {
|
|
|
|
BlockProcessingOutcome::Processed { block_root } => {
|
|
|
|
trace!(
|
|
|
|
self.log,
|
|
|
|
"Beacon block imported";
|
|
|
|
"block_root" => format!("{:?}", block_root),
|
2020-02-10 23:19:36 +00:00
|
|
|
"block_slot" => format!("{:?}", block.slot().as_u64()),
|
2019-09-14 19:41:35 +00:00
|
|
|
);
|
|
|
|
let _ = self.event_handler.register(EventKind::BeaconBlockImported {
|
|
|
|
block_root: *block_root,
|
|
|
|
block: Box::new(block),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
other => {
|
2019-11-29 11:25:36 +00:00
|
|
|
trace!(
|
2019-09-14 19:41:35 +00:00
|
|
|
self.log,
|
|
|
|
"Beacon block rejected";
|
|
|
|
"reason" => format!("{:?}", other),
|
|
|
|
);
|
|
|
|
let _ = self.event_handler.register(EventKind::BeaconBlockRejected {
|
|
|
|
reason: format!("Invalid block: {:?}", other),
|
|
|
|
block: Box::new(block),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
error!(
|
|
|
|
self.log,
|
|
|
|
"Beacon block processing error";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
);
|
|
|
|
let _ = self.event_handler.register(EventKind::BeaconBlockRejected {
|
|
|
|
reason: format!("Internal error: {:?}", e),
|
|
|
|
block: Box::new(block),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
outcome
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Accept some block and attempt to add it to block DAG.
|
|
|
|
///
|
|
|
|
/// Will accept blocks from prior slots, however it will reject any block from a future slot.
|
|
|
|
fn process_block_internal(
|
|
|
|
&self,
|
2020-02-10 23:19:36 +00:00
|
|
|
signed_block: SignedBeaconBlock<T::EthSpec>,
|
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
|
|
|
) -> Result<BlockProcessingOutcome, Error> {
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::BLOCK_PROCESSING_REQUESTS);
|
|
|
|
let full_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_TIMES);
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
let block = &signed_block.message;
|
|
|
|
|
2019-06-13 03:54:16 +00:00
|
|
|
let finalized_slot = self
|
2020-01-06 06:30:37 +00:00
|
|
|
.head_info()?
|
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
|
|
|
.finalized_checkpoint
|
|
|
|
.epoch
|
2019-06-13 03:54:16 +00:00
|
|
|
.start_slot(T::EthSpec::slots_per_epoch());
|
2019-06-20 00:59:19 +00:00
|
|
|
|
2019-06-07 06:46:07 +00:00
|
|
|
if block.slot == 0 {
|
2019-06-13 03:54:16 +00:00
|
|
|
return Ok(BlockProcessingOutcome::GenesisBlock);
|
2019-06-07 06:46:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 06:05:07 +00:00
|
|
|
if block.slot >= MAXIMUM_BLOCK_SLOT_NUMBER {
|
|
|
|
return Ok(BlockProcessingOutcome::BlockSlotLimitReached);
|
|
|
|
}
|
|
|
|
|
2019-09-03 04:18:45 +00:00
|
|
|
if block.slot <= finalized_slot {
|
|
|
|
return Ok(BlockProcessingOutcome::WouldRevertFinalizedSlot {
|
|
|
|
block_slot: block.slot,
|
2019-09-30 03:58:45 +00:00
|
|
|
finalized_slot,
|
2019-09-03 04:18:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-29 04:05:00 +00:00
|
|
|
// Reject any block if its parent is not known to fork choice.
|
|
|
|
//
|
|
|
|
// A block that is not in fork choice is either:
|
|
|
|
//
|
|
|
|
// - Not yet imported: we should reject this block because we should only import a child
|
|
|
|
// after its parent has been fully imported.
|
|
|
|
// - Pre-finalized: if the parent block is _prior_ to finalization, we should ignore it
|
|
|
|
// because it will revert finalization. Note that the finalized block is stored in fork
|
|
|
|
// choice, so we will not reject any child of the finalized block (this is relevant during
|
|
|
|
// genesis).
|
|
|
|
if !self.fork_choice.contains_block(&block.parent_root) {
|
|
|
|
return Ok(BlockProcessingOutcome::ParentUnknown {
|
|
|
|
parent: block.parent_root,
|
|
|
|
reference_location: "fork_choice",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
let block_root_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_BLOCK_ROOT);
|
|
|
|
|
2019-08-14 00:55:24 +00:00
|
|
|
let block_root = block.canonical_root();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(block_root_timer);
|
|
|
|
|
2019-06-07 06:46:07 +00:00
|
|
|
if block_root == self.genesis_block_root {
|
2019-06-13 03:54:16 +00:00
|
|
|
return Ok(BlockProcessingOutcome::GenesisBlock);
|
2019-06-07 06:46:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 04:26:30 +00:00
|
|
|
let present_slot = self.slot()?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
if block.slot > present_slot {
|
2019-06-13 03:54:16 +00:00
|
|
|
return Ok(BlockProcessingOutcome::FutureSlot {
|
|
|
|
present_slot,
|
|
|
|
block_slot: block.slot,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-08 02:58:01 +00:00
|
|
|
// Check if the block is already known. We know it is post-finalization, so it is
|
2020-01-29 04:05:00 +00:00
|
|
|
// sufficient to check the fork choice.
|
|
|
|
if self.fork_choice.contains_block(&block_root) {
|
2020-01-08 02:58:01 +00:00
|
|
|
return Ok(BlockProcessingOutcome::BlockIsAlreadyKnown);
|
|
|
|
}
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
// Records the time taken to load the block and state from the database during block
|
|
|
|
// processing.
|
|
|
|
let db_read_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_DB_READ);
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
// Load the blocks parent block from the database, returning invalid if that block is not
|
|
|
|
// found.
|
2020-02-10 00:30:21 +00:00
|
|
|
let parent_block = match self.get_block(&block.parent_root)? {
|
|
|
|
Some(block) => block,
|
|
|
|
None => {
|
|
|
|
return Ok(BlockProcessingOutcome::ParentUnknown {
|
|
|
|
parent: block.parent_root,
|
|
|
|
reference_location: "database",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
// Load the parent blocks state from the database, returning an error if it is not found.
|
2019-09-02 14:34:41 +00:00
|
|
|
// It is an error because if we know the parent block we should also know the parent state.
|
2020-02-10 23:19:36 +00:00
|
|
|
let parent_state_root = parent_block.state_root();
|
2019-02-14 01:09:18 +00:00
|
|
|
let parent_state = self
|
2020-02-10 23:19:36 +00:00
|
|
|
.get_state(&parent_state_root, Some(parent_block.slot()))?
|
2019-11-26 23:54:46 +00:00
|
|
|
.ok_or_else(|| {
|
|
|
|
Error::DBInconsistent(format!("Missing state {:?}", parent_state_root))
|
|
|
|
})?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(db_read_timer);
|
|
|
|
|
2019-09-09 00:55:15 +00:00
|
|
|
write_block(&block, block_root, &self.log);
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
let catchup_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CATCHUP_STATE);
|
|
|
|
|
2020-02-10 00:30:21 +00:00
|
|
|
// Keep a batch of any states that were "skipped" (block-less) in between the parent state
|
|
|
|
// slot and the block slot. These will be stored in the database.
|
|
|
|
let mut intermediate_states = StateBatch::new();
|
2019-08-23 05:53:53 +00:00
|
|
|
|
2019-03-23 07:48:09 +00:00
|
|
|
// Transition the parent state to the block slot.
|
2019-05-25 10:51:15 +00:00
|
|
|
let mut state: BeaconState<T::EthSpec> = parent_state;
|
2019-12-09 03:20:25 +00:00
|
|
|
let distance = block.slot.as_u64().saturating_sub(state.slot.as_u64());
|
|
|
|
for i in 0..distance {
|
2020-01-03 04:09:00 +00:00
|
|
|
let state_root = if i == 0 {
|
2020-02-10 23:19:36 +00:00
|
|
|
parent_block.state_root()
|
2020-01-03 04:09:00 +00:00
|
|
|
} else {
|
2020-02-10 00:30:21 +00:00
|
|
|
// This is a new state we've reached, so stage it for storage in the DB.
|
|
|
|
// Computing the state root here is time-equivalent to computing it during slot
|
|
|
|
// processing, but we get early access to it.
|
|
|
|
let state_root = state.update_tree_hash_cache()?;
|
|
|
|
intermediate_states.add_state(state_root, &state)?;
|
|
|
|
state_root
|
2020-01-03 04:09:00 +00:00
|
|
|
};
|
|
|
|
|
2020-02-10 00:30:21 +00:00
|
|
|
per_slot_processing(&mut state, Some(state_root), &self.spec)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(catchup_timer);
|
|
|
|
|
|
|
|
let committee_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_COMMITTEE);
|
|
|
|
|
2019-08-14 00:55:24 +00:00
|
|
|
state.build_committee_cache(RelativeEpoch::Previous, &self.spec)?;
|
2019-06-08 11:57:25 +00:00
|
|
|
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
|
2019-06-04 03:13:38 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(committee_timer);
|
|
|
|
|
2019-09-09 01:11:16 +00:00
|
|
|
write_state(
|
|
|
|
&format!("state_pre_block_{}", block_root),
|
|
|
|
&state,
|
|
|
|
&self.log,
|
|
|
|
);
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
let core_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CORE);
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
// Apply the received block to its parent state (which has been transitioned into this
|
|
|
|
// slot).
|
2019-08-29 01:34:25 +00:00
|
|
|
match per_block_processing(
|
|
|
|
&mut state,
|
2020-02-10 23:19:36 +00:00
|
|
|
&signed_block,
|
2019-08-29 01:34:25 +00:00
|
|
|
Some(block_root),
|
2019-12-18 01:22:50 +00:00
|
|
|
BlockSignatureStrategy::VerifyBulk,
|
2019-08-29 01:34:25 +00:00
|
|
|
&self.spec,
|
|
|
|
) {
|
2019-06-13 03:54:16 +00:00
|
|
|
Err(BlockProcessingError::BeaconStateError(e)) => {
|
|
|
|
return Err(Error::BeaconStateError(e))
|
|
|
|
}
|
|
|
|
Err(e) => return Ok(BlockProcessingOutcome::PerBlockProcessingError(e)),
|
|
|
|
_ => {}
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(core_timer);
|
|
|
|
|
|
|
|
let state_root_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_STATE_ROOT);
|
|
|
|
|
2019-12-09 03:20:25 +00:00
|
|
|
let state_root = state.update_tree_hash_cache()?;
|
|
|
|
|
|
|
|
metrics::stop_timer(state_root_timer);
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-09-09 00:55:15 +00:00
|
|
|
write_state(
|
|
|
|
&format!("state_post_block_{}", block_root),
|
|
|
|
&state,
|
|
|
|
&self.log,
|
|
|
|
);
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
if block.state_root != state_root {
|
2019-09-03 04:18:45 +00:00
|
|
|
return Ok(BlockProcessingOutcome::StateRootMismatch {
|
|
|
|
block: block.state_root,
|
|
|
|
local: state_root,
|
|
|
|
});
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 04:05:00 +00:00
|
|
|
let fork_choice_register_timer =
|
|
|
|
metrics::start_timer(&metrics::BLOCK_PROCESSING_FORK_CHOICE_REGISTER);
|
|
|
|
|
2020-03-05 06:19:35 +00:00
|
|
|
// If there are new validators in this block, update our pubkey cache.
|
|
|
|
//
|
|
|
|
// We perform this _before_ adding the block to fork choice because the pubkey cache is
|
|
|
|
// used by attestation processing which will only process an attestation if the block is
|
|
|
|
// known to fork choice. This ordering ensure that the pubkey cache is always up-to-date.
|
|
|
|
self.validator_pubkey_cache
|
|
|
|
.try_write_for(VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::ValidatorPubkeyCacheLockTimeout)?
|
|
|
|
.import_new_pubkeys(&state)?;
|
|
|
|
|
|
|
|
// If the imported block is in the previous or current epochs (according to the
|
|
|
|
// wall-clock), check to see if this is the first block of the epoch. If so, add the
|
|
|
|
// committee to the shuffling cache.
|
|
|
|
if state.current_epoch() + 1 >= self.epoch()?
|
|
|
|
&& parent_block.slot().epoch(T::EthSpec::slots_per_epoch()) != state.current_epoch()
|
|
|
|
{
|
|
|
|
let mut shuffling_cache = self
|
|
|
|
.shuffling_cache
|
|
|
|
.try_write_for(ATTESTATION_CACHE_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::AttestationCacheLockTimeout)?;
|
|
|
|
|
|
|
|
let committee_cache = state.committee_cache(RelativeEpoch::Current)?;
|
|
|
|
|
|
|
|
let epoch_start_slot = state
|
|
|
|
.current_epoch()
|
|
|
|
.start_slot(T::EthSpec::slots_per_epoch());
|
|
|
|
let target_root = if state.slot == epoch_start_slot {
|
|
|
|
block_root
|
|
|
|
} else {
|
|
|
|
*state.get_block_root(epoch_start_slot)?
|
|
|
|
};
|
|
|
|
|
|
|
|
shuffling_cache.insert(state.current_epoch(), target_root, committee_cache);
|
|
|
|
}
|
|
|
|
|
2020-01-29 04:05:00 +00:00
|
|
|
// Register the new block with the fork choice service.
|
|
|
|
if let Err(e) = self
|
|
|
|
.fork_choice
|
|
|
|
.process_block(self, &state, &block, block_root)
|
|
|
|
{
|
|
|
|
error!(
|
|
|
|
self.log,
|
|
|
|
"Add block to fork choice failed";
|
|
|
|
"block_root" => format!("{}", block_root),
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics::stop_timer(fork_choice_register_timer);
|
|
|
|
|
2020-02-10 00:30:21 +00:00
|
|
|
self.head_tracker.register_block(block_root, &block);
|
|
|
|
metrics::observe(
|
|
|
|
&metrics::OPERATIONS_PER_BLOCK_ATTESTATION,
|
|
|
|
block.body.attestations.len() as f64,
|
|
|
|
);
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
let db_write_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_DB_WRITE);
|
|
|
|
|
2020-02-10 00:30:21 +00:00
|
|
|
// Store all the states between the parent block state and this block's slot before storing
|
2019-08-23 05:53:53 +00:00
|
|
|
// the final state.
|
2020-02-10 00:30:21 +00:00
|
|
|
intermediate_states.commit(&*self.store)?;
|
2019-08-23 05:53:53 +00:00
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
// Store the block and state.
|
2019-12-12 01:48:18 +00:00
|
|
|
// NOTE: we store the block *after* the state to guard against inconsistency in the event of
|
|
|
|
// a crash, as states are usually looked up from blocks, not the other way around. A better
|
|
|
|
// solution would be to use a database transaction (once our choice of database and API
|
|
|
|
// settles down).
|
|
|
|
// See: https://github.com/sigp/lighthouse/issues/692
|
2020-02-10 00:30:21 +00:00
|
|
|
self.store.put_state(&state_root, state)?;
|
2020-02-10 23:19:36 +00:00
|
|
|
self.store.put_block(&block_root, signed_block)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(db_write_timer);
|
|
|
|
|
|
|
|
metrics::inc_counter(&metrics::BLOCK_PROCESSING_SUCCESSES);
|
2019-12-09 03:20:25 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::stop_timer(full_timer);
|
2019-05-28 07:30:09 +00:00
|
|
|
|
2019-06-20 08:46:03 +00:00
|
|
|
Ok(BlockProcessingOutcome::Processed { block_root })
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 09:14:52 +00:00
|
|
|
/// Produce a new block at the given `slot`.
|
2019-02-14 01:09:18 +00:00
|
|
|
///
|
|
|
|
/// The produced block will not be inherently valid, it must be signed by a block producer.
|
|
|
|
/// Block signing is out of the scope of this function and should be done by a separate program.
|
2019-03-07 01:53:15 +00:00
|
|
|
pub fn produce_block(
|
|
|
|
&self,
|
|
|
|
randao_reveal: Signature,
|
2019-08-29 09:14:52 +00:00
|
|
|
slot: Slot,
|
Eth1 Integration (#542)
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Initial commit. web3 api working.
* Tidied up lib. Add function for fetching logs.
* Refactor with `Eth1DataFetcher` trait
* Add parsing for deposit contract logs and get_eth1_data function
* Add `get_eth1_votes` function
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Fix merge issue
* Refactor with `Config` struct. Remote `ContractConfig`
* Rename eth1_chain crate to eth1
* Rename files and read abi file using `fs::read`
* Move eth1 to lib
* Remove unnecessary mutability constraint
* Add `Web3Backend` for returning actual eth1 data
* Refactor `get_eth1_votes` to return a Result
* Delete `eth1_chain` crate
* Return `Result` from `get_deposits`
* Fix range of deposits to return to beacon chain
* Add `get_block_height_by_hash` trait function
* Add naive method for getting `previous_eth1_distance`
* Add eth1 config params to main config
* Add instructions for setting up eth1 testing environment
* Add build script to fetch deposit contract abi
* Contract ABI is part of compiled binary
* Fix minor bugs
* Move docs to lib
* Add timeout to config
* Remove print statements
* Change warn to error
* Fix typos
* Removed prints in test and get timeout value from config
* Fixed error types
* Added logging to web3_fetcher
* Refactor for modified web3 api
* Fix minor stuff
* Add build script
* Tidy, hide eth1 integration tests behind flag
* Add http crate
* Add first stages of eth1_test_rig
* Fix deposits on test rig
* Fix bug with deposit count method
* Add block hash getter to http eth1
* Clean eth1 http crate and tests
* Add script to start ganache
* Adds deposit tree to eth1-http
* Extend deposit tree tests
* Tidy tests in eth1-http
* Add more detail to get block request
* Add block cache to eth1-http
* Rename deposit tree to deposit cache
* Add inital updating to eth1-http
* Tidy updater
* Fix compile bugs in tests
* Adds an Eth1DataCache builder
* Reorg eth1-http files
* Add (failing) tests for eth1 updater
* Rename files, fix bug in eth1-http
* Ensure that ganache timestamps are increasing
* Fix bugs with getting eth1data ancestors
* Improve eth1 testing, fix bugs
* Add truncate method to block cache
* Add pruning to block cache update process
* Add tests for block pruning
* Allow for dropping an expired cache.
* Add more comments
* Add first compiling version of deposit updater
* Add common fn for getting range of required blocks
* Add passing deposit update test
* Improve tests
* Fix block pruning bug
* Add tests for running two updates at once
* Add updater services to eth1
* Add deposit collection to beacon chain
* Add incomplete builder experiments
* Add first working version of beacon chain builder
* Update test harness to new beacon chain type
* Rename builder file, tidy
* Add first working client builder
* Progress further on client builder
* Update becaon node binary to use client builder
* Ensure release tests compile
* Remove old eth1 crate
* Add first pass of new lighthouse binary
* Fix websocket server startup
* Remove old binary code from beacon_node crate
* Add first working beacon node tests
* Add genesis crate, new eth1 cache_2
* Add Serivce to Eth1Cache
* Refactor with general eth1 improvements
* Add passing genesis test
* Tidy, add comments
* Add more comments to eth1 service
* Add further eth1 progress
* Fix some bugs with genesis
* Fix eth1 bugs, make eth1 linking more efficient
* Shift logic in genesis service
* Add more comments to genesis service
* Add gzip, max request values, timeouts to http
* Update testnet parameters to suit goerli testnet
* Add ability to vary Fork, fix custom spec
* Be more explicit about deposit fork version
* Start adding beacon chain eth1 option
* Add more flexibility to prod client
* Further runtime refactoring
* Allow for starting from store
* Add bootstrapping to client config
* Add remote_beacon_node crate
* Update eth1 service for more configurability
* Update eth1 tests to use less runtimes
* Patch issues with tests using too many files
* Move dummy eth1 backend flag
* Ensure all tests pass
* Add ganache-cli to Dockerfile
* Use a special docker hub image for testing
* Appease clippy
* Move validator client into lighthouse binary
* Allow starting with dummy eth1 backend
* Improve logging
* Fix dummy eth1 backend from cli
* Add extra testnet command
* Ensure consistent spec in beacon node
* Update eth1 rig to work on goerli
* Tidy lcli, start adding support for yaml config
* Add incomplete YamlConfig struct
* Remove efforts at YamlConfig
* Add incomplete eth1 voting. Blocked on spec issues
* Add (untested) first pass at eth1 vote algo
* Add tests for winning vote
* Add more tests for eth1 chain
* Add more eth1 voting tests
* Added more eth1 voting testing
* Change test name
* Add more tests to eth1 chain
* Tidy eth1 generics, add more tests
* Improve comments
* Tidy beacon_node tests
* Tidy, rename JsonRpc.. to Caching..
* Tidy voting logic
* Tidy builder docs
* Add comments, tidy eth1
* Add more comments to eth1
* Fix bug with winning_vote
* Add doc comments to the `ClientBuilder`
* Remove commented-out code
* Improve `ClientBuilder` docs
* Add comments to client config
* Add decoding test for `ClientConfig`
* Remove unused `DepositSet` struct
* Tidy `block_cache`
* Remove commented out lines
* Remove unused code in `eth1` crate
* Remove old validator binary `main.rs`
* Tidy, fix tests compile error
* Add initial tests for get_deposits
* Remove dead code in eth1_test_rig
* Update TestingDepositBuilder
* Add testing for getting eth1 deposits
* Fix duplicate rand dep
* Remove dead code
* Remove accidentally-added files
* Fix comment in eth1_genesis_service
* Add .gitignore for eth1_test_rig
* Fix bug in eth1_genesis_service
* Remove dead code from eth2_config
* Fix tabs/spaces in root Cargo.toml
* Tidy eth1 crate
* Allow for re-use of eth1 service after genesis
* Update docs for new CLI
* Change README gif
* Tidy eth1 http module
* Tidy eth1 service
* Tidy environment crate
* Remove unused file
* Tidy, add comments
* Remove commented-out code
* Address majority of Michael's comments
* Address other PR comments
* Add link to issue alongside TODO
2019-11-15 03:47:51 +00:00
|
|
|
) -> Result<BeaconBlockAndState<T::EthSpec>, BlockProductionError> {
|
2019-08-29 09:14:52 +00:00
|
|
|
let state = self
|
2020-03-04 06:10:22 +00:00
|
|
|
.state_at_slot(slot - 1, StateSkipConfig::WithStateRoots)
|
2019-08-29 09:14:52 +00:00
|
|
|
.map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
self.produce_block_on_state(state, slot, randao_reveal)
|
2019-06-18 17:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Produce a block for some `slot` upon the given `state`.
|
|
|
|
///
|
|
|
|
/// Typically the `self.produce_block()` function should be used, instead of calling this
|
|
|
|
/// function directly. This function is useful for purposefully creating forks or blocks at
|
|
|
|
/// non-current slots.
|
|
|
|
///
|
|
|
|
/// The given state will be advanced to the given `produce_at_slot`, then a block will be
|
|
|
|
/// produced at that slot height.
|
|
|
|
pub fn produce_block_on_state(
|
|
|
|
&self,
|
|
|
|
mut state: BeaconState<T::EthSpec>,
|
|
|
|
produce_at_slot: Slot,
|
|
|
|
randao_reveal: Signature,
|
Eth1 Integration (#542)
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Initial commit. web3 api working.
* Tidied up lib. Add function for fetching logs.
* Refactor with `Eth1DataFetcher` trait
* Add parsing for deposit contract logs and get_eth1_data function
* Add `get_eth1_votes` function
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Fix merge issue
* Refactor with `Config` struct. Remote `ContractConfig`
* Rename eth1_chain crate to eth1
* Rename files and read abi file using `fs::read`
* Move eth1 to lib
* Remove unnecessary mutability constraint
* Add `Web3Backend` for returning actual eth1 data
* Refactor `get_eth1_votes` to return a Result
* Delete `eth1_chain` crate
* Return `Result` from `get_deposits`
* Fix range of deposits to return to beacon chain
* Add `get_block_height_by_hash` trait function
* Add naive method for getting `previous_eth1_distance`
* Add eth1 config params to main config
* Add instructions for setting up eth1 testing environment
* Add build script to fetch deposit contract abi
* Contract ABI is part of compiled binary
* Fix minor bugs
* Move docs to lib
* Add timeout to config
* Remove print statements
* Change warn to error
* Fix typos
* Removed prints in test and get timeout value from config
* Fixed error types
* Added logging to web3_fetcher
* Refactor for modified web3 api
* Fix minor stuff
* Add build script
* Tidy, hide eth1 integration tests behind flag
* Add http crate
* Add first stages of eth1_test_rig
* Fix deposits on test rig
* Fix bug with deposit count method
* Add block hash getter to http eth1
* Clean eth1 http crate and tests
* Add script to start ganache
* Adds deposit tree to eth1-http
* Extend deposit tree tests
* Tidy tests in eth1-http
* Add more detail to get block request
* Add block cache to eth1-http
* Rename deposit tree to deposit cache
* Add inital updating to eth1-http
* Tidy updater
* Fix compile bugs in tests
* Adds an Eth1DataCache builder
* Reorg eth1-http files
* Add (failing) tests for eth1 updater
* Rename files, fix bug in eth1-http
* Ensure that ganache timestamps are increasing
* Fix bugs with getting eth1data ancestors
* Improve eth1 testing, fix bugs
* Add truncate method to block cache
* Add pruning to block cache update process
* Add tests for block pruning
* Allow for dropping an expired cache.
* Add more comments
* Add first compiling version of deposit updater
* Add common fn for getting range of required blocks
* Add passing deposit update test
* Improve tests
* Fix block pruning bug
* Add tests for running two updates at once
* Add updater services to eth1
* Add deposit collection to beacon chain
* Add incomplete builder experiments
* Add first working version of beacon chain builder
* Update test harness to new beacon chain type
* Rename builder file, tidy
* Add first working client builder
* Progress further on client builder
* Update becaon node binary to use client builder
* Ensure release tests compile
* Remove old eth1 crate
* Add first pass of new lighthouse binary
* Fix websocket server startup
* Remove old binary code from beacon_node crate
* Add first working beacon node tests
* Add genesis crate, new eth1 cache_2
* Add Serivce to Eth1Cache
* Refactor with general eth1 improvements
* Add passing genesis test
* Tidy, add comments
* Add more comments to eth1 service
* Add further eth1 progress
* Fix some bugs with genesis
* Fix eth1 bugs, make eth1 linking more efficient
* Shift logic in genesis service
* Add more comments to genesis service
* Add gzip, max request values, timeouts to http
* Update testnet parameters to suit goerli testnet
* Add ability to vary Fork, fix custom spec
* Be more explicit about deposit fork version
* Start adding beacon chain eth1 option
* Add more flexibility to prod client
* Further runtime refactoring
* Allow for starting from store
* Add bootstrapping to client config
* Add remote_beacon_node crate
* Update eth1 service for more configurability
* Update eth1 tests to use less runtimes
* Patch issues with tests using too many files
* Move dummy eth1 backend flag
* Ensure all tests pass
* Add ganache-cli to Dockerfile
* Use a special docker hub image for testing
* Appease clippy
* Move validator client into lighthouse binary
* Allow starting with dummy eth1 backend
* Improve logging
* Fix dummy eth1 backend from cli
* Add extra testnet command
* Ensure consistent spec in beacon node
* Update eth1 rig to work on goerli
* Tidy lcli, start adding support for yaml config
* Add incomplete YamlConfig struct
* Remove efforts at YamlConfig
* Add incomplete eth1 voting. Blocked on spec issues
* Add (untested) first pass at eth1 vote algo
* Add tests for winning vote
* Add more tests for eth1 chain
* Add more eth1 voting tests
* Added more eth1 voting testing
* Change test name
* Add more tests to eth1 chain
* Tidy eth1 generics, add more tests
* Improve comments
* Tidy beacon_node tests
* Tidy, rename JsonRpc.. to Caching..
* Tidy voting logic
* Tidy builder docs
* Add comments, tidy eth1
* Add more comments to eth1
* Fix bug with winning_vote
* Add doc comments to the `ClientBuilder`
* Remove commented-out code
* Improve `ClientBuilder` docs
* Add comments to client config
* Add decoding test for `ClientConfig`
* Remove unused `DepositSet` struct
* Tidy `block_cache`
* Remove commented out lines
* Remove unused code in `eth1` crate
* Remove old validator binary `main.rs`
* Tidy, fix tests compile error
* Add initial tests for get_deposits
* Remove dead code in eth1_test_rig
* Update TestingDepositBuilder
* Add testing for getting eth1 deposits
* Fix duplicate rand dep
* Remove dead code
* Remove accidentally-added files
* Fix comment in eth1_genesis_service
* Add .gitignore for eth1_test_rig
* Fix bug in eth1_genesis_service
* Remove dead code from eth2_config
* Fix tabs/spaces in root Cargo.toml
* Tidy eth1 crate
* Allow for re-use of eth1 service after genesis
* Update docs for new CLI
* Change README gif
* Tidy eth1 http module
* Tidy eth1 service
* Tidy environment crate
* Remove unused file
* Tidy, add comments
* Remove commented-out code
* Address majority of Michael's comments
* Address other PR comments
* Add link to issue alongside TODO
2019-11-15 03:47:51 +00:00
|
|
|
) -> Result<BeaconBlockAndState<T::EthSpec>, BlockProductionError> {
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::BLOCK_PRODUCTION_REQUESTS);
|
|
|
|
let timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_TIMES);
|
2019-02-14 01:09:18 +00:00
|
|
|
|
Eth1 Integration (#542)
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Initial commit. web3 api working.
* Tidied up lib. Add function for fetching logs.
* Refactor with `Eth1DataFetcher` trait
* Add parsing for deposit contract logs and get_eth1_data function
* Add `get_eth1_votes` function
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Fix merge issue
* Refactor with `Config` struct. Remote `ContractConfig`
* Rename eth1_chain crate to eth1
* Rename files and read abi file using `fs::read`
* Move eth1 to lib
* Remove unnecessary mutability constraint
* Add `Web3Backend` for returning actual eth1 data
* Refactor `get_eth1_votes` to return a Result
* Delete `eth1_chain` crate
* Return `Result` from `get_deposits`
* Fix range of deposits to return to beacon chain
* Add `get_block_height_by_hash` trait function
* Add naive method for getting `previous_eth1_distance`
* Add eth1 config params to main config
* Add instructions for setting up eth1 testing environment
* Add build script to fetch deposit contract abi
* Contract ABI is part of compiled binary
* Fix minor bugs
* Move docs to lib
* Add timeout to config
* Remove print statements
* Change warn to error
* Fix typos
* Removed prints in test and get timeout value from config
* Fixed error types
* Added logging to web3_fetcher
* Refactor for modified web3 api
* Fix minor stuff
* Add build script
* Tidy, hide eth1 integration tests behind flag
* Add http crate
* Add first stages of eth1_test_rig
* Fix deposits on test rig
* Fix bug with deposit count method
* Add block hash getter to http eth1
* Clean eth1 http crate and tests
* Add script to start ganache
* Adds deposit tree to eth1-http
* Extend deposit tree tests
* Tidy tests in eth1-http
* Add more detail to get block request
* Add block cache to eth1-http
* Rename deposit tree to deposit cache
* Add inital updating to eth1-http
* Tidy updater
* Fix compile bugs in tests
* Adds an Eth1DataCache builder
* Reorg eth1-http files
* Add (failing) tests for eth1 updater
* Rename files, fix bug in eth1-http
* Ensure that ganache timestamps are increasing
* Fix bugs with getting eth1data ancestors
* Improve eth1 testing, fix bugs
* Add truncate method to block cache
* Add pruning to block cache update process
* Add tests for block pruning
* Allow for dropping an expired cache.
* Add more comments
* Add first compiling version of deposit updater
* Add common fn for getting range of required blocks
* Add passing deposit update test
* Improve tests
* Fix block pruning bug
* Add tests for running two updates at once
* Add updater services to eth1
* Add deposit collection to beacon chain
* Add incomplete builder experiments
* Add first working version of beacon chain builder
* Update test harness to new beacon chain type
* Rename builder file, tidy
* Add first working client builder
* Progress further on client builder
* Update becaon node binary to use client builder
* Ensure release tests compile
* Remove old eth1 crate
* Add first pass of new lighthouse binary
* Fix websocket server startup
* Remove old binary code from beacon_node crate
* Add first working beacon node tests
* Add genesis crate, new eth1 cache_2
* Add Serivce to Eth1Cache
* Refactor with general eth1 improvements
* Add passing genesis test
* Tidy, add comments
* Add more comments to eth1 service
* Add further eth1 progress
* Fix some bugs with genesis
* Fix eth1 bugs, make eth1 linking more efficient
* Shift logic in genesis service
* Add more comments to genesis service
* Add gzip, max request values, timeouts to http
* Update testnet parameters to suit goerli testnet
* Add ability to vary Fork, fix custom spec
* Be more explicit about deposit fork version
* Start adding beacon chain eth1 option
* Add more flexibility to prod client
* Further runtime refactoring
* Allow for starting from store
* Add bootstrapping to client config
* Add remote_beacon_node crate
* Update eth1 service for more configurability
* Update eth1 tests to use less runtimes
* Patch issues with tests using too many files
* Move dummy eth1 backend flag
* Ensure all tests pass
* Add ganache-cli to Dockerfile
* Use a special docker hub image for testing
* Appease clippy
* Move validator client into lighthouse binary
* Allow starting with dummy eth1 backend
* Improve logging
* Fix dummy eth1 backend from cli
* Add extra testnet command
* Ensure consistent spec in beacon node
* Update eth1 rig to work on goerli
* Tidy lcli, start adding support for yaml config
* Add incomplete YamlConfig struct
* Remove efforts at YamlConfig
* Add incomplete eth1 voting. Blocked on spec issues
* Add (untested) first pass at eth1 vote algo
* Add tests for winning vote
* Add more tests for eth1 chain
* Add more eth1 voting tests
* Added more eth1 voting testing
* Change test name
* Add more tests to eth1 chain
* Tidy eth1 generics, add more tests
* Improve comments
* Tidy beacon_node tests
* Tidy, rename JsonRpc.. to Caching..
* Tidy voting logic
* Tidy builder docs
* Add comments, tidy eth1
* Add more comments to eth1
* Fix bug with winning_vote
* Add doc comments to the `ClientBuilder`
* Remove commented-out code
* Improve `ClientBuilder` docs
* Add comments to client config
* Add decoding test for `ClientConfig`
* Remove unused `DepositSet` struct
* Tidy `block_cache`
* Remove commented out lines
* Remove unused code in `eth1` crate
* Remove old validator binary `main.rs`
* Tidy, fix tests compile error
* Add initial tests for get_deposits
* Remove dead code in eth1_test_rig
* Update TestingDepositBuilder
* Add testing for getting eth1 deposits
* Fix duplicate rand dep
* Remove dead code
* Remove accidentally-added files
* Fix comment in eth1_genesis_service
* Add .gitignore for eth1_test_rig
* Fix bug in eth1_genesis_service
* Remove dead code from eth2_config
* Fix tabs/spaces in root Cargo.toml
* Tidy eth1 crate
* Allow for re-use of eth1 service after genesis
* Update docs for new CLI
* Change README gif
* Tidy eth1 http module
* Tidy eth1 service
* Tidy environment crate
* Remove unused file
* Tidy, add comments
* Remove commented-out code
* Address majority of Michael's comments
* Address other PR comments
* Add link to issue alongside TODO
2019-11-15 03:47:51 +00:00
|
|
|
let eth1_chain = self
|
|
|
|
.eth1_chain
|
|
|
|
.as_ref()
|
|
|
|
.ok_or_else(|| BlockProductionError::NoEth1ChainConnection)?;
|
|
|
|
|
2019-06-18 17:01:58 +00:00
|
|
|
// If required, transition the new state to the present slot.
|
2020-01-03 04:09:00 +00:00
|
|
|
//
|
|
|
|
// Note: supplying some `state_root` when it it is known would be a cheap and easy
|
|
|
|
// optimization.
|
2019-06-20 08:46:03 +00:00
|
|
|
while state.slot < produce_at_slot {
|
2020-01-03 04:09:00 +00:00
|
|
|
per_slot_processing(&mut state, None, &self.spec)?;
|
2019-06-18 17:01:58 +00:00
|
|
|
}
|
2019-03-21 20:11:04 +00:00
|
|
|
|
2019-06-18 17:01:58 +00:00
|
|
|
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
|
2019-02-14 01:09:18 +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 parent_root = if state.slot > 0 {
|
2019-06-07 06:46:07 +00:00
|
|
|
*state
|
|
|
|
.get_block_root(state.slot - 1)
|
|
|
|
.map_err(|_| BlockProductionError::UnableToGetBlockRootFromState)?
|
|
|
|
} else {
|
|
|
|
state.latest_block_header.canonical_root()
|
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-06-18 17:01:58 +00:00
|
|
|
let mut graffiti: [u8; 32] = [0; 32];
|
|
|
|
graffiti.copy_from_slice(GRAFFITI.as_bytes());
|
|
|
|
|
2019-06-08 11:57:25 +00:00
|
|
|
let (proposer_slashings, attester_slashings) =
|
2019-06-18 17:01:58 +00:00
|
|
|
self.op_pool.get_slashings(&state, &self.spec);
|
2019-03-29 07:30:03 +00:00
|
|
|
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
let eth1_data = eth1_chain.eth1_data_for_block_production(&state, &self.spec)?;
|
|
|
|
let deposits = eth1_chain
|
|
|
|
.deposits_for_block_inclusion(&state, ð1_data, &self.spec)?
|
|
|
|
.into();
|
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
let mut block = SignedBeaconBlock {
|
|
|
|
message: BeaconBlock {
|
|
|
|
slot: state.slot,
|
|
|
|
parent_root,
|
|
|
|
state_root: Hash256::zero(),
|
|
|
|
body: BeaconBlockBody {
|
|
|
|
randao_reveal,
|
|
|
|
eth1_data,
|
|
|
|
graffiti,
|
|
|
|
proposer_slashings: proposer_slashings.into(),
|
|
|
|
attester_slashings: attester_slashings.into(),
|
|
|
|
attestations: self
|
|
|
|
.op_pool
|
|
|
|
.get_attestations(&state, &self.spec)
|
|
|
|
.map_err(BlockProductionError::OpPoolError)?
|
|
|
|
.into(),
|
|
|
|
deposits,
|
|
|
|
voluntary_exits: self.op_pool.get_voluntary_exits(&state, &self.spec).into(),
|
|
|
|
},
|
|
|
|
},
|
Eth1 Integration (#542)
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Initial commit. web3 api working.
* Tidied up lib. Add function for fetching logs.
* Refactor with `Eth1DataFetcher` trait
* Add parsing for deposit contract logs and get_eth1_data function
* Add `get_eth1_votes` function
* Refactor to cache Eth1Data
* Fix merge conflicts and minor refactorings
* Rename Eth1Cache to Eth1DataCache
* Refactor events subscription
* Add deposits module to interface with BeaconChain deposits
* Remove utils
* Rename to types.rs and add trait constraints to Eth1DataFetcher
* Confirm to trait constraints. Make Web3DataFetcher cloneable
* Make fetcher object member of deposit and eth1_data cache and other fixes
* Fix update_cache function
* Move fetch_eth1_data to impl block
* Fix deposit tests
* Create Eth1 object for interfacing with Beacon chain
* Add `run` function for running update_cache and subscribe_deposit_logs tasks
* Add logging
* Run `cargo fmt` and make tests pass
* Convert sync functions to async
* Add timeouts to web3 functions
* Return futures from cache functions
* Add failed chaining of futures
* Working cache updation
* Clean up tests and `update_cache` function
* Refactor `get_eth1_data` functions to work with future returning functions
* Refactor eth1 `run` function to work with modified `update_cache` api
* Minor changes
* Add distance parameter to `update_cache`
* Fix tests and other minor fixes
* Working integration with cache and deposits
* Add merkle_tree construction, proof generation and verification code
* Add function to construct and fetch Deposits for BeaconNode
* Add error handling
* Import ssz
* Add error handling to eth1 cache and fix minor errors
* Run rustfmt
* Fix minor bug
* Rename Eth1Error and change to Result<T>
* Change deposit fetching mechanism from notification based to poll based
* Add deposits from eth1 chain in a given range every `x` blocks
* Modify `run` function to accommodate changes
* Minor fixes
* Fix formatting
* Fix merge issue
* Refactor with `Config` struct. Remote `ContractConfig`
* Rename eth1_chain crate to eth1
* Rename files and read abi file using `fs::read`
* Move eth1 to lib
* Remove unnecessary mutability constraint
* Add `Web3Backend` for returning actual eth1 data
* Refactor `get_eth1_votes` to return a Result
* Delete `eth1_chain` crate
* Return `Result` from `get_deposits`
* Fix range of deposits to return to beacon chain
* Add `get_block_height_by_hash` trait function
* Add naive method for getting `previous_eth1_distance`
* Add eth1 config params to main config
* Add instructions for setting up eth1 testing environment
* Add build script to fetch deposit contract abi
* Contract ABI is part of compiled binary
* Fix minor bugs
* Move docs to lib
* Add timeout to config
* Remove print statements
* Change warn to error
* Fix typos
* Removed prints in test and get timeout value from config
* Fixed error types
* Added logging to web3_fetcher
* Refactor for modified web3 api
* Fix minor stuff
* Add build script
* Tidy, hide eth1 integration tests behind flag
* Add http crate
* Add first stages of eth1_test_rig
* Fix deposits on test rig
* Fix bug with deposit count method
* Add block hash getter to http eth1
* Clean eth1 http crate and tests
* Add script to start ganache
* Adds deposit tree to eth1-http
* Extend deposit tree tests
* Tidy tests in eth1-http
* Add more detail to get block request
* Add block cache to eth1-http
* Rename deposit tree to deposit cache
* Add inital updating to eth1-http
* Tidy updater
* Fix compile bugs in tests
* Adds an Eth1DataCache builder
* Reorg eth1-http files
* Add (failing) tests for eth1 updater
* Rename files, fix bug in eth1-http
* Ensure that ganache timestamps are increasing
* Fix bugs with getting eth1data ancestors
* Improve eth1 testing, fix bugs
* Add truncate method to block cache
* Add pruning to block cache update process
* Add tests for block pruning
* Allow for dropping an expired cache.
* Add more comments
* Add first compiling version of deposit updater
* Add common fn for getting range of required blocks
* Add passing deposit update test
* Improve tests
* Fix block pruning bug
* Add tests for running two updates at once
* Add updater services to eth1
* Add deposit collection to beacon chain
* Add incomplete builder experiments
* Add first working version of beacon chain builder
* Update test harness to new beacon chain type
* Rename builder file, tidy
* Add first working client builder
* Progress further on client builder
* Update becaon node binary to use client builder
* Ensure release tests compile
* Remove old eth1 crate
* Add first pass of new lighthouse binary
* Fix websocket server startup
* Remove old binary code from beacon_node crate
* Add first working beacon node tests
* Add genesis crate, new eth1 cache_2
* Add Serivce to Eth1Cache
* Refactor with general eth1 improvements
* Add passing genesis test
* Tidy, add comments
* Add more comments to eth1 service
* Add further eth1 progress
* Fix some bugs with genesis
* Fix eth1 bugs, make eth1 linking more efficient
* Shift logic in genesis service
* Add more comments to genesis service
* Add gzip, max request values, timeouts to http
* Update testnet parameters to suit goerli testnet
* Add ability to vary Fork, fix custom spec
* Be more explicit about deposit fork version
* Start adding beacon chain eth1 option
* Add more flexibility to prod client
* Further runtime refactoring
* Allow for starting from store
* Add bootstrapping to client config
* Add remote_beacon_node crate
* Update eth1 service for more configurability
* Update eth1 tests to use less runtimes
* Patch issues with tests using too many files
* Move dummy eth1 backend flag
* Ensure all tests pass
* Add ganache-cli to Dockerfile
* Use a special docker hub image for testing
* Appease clippy
* Move validator client into lighthouse binary
* Allow starting with dummy eth1 backend
* Improve logging
* Fix dummy eth1 backend from cli
* Add extra testnet command
* Ensure consistent spec in beacon node
* Update eth1 rig to work on goerli
* Tidy lcli, start adding support for yaml config
* Add incomplete YamlConfig struct
* Remove efforts at YamlConfig
* Add incomplete eth1 voting. Blocked on spec issues
* Add (untested) first pass at eth1 vote algo
* Add tests for winning vote
* Add more tests for eth1 chain
* Add more eth1 voting tests
* Added more eth1 voting testing
* Change test name
* Add more tests to eth1 chain
* Tidy eth1 generics, add more tests
* Improve comments
* Tidy beacon_node tests
* Tidy, rename JsonRpc.. to Caching..
* Tidy voting logic
* Tidy builder docs
* Add comments, tidy eth1
* Add more comments to eth1
* Fix bug with winning_vote
* Add doc comments to the `ClientBuilder`
* Remove commented-out code
* Improve `ClientBuilder` docs
* Add comments to client config
* Add decoding test for `ClientConfig`
* Remove unused `DepositSet` struct
* Tidy `block_cache`
* Remove commented out lines
* Remove unused code in `eth1` crate
* Remove old validator binary `main.rs`
* Tidy, fix tests compile error
* Add initial tests for get_deposits
* Remove dead code in eth1_test_rig
* Update TestingDepositBuilder
* Add testing for getting eth1 deposits
* Fix duplicate rand dep
* Remove dead code
* Remove accidentally-added files
* Fix comment in eth1_genesis_service
* Add .gitignore for eth1_test_rig
* Fix bug in eth1_genesis_service
* Remove dead code from eth2_config
* Fix tabs/spaces in root Cargo.toml
* Tidy eth1 crate
* Allow for re-use of eth1 service after genesis
* Update docs for new CLI
* Change README gif
* Tidy eth1 http module
* Tidy eth1 service
* Tidy environment crate
* Remove unused file
* Tidy, add comments
* Remove commented-out code
* Address majority of Michael's comments
* Address other PR comments
* Add link to issue alongside TODO
2019-11-15 03:47:51 +00:00
|
|
|
// The block is not signed here, that is the task of a validator client.
|
|
|
|
signature: Signature::empty_signature(),
|
2019-02-14 01:09:18 +00:00
|
|
|
};
|
|
|
|
|
2019-08-29 01:34:25 +00:00
|
|
|
per_block_processing(
|
|
|
|
&mut state,
|
|
|
|
&block,
|
|
|
|
None,
|
|
|
|
BlockSignatureStrategy::NoVerification,
|
|
|
|
&self.spec,
|
|
|
|
)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-12-09 03:20:25 +00:00
|
|
|
let state_root = state.update_tree_hash_cache()?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
block.message.state_root = state_root;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::BLOCK_PRODUCTION_SUCCESSES);
|
|
|
|
metrics::stop_timer(timer);
|
2019-05-28 07:30:09 +00:00
|
|
|
|
2019-09-09 20:43:08 +00:00
|
|
|
trace!(
|
|
|
|
self.log,
|
|
|
|
"Produced beacon block";
|
2020-02-10 23:19:36 +00:00
|
|
|
"parent" => format!("{}", block.message.parent_root),
|
|
|
|
"attestations" => block.message.body.attestations.len(),
|
|
|
|
"slot" => block.message.slot
|
2019-09-09 20:43:08 +00:00
|
|
|
);
|
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
Ok((block.message, state))
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-05-29 07:52:43 +00:00
|
|
|
/// Execute the fork choice algorithm and enthrone the result as the canonical head.
|
2019-02-14 01:09:18 +00:00
|
|
|
pub fn fork_choice(&self) -> Result<(), Error> {
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::FORK_CHOICE_REQUESTS);
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// Start fork choice metrics timer.
|
2019-08-19 11:02:34 +00:00
|
|
|
let timer = metrics::start_timer(&metrics::FORK_CHOICE_TIMES);
|
2019-05-29 07:52:43 +00:00
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// Determine the root of the block that is the head of the chain.
|
2019-06-15 19:05:34 +00:00
|
|
|
let beacon_block_root = self.fork_choice.find_head(&self)?;
|
2019-05-29 07:52:43 +00:00
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// If a new head was chosen.
|
2020-01-06 06:30:37 +00:00
|
|
|
let result = if beacon_block_root != self.head_info()?.block_root {
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::FORK_CHOICE_CHANGED_HEAD);
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2020-02-10 00:30:21 +00:00
|
|
|
let beacon_block = self
|
|
|
|
.get_block(&beacon_block_root)?
|
2019-05-31 07:51:32 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconBlock(beacon_block_root))?;
|
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
let beacon_state_root = beacon_block.state_root();
|
2019-05-31 07:51:32 +00:00
|
|
|
let beacon_state: BeaconState<T::EthSpec> = self
|
2020-02-10 23:19:36 +00:00
|
|
|
.get_state(&beacon_state_root, Some(beacon_block.slot()))?
|
2019-05-31 07:51:32 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconState(beacon_state_root))?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2020-01-06 06:30:37 +00:00
|
|
|
let previous_slot = self.head_info()?.slot;
|
2020-02-10 23:19:36 +00:00
|
|
|
let new_slot = beacon_block.slot();
|
2019-07-29 03:45:45 +00:00
|
|
|
|
2019-12-09 12:14:13 +00:00
|
|
|
// Note: this will declare a re-org if we skip `SLOTS_PER_HISTORICAL_ROOT` blocks
|
|
|
|
// between calls to fork choice without swapping between chains. This seems like an
|
|
|
|
// extreme-enough scenario that a warning is fine.
|
2020-01-06 06:30:37 +00:00
|
|
|
let is_reorg = self.head_info()?.block_root
|
2019-12-09 12:14:13 +00:00
|
|
|
!= beacon_state
|
2020-01-06 06:30:37 +00:00
|
|
|
.get_block_root(self.head_info()?.slot)
|
2019-12-09 12:14:13 +00:00
|
|
|
.map(|root| *root)
|
|
|
|
.unwrap_or_else(|_| Hash256::random());
|
2019-09-15 02:26:09 +00:00
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// If we switched to a new chain (instead of building atop the present chain).
|
2019-09-15 02:26:09 +00:00
|
|
|
if is_reorg {
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::FORK_CHOICE_REORG_COUNT);
|
2019-07-29 03:45:45 +00:00
|
|
|
warn!(
|
|
|
|
self.log,
|
|
|
|
"Beacon chain re-org";
|
2020-01-06 06:30:37 +00:00
|
|
|
"previous_head" => format!("{}", self.head_info()?.block_root),
|
2019-07-29 03:45:45 +00:00
|
|
|
"previous_slot" => previous_slot,
|
2020-02-10 23:19:36 +00:00
|
|
|
"new_head_parent" => format!("{}", beacon_block.parent_root()),
|
2019-09-09 20:43:08 +00:00
|
|
|
"new_head" => format!("{}", beacon_block_root),
|
2019-07-29 03:45:45 +00:00
|
|
|
"new_slot" => new_slot
|
|
|
|
);
|
|
|
|
} else {
|
2019-10-02 01:04:56 +00:00
|
|
|
debug!(
|
|
|
|
self.log,
|
|
|
|
"Head beacon block";
|
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
|
|
|
"justified_root" => format!("{}", beacon_state.current_justified_checkpoint.root),
|
2019-09-09 21:12:47 +00:00
|
|
|
"justified_epoch" => beacon_state.current_justified_checkpoint.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
|
|
|
"finalized_root" => format!("{}", beacon_state.finalized_checkpoint.root),
|
2019-09-09 21:12:47 +00:00
|
|
|
"finalized_epoch" => beacon_state.finalized_checkpoint.epoch,
|
2019-12-06 07:44:38 +00:00
|
|
|
"root" => format!("{}", beacon_block_root),
|
|
|
|
"slot" => new_slot,
|
2019-07-29 03:45:45 +00:00
|
|
|
);
|
2019-05-29 07:52:43 +00:00
|
|
|
};
|
|
|
|
|
2020-01-06 06:30:37 +00:00
|
|
|
let old_finalized_epoch = self.head_info()?.finalized_checkpoint.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
|
|
|
let new_finalized_epoch = beacon_state.finalized_checkpoint.epoch;
|
|
|
|
let finalized_root = beacon_state.finalized_checkpoint.root;
|
2019-06-23 04:47:23 +00:00
|
|
|
|
|
|
|
// Never revert back past a finalized epoch.
|
|
|
|
if new_finalized_epoch < old_finalized_epoch {
|
|
|
|
Err(Error::RevertedFinalizedEpoch {
|
|
|
|
previous_epoch: old_finalized_epoch,
|
|
|
|
new_epoch: new_finalized_epoch,
|
|
|
|
})
|
|
|
|
} else {
|
2020-01-06 06:30:37 +00:00
|
|
|
let previous_head_beacon_block_root = self
|
|
|
|
.canonical_head
|
|
|
|
.try_read_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?
|
|
|
|
.beacon_block_root;
|
2019-09-15 02:26:09 +00:00
|
|
|
let current_head_beacon_block_root = beacon_block_root;
|
|
|
|
|
|
|
|
let mut new_head = CheckPoint {
|
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
|
|
|
beacon_block,
|
2019-06-23 04:47:23 +00:00
|
|
|
beacon_block_root,
|
|
|
|
beacon_state,
|
|
|
|
beacon_state_root,
|
2019-09-15 02:26:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
new_head.beacon_state.build_all_caches(&self.spec)?;
|
|
|
|
|
|
|
|
let timer = metrics::start_timer(&metrics::UPDATE_HEAD_TIMES);
|
|
|
|
|
|
|
|
// Update the checkpoint that stores the head of the chain at the time it received the
|
|
|
|
// block.
|
2020-01-06 06:30:37 +00:00
|
|
|
*self
|
|
|
|
.canonical_head
|
|
|
|
.try_write_for(HEAD_LOCK_TIMEOUT)
|
|
|
|
.ok_or_else(|| Error::CanonicalHeadLockTimeout)? = new_head;
|
2019-09-15 02:26:09 +00:00
|
|
|
|
|
|
|
metrics::stop_timer(timer);
|
|
|
|
|
2020-03-06 05:09:41 +00:00
|
|
|
if previous_slot.epoch(T::EthSpec::slots_per_epoch())
|
|
|
|
< new_slot.epoch(T::EthSpec::slots_per_epoch())
|
|
|
|
|| is_reorg
|
|
|
|
{
|
|
|
|
self.persist_head_and_fork_choice()?;
|
|
|
|
}
|
2019-09-15 02:26:09 +00:00
|
|
|
|
|
|
|
let _ = self.event_handler.register(EventKind::BeaconHeadChanged {
|
|
|
|
reorg: is_reorg,
|
|
|
|
previous_head_beacon_block_root,
|
|
|
|
current_head_beacon_block_root,
|
|
|
|
});
|
2019-06-23 04:47:23 +00:00
|
|
|
|
|
|
|
if new_finalized_epoch != old_finalized_epoch {
|
|
|
|
self.after_finalization(old_finalized_epoch, finalized_root)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ok(())
|
2019-08-19 11:02:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// End fork choice metrics timer.
|
|
|
|
metrics::stop_timer(timer);
|
|
|
|
|
2019-09-30 03:58:45 +00:00
|
|
|
if result.is_err() {
|
2019-08-19 11:02:34 +00:00
|
|
|
metrics::inc_counter(&metrics::FORK_CHOICE_ERRORS);
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
2019-08-19 11:02:34 +00:00
|
|
|
|
|
|
|
result
|
2019-06-23 04:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Called after `self` has had a new block finalized.
|
|
|
|
///
|
|
|
|
/// Performs pruning and finality-based optimizations.
|
|
|
|
fn after_finalization(
|
|
|
|
&self,
|
|
|
|
old_finalized_epoch: Epoch,
|
|
|
|
finalized_block_root: Hash256,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let finalized_block = self
|
|
|
|
.store
|
2020-02-10 00:30:21 +00:00
|
|
|
.get_block(&finalized_block_root)?
|
2020-02-10 23:19:36 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconBlock(finalized_block_root))?
|
|
|
|
.message;
|
2019-06-23 04:47:23 +00:00
|
|
|
|
|
|
|
let new_finalized_epoch = finalized_block.slot.epoch(T::EthSpec::slots_per_epoch());
|
|
|
|
|
|
|
|
if new_finalized_epoch < old_finalized_epoch {
|
|
|
|
Err(Error::RevertedFinalizedEpoch {
|
|
|
|
previous_epoch: old_finalized_epoch,
|
|
|
|
new_epoch: new_finalized_epoch,
|
|
|
|
})
|
|
|
|
} else {
|
2020-01-29 04:05:00 +00:00
|
|
|
self.fork_choice.prune()?;
|
2019-06-23 04:47:23 +00:00
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
let finalized_state = self
|
2020-01-08 02:58:01 +00:00
|
|
|
.get_state_caching_only_with_committee_caches(
|
|
|
|
&finalized_block.state_root,
|
|
|
|
Some(finalized_block.slot),
|
|
|
|
)?
|
2019-08-19 11:02:34 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconState(finalized_block.state_root))?;
|
|
|
|
|
|
|
|
self.op_pool.prune_all(&finalized_state, &self.spec);
|
|
|
|
|
2019-11-26 23:54:46 +00:00
|
|
|
// TODO: configurable max finality distance
|
|
|
|
let max_finality_distance = 0;
|
|
|
|
self.store_migrator.freeze_to_state(
|
|
|
|
finalized_block.state_root,
|
|
|
|
finalized_state,
|
|
|
|
max_finality_distance,
|
|
|
|
);
|
|
|
|
|
2019-09-15 02:26:09 +00:00
|
|
|
let _ = self.event_handler.register(EventKind::BeaconFinalization {
|
|
|
|
epoch: new_finalized_epoch,
|
|
|
|
root: finalized_block_root,
|
|
|
|
});
|
|
|
|
|
2019-06-23 04:47:23 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 08:09:01 +00:00
|
|
|
/// Returns `true` if the given block root has not been processed.
|
|
|
|
pub fn is_new_block_root(&self, beacon_block_root: &Hash256) -> Result<bool, Error> {
|
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
|
|
|
Ok(!self
|
|
|
|
.store
|
2020-02-10 23:19:36 +00:00
|
|
|
.exists::<SignedBeaconBlock<T::EthSpec>>(beacon_block_root)?)
|
2019-03-29 08:09:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 05:53:59 +00:00
|
|
|
/// Dumps the entire canonical chain, from the head to genesis to a vector for analysis.
|
|
|
|
///
|
|
|
|
/// This could be a very expensive operation and should only be done in testing/analysis
|
|
|
|
/// activities.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub fn chain_dump(&self) -> Result<Vec<CheckPoint<T::EthSpec>>, Error> {
|
2019-03-18 05:53:59 +00:00
|
|
|
let mut dump = vec![];
|
|
|
|
|
|
|
|
let mut last_slot = CheckPoint {
|
2020-01-21 07:38:56 +00:00
|
|
|
beacon_block: self.head()?.beacon_block,
|
2020-01-06 06:30:37 +00:00
|
|
|
beacon_block_root: self.head()?.beacon_block_root,
|
2020-01-21 07:38:56 +00:00
|
|
|
beacon_state: self.head()?.beacon_state,
|
2020-01-06 06:30:37 +00:00
|
|
|
beacon_state_root: self.head()?.beacon_state_root,
|
2019-03-18 05:53:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dump.push(last_slot.clone());
|
|
|
|
|
|
|
|
loop {
|
2020-02-10 23:19:36 +00:00
|
|
|
let beacon_block_root = last_slot.beacon_block.parent_root();
|
2019-03-18 05:53:59 +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
|
|
|
if beacon_block_root == Hash256::zero() {
|
2019-03-18 05:53:59 +00:00
|
|
|
break; // Genesis has been reached.
|
|
|
|
}
|
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
let beacon_block = self.store.get_block(&beacon_block_root)?.ok_or_else(|| {
|
|
|
|
Error::DBInconsistent(format!("Missing block {}", beacon_block_root))
|
|
|
|
})?;
|
|
|
|
let beacon_state_root = beacon_block.state_root();
|
2019-11-26 23:54:46 +00:00
|
|
|
let beacon_state = self
|
|
|
|
.store
|
2020-02-10 23:19:36 +00:00
|
|
|
.get_state(&beacon_state_root, Some(beacon_block.slot()))?
|
2019-11-26 23:54:46 +00:00
|
|
|
.ok_or_else(|| {
|
|
|
|
Error::DBInconsistent(format!("Missing state {:?}", beacon_state_root))
|
|
|
|
})?;
|
2019-03-18 05:53:59 +00:00
|
|
|
|
|
|
|
let slot = CheckPoint {
|
|
|
|
beacon_block,
|
|
|
|
beacon_block_root,
|
|
|
|
beacon_state,
|
|
|
|
beacon_state_root,
|
|
|
|
};
|
|
|
|
|
|
|
|
dump.push(slot.clone());
|
|
|
|
last_slot = slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump.reverse();
|
|
|
|
|
|
|
|
Ok(dump)
|
|
|
|
}
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
impl<T: BeaconChainTypes> Drop for BeaconChain<T> {
|
|
|
|
fn drop(&mut self) {
|
2020-03-06 05:09:41 +00:00
|
|
|
let drop = || -> Result<(), Error> {
|
|
|
|
self.persist_head_and_fork_choice()?;
|
|
|
|
self.persist_op_pool()?;
|
|
|
|
self.persist_eth1_cache()
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Err(e) = drop() {
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
error!(
|
|
|
|
self.log,
|
2020-03-06 05:09:41 +00:00
|
|
|
"Failed to persist on BeaconChain drop";
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
"error" => format!("{:?}", e)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
info!(
|
|
|
|
self.log,
|
2020-03-06 05:09:41 +00:00
|
|
|
"Saved beacon chain to disk";
|
Prepare for public testnet (#628)
* Update to spec v0.9.0
* Update to v0.9.1
* Bump spec tags for v0.9.1
* Formatting, fix CI failures
* Resolve accidental KeyPair merge conflict
* Document new BeaconState functions
* Add `validator` changes from `validator-to-rest`
* Add initial (failing) REST api tests
* Fix signature parsing
* Add more tests
* Refactor http router
* Add working tests for publish beacon block
* Add validator duties tests
* Move account_manager under `lighthouse` binary
* Unify logfile handling in `environment` crate.
* Fix incorrect cache drops in `advance_caches`
* Update fork choice for v0.9.1
* Add `deposit_contract` crate
* Add progress on validator onboarding
* Add unfinished attesation code
* Update account manager CLI
* Write eth1 data file as hex string
* Integrate ValidatorDirectory with validator_client
* Move ValidatorDirectory into validator_client
* Clean up some FIXMEs
* Add beacon_chain_sim
* Fix a few docs/logs
* Expand `beacon_chain_sim`
* Fix spec for `beacon_chain_sim
* More testing for api
* Start work on attestation endpoint
* Reject empty attestations
* Allow attestations to genesis block
* Add working tests for `rest_api` validator endpoint
* Remove grpc from beacon_node
* Start heavy refactor of validator client
- Block production is working
* Prune old validator client files
* Start works on attestation service
* Add attestation service to validator client
* Use full pubkey for validator directories
* Add validator duties post endpoint
* Use par_iter for keypair generation
* Use bulk duties request in validator client
* Add version http endpoint tests
* Add interop keys and startup wait
* Ensure a prompt exit
* Add duties pruning
* Fix compile error in beacon node tests
* Add github workflow
* Modify rust.yaml
* Modify gitlab actions
* Add to CI file
* Add sudo to CI npm install
* Move cargo fmt to own job in tests
* Fix cargo fmt in CI
* Add rustup update before cargo fmt
* Change name of CI job
* Make other CI jobs require cargo fmt
* Add CI badge
* Remove gitlab and travis files
* Add different http timeout for debug
* Update docker file, use makefile in CI
* Use make in the dockerfile, skip the test
* Use the makefile for debug GI test
* Update book
* Tidy grpc and misc things
* Apply discv5 fixes
* Address other minor issues
* Fix warnings
* Attempt fix for addr parsing
* Tidy validator config, CLIs
* Tidy comments
* Tidy signing, reduce ForkService duplication
* Fail if skipping too many slots
* Set default recent genesis time to 0
* Add custom http timeout to validator
* Fix compile bug in node_test_rig
* Remove old bootstrap flag from val CLI
* Update docs
* Tidy val client
* Change val client log levels
* Add comments, more validity checks
* Fix compile error, add comments
* Undo changes to eth2-libp2p/src
* Reduce duplication of keypair generation
* Add more logging for validator duties
* Fix beacon_chain_sim, nitpicks
* Fix compile error, minor nits
* Update to use v0.9.2 version of deposit contract
* Add efforts to automate eth1 testnet deployment
* Fix lcli testnet deployer
* Modify bn CLI to parse eth2_testnet_dir
* Progress with account_manager deposit tools
* Make account manager submit deposits
* Add password option for submitting deposits
* Allow custom deposit amount
* Add long names to lcli clap
* Add password option to lcli deploy command
* Fix minor bugs whilst testing
* Address Michael's comments
* Add refund-deposit-contract to lcli
* Use time instead of skip count for denying long skips
* Improve logging for eth1
* Fix bug with validator services exiting on error
* Drop the block cache after genesis
* Modify eth1 testnet config
* Improve eth1 logging
* Make validator wait until genesis time
* Fix bug in eth1 voting
* Add more logging to eth1 voting
* Handle errors in eth1 http module
* Set SECONDS_PER_DAY to sensible minimum
* Shorten delay before testnet start
* Ensure eth1 block is produced without any votes
* Improve eth1 logging
* Fix broken tests in eth1
* Tidy code in rest_api
* Fix failing test in deposit_contract
* Make CLI args more consistent
* Change validator/duties endpoint
* Add time-based skip slot limiting
* Add new error type missed in previous commit
* Add log when waiting for genesis
* Refactor beacon node CLI
* Remove unused dep
* Add lcli eth1-genesis command
* Fix bug in master merge
* Apply clippy lints to beacon node
* Add support for YamlConfig in Eth2TestnetDir
* Upgrade tesnet deposit contract version
* Remove unnecessary logging and correct formatting
* Add a hardcoded eth2 testnet config
* Ensure http server flag works. Overwrite configs with flags.
* Ensure boot nodes are loaded from testnet dir
* Fix account manager CLI bugs
* Fix bugs with beacon node cli
* Allow testnet dir without boot nodes
* Write genesis state as SSZ
* Remove ---/n from the start of testnet_dir files
* Set default libp2p address
* Tidy account manager CLI, add logging
* Add check to see if testnet dir exists
* Apply reviewers suggestions
* Add HeadTracker struct
* Add fork choice persistence
* Shorten slot time for simulator
* Add the /beacon/heads API endpoint
* Update hardcoded testnet
* Add tests for BeaconChain persistence + fix bugs
* Extend BeaconChain persistence testing
* Ensure chain is finalized b4 persistence tests
* Ensure boot_enr.yaml is include in binary
* Refactor beacon_chain_sim
* Move files about in beacon sim
* Update beacon_chain_sim
* Fix bug with deposit inclusion
* Increase log in genesis service, fix todo
* Tidy sim, fix broken rest_api tests
* Fix more broken tests
* Update testnet
* Fix broken rest api test
* Tidy account manager CLI
* Use tempdir for account manager
* Stop hardcoded testnet dir from creating dir
* Rename Eth2TestnetDir to Eth2TestnetConfig
* Change hardcoded -> hard_coded
* Tidy account manager
* Add log to account manager
* Tidy, ensure head tracker is loaded from disk
* Tidy beacon chain builder
* Tidy eth1_chain
* Adds log support for simulator
* Revert "Adds log support for simulator"
This reverts commit ec77c66a052350f551db145cf20f213823428dd3.
* Adds log support for simulator
* Tidy after self-review
* Change default log level
* Address Michael's delicious PR comments
* Fix off-by-one in tests
2019-12-03 04:28:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 00:55:15 +00:00
|
|
|
fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) {
|
2019-09-09 01:57:48 +00:00
|
|
|
if WRITE_BLOCK_PROCESSING_SSZ {
|
2020-03-04 21:07:27 +00:00
|
|
|
let root = state.tree_hash_root();
|
2019-09-09 01:57:48 +00:00
|
|
|
let filename = format!("{}_slot_{}_root_{}.ssz", prefix, state.slot, root);
|
|
|
|
let mut path = std::env::temp_dir().join("lighthouse");
|
|
|
|
let _ = fs::create_dir_all(path.clone());
|
|
|
|
path = path.join(filename);
|
|
|
|
|
|
|
|
match fs::File::create(path.clone()) {
|
|
|
|
Ok(mut file) => {
|
|
|
|
let _ = file.write_all(&state.as_ssz_bytes());
|
|
|
|
}
|
|
|
|
Err(e) => error!(
|
|
|
|
log,
|
|
|
|
"Failed to log state";
|
|
|
|
"path" => format!("{:?}", path),
|
|
|
|
"error" => format!("{:?}", e)
|
|
|
|
),
|
2019-09-09 00:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_block<T: EthSpec>(block: &BeaconBlock<T>, root: Hash256, log: &Logger) {
|
2019-09-09 01:57:48 +00:00
|
|
|
if WRITE_BLOCK_PROCESSING_SSZ {
|
|
|
|
let filename = format!("block_slot_{}_root{}.ssz", block.slot, root);
|
|
|
|
let mut path = std::env::temp_dir().join("lighthouse");
|
|
|
|
let _ = fs::create_dir_all(path.clone());
|
|
|
|
path = path.join(filename);
|
|
|
|
|
|
|
|
match fs::File::create(path.clone()) {
|
|
|
|
Ok(mut file) => {
|
|
|
|
let _ = file.write_all(&block.as_ssz_bytes());
|
|
|
|
}
|
|
|
|
Err(e) => error!(
|
|
|
|
log,
|
|
|
|
"Failed to log block";
|
|
|
|
"path" => format!("{:?}", path),
|
|
|
|
"error" => format!("{:?}", e)
|
|
|
|
),
|
2019-09-09 00:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
impl From<DBError> for Error {
|
|
|
|
fn from(e: DBError) -> Error {
|
2019-05-21 07:27:06 +00:00
|
|
|
Error::DBError(e)
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ForkChoiceError> for Error {
|
|
|
|
fn from(e: ForkChoiceError) -> Error {
|
|
|
|
Error::ForkChoiceError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 05:12:24 +00:00
|
|
|
impl From<BeaconStateError> for Error {
|
|
|
|
fn from(e: BeaconStateError) -> Error {
|
|
|
|
Error::BeaconStateError(e)
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
}
|