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

Shard node #1

Open
wants to merge 152 commits into
base: interop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
5a2fe23
Initiate shard node and behavior - step-by-step
villanuevawill Aug 5, 2019
62cf13f
Piece by piece - adding the store for the shard chain
villanuevawill Aug 6, 2019
e5c5558
Update chain spec to manage phase 1 constants as well
villanuevawill Aug 6, 2019
f443458
Remove beacon specific fields and add shard specific fields
villanuevawill Aug 6, 2019
a0e7a58
Begin narrowing down the functions required for the shard state
villanuevawill Aug 6, 2019
11add85
Include a number of important shard types
villanuevawill Aug 7, 2019
7a05ec9
Update shard chain logic with all the appropriate functions needed an…
villanuevawill Aug 7, 2019
276c676
Include shard chain checkpoint
villanuevawill Aug 7, 2019
6cc277c
Included parent beacon chain logic
villanuevawill Aug 8, 2019
64f90cf
Add rest of store logic for shard... all majorly duplicated :)
villanuevawill Aug 8, 2019
c401a2d
Began trait functions for beacon wrapper and began fork choice rules
villanuevawill Aug 8, 2019
2ff15d2
Build fork choice logic
villanuevawill Aug 8, 2019
2759a8a
Include proper dependencies and errors file
villanuevawill Aug 14, 2019
0126774
Attestation data for a shard needs to include a target slot
villanuevawill Aug 16, 2019
0433d72
Initialize the shard operation pool
villanuevawill Aug 16, 2019
e1d2c04
bring operation pool logic/pseudocoding in check with requirements
villanuevawill Aug 16, 2019
5631314
add Slot logic
villanuevawill Aug 19, 2019
b3d6f58
Include period committee structure
villanuevawill Aug 21, 2019
4e81157
Include logic around start period for committee
villanuevawill Aug 21, 2019
295efcd
Fix reference to spec
villanuevawill Aug 21, 2019
0a331cb
Updated to calculate a period committee :)
villanuevawill Aug 21, 2019
0075869
Setup function for proposer index
villanuevawill Aug 21, 2019
7a739d2
Removed specific shard committee logic and pass through an argument f…
villanuevawill Aug 23, 2019
d8902e3
added additional phase 1 required variables/values
villanuevawill Aug 23, 2019
0341121
Include lookahead on slot to epcoh calculation
villanuevawill Aug 23, 2019
abf4aec
Drastically simplify shard state
villanuevawill Aug 23, 2019
757d17b
Simplify shard eth 2 types
villanuevawill Aug 23, 2019
6b57c9f
Fill in persistent committee/stored committee logic
villanuevawill Aug 23, 2019
3c994bd
Persistent committe data structure (maybe remove later)
villanuevawill Aug 23, 2019
dfdd108
For now keep the get_shard_proposer function in the beacon state
villanuevawill Aug 23, 2019
7bc5a50
compiler error part 1 - rust noob
villanuevawill Aug 23, 2019
f85e097
Compiler part 2. Add relative period.
villanuevawill Sep 2, 2019
134f469
Include period struct
villanuevawill Sep 2, 2019
d79cb3a
Epochs can be converted into a Period
villanuevawill Sep 2, 2019
c7e1013
Include relative period logic
villanuevawill Sep 2, 2019
24976ba
Update chain spec to include period committee roots
villanuevawill Sep 3, 2019
aa086ae
Period committee uses period vs. epoch now
villanuevawill Sep 3, 2019
6e4cdc3
Support PeriodCommittees in the beacon state - with cache and histori…
villanuevawill Sep 3, 2019
4fd6668
Define period committee cache
villanuevawill Sep 4, 2019
b34f78f
Update period committee to have owned/sliced
villanuevawill Sep 4, 2019
d2d7289
Update beacon state to use period committee caches
villanuevawill Sep 4, 2019
387583e
Period committee is a vec of vectors. Not sure if this is the best wa…
villanuevawill Sep 4, 2019
2eed9ac
Period committee initialization is correct
villanuevawill Sep 4, 2019
5a7990f
Change persistent committee to naturally a owned type
villanuevawill Sep 4, 2019
676c1b5
Remove ref in persistent committee struct
villanuevawill Sep 5, 2019
0b9a230
Period Committee Cache has get committee call
villanuevawill Sep 5, 2019
9d4dd95
fmt - rearranged
villanuevawill Sep 5, 2019
97a973c
Get shard committee function
villanuevawill Sep 6, 2019
92d3e01
Shard proposer index, Shard committee logic completed :)
villanuevawill Sep 6, 2019
e9c6b9d
Shard block header compile - minor changes to store iter/pending att
villanuevawill Sep 6, 2019
27de610
Shard Block is more in line with intended spec.
villanuevawill Sep 9, 2019
2600742
Added shard attestation
villanuevawill Sep 9, 2019
269531e
Op pool logic on attestation being situated
villanuevawill Sep 9, 2019
a6f54ff
Shard Operation Pool logic adjusted for shards
villanuevawill Sep 9, 2019
7fa6e0e
Add op pool into cargo.toml and include some shard attestation changes.
villanuevawill Sep 10, 2019
31b7211
Shard block types compiling
villanuevawill Sep 10, 2019
71c6a3c
Shard state functioning
villanuevawill Sep 12, 2019
1652446
Operation pool setup/compiling properly
villanuevawill Sep 12, 2019
167a2d8
Shard node store functioning and compiling :)
villanuevawill Sep 12, 2019
61cc293
Placeholder for epoch period committee state transition
villanuevawill Sep 12, 2019
f363ca7
Basic shard block/state processing functions
villanuevawill Sep 12, 2019
f833bad
Remove cargo from shard node for now
villanuevawill Sep 13, 2019
6e8258e
Inclue all state transition functions for period committees and roots
villanuevawill Sep 13, 2019
a2654d5
mock part for period processing on the shard
villanuevawill Sep 13, 2019
bcb0a62
ItemStore container also holds period cache
villanuevawill Sep 13, 2019
fdf085d
Shard state now implements shardspec
villanuevawill Sep 14, 2019
7699f24
Shard Slot Processing used and corrected
villanuevawill Sep 14, 2019
8d85f39
Fields follow names closely to spec - added latest header to state
villanuevawill Sep 14, 2019
6cb3997
Shard State holds shard block header
villanuevawill Sep 14, 2019
46429bf
Update iterators to work properly with shard state/blocks
villanuevawill Sep 14, 2019
cda140e
Type updates for ShardSpec
villanuevawill Sep 14, 2019
d6c6b46
lmd ghost using right trait for shardspec and iterators
villanuevawill Sep 14, 2019
2cded1e
Shard chain dependencies in check and all is compiling
villanuevawill Sep 14, 2019
c278cd2
Initiial shard chain interfaces
villanuevawill Sep 14, 2019
64e35da
Update iterator since skip blocks do have a stored state
villanuevawill Sep 14, 2019
07c3fce
slot processing has state root update logic for skip slots from genesis
villanuevawill Sep 14, 2019
19d977a
Continued shard chain interfaces in place
villanuevawill Sep 14, 2019
00c3a7b
Included Slot -> ShardSlot conversion function
villanuevawill Sep 14, 2019
0cee3d8
Update shard chain error conversions
villanuevawill Sep 14, 2019
5ca4ab0
Build validator index interface + build cache interface
villanuevawill Sep 14, 2019
c5b64e8
Implemented slot clock functionalities
villanuevawill Sep 14, 2019
96b71a8
Let beacon state error trickle up to shard chain & fix calcs on shard…
villanuevawill Sep 14, 2019
b21d6dc
Add shard block processing without fork choice for now
villanuevawill Sep 14, 2019
3a65640
Fork choice errors implemented and find_head()
villanuevawill Sep 15, 2019
138e19b
Include process block and find head for for choice
villanuevawill Sep 15, 2019
f9de536
fork choice gadget completed for attestations and block process
villanuevawill Sep 15, 2019
55d0e0a
fork choice finalization
villanuevawill Sep 15, 2019
c8a26e4
Simplified logic and just pass curent beacon state vs. looking up roo…
villanuevawill Sep 15, 2019
efae563
shard fork choice and updating canonical head completed
villanuevawill Sep 15, 2019
29e8e24
Attestations added to op pool
villanuevawill Sep 15, 2019
6a05560
Implemented "after crosslink" functionality
villanuevawill Sep 15, 2019
af19cfc
Add check for crosslink into fork_choice call
villanuevawill Sep 15, 2019
e130271
add rwlock for current crosslink
villanuevawill Sep 15, 2019
a065ea2
Block production enbled now :) - get_attestation from op pool returns…
villanuevawill Sep 15, 2019
ab125c9
remove grafiti
villanuevawill Sep 15, 2019
53ca003
Added shard committee function
villanuevawill Sep 15, 2019
d3f1ad1
Fix runtime issues
villanuevawill Sep 16, 2019
0ecb00f
Formatting :)
villanuevawill Sep 16, 2019
01a456c
Include shard chain harness to begin experimentation
villanuevawill Sep 17, 2019
d7126b9
Shard chain no longer needs intiialization with a genesis block
villanuevawill Sep 17, 2019
acdf501
Shard chain initiated in harness
villanuevawill Sep 17, 2019
d954de1
Temporarily add even more duplication :) ShardSlotClock
villanuevawill Sep 17, 2019
f68daea
Utility functions added to harness
villanuevawill Sep 17, 2019
2dddc30
Include attestation aggregation for harness. Make shard chain func le…
villanuevawill Sep 17, 2019
f2a5b41
included extend shard chain function
villanuevawill Sep 17, 2019
0a8f17f
Add get block root at epoch function to shard chain - using iterators
villanuevawill Sep 18, 2019
e65f8a7
Beacon chain requires data root for crosslink now
villanuevawill Sep 18, 2019
0c17b80
Add crosslink logic
villanuevawill Sep 18, 2019
fea6c6a
Move attestations into vector before refactor to direct bitfield. fur…
villanuevawill Sep 18, 2019
5225b97
Update iterators to actually look up proper values in line with store…
villanuevawill Sep 23, 2019
663e586
Fork choice operating on the right attestation set. harness tests rep…
villanuevawill Sep 23, 2019
fba0ecf
Include data and exec_env_states as part of phase 2
villanuevawill Sep 25, 2019
2717233
split shard_state_processing into own directory
wilbarnes Sep 18, 2019
6977fce
moving shard block errors into own file in subdir
wilbarnes Sep 18, 2019
0e96e6c
moved shard slot errors and process_shard_slot into own file
wilbarnes Sep 18, 2019
8c2d6b0
Cargo.toml needs to be capitalized
wilbarnes Sep 18, 2019
fa3e852
rm shard dependences from state_processing & updated shard_chain errors
wilbarnes Sep 18, 2019
0d679bf
updated shard_state_processing dependency path in shard_chain Cargo.toml
wilbarnes Sep 18, 2019
d02ac11
shard_state_processing Cargo.toml package name correctly updated
wilbarnes Sep 18, 2019
3e0e890
split shard_state_processing into own directory
wilbarnes Sep 18, 2019
4ff94b7
moved shard slot errors and process_shard_slot into own file
wilbarnes Sep 18, 2019
227fe75
update shard_state_processing Cargo.toml & remove benches remnant
wilbarnes Sep 18, 2019
f8be397
shard_state_processing lib.rs was in wrong dir
wilbarnes Sep 18, 2019
275dcb9
renaming to process_shard_slot.rs
wilbarnes Sep 18, 2019
5c577c1
fixing dependencies, errors, and renaming functions
wilbarnes Sep 18, 2019
3e0a347
removing unused libraries and commented out code
wilbarnes Sep 18, 2019
cb2db2f
adding shard_state_processing functions to library
wilbarnes Sep 19, 2019
28da2de
adding additional phase 1 chain_spec values
wilbarnes Sep 23, 2019
5018a87
adding basic fee logic for shard state transition
wilbarnes Sep 23, 2019
3537e68
commenting out function logic, replacing process_shard_state_header l…
wilbarnes Sep 25, 2019
06a5e3d
commenting out chain_spec variables and other toml file fixes
wilbarnes Sep 25, 2019
8faa553
Resolved error handling, previous rebase error, and state references.
villanuevawill Sep 25, 2019
b856a4e
author update, remove chain_spec variables
wilbarnes Sep 25, 2019
937322c
Merge pull request #3 from wilbarnes/shard_state_processing
villanuevawill Sep 25, 2019
72f8ea1
Make rust beautiful again
villanuevawill Sep 25, 2019
b89d650
Provide way to pass a block body through
villanuevawill Sep 25, 2019
d4292b8
Basic shard node running via clap tools
villanuevawill Sep 25, 2019
0c9a785
Update shard chain to be a reference within the harness (so it can be…
villanuevawill Sep 26, 2019
17a476f
Included rest api - it is a mirror of what is on "interop" branch ups…
villanuevawill Sep 26, 2019
30ee393
Include a beginning - functional simulation/harness. Need to spawn se…
villanuevawill Sep 26, 2019
4691cd7
Proper logging, API server functioning
villanuevawill Sep 26, 2019
afa1a5b
Support current block and state endpoints for shard 0
villanuevawill Sep 26, 2019
e8ede47
Remove fake crypto, cleanup
villanuevawill Sep 26, 2019
20d7070
Body data for op pool
villanuevawill Sep 26, 2019
d842832
Boy data for each block is submitted via op-pool for now.
villanuevawill Sep 26, 2019
0d51f54
api service set - endpoints set for getting blocks, state and writing…
villanuevawill Sep 27, 2019
78c555d
Refactored to use client modely
villanuevawill Sep 27, 2019
bf19ef9
Included logging on rest api endpoints
villanuevawill Sep 27, 2019
cd91b02
Clean up unused imports
villanuevawill Sep 27, 2019
158f5a6
Added further logging to beacon chain and shard chain
villanuevawill Sep 27, 2019
d299205
Fix some off by one errors :) improve logging
villanuevawill Sep 28, 2019
2fc9064
Fixed last set of off by one errors :) major todo to have utility fun…
villanuevawill Sep 29, 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
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[workspace]
members = [
"eth2/lmd_ghost",
"eth2/shard_lmd_ghost",
"eth2/operation_pool",
"eth2/shard_operation_pool",
"eth2/state_processing",
"eth2/types",
"eth2/utils/bls",
Expand Down Expand Up @@ -33,6 +35,11 @@ members = [
"beacon_node/rpc",
"beacon_node/version",
"beacon_node/beacon_chain",
"shard_node",
"shard_node/shard_store",
"shard_node/shard_chain",
"shard_node/shard_client",
"shard_node/rest_api",
"tests/ef_tests",
"protos",
"validator_client",
Expand Down
4 changes: 4 additions & 0 deletions beacon_node/beacon_chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
slot_clock = { path = "../../eth2/utils/slot_clock" }
slog = { version = "^2.2.3" , features = ["max_level_trace"] }
sloggers = { version = "^0.3" }
slog-term = "^2.4.0"
slog-async = "^2.3.0"
eth2_ssz = { path = "../../eth2/utils/ssz" }
eth2_ssz_derive = { path = "../../eth2/utils/ssz_derive" }
state_processing = { path = "../../eth2/state_processing" }
Expand Down
40 changes: 33 additions & 7 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
use crate::metrics::Metrics;
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
use lmd_ghost::LmdGhost;
use log::trace;
use operation_pool::DepositInsertStatus;
use operation_pool::{OperationPool, PersistedOperationPool};
use parking_lot::{RwLock, RwLockReadGuard};
use slog::{info, Logger};
use slot_clock::SlotClock;
use state_processing::per_block_processing::errors::{
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
Expand Down Expand Up @@ -83,6 +83,8 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub fork_choice: ForkChoice<T>,
/// Stores metrics about this `BeaconChain`.
pub metrics: Metrics,

pub log: Logger,
}

impl<T: BeaconChainTypes> BeaconChain<T> {
Expand All @@ -93,6 +95,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
mut genesis_state: BeaconState<T::EthSpec>,
genesis_block: BeaconBlock,
spec: ChainSpec,
log: Logger,
) -> Result<Self, Error> {
genesis_state.build_all_caches(&spec)?;

Expand All @@ -106,6 +109,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let genesis_block_root = genesis_block.block_header().canonical_root();
store.put(&spec.zero_hash, &genesis_block)?;

info!(log, "Beacon chain initialized from genesis";
"gensis_slot" => genesis_state.slot,
"state_root" => format!("{}", state_root),
"block_root" => format!("{}", genesis_block_root),
);

let canonical_head = RwLock::new(CheckPoint::new(
genesis_block.clone(),
genesis_block_root,
Expand All @@ -123,13 +132,15 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
fork_choice: ForkChoice::new(store.clone(), &genesis_block, genesis_block_root),
metrics: Metrics::new()?,
store,
log,
})
}

/// Attempt to load an existing instance from the given `store`.
pub fn from_store(
store: Arc<T::Store>,
spec: ChainSpec,
log: Logger,
) -> Result<Option<BeaconChain<T>>, Error> {
let key = Hash256::from_slice(&BEACON_CHAIN_DB_KEY.as_bytes());
let p: PersistedBeaconChain<T> = match store.get(&key) {
Expand Down Expand Up @@ -159,6 +170,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
genesis_block_root: p.genesis_block_root,
metrics: Metrics::new()?,
store,
log,
}))
}

