use of com.radixdlt.hotstuff.bft.BFTValidator in project radixdlt by radixdlt.
the class WeightedRotatingLeaders method getProposer.
@Override
public BFTNode getProposer(View view) {
nextLeaderComputer.computeToView(view);
// validator will only be null if the view supplied is before the cache
// window
BFTValidator validator = nextLeaderComputer.checkCacheForProposer(view);
if (validator != null) {
// dynamic program cache successful
return validator.getNode();
} else {
// cache doesn't have value, do the expensive operation
CachingNextLeaderComputer computer = new CachingNextLeaderComputer(validatorSet, weightsComparator, 1);
return computer.resetToView(view).getNode();
}
}
use of com.radixdlt.hotstuff.bft.BFTValidator 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);
}
Aggregations