1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#![cfg_attr(not(feature = "std"), no_std, feature(alloc), feature(alloc_prelude), feature(prelude_import))]
#![warn(missing_docs)]
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
pub(crate) mod prelude {
pub use core::prelude::v1::*;
pub use alloc::prelude::v1::*;
}
#[cfg(not(feature = "std"))]
#[allow(unused)]
#[prelude_import]
use crate::prelude::*;
#[cfg(feature = "parity-codec")]
extern crate parity_codec as codec;
mod attestation;
mod block;
mod eth1;
mod slashing;
mod state;
mod validator;
mod util;
mod error;
mod config;
mod executive;
mod primitives;
pub use attestation::*;
pub use block::*;
pub use eth1::*;
pub use slashing::*;
pub use state::*;
pub use validator::*;
pub use error::*;
pub use config::*;
pub use executive::*;
pub use primitives::*;
pub type Gwei = u64;
pub type Slot = u64;
pub type Epoch = u64;
pub type Shard = u64;
pub type Timestamp = u64;
pub type ValidatorIndex = u64;
pub fn execute_block<C: Config>(block: &BeaconBlock, state: &mut BeaconState, config: &C) -> Result<(), Error> {
let mut executive = Executive::new(state, config);
while executive.state().slot < block.slot {
executive.update_cache();
if (executive.state().slot + 1) % config.slots_per_epoch() == 0 {
executive.update_justification_and_finalization()?;
executive.update_crosslinks()?;
executive.update_eth1_period();
executive.update_rewards()?;
executive.update_ejections();
executive.update_registry_and_shuffling_data()?;
executive.update_slashings();
executive.update_exit_queue();
executive.update_finalize()?;
}
executive.advance_slot();
if executive.state().slot == block.slot {
executive.process_block_header(block)?;
executive.process_randao(block)?;
executive.process_eth1_data(block);
if block.body.proposer_slashings.len() > config.max_proposer_slashings() {
return Err(Error::TooManyProposerSlashings)
}
for slashing in &block.body.proposer_slashings {
executive.push_proposer_slashing(slashing.clone())?;
}
if block.body.attester_slashings.len() > config.max_attester_slashings() {
return Err(Error::TooManyAttesterSlashings)
}
for slashing in &block.body.attester_slashings {
executive.push_attester_slashing(slashing.clone())?;
}
if block.body.attestations.len() > config.max_attestations() {
return Err(Error::TooManyAttestations)
}
for attestation in &block.body.attestations {
executive.push_attestation(attestation.clone())?;
}
if block.body.deposits.len() > config.max_deposits() {
return Err(Error::TooManyDeposits)
}
for deposit in &block.body.deposits {
executive.push_deposit(deposit.clone())?;
}
if block.body.voluntary_exits.len() > config.max_voluntary_exits() {
return Err(Error::TooManyVoluntaryExits)
}
for voluntary_exit in &block.body.voluntary_exits {
executive.push_voluntary_exit(voluntary_exit.clone())?;
}
if block.body.transfers.len() > config.max_transfers() {
return Err(Error::TooManyTransfers)
}
for transfer in &block.body.transfers {
executive.push_transfer(transfer.clone())?;
}
}
}
Ok(())
}