Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Update v0.6: mandatory deposits (ethereum/consensus-specs#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas committed May 2, 2019
1 parent d79988c commit 8aaf5ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions beacon/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub enum Error {
TooManyAttestations,
/// Too many deposits in a block.
TooManyDeposits,
/// Too few deposits in a block.
TooFewDeposits,
/// Too many voluntary exits in a block.
TooManyVoluntaryExits,
/// Too many transfers in a block.
Expand Down
6 changes: 2 additions & 4 deletions beacon/src/eth1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ pub struct Eth1Data {
/// Root of the deposit tree
pub deposit_root: H256,
/// Total number of deposits
// TODO: this field is not present in current test spec.
// pub deposit_count: u64,
pub deposit_count: u64,
/// Block hash
pub block_hash: H256,
}
Expand All @@ -45,8 +44,7 @@ impl Eth1Data {
pub fn empty() -> Self {
Self {
deposit_root: H256::default(),
// TODO: this field is not present in current test spec.
// deposit_count: 0,
deposit_count: 0,
block_hash: H256::default(),
}
}
Expand Down
8 changes: 8 additions & 0 deletions beacon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub use executive::*;
pub use primitives::*;

use ssz::Hashable;
use core::cmp;

/// Gwei as in the currency ETH.
pub type Gwei = u64;
Expand Down Expand Up @@ -202,6 +203,10 @@ pub fn apply_transaction<C: Config>(block: &mut UnsealedBeaconBlock, state: &mut
pub fn finalize_block<C: Config>(block: &mut UnsealedBeaconBlock, state: &mut BeaconState, config: &C) -> Result<(), Error> {
let mut executive = Executive::new(state, config);

if block.body.deposits.len() != cmp::min(config.max_deposits(), (executive.state().latest_eth1_data.deposit_count - executive.state().deposit_index) as usize) {
return Err(Error::TooFewDeposits)
}

executive.process_block_header(block)?;
Ok(())
}
Expand Down Expand Up @@ -255,6 +260,9 @@ pub fn execute_block<C: Config>(block: &BeaconBlock, state: &mut BeaconState, co
if block.body.deposits.len() > config.max_deposits() {
return Err(Error::TooManyDeposits)
}
if block.body.deposits.len() != cmp::min(config.max_deposits(), (executive.state().latest_eth1_data.deposit_count - executive.state().deposit_index) as usize) {
return Err(Error::TooFewDeposits)
}
for deposit in &block.body.deposits {
executive.push_deposit(deposit.clone())?;
}
Expand Down

0 comments on commit 8aaf5ab

Please sign in to comment.