Expand Down Expand Up @@ -395,10 +407,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&self,
validator_index: usize,
) -> Result<Option<(Slot, u64)>, BeaconStateError> {
trace!(
"BeaconChain::validator_attestion_slot_and_shard: validator_index: {}",
validator_index
);
if let Some(attestation_duty) = self
.state
.read()
Expand All @@ -418,7 +426,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let head_block_root = self.head().beacon_block_root;
let head_block_slot = self.head().beacon_block.slot;

self.produce_attestation_data_for_block(shard, head_block_root, head_block_slot, &*state)
self.produce_attestation_data_for_block(
shard,
head_block_root,
head_block_slot,
Hash256::zero(),
&*state,
)
}

/// Produce an `AttestationData` that attests to the chain denoted by `block_root` and `state`.
Expand All @@ -430,6 +444,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
shard: u64,
head_block_root: Hash256,
head_block_slot: Slot,
crosslink_data_root: Hash256,
state: &BeaconState<T::EthSpec>,
) -> Result<AttestationData, Error> {
// Collect some metrics.
Expand Down Expand Up @@ -478,7 +493,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
target_root,
shard,
previous_crosslink_root,
crosslink_data_root: Hash256::zero(),
crosslink_data_root,
})
}

Expand Down Expand Up @@ -796,6 +811,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
new_epoch: new_finalized_epoch,
})
} else {
info!(self.log, "Beacon Fork choice produces new head";
"block_root" => format!("{}", &beacon_block_root),
"state_root" => format!("{}", &beacon_state_root),
"slot" => format!("{}", &beacon_block.slot),
);

self.update_canonical_head(CheckPoint {
beacon_block: beacon_block,
beacon_block_root,
Expand Down Expand Up @@ -866,6 +887,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
new_epoch: new_finalized_epoch,
})
} else {
info!(self.log, "Beacon Finalization Detected";
"root" => format!("{}", finalized_block_root),
"pruning fork choice from slot" => format!("{}", finalized_block.slot),
);

self.fork_choice
.process_finalization(&finalized_block, finalized_block_root)?;

Expand Down
5 changes: 4 additions & 1 deletion beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{BeaconChain, BeaconChainTypes, BlockProcessingOutcome};
use lmd_ghost::LmdGhost;
use slog::Logger;
use slot_clock::SlotClock;
use slot_clock::TestingSlotClock;
use state_processing::per_slot_processing;
Expand Down Expand Up @@ -80,7 +81,7 @@ where
E: EthSpec,
{
/// Instantiate a new harness with `validator_count` initial validators.
pub fn new(validator_count: usize) -> Self {
pub fn new(validator_count: usize, log: Logger) -> Self {
let spec = E::default_spec();

let store = Arc::new(MemoryStore::open());
Expand All @@ -105,6 +106,7 @@ where
genesis_state,
genesis_block,
spec.clone(),
log,
)
.expect("Terminate if beacon chain generation fails");

Expand Down Expand Up @@ -291,6 +293,7 @@ where
cc.shard,
head_block_root,
head_block_slot,
Hash256::zero(),
state,
)
.expect("should produce attestation data");
Expand Down
15 changes: 12 additions & 3 deletions beacon_node/client/src/beacon_chain_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ where
T: BeaconChainTypes<Store = U, EthSpec = V>,
T::LmdGhost: LmdGhost<U, V>,
{
if let Ok(Some(beacon_chain)) = BeaconChain::from_store(store.clone(), spec.clone()) {
if let Ok(Some(beacon_chain)) =
BeaconChain::from_store(store.clone(), spec.clone(), log.clone())
{
info!(
log,
"Loaded BeaconChain from store";
Expand Down Expand Up @@ -78,7 +80,14 @@ where

// Genesis chain
//TODO: Handle error correctly
BeaconChain::from_genesis(store, slot_clock, genesis_state, genesis_block, spec)
.expect("Terminate if beacon chain generation fails")
BeaconChain::from_genesis(
store,
slot_clock,
genesis_state,
genesis_block,
spec,
log.clone(),
)
.expect("Terminate if beacon chain generation fails")
}
}
19 changes: 18 additions & 1 deletion beacon_node/store/src/impls/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@ use crate::*;
use ssz::{Decode, DecodeError, Encode};
use ssz_derive::{Decode, Encode};
use std::convert::TryInto;
use types::beacon_state::{CommitteeCache, CACHED_EPOCHS};
use types::beacon_state::{CommitteeCache, PeriodCommitteeCache, CACHED_EPOCHS, CACHED_PERIODS};

/// A container for storing `BeaconState` components.
#[derive(Encode, Decode)]
struct StorageContainer {
state_bytes: Vec<u8>,
committee_caches_bytes: Vec<Vec<u8>>,
period_caches_bytes: Vec<Vec<u8>>,
}

impl StorageContainer {
/// Create a new instance for storing a `BeaconState`.
pub fn new<T: EthSpec>(state: &BeaconState<T>) -> Self {
let mut committee_caches_bytes = vec![];
let mut period_caches_bytes = vec![];

for cache in state.committee_caches[..].iter() {
committee_caches_bytes.push(cache.as_ssz_bytes());
}

for cache in state.period_caches[..].iter() {
period_caches_bytes.push(cache.as_ssz_bytes());
}

Self {
state_bytes: state.as_ssz_bytes(),
committee_caches_bytes,
period_caches_bytes,
}
}
}
Expand All @@ -43,6 +50,16 @@ impl<T: EthSpec> TryInto<BeaconState<T>> for StorageContainer {
state.committee_caches[i] = CommitteeCache::from_ssz_bytes(bytes)?;
}

for i in 0..CACHED_PERIODS {
let bytes = &self.period_caches_bytes.get(i).ok_or_else(|| {
Error::SszDecodeError(DecodeError::BytesInvalid(
"Insufficient period committees for BeaconState".to_string(),
))
})?;

state.period_caches[i] = PeriodCommitteeCache::from_ssz_bytes(bytes)?;
}

Ok(state)
}
}
Expand Down
22 changes: 22 additions & 0 deletions eth2/shard_lmd_ghost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "shard_lmd_ghost"
version = "0.1.0"
authors = ["Age Manning <[email protected]>", "Paul Hauner <[email protected]>"]
edition = "2018"

[dependencies]
parking_lot = "0.7"
shard_store = { path = "../../shard_node/shard_store" }
eth2_ssz = { path = "../utils/ssz" }
state_processing = { path = "../state_processing" }
types = { path = "../types" }
log = "0.4.6"
bit-vec = "0.5.0"

[dev-dependencies]
criterion = "0.2"
hex = "0.3.2"
yaml-rust = "0.4.2"
bls = { path = "../utils/bls" }
slot_clock = { path = "../utils/slot_clock" }
env_logger = "0.6.0"
46 changes: 46 additions & 0 deletions eth2/shard_lmd_ghost/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
mod reduced_tree;

use shard_store::Store;
use std::sync::Arc;
use types::{Hash256, ShardBlock, ShardSlot, ShardSpec};

pub use reduced_tree::ThreadSafeReducedTree;

pub type Result<T> = std::result::Result<T, String>;

pub trait LmdGhost<S: Store, E: ShardSpec>: Send + Sync {
/// Create a new instance, with the given `store` and `finalized_root`.
fn new(store: Arc<S>, finalized_block: &ShardBlock, finalized_root: Hash256) -> Self;

/// Process an attestation message from some validator that attests to some `block_hash`
/// representing a block at some `block_slot`.
fn process_attestation(
&self,
validator_index: usize,
block_hash: Hash256,
block_slot: ShardSlot,
) -> Result<()>;

/// Process a block that was seen on the network.
fn process_block(&self, block: &ShardBlock, block_hash: Hash256) -> Result<()>;

/// Returns the head of the chain, starting the search at `start_block_root` and moving upwards
/// (in block height).
fn find_head<F>(
&self,
start_block_slot: ShardSlot,
start_block_root: Hash256,
weight: F,
) -> Result<Hash256>
where
F: Fn(usize) -> Option<u64> + Copy;

/// Provide an indication that the blockchain has been finalized at the given `finalized_block`.
///
/// `finalized_block_root` must be the root of `finalized_block`.
fn update_finalized_root(
&self,
finalized_block: &ShardBlock,
finalized_block_root: Hash256,
) -> Result<()>;
}
Loading