Skip to content
Snippets Groups Projects
Commit 86c4fe88 authored by Wei Tang's avatar Wei Tang
Browse files

beacon: total_balance and total_active_balance

parent deeae6a4
Branches
No related merge requests found
......@@ -179,13 +179,26 @@ impl<C: Config> BeaconState<C> {
let compact_balance = validator.effective_balance / C::effective_balance_increment();
let compact_validator = (index << 16) +
(if validator.slashed { 1 } else { 0 } << 15) + compact_balance;
committees[shard as usize].compact_validators.append(compact_validator);
committees[shard as usize].compact_validators.push(compact_validator);
}
}
Ok(tree_root::<C::Digest, _>(&committees))
}
pub fn total_balance(&self, indices: &[ValidatorIndex]) -> Gwei {
max(
indices.iter().fold(0, |sum, index| {
sum + self.validators[*index as usize].effective_balance
}),
1
)
}
pub fn total_active_balance(&self) -> Gwei {
self.total_balance(&self.active_validator_indices(self.current_epoch()))
}
pub fn domain(&self, domain_type: Uint, message_epoch: Option<Uint>) -> Uint {
let epoch = message_epoch.unwrap_or(self.current_epoch());
let fork_version = if epoch < self.fork.epoch {
......
......@@ -27,3 +27,4 @@ pub type Epoch = Uint;
pub type Slot = Uint;
pub type ValidatorIndex = Uint;
pub type Shard = Uint;
pub type Gwei = Uint;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment