@Test void computeDeltas_validatorDisappears() { final UInt64 BALANCE = UInt64.valueOf(42); indices.put(getHash(1), 0); indices.put(getHash(2), 1); oldBalances.addAll(List.of(BALANCE, BALANCE)); newBalances.add(BALANCE); for (int i = 0; i < 2; i++) { VoteTracker vote = store.getVote(UInt64.valueOf(i)); vote.setCurrentRoot(getHash(1)); vote.setNextRoot(getHash(2)); } List<Long> deltas = computeDeltas(store, indices, oldBalances, newBalances); assertThat(deltas).hasSize(2); assertThat(deltas.get(0)).isEqualTo(-BALANCE.longValue() * 2); assertThat(deltas.get(1)).isEqualTo(BALANCE.longValue()); votesShouldBeUpdated(store); }
static List<Long> computeDeltas( MutableStore store, Map<Bytes32, Integer> indices, List<UInt64> oldBalances, List<UInt64> newBalances) { List<Long> deltas = new ArrayList<>(Collections.nCopies(indices.size(), 0L)); for (UInt64 validatorIndex : store.getVotedValidatorIndices()) { VoteTracker vote = store.getVote(validatorIndex); if (vote.getCurrentRoot().equals(Bytes32.ZERO) && vote.getNextRoot().equals(Bytes32.ZERO)) { LOG.warn("ProtoArrayForkChoiceStrategy: Unexpected zero hashes in voted validator votes"); continue; } int validatorIndexInt = toIntExact(validatorIndex.longValue()); UInt64 oldBalance = oldBalances.size() > validatorIndexInt ? oldBalances.get(validatorIndexInt) : UInt64.ZERO; UInt64 newBalance = newBalances.size() > validatorIndexInt ? newBalances.get(validatorIndexInt) : UInt64.ZERO; if (!vote.getCurrentRoot().equals(vote.getNextRoot()) || !oldBalance.equals(newBalance)) { Integer currentDeltaIndex = indices.get(vote.getCurrentRoot()); if (currentDeltaIndex != null) { checkState( currentDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = subtractExact(deltas.get(currentDeltaIndex), oldBalance.longValue()); deltas.set(currentDeltaIndex, delta); } Integer nextDeltaIndex = indices.get(vote.getNextRoot()); if (nextDeltaIndex != null) { checkState( nextDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = addExact(deltas.get(nextDeltaIndex), newBalance.longValue()); deltas.set(nextDeltaIndex, delta); } vote.setCurrentRoot(vote.getNextRoot()); } } return deltas; }
ProtoArrayScoreCalculator { static List<Long> computeDeltas( MutableStore store, Map<Bytes32, Integer> indices, List<UInt64> oldBalances, List<UInt64> newBalances) { List<Long> deltas = new ArrayList<>(Collections.nCopies(indices.size(), 0L)); for (UInt64 validatorIndex : store.getVotedValidatorIndices()) { VoteTracker vote = store.getVote(validatorIndex); if (vote.getCurrentRoot().equals(Bytes32.ZERO) && vote.getNextRoot().equals(Bytes32.ZERO)) { LOG.warn("ProtoArrayForkChoiceStrategy: Unexpected zero hashes in voted validator votes"); continue; } int validatorIndexInt = toIntExact(validatorIndex.longValue()); UInt64 oldBalance = oldBalances.size() > validatorIndexInt ? oldBalances.get(validatorIndexInt) : UInt64.ZERO; UInt64 newBalance = newBalances.size() > validatorIndexInt ? newBalances.get(validatorIndexInt) : UInt64.ZERO; if (!vote.getCurrentRoot().equals(vote.getNextRoot()) || !oldBalance.equals(newBalance)) { Integer currentDeltaIndex = indices.get(vote.getCurrentRoot()); if (currentDeltaIndex != null) { checkState( currentDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = subtractExact(deltas.get(currentDeltaIndex), oldBalance.longValue()); deltas.set(currentDeltaIndex, delta); } Integer nextDeltaIndex = indices.get(vote.getNextRoot()); if (nextDeltaIndex != null) { checkState( nextDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = addExact(deltas.get(nextDeltaIndex), newBalance.longValue()); deltas.set(nextDeltaIndex, delta); } vote.setCurrentRoot(vote.getNextRoot()); } } return deltas; } }
ProtoArrayScoreCalculator { static List<Long> computeDeltas( MutableStore store, Map<Bytes32, Integer> indices, List<UInt64> oldBalances, List<UInt64> newBalances) { List<Long> deltas = new ArrayList<>(Collections.nCopies(indices.size(), 0L)); for (UInt64 validatorIndex : store.getVotedValidatorIndices()) { VoteTracker vote = store.getVote(validatorIndex); if (vote.getCurrentRoot().equals(Bytes32.ZERO) && vote.getNextRoot().equals(Bytes32.ZERO)) { LOG.warn("ProtoArrayForkChoiceStrategy: Unexpected zero hashes in voted validator votes"); continue; } int validatorIndexInt = toIntExact(validatorIndex.longValue()); UInt64 oldBalance = oldBalances.size() > validatorIndexInt ? oldBalances.get(validatorIndexInt) : UInt64.ZERO; UInt64 newBalance = newBalances.size() > validatorIndexInt ? newBalances.get(validatorIndexInt) : UInt64.ZERO; if (!vote.getCurrentRoot().equals(vote.getNextRoot()) || !oldBalance.equals(newBalance)) { Integer currentDeltaIndex = indices.get(vote.getCurrentRoot()); if (currentDeltaIndex != null) { checkState( currentDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = subtractExact(deltas.get(currentDeltaIndex), oldBalance.longValue()); deltas.set(currentDeltaIndex, delta); } Integer nextDeltaIndex = indices.get(vote.getNextRoot()); if (nextDeltaIndex != null) { checkState( nextDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = addExact(deltas.get(nextDeltaIndex), newBalance.longValue()); deltas.set(nextDeltaIndex, delta); } vote.setCurrentRoot(vote.getNextRoot()); } } return deltas; }  }
ProtoArrayScoreCalculator { static List<Long> computeDeltas( MutableStore store, Map<Bytes32, Integer> indices, List<UInt64> oldBalances, List<UInt64> newBalances) { List<Long> deltas = new ArrayList<>(Collections.nCopies(indices.size(), 0L)); for (UInt64 validatorIndex : store.getVotedValidatorIndices()) { VoteTracker vote = store.getVote(validatorIndex); if (vote.getCurrentRoot().equals(Bytes32.ZERO) && vote.getNextRoot().equals(Bytes32.ZERO)) { LOG.warn("ProtoArrayForkChoiceStrategy: Unexpected zero hashes in voted validator votes"); continue; } int validatorIndexInt = toIntExact(validatorIndex.longValue()); UInt64 oldBalance = oldBalances.size() > validatorIndexInt ? oldBalances.get(validatorIndexInt) : UInt64.ZERO; UInt64 newBalance = newBalances.size() > validatorIndexInt ? newBalances.get(validatorIndexInt) : UInt64.ZERO; if (!vote.getCurrentRoot().equals(vote.getNextRoot()) || !oldBalance.equals(newBalance)) { Integer currentDeltaIndex = indices.get(vote.getCurrentRoot()); if (currentDeltaIndex != null) { checkState( currentDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = subtractExact(deltas.get(currentDeltaIndex), oldBalance.longValue()); deltas.set(currentDeltaIndex, delta); } Integer nextDeltaIndex = indices.get(vote.getNextRoot()); if (nextDeltaIndex != null) { checkState( nextDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = addExact(deltas.get(nextDeltaIndex), newBalance.longValue()); deltas.set(nextDeltaIndex, delta); } vote.setCurrentRoot(vote.getNextRoot()); } } return deltas; }   }
ProtoArrayScoreCalculator { static List<Long> computeDeltas( MutableStore store, Map<Bytes32, Integer> indices, List<UInt64> oldBalances, List<UInt64> newBalances) { List<Long> deltas = new ArrayList<>(Collections.nCopies(indices.size(), 0L)); for (UInt64 validatorIndex : store.getVotedValidatorIndices()) { VoteTracker vote = store.getVote(validatorIndex); if (vote.getCurrentRoot().equals(Bytes32.ZERO) && vote.getNextRoot().equals(Bytes32.ZERO)) { LOG.warn("ProtoArrayForkChoiceStrategy: Unexpected zero hashes in voted validator votes"); continue; } int validatorIndexInt = toIntExact(validatorIndex.longValue()); UInt64 oldBalance = oldBalances.size() > validatorIndexInt ? oldBalances.get(validatorIndexInt) : UInt64.ZERO; UInt64 newBalance = newBalances.size() > validatorIndexInt ? newBalances.get(validatorIndexInt) : UInt64.ZERO; if (!vote.getCurrentRoot().equals(vote.getNextRoot()) || !oldBalance.equals(newBalance)) { Integer currentDeltaIndex = indices.get(vote.getCurrentRoot()); if (currentDeltaIndex != null) { checkState( currentDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = subtractExact(deltas.get(currentDeltaIndex), oldBalance.longValue()); deltas.set(currentDeltaIndex, delta); } Integer nextDeltaIndex = indices.get(vote.getNextRoot()); if (nextDeltaIndex != null) { checkState( nextDeltaIndex < deltas.size(), "ProtoArrayForkChoice: Invalid node delta index"); long delta = addExact(deltas.get(nextDeltaIndex), newBalance.longValue()); deltas.set(nextDeltaIndex, delta); } vote.setCurrentRoot(vote.getNextRoot()); } } return deltas; }    }