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-06-15 18:03:29 +00:00
|
|
|
use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
|
2019-08-05 06:25:21 +00:00
|
|
|
use crate::iter::{ReverseBlockRootIterator, ReverseStateRootIterator};
|
2019-05-28 07:30:09 +00:00
|
|
|
use crate::metrics::Metrics;
|
2019-05-27 06:13:32 +00:00
|
|
|
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
|
2019-06-15 18:03:29 +00:00
|
|
|
use lmd_ghost::LmdGhost;
|
2019-06-20 00:59:19 +00:00
|
|
|
use log::trace;
|
2019-03-29 07:54:01 +00:00
|
|
|
use operation_pool::DepositInsertStatus;
|
2019-06-18 07:55:18 +00:00
|
|
|
use operation_pool::{OperationPool, PersistedOperationPool};
|
2019-02-14 01:09:18 +00:00
|
|
|
use parking_lot::{RwLock, RwLockReadGuard};
|
2019-07-29 03:45:45 +00:00
|
|
|
use slog::{error, info, warn, Logger};
|
2019-02-14 01:09:18 +00:00
|
|
|
use slot_clock::SlotClock;
|
2019-03-30 08:11:52 +00:00
|
|
|
use state_processing::per_block_processing::errors::{
|
2019-08-06 17:17:15 +00:00
|
|
|
AttesterSlashingValidationError, DepositValidationError, ExitValidationError,
|
|
|
|
ProposerSlashingValidationError, TransferValidationError,
|
2019-03-29 07:54:01 +00:00
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
use state_processing::{
|
2019-08-06 17:17:15 +00:00
|
|
|
common, per_block_processing, per_block_processing_without_verifying_block_signature,
|
|
|
|
per_slot_processing, BlockProcessingError,
|
2019-02-14 01:09:18 +00:00
|
|
|
};
|
|
|
|
use std::sync::Arc;
|
2019-08-05 06:25:21 +00:00
|
|
|
use store::iter::{BlockRootsIterator, StateRootsIterator};
|
2019-05-21 08:20:23 +00:00
|
|
|
use store::{Error as DBError, 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------|
|
|
|
|
pub const GRAFFITI: &str = "sigp/lighthouse-0.0.0-prerelease";
|
|
|
|
|
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 },
|
2019-06-13 03:54:16 +00:00
|
|
|
/// The blocks parent_root is unknown.
|
|
|
|
ParentUnknown { parent: Hash256 },
|
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.
|
|
|
|
StateRootMismatch,
|
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.
|
|
|
|
FinalizedSlot,
|
|
|
|
/// Block is already known, no need to re-import.
|
|
|
|
BlockIsAlreadyKnown,
|
2019-02-14 01:09:18 +00:00
|
|
|
/// The block could not be applied to the state, it is invalid.
|
|
|
|
PerBlockProcessingError(BlockProcessingError),
|
|
|
|
}
|
|
|
|
|
2019-08-07 03:20:15 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum AttestationProcessingOutcome {
|
|
|
|
Processed,
|
|
|
|
UnknownHeadBlock { beacon_block_root: Hash256 },
|
|
|
|
}
|
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
pub trait BeaconChainTypes {
|
|
|
|
type Store: store::Store;
|
|
|
|
type SlotClock: slot_clock::SlotClock;
|
2019-06-15 18:03:29 +00:00
|
|
|
type LmdGhost: LmdGhost<Self::Store, Self::EthSpec>;
|
2019-05-25 10:51:15 +00:00
|
|
|
type EthSpec: types::EthSpec;
|
|
|
|
}
|
|
|
|
|
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-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-07-26 19:26:06 +00:00
|
|
|
/// Stores a "snapshot" of the chain at the time the head-of-the-chain block was received.
|
2019-05-25 10:51:15 +00:00
|
|
|
canonical_head: RwLock<CheckPoint<T::EthSpec>>,
|
2019-05-31 07:32:20 +00:00
|
|
|
/// The same state from `self.canonical_head`, but updated at the start of each slot with a
|
2019-07-26 19:26:06 +00:00
|
|
|
/// skip slot if no block is received. This is effectively a cache that avoids repeating calls
|
2019-05-31 07:32:20 +00:00
|
|
|
/// to `per_slot_processing`.
|
2019-05-30 08:38:41 +00:00
|
|
|
state: RwLock<BeaconState<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-05-31 07:32:20 +00:00
|
|
|
/// Stores metrics about this `BeaconChain`.
|
2019-05-28 07:30:09 +00:00
|
|
|
pub metrics: Metrics,
|
2019-07-29 03:45:45 +00:00
|
|
|
/// Logging to CLI, etc.
|
|
|
|
log: Logger,
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
impl<T: BeaconChainTypes> BeaconChain<T> {
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Instantiate a new Beacon Chain, from genesis.
|
2019-03-08 04:33:45 +00:00
|
|
|
pub fn from_genesis(
|
2019-05-25 10:51:15 +00:00
|
|
|
store: Arc<T::Store>,
|
|
|
|
slot_clock: T::SlotClock,
|
|
|
|
mut genesis_state: BeaconState<T::EthSpec>,
|
2019-08-06 03:29:27 +00:00
|
|
|
mut genesis_block: BeaconBlock<T::EthSpec>,
|
2019-02-14 01:09:18 +00:00
|
|
|
spec: ChainSpec,
|
2019-07-29 03:45:45 +00:00
|
|
|
log: Logger,
|
2019-02-14 01:09:18 +00:00
|
|
|
) -> Result<Self, Error> {
|
2019-06-16 06:24:33 +00:00
|
|
|
genesis_state.build_all_caches(&spec)?;
|
|
|
|
|
2019-08-06 03:29:27 +00:00
|
|
|
let genesis_state_root = genesis_state.canonical_root();
|
|
|
|
store.put(&genesis_state_root, &genesis_state)?;
|
|
|
|
|
|
|
|
genesis_block.state_root = genesis_state_root;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-06-01 05:02:19 +00:00
|
|
|
let genesis_block_root = genesis_block.block_header().canonical_root();
|
|
|
|
store.put(&genesis_block_root, &genesis_block)?;
|
2019-06-01 02:56:35 +00:00
|
|
|
|
2019-06-07 06:46:07 +00:00
|
|
|
// Also store the genesis block under the `ZERO_HASH` key.
|
2019-08-06 03:29:27 +00:00
|
|
|
let genesis_block_root = genesis_block.canonical_root();
|
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
|
|
|
store.put(&Hash256::zero(), &genesis_block)?;
|
2019-06-07 06:46:07 +00:00
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
let canonical_head = RwLock::new(CheckPoint::new(
|
|
|
|
genesis_block.clone(),
|
2019-06-01 05:02:19 +00:00
|
|
|
genesis_block_root,
|
2019-02-14 01:09:18 +00:00
|
|
|
genesis_state.clone(),
|
2019-08-06 03:29:27 +00:00
|
|
|
genesis_state_root,
|
2019-02-14 01:09:18 +00:00
|
|
|
));
|
|
|
|
|
2019-08-06 03:29:27 +00:00
|
|
|
info!(log, "BeaconChain init";
|
|
|
|
"genesis_validator_count" => genesis_state.validators.len(),
|
|
|
|
"genesis_state_root" => format!("{}", genesis_state_root),
|
|
|
|
"genesis_block_root" => format!("{}", genesis_block_root),
|
|
|
|
);
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
Ok(Self {
|
2019-06-08 11:57:25 +00:00
|
|
|
spec,
|
2019-02-14 01:09:18 +00:00
|
|
|
slot_clock,
|
2019-03-30 01:26:25 +00:00
|
|
|
op_pool: OperationPool::new(),
|
2019-02-22 05:14:16 +00:00
|
|
|
state: RwLock::new(genesis_state),
|
2019-02-14 01:09:18 +00:00
|
|
|
canonical_head,
|
2019-06-01 05:02:19 +00:00
|
|
|
genesis_block_root,
|
2019-06-23 04:47:23 +00:00
|
|
|
fork_choice: ForkChoice::new(store.clone(), &genesis_block, genesis_block_root),
|
2019-05-28 07:30:09 +00:00
|
|
|
metrics: Metrics::new()?,
|
2019-06-15 22:19:08 +00:00
|
|
|
store,
|
2019-07-29 03:45:45 +00:00
|
|
|
log,
|
2019-02-14 01:09:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-27 06:13:32 +00:00
|
|
|
/// Attempt to load an existing instance from the given `store`.
|
2019-06-08 11:57:25 +00:00
|
|
|
pub fn from_store(
|
|
|
|
store: Arc<T::Store>,
|
|
|
|
spec: ChainSpec,
|
2019-07-29 03:45:45 +00:00
|
|
|
log: Logger,
|
2019-06-08 11:57:25 +00:00
|
|
|
) -> Result<Option<BeaconChain<T>>, Error> {
|
2019-05-27 06:13:32 +00:00
|
|
|
let key = Hash256::from_slice(&BEACON_CHAIN_DB_KEY.as_bytes());
|
|
|
|
let p: PersistedBeaconChain<T> = match store.get(&key) {
|
|
|
|
Err(e) => return Err(e.into()),
|
|
|
|
Ok(None) => return Ok(None),
|
|
|
|
Ok(Some(p)) => p,
|
|
|
|
};
|
|
|
|
|
|
|
|
let slot_clock = T::SlotClock::new(
|
|
|
|
spec.genesis_slot,
|
|
|
|
p.state.genesis_time,
|
|
|
|
spec.seconds_per_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
|
|
|
let last_finalized_root = p.canonical_head.beacon_state.finalized_checkpoint.root;
|
2019-06-23 04:47:23 +00:00
|
|
|
let last_finalized_block = &p.canonical_head.beacon_block;
|
2019-05-27 06:13:32 +00:00
|
|
|
|
2019-06-18 07:55:18 +00:00
|
|
|
let op_pool = p.op_pool.into_operation_pool(&p.state, &spec);
|
|
|
|
|
2019-05-27 06:13:32 +00:00
|
|
|
Ok(Some(BeaconChain {
|
2019-06-08 11:57:25 +00:00
|
|
|
spec,
|
2019-05-27 06:13:32 +00:00
|
|
|
slot_clock,
|
2019-06-23 04:47:23 +00:00
|
|
|
fork_choice: ForkChoice::new(store.clone(), last_finalized_block, last_finalized_root),
|
2019-06-18 07:55:18 +00:00
|
|
|
op_pool,
|
2019-05-27 06:13:32 +00:00
|
|
|
canonical_head: RwLock::new(p.canonical_head),
|
|
|
|
state: RwLock::new(p.state),
|
2019-06-01 05:02:19 +00:00
|
|
|
genesis_block_root: p.genesis_block_root,
|
2019-05-28 07:30:09 +00:00
|
|
|
metrics: Metrics::new()?,
|
2019-06-15 18:03:29 +00:00
|
|
|
store,
|
2019-07-29 03:45:45 +00:00
|
|
|
log,
|
2019-05-27 06:13:32 +00:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Attempt to save this instance to `self.store`.
|
|
|
|
pub fn persist(&self) -> Result<(), Error> {
|
|
|
|
let p: PersistedBeaconChain<T> = PersistedBeaconChain {
|
|
|
|
canonical_head: self.canonical_head.read().clone(),
|
2019-06-18 07:55:18 +00:00
|
|
|
op_pool: PersistedOperationPool::from_operation_pool(&self.op_pool),
|
2019-06-01 05:02:19 +00:00
|
|
|
genesis_block_root: self.genesis_block_root,
|
2019-05-27 06:13:32 +00:00
|
|
|
state: self.state.read().clone(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let key = Hash256::from_slice(&BEACON_CHAIN_DB_KEY.as_bytes());
|
|
|
|
self.store.put(&key, &p)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-03-24 01:49:59 +00:00
|
|
|
/// Returns the beacon block body for each beacon block root in `roots`.
|
|
|
|
///
|
|
|
|
/// Fails if any root in `roots` does not have a corresponding 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
|
|
|
pub fn get_block_bodies(
|
|
|
|
&self,
|
|
|
|
roots: &[Hash256],
|
|
|
|
) -> Result<Vec<BeaconBlockBody<T::EthSpec>>, Error> {
|
|
|
|
let bodies: Result<Vec<_>, _> = roots
|
2019-03-24 01:49:59 +00:00
|
|
|
.iter()
|
|
|
|
.map(|root| match self.get_block(root)? {
|
|
|
|
Some(block) => Ok(block.body),
|
2019-06-10 15:01:25 +00:00
|
|
|
None => Err(Error::DBInconsistent(format!("Missing block: {}", root))),
|
2019-03-24 01:49:59 +00:00
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(bodies?)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the beacon block header for each beacon block root in `roots`.
|
|
|
|
///
|
|
|
|
/// Fails if any root in `roots` does not have a corresponding block.
|
|
|
|
pub fn get_block_headers(&self, roots: &[Hash256]) -> Result<Vec<BeaconBlockHeader>, Error> {
|
|
|
|
let headers: Result<Vec<BeaconBlockHeader>, _> = roots
|
|
|
|
.iter()
|
|
|
|
.map(|root| match self.get_block(root)? {
|
|
|
|
Some(block) => Ok(block.block_header()),
|
|
|
|
None => Err(Error::DBInconsistent("Missing block".into())),
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Ok(headers?)
|
|
|
|
}
|
2019-08-05 06:25:21 +00:00
|
|
|
|
|
|
|
/// Iterates through all the `BeaconBlock` roots and slots, first returning
|
|
|
|
/// `self.head().beacon_block` then all prior blocks until either genesis or if the database
|
|
|
|
/// fails to return a prior block.
|
2019-06-06 04:27:17 +00:00
|
|
|
///
|
2019-08-05 06:25:21 +00:00
|
|
|
/// Returns duplicate roots for skip-slots.
|
2019-06-06 04:27:17 +00:00
|
|
|
///
|
2019-08-05 06:25:21 +00:00
|
|
|
/// Iterator returns `(Hash256, Slot)`.
|
2019-06-05 03:33:32 +00:00
|
|
|
///
|
2019-08-05 06:25:21 +00:00
|
|
|
/// ## Note
|
2019-06-05 03:33:32 +00:00
|
|
|
///
|
2019-08-05 06:25:21 +00:00
|
|
|
/// Because 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.
|
2019-08-08 06:47:24 +00:00
|
|
|
pub fn rev_iter_block_roots(&self) -> ReverseBlockRootIterator<T::EthSpec, T::Store> {
|
2019-08-05 06:25:21 +00:00
|
|
|
let state = &self.head().beacon_state;
|
|
|
|
let block_root = self.head().beacon_block_root;
|
|
|
|
let block_slot = state.slot;
|
|
|
|
|
2019-08-08 06:47:24 +00:00
|
|
|
let iter = BlockRootsIterator::owned(self.store.clone(), state.clone());
|
2019-08-05 06:25:21 +00:00
|
|
|
|
|
|
|
ReverseBlockRootIterator::new((block_root, block_slot), iter)
|
2019-06-18 16:06:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 06:25:21 +00:00
|
|
|
/// Iterates through all the `BeaconState` roots and slots, first returning
|
|
|
|
/// `self.head().beacon_state` then all prior states until either genesis or if the database
|
|
|
|
/// fails to return a prior state.
|
|
|
|
///
|
|
|
|
/// Iterator returns `(Hash256, Slot)`.
|
2019-07-16 07:28:15 +00:00
|
|
|
///
|
2019-08-05 06:25:21 +00:00
|
|
|
/// ## Note
|
2019-07-16 07:28:15 +00:00
|
|
|
///
|
2019-08-05 06:25:21 +00:00
|
|
|
/// Because 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.
|
2019-08-08 06:47:24 +00:00
|
|
|
pub fn rev_iter_state_roots(&self) -> ReverseStateRootIterator<T::EthSpec, T::Store> {
|
2019-08-05 06:25:21 +00:00
|
|
|
let state = &self.head().beacon_state;
|
|
|
|
let state_root = self.head().beacon_state_root;
|
|
|
|
let state_slot = state.slot;
|
2019-06-18 16:06:23 +00:00
|
|
|
|
2019-08-08 06:47:24 +00:00
|
|
|
let iter = StateRootsIterator::owned(self.store.clone(), state.clone());
|
2019-08-05 06:25:21 +00:00
|
|
|
|
|
|
|
ReverseStateRootIterator::new((state_root, state_slot), iter)
|
2019-06-05 03:33:32 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
) -> Result<Option<BeaconBlock<T::EthSpec>>, Error> {
|
2019-05-21 07:27:06 +00:00
|
|
|
Ok(self.store.get(block_root)?)
|
2019-03-23 02:23:44 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 02:36:10 +00:00
|
|
|
/// Returns a read-lock guarded `BeaconState` which is the `canonical_head` that has been
|
|
|
|
/// updated to match the current slot clock.
|
2019-08-05 06:25:21 +00:00
|
|
|
pub fn speculative_state(&self) -> Result<RwLockReadGuard<BeaconState<T::EthSpec>>, Error> {
|
|
|
|
// TODO: ensure the state has done a catch-up.
|
|
|
|
|
|
|
|
Ok(self.state.read())
|
2019-06-01 02:36:10 +00:00
|
|
|
}
|
|
|
|
|
2019-05-31 07:32:20 +00:00
|
|
|
/// Returns a read-lock guarded `CheckPoint` struct for reading the head (as chosen by the
|
|
|
|
/// fork-choice rule).
|
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
pub fn head(&self) -> RwLockReadGuard<CheckPoint<T::EthSpec>> {
|
|
|
|
self.canonical_head.read()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the slot of the highest block in the canonical chain.
|
|
|
|
pub fn best_slot(&self) -> Slot {
|
|
|
|
self.canonical_head.read().beacon_block.slot
|
|
|
|
}
|
2019-03-24 05:35:07 +00:00
|
|
|
|
|
|
|
/// Ensures the current canonical `BeaconState` has been transitioned to match the `slot_clock`.
|
|
|
|
pub fn catchup_state(&self) -> Result<(), Error> {
|
2019-06-08 11:57:25 +00:00
|
|
|
let spec = &self.spec;
|
2019-05-31 07:32:20 +00:00
|
|
|
|
2019-03-24 05:35:07 +00:00
|
|
|
let present_slot = match self.slot_clock.present_slot() {
|
|
|
|
Ok(Some(slot)) => slot,
|
|
|
|
_ => return Err(Error::UnableToReadSlot),
|
|
|
|
};
|
|
|
|
|
2019-06-20 00:59:19 +00:00
|
|
|
if self.state.read().slot < present_slot {
|
|
|
|
let mut state = self.state.write();
|
2019-03-24 05:35:07 +00:00
|
|
|
|
2019-06-20 00:59:19 +00:00
|
|
|
// If required, transition the new state to the present slot.
|
|
|
|
for _ in state.slot.as_u64()..present_slot.as_u64() {
|
|
|
|
// Ensure the next epoch state caches are built in case of an epoch transition.
|
|
|
|
state.build_committee_cache(RelativeEpoch::Next, spec)?;
|
2019-03-26 23:34:52 +00:00
|
|
|
|
2019-06-20 00:59:19 +00:00
|
|
|
per_slot_processing(&mut *state, spec)?;
|
|
|
|
}
|
2019-03-31 02:40:12 +00:00
|
|
|
|
2019-06-20 00:59:19 +00:00
|
|
|
state.build_all_caches(spec)?;
|
|
|
|
}
|
2019-03-31 02:40:12 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Build all of the caches on the current state.
|
|
|
|
///
|
|
|
|
/// Ideally this shouldn't be required, however we leave it here for testing.
|
|
|
|
pub fn ensure_state_caches_are_built(&self) -> Result<(), Error> {
|
2019-06-08 11:57:25 +00:00
|
|
|
self.state.write().build_all_caches(&self.spec)?;
|
2019-03-24 05:35:07 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
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`.
|
2019-02-14 01:09:18 +00:00
|
|
|
pub fn validator_index(&self, pubkey: &PublicKey) -> Option<usize> {
|
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
|
|
|
for (i, validator) in self.head().beacon_state.validators.iter().enumerate() {
|
2019-02-14 01:09:18 +00:00
|
|
|
if validator.pubkey == *pubkey {
|
|
|
|
return Some(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reads the slot clock, returns `None` if the slot is unavailable.
|
|
|
|
///
|
|
|
|
/// 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).
|
|
|
|
///
|
|
|
|
/// This is distinct to `present_slot`, which simply reads the latest state. If a
|
|
|
|
/// call to `read_slot_clock` results in a higher slot than a call to `present_slot`,
|
|
|
|
/// `self.state` should undergo per slot processing.
|
|
|
|
pub fn read_slot_clock(&self) -> Option<Slot> {
|
|
|
|
match self.slot_clock.present_slot() {
|
|
|
|
Ok(Some(some_slot)) => Some(some_slot),
|
|
|
|
Ok(None) => None,
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-26 23:36:20 +00:00
|
|
|
/// Reads the slot clock (see `self.read_slot_clock()` and returns the number of slots since
|
|
|
|
/// genesis.
|
|
|
|
pub fn slots_since_genesis(&self) -> Option<SlotHeight> {
|
|
|
|
let now = self.read_slot_clock()?;
|
2019-06-08 11:57:25 +00:00
|
|
|
let genesis_slot = self.spec.genesis_slot;
|
2019-03-26 23:36:20 +00:00
|
|
|
|
2019-05-31 07:32:20 +00:00
|
|
|
if now < genesis_slot {
|
2019-03-26 23:36:20 +00:00
|
|
|
None
|
|
|
|
} else {
|
2019-05-31 07:32:20 +00:00
|
|
|
Some(SlotHeight::from(now.as_u64() - genesis_slot.as_u64()))
|
2019-03-26 23:36:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Returns slot of the present state.
|
|
|
|
///
|
|
|
|
/// This is distinct to `read_slot_clock`, which reads from the actual system clock. If
|
|
|
|
/// `self.state` has not been transitioned it is possible for the system clock to be on a
|
|
|
|
/// different slot to what is returned from this call.
|
|
|
|
pub fn present_slot(&self) -> Slot {
|
|
|
|
self.state.read().slot
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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> {
|
|
|
|
// Ensures that the present state has been advanced to the present slot, skipping slots if
|
|
|
|
// blocks are not present.
|
|
|
|
self.catchup_state()?;
|
|
|
|
|
|
|
|
// TODO: permit lookups of the proposer at any slot.
|
2019-03-17 07:10:20 +00:00
|
|
|
let index = self.state.read().get_beacon_proposer_index(
|
|
|
|
slot,
|
|
|
|
RelativeEpoch::Current,
|
2019-06-08 11:57:25 +00:00
|
|
|
&self.spec,
|
2019-03-17 07:10:20 +00:00
|
|
|
)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
Ok(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the attestation slot and shard for a given validator index.
|
|
|
|
///
|
|
|
|
/// Information is read from the current state, so only information from the present and prior
|
|
|
|
/// epoch is available.
|
2019-07-26 19:26:06 +00:00
|
|
|
pub fn validator_attestation_slot_and_shard(
|
2019-02-14 01:09:18 +00:00
|
|
|
&self,
|
|
|
|
validator_index: usize,
|
2019-02-15 05:12:24 +00:00
|
|
|
) -> Result<Option<(Slot, u64)>, BeaconStateError> {
|
2019-02-15 08:23:22 +00:00
|
|
|
trace!(
|
2019-07-26 19:26:06 +00:00
|
|
|
"BeaconChain::validator_attestation_slot_and_shard: validator_index: {}",
|
2019-02-15 08:23:22 +00:00
|
|
|
validator_index
|
|
|
|
);
|
2019-03-17 07:10:20 +00:00
|
|
|
if let Some(attestation_duty) = self
|
2019-02-22 05:14:16 +00:00
|
|
|
.state
|
2019-02-14 01:09:18 +00:00
|
|
|
.read()
|
2019-06-03 06:13:51 +00:00
|
|
|
.get_attestation_duties(validator_index, RelativeEpoch::Current)?
|
2019-02-14 01:09:18 +00:00
|
|
|
{
|
2019-03-17 07:10:20 +00:00
|
|
|
Ok(Some((attestation_duty.slot, attestation_duty.shard)))
|
2019-02-14 01:09:18 +00:00
|
|
|
} else {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
2019-06-21 01:37:02 +00:00
|
|
|
///
|
|
|
|
/// Attests to the canonical chain.
|
2019-03-30 05:02:09 +00:00
|
|
|
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
2019-06-20 08:46:03 +00:00
|
|
|
let state = self.state.read();
|
|
|
|
let head_block_root = self.head().beacon_block_root;
|
|
|
|
|
2019-08-08 06:47:24 +00:00
|
|
|
self.produce_attestation_data_for_block(shard, head_block_root, &*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.
|
2019-06-20 08:46:03 +00:00
|
|
|
pub fn produce_attestation_data_for_block(
|
|
|
|
&self,
|
|
|
|
shard: u64,
|
|
|
|
head_block_root: Hash256,
|
|
|
|
state: &BeaconState<T::EthSpec>,
|
|
|
|
) -> Result<AttestationData, Error> {
|
|
|
|
// Collect some metrics.
|
|
|
|
self.metrics.attestation_production_requests.inc();
|
|
|
|
let timer = self.metrics.attestation_production_times.start_timer();
|
|
|
|
|
|
|
|
// The `target_root` is the root of the first block of the current epoch.
|
2019-08-08 06:47:24 +00:00
|
|
|
let target_root = self
|
|
|
|
.rev_iter_block_roots()
|
|
|
|
.find(|(_root, slot)| *slot % T::EthSpec::slots_per_epoch() == 0)
|
|
|
|
.map(|(root, _slot)| root)
|
|
|
|
.ok_or_else(|| Error::UnableToFindTargetRoot(self.head().beacon_state.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
|
|
|
let target = Checkpoint {
|
|
|
|
epoch: state.current_epoch(),
|
|
|
|
root: target_root,
|
|
|
|
};
|
2019-06-20 08:46:03 +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_crosslink = state.get_current_crosslink(shard)?;
|
|
|
|
let crosslink = Crosslink {
|
|
|
|
shard,
|
|
|
|
parent_root: Hash256::from_slice(&parent_crosslink.tree_hash_root()),
|
|
|
|
start_epoch: parent_crosslink.end_epoch,
|
|
|
|
end_epoch: std::cmp::min(
|
|
|
|
target.epoch,
|
|
|
|
parent_crosslink.end_epoch + self.spec.max_epochs_per_crosslink,
|
|
|
|
),
|
|
|
|
data_root: Hash256::zero(),
|
|
|
|
};
|
2019-06-20 08:46:03 +00:00
|
|
|
|
|
|
|
// Collect some metrics.
|
|
|
|
self.metrics.attestation_production_successes.inc();
|
|
|
|
timer.observe_duration();
|
|
|
|
|
|
|
|
Ok(AttestationData {
|
|
|
|
beacon_block_root: head_block_root,
|
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
|
|
|
source: state.current_justified_checkpoint.clone(),
|
|
|
|
target,
|
|
|
|
crosslink,
|
2019-06-20 08:46:03 +00:00
|
|
|
})
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 06:47:24 +00:00
|
|
|
/// Accept a new, potentially invalid attestation from the network.
|
2019-03-29 07:40:50 +00:00
|
|
|
///
|
|
|
|
/// If valid, the attestation is added to the `op_pool` and aggregated with another attestation
|
|
|
|
/// if possible.
|
2019-08-07 03:20:15 +00:00
|
|
|
pub fn process_attestation(
|
|
|
|
&self,
|
|
|
|
attestation: Attestation<T::EthSpec>,
|
|
|
|
) -> Result<AttestationProcessingOutcome, Error> {
|
|
|
|
// From the store, load the attestation's "head block".
|
|
|
|
//
|
|
|
|
// An honest validator would have set this block to be the head of the chain (i.e., the
|
|
|
|
// result of running fork choice).
|
|
|
|
if let Some(attestation_head_block) = self
|
|
|
|
.store
|
|
|
|
.get::<BeaconBlock<T::EthSpec>>(&attestation.data.beacon_block_root)?
|
|
|
|
{
|
|
|
|
// Attempt to process the attestation using the `self.head()` state.
|
|
|
|
//
|
|
|
|
// This is purely an effort to avoid loading a `BeaconState` unnecessarily from the DB.
|
2019-08-07 06:02:30 +00:00
|
|
|
let optional_outcome: Option<Result<AttestationProcessingOutcome, Error>> = {
|
2019-08-07 03:20:15 +00:00
|
|
|
// Take a read lock on the head beacon state.
|
|
|
|
//
|
|
|
|
// The purpose of this whole `let processed ...` block is to ensure that the read
|
|
|
|
// lock is dropped if we don't end up using the head beacon state.
|
|
|
|
let state = &self.head().beacon_state;
|
|
|
|
|
|
|
|
// If it turns out that the attestation was made using the head state, then there
|
|
|
|
// is no need to load a state from the database to process the attestation.
|
|
|
|
if state.current_epoch() == attestation_head_block.epoch()
|
2019-08-07 06:02:30 +00:00
|
|
|
&& (state
|
2019-08-07 03:20:15 +00:00
|
|
|
.get_block_root(attestation_head_block.slot)
|
|
|
|
.map(|root| *root == attestation.data.beacon_block_root)
|
|
|
|
.unwrap_or_else(|_| false)
|
2019-08-07 06:02:30 +00:00
|
|
|
|| attestation.data.beacon_block_root == self.head().beacon_block_root)
|
2019-08-07 03:20:15 +00:00
|
|
|
{
|
|
|
|
// The head state is able to be used to validate this attestation. No need to load
|
|
|
|
// anything from the database.
|
|
|
|
Some(self.process_attestation_for_state_and_block(
|
|
|
|
attestation.clone(),
|
|
|
|
state,
|
|
|
|
&attestation_head_block,
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: we could try and see if the "speculative state" (e.g., self.state) can support
|
|
|
|
// this, without needing to load it from the db.
|
|
|
|
|
2019-08-07 06:02:30 +00:00
|
|
|
if let Some(outcome) = optional_outcome {
|
|
|
|
outcome
|
2019-08-07 03:20:15 +00:00
|
|
|
} else {
|
|
|
|
// The state required to verify this attestation must be loaded from the database.
|
|
|
|
let mut state: BeaconState<T::EthSpec> = self
|
|
|
|
.store
|
|
|
|
.get(&attestation_head_block.state_root)?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconState(attestation_head_block.state_root))?;
|
|
|
|
|
|
|
|
// Ensure the state loaded from the database matches the state of the attestation
|
|
|
|
// head block.
|
|
|
|
for _ in state.slot.as_u64()..attestation_head_block.slot.as_u64() {
|
|
|
|
per_slot_processing(&mut state, &self.spec)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.process_attestation_for_state_and_block(
|
|
|
|
attestation,
|
|
|
|
&state,
|
|
|
|
&attestation_head_block,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Reject any block where we have not processed `attestation.data.beacon_block_root`.
|
|
|
|
//
|
|
|
|
// This is likely overly restrictive, we could store the attestation for later
|
|
|
|
// processing.
|
|
|
|
warn!(
|
|
|
|
self.log,
|
|
|
|
"Dropping attestation for unknown block";
|
|
|
|
"block" => format!("{}", attestation.data.beacon_block_root)
|
|
|
|
);
|
|
|
|
Ok(AttestationProcessingOutcome::UnknownHeadBlock {
|
|
|
|
beacon_block_root: attestation.data.beacon_block_root,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn process_attestation_for_state_and_block(
|
|
|
|
&self,
|
|
|
|
attestation: Attestation<T::EthSpec>,
|
|
|
|
state: &BeaconState<T::EthSpec>,
|
2019-08-08 06:47:24 +00:00
|
|
|
block: &BeaconBlock<T::EthSpec>,
|
2019-08-07 03:20:15 +00:00
|
|
|
) -> Result<AttestationProcessingOutcome, Error> {
|
2019-05-29 07:52:43 +00:00
|
|
|
self.metrics.attestation_processing_requests.inc();
|
|
|
|
let timer = self.metrics.attestation_processing_times.start_timer();
|
|
|
|
|
2019-08-07 03:20:15 +00:00
|
|
|
if self
|
|
|
|
.fork_choice
|
|
|
|
.should_process_attestation(state, &attestation)?
|
|
|
|
{
|
|
|
|
// TODO: check validation.
|
|
|
|
let indexed_attestation = common::get_indexed_attestation(state, &attestation)?;
|
|
|
|
per_block_processing::is_valid_indexed_attestation(
|
|
|
|
state,
|
|
|
|
&indexed_attestation,
|
|
|
|
&self.spec,
|
|
|
|
)?;
|
|
|
|
self.fork_choice.process_attestation(&state, &attestation)?;
|
2019-07-11 14:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 11:57:25 +00:00
|
|
|
let result = self
|
|
|
|
.op_pool
|
2019-08-07 03:20:15 +00:00
|
|
|
.insert_attestation(attestation, state, &self.spec);
|
2019-05-29 07:52:43 +00:00
|
|
|
|
2019-06-15 22:19:08 +00:00
|
|
|
timer.observe_duration();
|
|
|
|
|
2019-05-29 07:52:43 +00:00
|
|
|
if result.is_ok() {
|
2019-06-04 07:10:25 +00:00
|
|
|
self.metrics.attestation_processing_successes.inc();
|
2019-05-29 07:52:43 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 03:20:15 +00:00
|
|
|
result
|
|
|
|
.map(|_| AttestationProcessingOutcome::Processed)
|
|
|
|
.map_err(|e| Error::AttestationValidationError(e))
|
|
|
|
}
|
|
|
|
|
2019-03-03 00:54:51 +00:00
|
|
|
/// Accept some deposit and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_deposit(
|
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
|
|
|
index: u64,
|
2019-03-29 07:54:01 +00:00
|
|
|
deposit: Deposit,
|
|
|
|
) -> Result<DepositInsertStatus, DepositValidationError> {
|
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
|
|
|
self.op_pool.insert_deposit(index, deposit)
|
2019-03-01 05:54:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:20:59 +00:00
|
|
|
/// Accept some exit and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_voluntary_exit(&self, exit: VoluntaryExit) -> Result<(), ExitValidationError> {
|
2019-03-29 07:54:01 +00:00
|
|
|
self.op_pool
|
2019-06-08 11:57:25 +00:00
|
|
|
.insert_voluntary_exit(exit, &*self.state.read(), &self.spec)
|
2019-03-04 01:20:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 06:23:11 +00:00
|
|
|
/// Accept some transfer and queue it for inclusion in an appropriate block.
|
2019-03-29 08:09:01 +00:00
|
|
|
pub fn process_transfer(&self, transfer: Transfer) -> Result<(), TransferValidationError> {
|
2019-03-29 07:54:01 +00:00
|
|
|
self.op_pool
|
2019-06-08 11:57:25 +00:00
|
|
|
.insert_transfer(transfer, &*self.state.read(), &self.spec)
|
2019-03-07 06:23:11 +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-06-08 11:57:25 +00:00
|
|
|
self.op_pool
|
|
|
|
.insert_proposer_slashing(proposer_slashing, &*self.state.read(), &self.spec)
|
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-06-08 11:57:25 +00:00
|
|
|
self.op_pool
|
|
|
|
.insert_attester_slashing(attester_slashing, &*self.state.read(), &self.spec)
|
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,
|
|
|
|
block: BeaconBlock<T::EthSpec>,
|
|
|
|
) -> Result<BlockProcessingOutcome, Error> {
|
2019-05-29 05:45:09 +00:00
|
|
|
self.metrics.block_processing_requests.inc();
|
2019-05-29 07:52:43 +00:00
|
|
|
let timer = self.metrics.block_processing_times.start_timer();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-06-13 03:54:16 +00:00
|
|
|
let finalized_slot = self
|
|
|
|
.state
|
|
|
|
.read()
|
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-13 03:54:16 +00:00
|
|
|
if block.slot <= finalized_slot {
|
|
|
|
return Ok(BlockProcessingOutcome::FinalizedSlot);
|
|
|
|
}
|
|
|
|
|
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-03-19 23:51:53 +00:00
|
|
|
let block_root = block.block_header().canonical_root();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
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-06-20 00:59:19 +00:00
|
|
|
let present_slot = self
|
|
|
|
.read_slot_clock()
|
|
|
|
.ok_or_else(|| Error::UnableToReadSlot)?;
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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 self.store.exists::<BeaconBlock<T::EthSpec>>(&block_root)? {
|
2019-06-13 03:54:16 +00:00
|
|
|
return Ok(BlockProcessingOutcome::BlockIsAlreadyKnown);
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load the blocks parent block from the database, returning invalid if that block is not
|
|
|
|
// found.
|
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_block: BeaconBlock<T::EthSpec> = match self.store.get(&block.parent_root)? {
|
|
|
|
Some(block) => block,
|
2019-02-14 01:09:18 +00:00
|
|
|
None => {
|
2019-06-13 03:54:16 +00:00
|
|
|
return Ok(BlockProcessingOutcome::ParentUnknown {
|
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
|
|
|
parent: block.parent_root,
|
2019-06-13 03:54:16 +00:00
|
|
|
});
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load the parent blocks state from the database, returning an error if it is not found.
|
|
|
|
// It is an error because if know the parent block we should also know the parent state.
|
2019-03-17 07:10:20 +00:00
|
|
|
let parent_state_root = parent_block.state_root;
|
2019-02-14 01:09:18 +00:00
|
|
|
let parent_state = self
|
2019-05-21 07:27:06 +00:00
|
|
|
.store
|
|
|
|
.get(&parent_state_root)?
|
2019-03-17 07:10:20 +00:00
|
|
|
.ok_or_else(|| Error::DBInconsistent(format!("Missing state {}", parent_state_root)))?;
|
2019-02-14 01:09:18 +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-03-23 07:48:09 +00:00
|
|
|
for _ in state.slot.as_u64()..block.slot.as_u64() {
|
2019-06-13 03:54:16 +00:00
|
|
|
per_slot_processing(&mut state, &self.spec)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
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-02-14 01:09:18 +00:00
|
|
|
// Apply the received block to its parent state (which has been transitioned into this
|
|
|
|
// slot).
|
2019-06-13 03:54:16 +00:00
|
|
|
match per_block_processing(&mut state, &block, &self.spec) {
|
|
|
|
Err(BlockProcessingError::BeaconStateError(e)) => {
|
|
|
|
return Err(Error::BeaconStateError(e))
|
|
|
|
}
|
|
|
|
Err(e) => return Ok(BlockProcessingOutcome::PerBlockProcessingError(e)),
|
|
|
|
_ => {}
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let state_root = state.canonical_root();
|
|
|
|
|
|
|
|
if block.state_root != state_root {
|
2019-06-13 03:54:16 +00:00
|
|
|
return Ok(BlockProcessingOutcome::StateRootMismatch);
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Store the block and state.
|
2019-05-21 07:27:06 +00:00
|
|
|
self.store.put(&block_root, &block)?;
|
|
|
|
self.store.put(&state_root, &state)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-05-29 07:55:38 +00:00
|
|
|
// Register the new block with the fork choice service.
|
2019-07-29 03:45:45 +00:00
|
|
|
if let Err(e) = self.fork_choice.process_block(&state, &block, block_root) {
|
|
|
|
error!(
|
|
|
|
self.log,
|
|
|
|
"fork choice failed to process_block";
|
|
|
|
"error" => format!("{:?}", e),
|
|
|
|
"block_root" => format!("{}", block_root),
|
|
|
|
"block_slot" => format!("{}", block.slot)
|
|
|
|
)
|
|
|
|
}
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-05-29 07:55:38 +00:00
|
|
|
// Execute the fork choice algorithm, enthroning a new head if discovered.
|
2019-02-14 01:09:18 +00:00
|
|
|
//
|
2019-05-29 07:55:38 +00:00
|
|
|
// Note: in the future we may choose to run fork-choice less often, potentially based upon
|
|
|
|
// some heuristic around number of attestations seen for the block.
|
2019-07-29 03:45:45 +00:00
|
|
|
if let Err(e) = self.fork_choice() {
|
|
|
|
error!(
|
|
|
|
self.log,
|
|
|
|
"fork choice failed to find head";
|
|
|
|
"error" => format!("{:?}", e)
|
|
|
|
)
|
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-05-29 05:45:09 +00:00
|
|
|
self.metrics.block_processing_successes.inc();
|
2019-06-03 23:25:00 +00:00
|
|
|
self.metrics
|
|
|
|
.operations_per_block_attestation
|
|
|
|
.observe(block.body.attestations.len() as f64);
|
2019-05-29 05:45:09 +00:00
|
|
|
timer.observe_duration();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/// Produce a new block at the present slot.
|
|
|
|
///
|
|
|
|
/// 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,
|
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<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError> {
|
2019-06-18 17:01:58 +00:00
|
|
|
let state = self.state.read().clone();
|
|
|
|
let slot = self
|
|
|
|
.read_slot_clock()
|
|
|
|
.ok_or_else(|| BlockProductionError::UnableToReadSlot)?;
|
|
|
|
|
|
|
|
self.produce_block_on_state(state, slot, randao_reveal)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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,
|
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<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError> {
|
2019-05-28 07:30:09 +00:00
|
|
|
self.metrics.block_production_requests.inc();
|
2019-05-29 07:52:43 +00:00
|
|
|
let timer = self.metrics.block_production_times.start_timer();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-06-18 17:01:58 +00:00
|
|
|
// If required, transition the new state to the present slot.
|
2019-06-20 08:46:03 +00:00
|
|
|
while state.slot < produce_at_slot {
|
2019-06-18 17:01:58 +00:00
|
|
|
per_slot_processing(&mut state, &self.spec)?;
|
|
|
|
}
|
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
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
let mut block = BeaconBlock {
|
|
|
|
slot: state.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
|
|
|
parent_root,
|
2019-02-14 01:09:18 +00:00
|
|
|
state_root: Hash256::zero(), // Updated after the state is calculated.
|
2019-06-03 23:37:40 +00:00
|
|
|
signature: Signature::empty_signature(), // To be completed by a validator.
|
2019-02-14 01:09:18 +00:00
|
|
|
body: BeaconBlockBody {
|
2019-03-17 07:10:20 +00:00
|
|
|
randao_reveal,
|
2019-06-20 00:59:19 +00:00
|
|
|
// TODO: replace with real data.
|
2019-03-17 07:10:20 +00:00
|
|
|
eth1_data: Eth1Data {
|
2019-08-06 03:29:27 +00:00
|
|
|
deposit_count: state.eth1_data.deposit_count,
|
2019-03-17 07:10:20 +00:00
|
|
|
deposit_root: Hash256::zero(),
|
|
|
|
block_hash: Hash256::zero(),
|
|
|
|
},
|
2019-06-18 17:01:58 +00:00
|
|
|
graffiti,
|
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
|
|
|
proposer_slashings: proposer_slashings.into(),
|
|
|
|
attester_slashings: attester_slashings.into(),
|
|
|
|
attestations: self.op_pool.get_attestations(&state, &self.spec).into(),
|
|
|
|
deposits: self.op_pool.get_deposits(&state).into(),
|
|
|
|
voluntary_exits: self.op_pool.get_voluntary_exits(&state, &self.spec).into(),
|
|
|
|
transfers: self.op_pool.get_transfers(&state, &self.spec).into(),
|
2019-02-14 01:09:18 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-06-08 11:57:25 +00:00
|
|
|
per_block_processing_without_verifying_block_signature(&mut state, &block, &self.spec)?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
let state_root = state.canonical_root();
|
|
|
|
|
|
|
|
block.state_root = state_root;
|
|
|
|
|
2019-05-28 07:30:09 +00:00
|
|
|
self.metrics.block_production_successes.inc();
|
2019-05-29 05:45:09 +00:00
|
|
|
timer.observe_duration();
|
2019-05-28 07:30:09 +00:00
|
|
|
|
2019-03-07 01:53:15 +00:00
|
|
|
Ok((block, 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-05-29 07:52:43 +00:00
|
|
|
self.metrics.fork_choice_requests.inc();
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// Start fork choice metrics timer.
|
2019-05-29 07:52:43 +00:00
|
|
|
let timer = self.metrics.fork_choice_times.start_timer();
|
|
|
|
|
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
|
|
|
// End fork choice metrics timer.
|
2019-05-29 07:52:43 +00:00
|
|
|
timer.observe_duration();
|
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// If a new head was chosen.
|
|
|
|
if beacon_block_root != self.head().beacon_block_root {
|
2019-05-29 07:52:43 +00:00
|
|
|
self.metrics.fork_choice_changed_head.inc();
|
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 beacon_block: BeaconBlock<T::EthSpec> = self
|
2019-05-21 07:27:06 +00:00
|
|
|
.store
|
2019-05-31 07:51:32 +00:00
|
|
|
.get(&beacon_block_root)?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconBlock(beacon_block_root))?;
|
|
|
|
|
|
|
|
let beacon_state_root = beacon_block.state_root;
|
|
|
|
let beacon_state: BeaconState<T::EthSpec> = self
|
2019-05-21 07:27:06 +00:00
|
|
|
.store
|
2019-05-31 07:51:32 +00:00
|
|
|
.get(&beacon_state_root)?
|
|
|
|
.ok_or_else(|| Error::MissingBeaconState(beacon_state_root))?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-07-29 03:45:45 +00:00
|
|
|
let previous_slot = self.head().beacon_block.slot;
|
|
|
|
let new_slot = beacon_block.slot;
|
|
|
|
|
2019-05-31 07:51:32 +00:00
|
|
|
// If we switched to a new chain (instead of building atop the present chain).
|
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 self.head().beacon_block_root != beacon_block.parent_root {
|
2019-05-29 07:52:43 +00:00
|
|
|
self.metrics.fork_choice_reorg_count.inc();
|
2019-07-29 03:45:45 +00:00
|
|
|
warn!(
|
|
|
|
self.log,
|
|
|
|
"Beacon chain re-org";
|
|
|
|
"previous_slot" => previous_slot,
|
|
|
|
"new_slot" => new_slot
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
info!(
|
|
|
|
self.log,
|
|
|
|
"new head 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),
|
|
|
|
"finalized_root" => format!("{}", beacon_state.finalized_checkpoint.root),
|
2019-07-29 03:45:45 +00:00
|
|
|
"root" => format!("{}", beacon_block_root),
|
|
|
|
"slot" => new_slot,
|
|
|
|
);
|
2019-05-29 07:52:43 +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 old_finalized_epoch = self.head().beacon_state.finalized_checkpoint.epoch;
|
|
|
|
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 {
|
|
|
|
self.update_canonical_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,
|
|
|
|
})?;
|
|
|
|
|
|
|
|
if new_finalized_epoch != old_finalized_epoch {
|
|
|
|
self.after_finalization(old_finalized_epoch, finalized_root)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ok(())
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
2019-06-23 04:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Update the canonical head to `new_head`.
|
|
|
|
fn update_canonical_head(&self, new_head: CheckPoint<T::EthSpec>) -> Result<(), Error> {
|
|
|
|
// Update the checkpoint that stores the head of the chain at the time it received the
|
|
|
|
// block.
|
|
|
|
*self.canonical_head.write() = new_head;
|
|
|
|
|
|
|
|
// Update the always-at-the-present-slot state we keep around for performance gains.
|
|
|
|
*self.state.write() = {
|
|
|
|
let mut state = self.canonical_head.read().beacon_state.clone();
|
|
|
|
|
|
|
|
let present_slot = match self.slot_clock.present_slot() {
|
|
|
|
Ok(Some(slot)) => slot,
|
|
|
|
_ => return Err(Error::UnableToReadSlot),
|
|
|
|
};
|
|
|
|
|
|
|
|
// If required, transition the new state to the present slot.
|
|
|
|
for _ in state.slot.as_u64()..present_slot.as_u64() {
|
|
|
|
per_slot_processing(&mut state, &self.spec)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
state.build_all_caches(&self.spec)?;
|
|
|
|
|
|
|
|
state
|
|
|
|
};
|
|
|
|
|
|
|
|
// Save `self` to `self.store`.
|
|
|
|
self.persist()?;
|
2019-02-14 01:09:18 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-03-18 05:53:59 +00:00
|
|
|
|
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
|
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
|
|
|
.get::<BeaconBlock<T::EthSpec>>(&finalized_block_root)?
|
2019-06-23 04:47:23 +00:00
|
|
|
.ok_or_else(|| Error::MissingBeaconBlock(finalized_block_root))?;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.fork_choice
|
|
|
|
.process_finalization(&finalized_block, finalized_block_root)?;
|
|
|
|
|
|
|
|
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
|
|
|
|
.exists::<BeaconBlock<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 {
|
|
|
|
beacon_block: self.head().beacon_block.clone(),
|
|
|
|
beacon_block_root: self.head().beacon_block_root,
|
|
|
|
beacon_state: self.head().beacon_state.clone(),
|
|
|
|
beacon_state_root: self.head().beacon_state_root,
|
|
|
|
};
|
|
|
|
|
|
|
|
dump.push(last_slot.clone());
|
|
|
|
|
|
|
|
loop {
|
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 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.
|
|
|
|
}
|
|
|
|
|
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 beacon_block: BeaconBlock<T::EthSpec> =
|
2019-05-21 07:27:06 +00:00
|
|
|
self.store.get(&beacon_block_root)?.ok_or_else(|| {
|
2019-03-18 05:53:59 +00:00
|
|
|
Error::DBInconsistent(format!("Missing block {}", beacon_block_root))
|
|
|
|
})?;
|
|
|
|
let beacon_state_root = beacon_block.state_root;
|
2019-05-21 07:27:06 +00:00
|
|
|
let beacon_state = self.store.get(&beacon_state_root)?.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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|