Altair consensus changes and refactors (#2279)

## Proposed Changes

Implement the consensus changes necessary for the upcoming Altair hard fork.

## Additional Info

This is quite a heavy refactor, with pivotal types like the `BeaconState` and `BeaconBlock` changing from structs to enums. This ripples through the whole codebase with field accesses changing to methods, e.g. `state.slot` => `state.slot()`.


Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
Michael Sproul
2021-07-09 06:15:32 +00:00
parent 89361573d4
commit b4689e20c6
271 changed files with 9652 additions and 8444 deletions

View File

@@ -31,9 +31,9 @@ pub fn complete_state_advance<T: EthSpec>(
target_slot: Slot,
spec: &ChainSpec,
) -> Result<(), Error> {
check_target_slot(state.slot, target_slot)?;
check_target_slot(state.slot(), target_slot)?;
while state.slot < target_slot {
while state.slot() < target_slot {
// Use the initial state root on the first iteration of the loop, then use `None` for any
// future iterations.
let state_root_opt = state_root_opt.take();
@@ -64,7 +64,7 @@ pub fn partial_state_advance<T: EthSpec>(
target_slot: Slot,
spec: &ChainSpec,
) -> Result<(), Error> {
check_target_slot(state.slot, target_slot)?;
check_target_slot(state.slot(), target_slot)?;
// The only time that a state root is mandatory is if a block has been applied to the state
// without it yet being advanced another slot.
@@ -72,13 +72,13 @@ pub fn partial_state_advance<T: EthSpec>(
// Failing to provide a state root in this scenario would result in corrupting the
// `state.block_roots` array, since the `state.latest_block_header` would contain an invalid
// (all-zeros) state root.
let mut initial_state_root = Some(if state.slot > state.latest_block_header.slot {
let mut initial_state_root = Some(if state.slot() > state.latest_block_header().slot {
state_root_opt.unwrap_or_else(Hash256::zero)
} else {
state_root_opt.ok_or(Error::StateRootNotProvided)?
});
while state.slot < target_slot {
while state.slot() < target_slot {
// Use the initial state root on the first iteration of the loop, then use `[0; 32]` for any
// later iterations.
//