Search in sources :

Example 11 with BFTValidatorSet

use of com.radixdlt.hotstuff.bft.BFTValidatorSet in project radixdlt by radixdlt.

the class WeightedRotatingLeadersTest method when_validators_distributed_by_fibonacci__then_leaders_also_distributed_in_fibonacci.

@Test
public void when_validators_distributed_by_fibonacci__then_leaders_also_distributed_in_fibonacci() {
    // fibonacci sequence can quickly explode so keep sizes small
    final int validatorSetSize = 8;
    final int sizeOfCache = 4;
    final Supplier<IntStream> fibonacci = () -> Stream.iterate(new int[] { 1, 1 }, t -> new int[] { t[1], t[0] + t[1] }).mapToInt(t -> t[0]).limit(validatorSetSize);
    final int sumOfPower = fibonacci.get().sum();
    this.validatorsInOrder = fibonacci.get().mapToObj(p -> BFTValidator.from(BFTNode.random(), UInt256.from(p))).collect(ImmutableList.toImmutableList());
    BFTValidatorSet validatorSet = BFTValidatorSet.from(validatorsInOrder);
    this.weightedRotatingLeaders = new WeightedRotatingLeaders(validatorSet, sizeOfCache);
    Map<BFTNode, UInt256> proposerCounts = Stream.iterate(View.of(0), View::next).limit(sumOfPower).map(this.weightedRotatingLeaders::getProposer).collect(groupingBy(p -> p, collectingAndThen(counting(), UInt256::from)));
    Map<BFTNode, UInt256> expected = validatorsInOrder.stream().collect(toMap(BFTValidator::getNode, BFTValidator::getPower));
    assertThat(proposerCounts).isEqualTo(expected);
}
Also used : IntStream(java.util.stream.IntStream) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Test(org.junit.Test) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) Supplier(java.util.function.Supplier) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ECKeyPair(com.radixdlt.crypto.ECKeyPair) View(com.radixdlt.hotstuff.bft.View) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableList(com.google.common.collect.ImmutableList) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) Map(java.util.Map) KeyComparator(com.radixdlt.utils.KeyComparator) Comparator(java.util.Comparator) UInt256(com.radixdlt.utils.UInt256) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) IntStream(java.util.stream.IntStream) UInt256(com.radixdlt.utils.UInt256) Test(org.junit.Test)

Aggregations

BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)11 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)10 Test (org.junit.Test)10 View (com.radixdlt.hotstuff.bft.View)4 Map (java.util.Map)4 AbstractModule (com.google.inject.AbstractModule)3 ECKeyPair (com.radixdlt.crypto.ECKeyPair)3 BFTValidator (com.radixdlt.hotstuff.bft.BFTValidator)3 ValidationState (com.radixdlt.hotstuff.bft.ValidationState)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashCode (com.google.common.hash.HashCode)2 Provides (com.google.inject.Provides)2 TypeLiteral (com.google.inject.TypeLiteral)2 SystemCounters (com.radixdlt.counters.SystemCounters)2 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)2 Hasher (com.radixdlt.crypto.Hasher)2 EventDispatcher (com.radixdlt.environment.EventDispatcher)2 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)2 ScheduledEventDispatcher (com.radixdlt.environment.ScheduledEventDispatcher)2 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)2