Skip to content

Commit

Permalink
Rename latest_penalized_exit_balances
Browse files Browse the repository at this point in the history
Brings into line with 1.0 spec.
Addresses part of Consensys#235.
  • Loading branch information
benjaminion committed Feb 4, 2019
1 parent 4e05785 commit 44606e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Expand Up @@ -92,7 +92,7 @@ public class BeaconState {
// Recent state
private ArrayList<CrosslinkRecord> latest_crosslinks;
private ArrayList<Bytes32> latest_block_roots = new ArrayList<>();
private ArrayList<Double> latest_penalized_exit_balances;
private ArrayList<Double> latest_penalized_balances;
private ArrayList<PendingAttestationRecord> latest_attestations;
private ArrayList<Bytes32> batched_block_roots = new ArrayList<>();

Expand Down Expand Up @@ -140,7 +140,7 @@ public BeaconState(
// Recent state
ArrayList<CrosslinkRecord> latest_crosslinks,
ArrayList<Bytes32> latest_block_roots,
ArrayList<Double> latest_penalized_exit_balances,
ArrayList<Double> latest_penalized_balances,
ArrayList<PendingAttestationRecord> latest_attestations,
ArrayList<Bytes32> batched_block_roots,
// PoW receipt root
Expand Down Expand Up @@ -175,7 +175,7 @@ public BeaconState(
// Recent state
this.latest_crosslinks = latest_crosslinks;
this.latest_block_roots = latest_block_roots;
this.latest_penalized_exit_balances = latest_penalized_exit_balances;
this.latest_penalized_balances = latest_penalized_balances;
this.latest_attestations = latest_attestations;
this.batched_block_roots = batched_block_roots;

Expand Down Expand Up @@ -544,9 +544,9 @@ public void exit_validator(BeaconState state, int index, int new_status) {

if (new_status == EXITED_WITH_PENALTY) {
int lpeb_index = toIntExact(state.getSlot()) / COLLECTIVE_PENALTY_CALCULATION_PERIOD;
latest_penalized_exit_balances.set(
latest_penalized_balances.set(
lpeb_index,
latest_penalized_exit_balances.get(lpeb_index) + get_effective_balance(state, index));
latest_penalized_balances.get(lpeb_index) + get_effective_balance(state, index));

int whistleblower_index = get_beacon_proposer_index(state, toIntExact(state.getSlot()));
double whistleblower_reward =
Expand Down Expand Up @@ -998,12 +998,12 @@ public void setPersistent_committees(ArrayList<ArrayList<Integer>> persistent_co
this.persistent_committees = persistent_committees;
}

public ArrayList<Double> getLatest_penalized_exit_balances() {
return latest_penalized_exit_balances;
public ArrayList<Double> getLatest_penalized_balances() {
return latest_penalized_balances;
}

public void setLatest_penalized_exit_balances(ArrayList<Double> latest_penalized_exit_balances) {
this.latest_penalized_exit_balances = latest_penalized_exit_balances;
public void setLatest_penalized_balances(ArrayList<Double> latest_penalized_balances) {
this.latest_penalized_balances = latest_penalized_balances;
}

public ArrayList<Bytes32> getLatest_randao_mixes() {
Expand Down
Expand Up @@ -114,12 +114,12 @@ public static void update_validator_registry(BeaconState state) {

int period_index =
Math.toIntExact(state.getSlot() / Constants.COLLECTIVE_PENALTY_CALCULATION_PERIOD);
ArrayList<Double> latest_penalized_exit_balances = state.getLatest_penalized_exit_balances();
ArrayList<Double> latest_penalized_balances = state.getLatest_penalized_balances();

double total_penalties =
latest_penalized_exit_balances.get(period_index)
+ latest_penalized_exit_balances.get(period_index - 1 < 0 ? period_index - 1 : 0)
+ latest_penalized_exit_balances.get(period_index - 2 < 0 ? period_index - 2 : 0);
latest_penalized_balances.get(period_index)
+ latest_penalized_balances.get(period_index - 1 < 0 ? period_index - 1 : 0)
+ latest_penalized_balances.get(period_index - 2 < 0 ? period_index - 2 : 0);

ArrayList<ValidatorRecord> to_penalize = to_penalize(active_validators);
}
Expand Down Expand Up @@ -204,9 +204,9 @@ private static void process_penalties_and_exits(BeaconState state) {
;
double total_at_start =
state
.getLatest_penalized_exit_balances()
.getLatest_penalized_balances()
.get((e + 1) % Constants.LATEST_PENALIZED_EXIT_LENGTH);
double total_at_end = state.getLatest_penalized_exit_balances().get(e);
double total_at_end = state.getLatest_penalized_balances().get(e);
double total_penalties = total_at_end - total_at_start;
double penalty =
BeaconStateUtil.get_effective_balance(state, validator)
Expand Down
Expand Up @@ -149,7 +149,7 @@ private BeaconState newState() {
state.getPersistent_committees().add(new_committee);

// Add penalized exit balances
state.getLatest_penalized_exit_balances().add(10.0);
state.getLatest_penalized_balances().add(10.0);

// Create shard_committees
ArrayList<ShardCommittee> new_shard_committees =
Expand Down

0 comments on commit 44606e0

Please sign in to comment.