Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to frozen spec ❄️ (v0.8.1) #444

Merged
merged 64 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b370534
types: first updates for v0.8
michaelsproul Jul 5, 2019
f48540b
state_processing: epoch processing v0.8.0
michaelsproul Jul 5, 2019
abee864
state_processing: block processing v0.8.0
michaelsproul Jul 10, 2019
feab0eb
tree_hash_derive: support generics in SignedRoot
michaelsproul Jul 11, 2019
02d878e
types v0.8: update to use ssz_types
michaelsproul Jul 11, 2019
abe2ca9
state_processing v0.8: use ssz_types
michaelsproul Jul 11, 2019
2fd7229
ssz_types: add bitwise methods and from_elem
michaelsproul Jul 11, 2019
df603d4
types: fix v0.8 FIXMEs
michaelsproul Jul 11, 2019
ddac8c9
ssz_types: add bitfield shift_up
michaelsproul Jul 11, 2019
3220afa
ssz_types: iterators and DerefMut for VariableList
michaelsproul Jul 12, 2019
e299ea1
types,state_processing: use VariableList
michaelsproul Jul 12, 2019
8c38808
ssz_types: fix BitVector Decode impl
michaelsproul Jul 16, 2019
8f74e72
types: fix test modules for v0.8 update
michaelsproul Jul 16, 2019
966c8d0
types: remove slow type-level arithmetic
michaelsproul Jul 16, 2019
31364ea
state_processing: fix tests for v0.8
michaelsproul Jul 17, 2019
5d1bc38
op_pool: update for v0.8
michaelsproul Jul 17, 2019
9d8346e
ssz_types: Bitfield difference length-independent
michaelsproul Jul 17, 2019
46c0b0a
Implement compact committee support
michaelsproul Jul 18, 2019
99d5e69
epoch_processing: committee & active index roots
michaelsproul Jul 18, 2019
d3b23e2
state_processing: genesis state builder v0.8
michaelsproul Jul 18, 2019
04ffe3c
state_processing: implement v0.8.1
michaelsproul Jul 18, 2019
d92cb3e
Further improve tree_hash
paulhauner Jul 17, 2019
e905534
Strip examples, tests from cached_tree_hash
paulhauner Jul 17, 2019
75cc431
Update TreeHash, un-impl CachedTreeHash
paulhauner Jul 17, 2019
d0200a6
Update bitfield TreeHash, un-impl CachedTreeHash
paulhauner Jul 17, 2019
75d5cf0
Update FixedLenVec TreeHash, unimpl CachedTreeHash
paulhauner Jul 17, 2019
9a86828
Update update tree_hash_derive for new TreeHash
paulhauner Jul 17, 2019
ed65d59
Fix TreeHash, un-impl CachedTreeHash for ssz_types
paulhauner Jul 17, 2019
e67725a
Remove fixed_len_vec, ssz benches
paulhauner Jul 18, 2019
b77dcb6
Remove boolean_bitfield crate
paulhauner Jul 18, 2019
ebf2dfd
Fix fake_crypto BLS compile errors
paulhauner Jul 18, 2019
11fb410
Update ef_tests for new v.8 type params
paulhauner Jul 18, 2019
f3e4b5a
Update ef_tests submodule to v0.8.1 tag
paulhauner Jul 18, 2019
b634b62
Make fixes to support parsing ssz ef_tests
paulhauner Jul 18, 2019
8478c4b
`compact_committee...` to `compact_committees...`
paulhauner Jul 18, 2019
e63e2a6
Derive more traits for `CompactCommittee`
paulhauner Jul 18, 2019
a299018
Flip bitfield byte-endianness
paulhauner Jul 19, 2019
18cff72
Fix tree_hash for bitfields
paulhauner Jul 19, 2019
3a10609
Modify CLI output for ef_tests
paulhauner Jul 19, 2019
f24e5f6
Bump ssz crate version
paulhauner Jul 19, 2019
c92a7e6
Update ssz_types doc comment
paulhauner Jul 19, 2019
d3eb35d
Del cached tree hash tests from ssz_static tests
paulhauner Jul 19, 2019
80e11bc
Tidy SSZ dependencies
paulhauner Jul 19, 2019
4682322
Rename ssz_types crate to eth2_ssz_types
paulhauner Jul 19, 2019
12aae28
validator_client: update for v0.8
michaelsproul Jul 18, 2019
bc2d26e
ssz_types: update union/difference for bit order swap
michaelsproul Jul 19, 2019
92c7e61
beacon_node: update for v0.8, EthSpec
michaelsproul Jul 19, 2019
5635742
types: disable cached tree hash, update min spec
michaelsproul Jul 19, 2019
531ce00
state_processing: fix slot bug in committee update
michaelsproul Jul 19, 2019
fec22d5
tests: temporarily disable fork choice harness test
michaelsproul Jul 22, 2019
6617f5d
committee cache: prevent out-of-bounds access
michaelsproul Jul 23, 2019
f9f7d5a
fix bug in get_indexed_attestation and simplify
michaelsproul Jul 23, 2019
d0301ba
state_proc: workaround for compact committees bug
michaelsproul Jul 26, 2019
81b42f3
v0.8: updates to make the EF tests pass
michaelsproul Jul 26, 2019
057c8c4
Merge remote-tracking branch 'origin/master' into v0.8
michaelsproul Jul 26, 2019
fc88a6d
rustfmt
michaelsproul Jul 26, 2019
fb8569c
ef_tests: add new epoch processing tests
michaelsproul Jul 26, 2019
184bf97
Merge branch 'master' into v0.8 (not compiling)
paulhauner Jul 29, 2019
966f0d1
Integrate v0.8 into master (compiles)
paulhauner Jul 29, 2019
5154396
Remove unused crates, fix clippy lints
paulhauner Jul 29, 2019
712a1bb
Replace v0.6.3 tags w/ v0.8.1
paulhauner Jul 30, 2019
0580f8a
Remove old comment
paulhauner Jul 30, 2019
0c1e35f
Ensure lmd ghost tests only run in release
paulhauner Jul 30, 2019
3bd4fcc
Update readme
paulhauner Jul 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ members = [
"eth2/state_processing",
"eth2/types",
"eth2/utils/bls",
"eth2/utils/boolean-bitfield",
"eth2/utils/cached_tree_hash",
"eth2/utils/compare_fields",
"eth2/utils/compare_fields_derive",
"eth2/utils/eth2_config",
"eth2/utils/fixed_len_vec",
"eth2/utils/hashing",
"eth2/utils/honey-badger-split",
"eth2/utils/merkle_proof",
"eth2/utils/int_to_bytes",
"eth2/utils/serde_hex",
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ user-facing functionality.

Current development overview:

- Specification `v0.6.3` implemented, optimized and passing test vectors.
- Rust-native libp2p integrated, with Gossipsub.
- Discv5 (P2P discovery mechanism) integration started.
- Specification `v0.8.1` implemented, optimized and passing test vectors.
- Rust-native libp2p with Gossipsub and Discv5.
- Metrics via Prometheus.
- Basic gRPC API, soon to be replaced with RESTful HTTP/JSON.

### Roadmap

- **July 2019**: `lighthouse-0.0.1` release: A stable testnet for developers with a useful
HTTP API.
- **Early-September 2019**: `lighthouse-0.0.1` release: A stable testnet for
developers with a useful HTTP API.
- **September 2019**: Inter-operability with other Ethereum 2.0 clients.
- **October 2019**: Public, multi-client testnet with user-facing functionality.
- **January 2020**: Production Beacon Chain testnet.
Expand Down Expand Up @@ -153,6 +152,8 @@ If you'd like some background on Sigma Prime, please see the [Lighthouse Update
- [`protos/`](protos/): protobuf/gRPC definitions that are common across the Lighthouse project.
- [`validator_client/`](validator_client/): the "Validator Client" binary and crates exclusively
associated with it.
- [`tests/`](tests/): code specific to testing, most notably contains the
Ethereum Foundation test vectors.

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion account_manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn main() {
}
};
default_dir.push(DEFAULT_DATA_DIR);
PathBuf::from(default_dir)
default_dir
}
};

Expand Down
127 changes: 71 additions & 56 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
store: Arc<T::Store>,
slot_clock: T::SlotClock,
mut genesis_state: BeaconState<T::EthSpec>,
genesis_block: BeaconBlock,
genesis_block: BeaconBlock<T::EthSpec>,
spec: ChainSpec,
log: Logger,
) -> Result<Self, Error> {
Expand All @@ -108,7 +108,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

// Also store the genesis block under the `ZERO_HASH` key.
let genesis_block_root = genesis_block.block_header().canonical_root();
store.put(&spec.zero_hash, &genesis_block)?;
store.put(&Hash256::zero(), &genesis_block)?;

let canonical_head = RwLock::new(CheckPoint::new(
genesis_block.clone(),
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
spec.seconds_per_slot,
);

let last_finalized_root = p.canonical_head.beacon_state.finalized_root;
let last_finalized_root = p.canonical_head.beacon_state.finalized_checkpoint.root;
let last_finalized_block = &p.canonical_head.beacon_block;

let op_pool = p.op_pool.into_operation_pool(&p.state, &spec);
Expand Down Expand Up @@ -187,8 +187,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// Returns the beacon block body for each beacon block root in `roots`.
///
/// Fails if any root in `roots` does not have a corresponding block.
pub fn get_block_bodies(&self, roots: &[Hash256]) -> Result<Vec<BeaconBlockBody>, Error> {
let bodies: Result<Vec<BeaconBlockBody>, _> = roots
pub fn get_block_bodies(
&self,
roots: &[Hash256],
) -> Result<Vec<BeaconBlockBody<T::EthSpec>>, Error> {
let bodies: Result<Vec<_>, _> = roots
.iter()
.map(|root| match self.get_block(root)? {
Some(block) => Ok(block.body),
Expand Down Expand Up @@ -259,7 +262,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// ## Errors
///
/// May return a database error.
pub fn get_block(&self, block_root: &Hash256) -> Result<Option<BeaconBlock>, Error> {
pub fn get_block(
&self,
block_root: &Hash256,
) -> Result<Option<BeaconBlock<T::EthSpec>>, Error> {
Ok(self.store.get(block_root)?)
}

Expand Down Expand Up @@ -321,15 +327,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

/// Returns the validator index (if any) for the given public key.
///
/// Information is retrieved from the present `beacon_state.validator_registry`.
/// Information is retrieved from the present `beacon_state.validators`.
pub fn validator_index(&self, pubkey: &PublicKey) -> Option<usize> {
for (i, validator) in self
.head()
.beacon_state
.validator_registry
.iter()
.enumerate()
{
for (i, validator) in self.head().beacon_state.validators.iter().enumerate() {
if validator.pubkey == *pubkey {
return Some(i);
}
Expand Down Expand Up @@ -469,23 +469,32 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} else {
*state.get_block_root(current_epoch_start_slot)?
};
let target = Checkpoint {
epoch: state.current_epoch(),
root: target_root,
};

let previous_crosslink_root =
Hash256::from_slice(&state.get_current_crosslink(shard)?.tree_hash_root());
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(),
};

// Collect some metrics.
self.metrics.attestation_production_successes.inc();
timer.observe_duration();

Ok(AttestationData {
beacon_block_root: head_block_root,
source_epoch: state.current_justified_epoch,
source_root: state.current_justified_root,
target_epoch: state.current_epoch(),
target_root,
shard,
previous_crosslink_root,
crosslink_data_root: Hash256::zero(),
source: state.current_justified_checkpoint.clone(),
target,
crosslink,
})
}

Expand All @@ -495,7 +504,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// if possible.
pub fn process_attestation(
&self,
attestation: Attestation,
attestation: Attestation<T::EthSpec>,
) -> Result<(), AttestationValidationError> {
self.metrics.attestation_processing_requests.inc();
let timer = self.metrics.attestation_processing_times.start_timer();
Expand Down Expand Up @@ -527,9 +536,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// Accept some deposit and queue it for inclusion in an appropriate block.
pub fn process_deposit(
&self,
index: u64,
deposit: Deposit,
) -> Result<DepositInsertStatus, DepositValidationError> {
self.op_pool.insert_deposit(deposit)
self.op_pool.insert_deposit(index, deposit)
}

/// Accept some exit and queue it for inclusion in an appropriate block.
Expand All @@ -556,7 +566,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// Accept some attester slashing and queue it for inclusion in an appropriate block.
pub fn process_attester_slashing(
&self,
attester_slashing: AttesterSlashing,
attester_slashing: AttesterSlashing<T::EthSpec>,
) -> Result<(), AttesterSlashingValidationError> {
self.op_pool
.insert_attester_slashing(attester_slashing, &*self.state.read(), &self.spec)
Expand All @@ -565,14 +575,18 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// 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.
pub fn process_block(&self, block: BeaconBlock) -> Result<BlockProcessingOutcome, Error> {
pub fn process_block(
&self,
block: BeaconBlock<T::EthSpec>,
) -> Result<BlockProcessingOutcome, Error> {
self.metrics.block_processing_requests.inc();
let timer = self.metrics.block_processing_times.start_timer();

let finalized_slot = self
.state
.read()
.finalized_epoch
.finalized_checkpoint
.epoch
.start_slot(T::EthSpec::slots_per_epoch());

if block.slot <= finalized_slot {
Expand Down Expand Up @@ -600,18 +614,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
});
}

if self.store.exists::<BeaconBlock>(&block_root)? {
if self.store.exists::<BeaconBlock<T::EthSpec>>(&block_root)? {
return Ok(BlockProcessingOutcome::BlockIsAlreadyKnown);
}

// Load the blocks parent block from the database, returning invalid if that block is not
// found.
let parent_block_root = block.previous_block_root;
let parent_block: BeaconBlock = match self.store.get(&parent_block_root)? {
Some(previous_block_root) => previous_block_root,
let parent_block: BeaconBlock<T::EthSpec> = match self.store.get(&block.parent_root)? {
Some(block) => block,
None => {
return Ok(BlockProcessingOutcome::ParentUnknown {
parent: parent_block_root,
parent: block.parent_root,
});
}
};
Expand Down Expand Up @@ -691,7 +704,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub fn produce_block(
&self,
randao_reveal: Signature,
) -> Result<(BeaconBlock, BeaconState<T::EthSpec>), BlockProductionError> {
) -> Result<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError> {
let state = self.state.read().clone();
let slot = self
.read_slot_clock()
Expand All @@ -713,7 +726,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
mut state: BeaconState<T::EthSpec>,
produce_at_slot: Slot,
randao_reveal: Signature,
) -> Result<(BeaconBlock, BeaconState<T::EthSpec>), BlockProductionError> {
) -> Result<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError> {
self.metrics.block_production_requests.inc();
let timer = self.metrics.block_production_times.start_timer();

Expand All @@ -724,7 +737,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;

let previous_block_root = if state.slot > 0 {
let parent_root = if state.slot > 0 {
*state
.get_block_root(state.slot - 1)
.map_err(|_| BlockProductionError::UnableToGetBlockRootFromState)?
Expand All @@ -740,7 +753,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

let mut block = BeaconBlock {
slot: state.slot,
previous_block_root,
parent_root,
state_root: Hash256::zero(), // Updated after the state is calculated.
signature: Signature::empty_signature(), // To be completed by a validator.
body: BeaconBlockBody {
Expand All @@ -752,12 +765,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
block_hash: Hash256::zero(),
},
graffiti,
proposer_slashings,
attester_slashings,
attestations: self.op_pool.get_attestations(&state, &self.spec),
deposits: self.op_pool.get_deposits(&state, &self.spec),
voluntary_exits: self.op_pool.get_voluntary_exits(&state, &self.spec),
transfers: self.op_pool.get_transfers(&state, &self.spec),
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(),
},
};

Expand Down Expand Up @@ -790,7 +803,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
if beacon_block_root != self.head().beacon_block_root {
self.metrics.fork_choice_changed_head.inc();

let beacon_block: BeaconBlock = self
let beacon_block: BeaconBlock<T::EthSpec> = self
.store
.get(&beacon_block_root)?
.ok_or_else(|| Error::MissingBeaconBlock(beacon_block_root))?;
Expand All @@ -805,7 +818,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let new_slot = beacon_block.slot;

// If we switched to a new chain (instead of building atop the present chain).
if self.head().beacon_block_root != beacon_block.previous_block_root {
if self.head().beacon_block_root != beacon_block.parent_root {
self.metrics.fork_choice_reorg_count.inc();
warn!(
self.log,
Expand All @@ -817,16 +830,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
info!(
self.log,
"new head block";
"justified_root" => format!("{}", beacon_state.current_justified_root),
"finalized_root" => format!("{}", beacon_state.finalized_root),
"justified_root" => format!("{}", beacon_state.current_justified_checkpoint.root),
"finalized_root" => format!("{}", beacon_state.finalized_checkpoint.root),
"root" => format!("{}", beacon_block_root),
"slot" => new_slot,
);
};

let old_finalized_epoch = self.head().beacon_state.finalized_epoch;
let new_finalized_epoch = beacon_state.finalized_epoch;
let finalized_root = beacon_state.finalized_root;
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;

// Never revert back past a finalized epoch.
if new_finalized_epoch < old_finalized_epoch {
Expand All @@ -836,7 +849,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
})
} else {
self.update_canonical_head(CheckPoint {
beacon_block: beacon_block,
beacon_block,
beacon_block_root,
beacon_state,
beacon_state_root,
Expand Down Expand Up @@ -894,7 +907,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
) -> Result<(), Error> {
let finalized_block = self
.store
.get::<BeaconBlock>(&finalized_block_root)?
.get::<BeaconBlock<T::EthSpec>>(&finalized_block_root)?
.ok_or_else(|| Error::MissingBeaconBlock(finalized_block_root))?;

let new_finalized_epoch = finalized_block.slot.epoch(T::EthSpec::slots_per_epoch());
Expand All @@ -914,7 +927,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

/// 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> {
Ok(!self.store.exists::<BeaconBlock>(beacon_block_root)?)
Ok(!self
.store
.exists::<BeaconBlock<T::EthSpec>>(beacon_block_root)?)
}

/// Dumps the entire canonical chain, from the head to genesis to a vector for analysis.
Expand All @@ -934,13 +949,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
dump.push(last_slot.clone());

loop {
let beacon_block_root = last_slot.beacon_block.previous_block_root;
let beacon_block_root = last_slot.beacon_block.parent_root;

if beacon_block_root == self.spec.zero_hash {
if beacon_block_root == Hash256::zero() {
break; // Genesis has been reached.
}

let beacon_block: BeaconBlock =
let beacon_block: BeaconBlock<T::EthSpec> =
self.store.get(&beacon_block_root)?.ok_or_else(|| {
Error::DBInconsistent(format!("Missing block {}", beacon_block_root))
})?;
Expand Down
Loading