@Test void noValidVotesInThisPeriod_eth1ChainNotLive() { BeaconState beaconState = createBeaconStateWithVotes(createEth1Data(STATE_DEPOSIT_COUNT)); assertThat(eth1DataCache.getEth1Vote(beaconState)).isEqualTo(stateEth1Data); }
public Eth1Data getEth1Vote(BeaconState state) { NavigableMap<UInt64, Eth1Data> votesToConsider = getVotesToConsider(state.getSlot(), state.getGenesis_time(), state.getEth1_data()); Map<Eth1Data, Eth1Vote> validVotes = new HashMap<>(); int i = 0; for (Eth1Data eth1Data : state.getEth1_data_votes()) { if (!votesToConsider.containsValue(eth1Data)) { continue; } final int currentIndex = i; Eth1Vote vote = validVotes.computeIfAbsent(eth1Data, key -> new Eth1Vote(currentIndex)); vote.incrementVotes(); i++; } Eth1Data defaultVote = votesToConsider.isEmpty() ? state.getEth1_data() : votesToConsider.lastEntry().getValue(); Optional<Eth1Data> vote = validVotes.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); return vote.orElse(defaultVote); }
Eth1DataCache { public Eth1Data getEth1Vote(BeaconState state) { NavigableMap<UInt64, Eth1Data> votesToConsider = getVotesToConsider(state.getSlot(), state.getGenesis_time(), state.getEth1_data()); Map<Eth1Data, Eth1Vote> validVotes = new HashMap<>(); int i = 0; for (Eth1Data eth1Data : state.getEth1_data_votes()) { if (!votesToConsider.containsValue(eth1Data)) { continue; } final int currentIndex = i; Eth1Vote vote = validVotes.computeIfAbsent(eth1Data, key -> new Eth1Vote(currentIndex)); vote.incrementVotes(); i++; } Eth1Data defaultVote = votesToConsider.isEmpty() ? state.getEth1_data() : votesToConsider.lastEntry().getValue(); Optional<Eth1Data> vote = validVotes.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); return vote.orElse(defaultVote); } }
Eth1DataCache { public Eth1Data getEth1Vote(BeaconState state) { NavigableMap<UInt64, Eth1Data> votesToConsider = getVotesToConsider(state.getSlot(), state.getGenesis_time(), state.getEth1_data()); Map<Eth1Data, Eth1Vote> validVotes = new HashMap<>(); int i = 0; for (Eth1Data eth1Data : state.getEth1_data_votes()) { if (!votesToConsider.containsValue(eth1Data)) { continue; } final int currentIndex = i; Eth1Vote vote = validVotes.computeIfAbsent(eth1Data, key -> new Eth1Vote(currentIndex)); vote.incrementVotes(); i++; } Eth1Data defaultVote = votesToConsider.isEmpty() ? state.getEth1_data() : votesToConsider.lastEntry().getValue(); Optional<Eth1Data> vote = validVotes.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); return vote.orElse(defaultVote); } Eth1DataCache(final Eth1VotingPeriod eth1VotingPeriod); }
Eth1DataCache { public Eth1Data getEth1Vote(BeaconState state) { NavigableMap<UInt64, Eth1Data> votesToConsider = getVotesToConsider(state.getSlot(), state.getGenesis_time(), state.getEth1_data()); Map<Eth1Data, Eth1Vote> validVotes = new HashMap<>(); int i = 0; for (Eth1Data eth1Data : state.getEth1_data_votes()) { if (!votesToConsider.containsValue(eth1Data)) { continue; } final int currentIndex = i; Eth1Vote vote = validVotes.computeIfAbsent(eth1Data, key -> new Eth1Vote(currentIndex)); vote.incrementVotes(); i++; } Eth1Data defaultVote = votesToConsider.isEmpty() ? state.getEth1_data() : votesToConsider.lastEntry().getValue(); Optional<Eth1Data> vote = validVotes.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); return vote.orElse(defaultVote); } Eth1DataCache(final Eth1VotingPeriod eth1VotingPeriod); void onBlockWithDeposit(final UInt64 blockTimestamp, final Eth1Data eth1Data); void onEth1Block(final Bytes32 blockHash, final UInt64 blockTimestamp); Eth1Data getEth1Vote(BeaconState state); }
Eth1DataCache { public Eth1Data getEth1Vote(BeaconState state) { NavigableMap<UInt64, Eth1Data> votesToConsider = getVotesToConsider(state.getSlot(), state.getGenesis_time(), state.getEth1_data()); Map<Eth1Data, Eth1Vote> validVotes = new HashMap<>(); int i = 0; for (Eth1Data eth1Data : state.getEth1_data_votes()) { if (!votesToConsider.containsValue(eth1Data)) { continue; } final int currentIndex = i; Eth1Vote vote = validVotes.computeIfAbsent(eth1Data, key -> new Eth1Vote(currentIndex)); vote.incrementVotes(); i++; } Eth1Data defaultVote = votesToConsider.isEmpty() ? state.getEth1_data() : votesToConsider.lastEntry().getValue(); Optional<Eth1Data> vote = validVotes.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey); return vote.orElse(defaultVote); } Eth1DataCache(final Eth1VotingPeriod eth1VotingPeriod); void onBlockWithDeposit(final UInt64 blockTimestamp, final Eth1Data eth1Data); void onEth1Block(final Bytes32 blockHash, final UInt64 blockTimestamp); Eth1Data getEth1Vote(BeaconState state);  }