diff --git a/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsClient.java b/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsClient.java index 8b5d4957e..5bda43471 100644 --- a/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsClient.java +++ b/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsClient.java @@ -36,7 +36,7 @@ public MtlsClient(SocketAddress address, ClientAuth clientAuth, String alias, Cl Limiter limiter = new GrpcClientLimiterBuilder().blockOnLimit(false).build(); channel = NettyChannelBuilder.forAddress(address) - // .executor(executor) + .executor(executor) .withOption(ChannelOption.TCP_NODELAY, true) .sslContext(supplier.forClient(clientAuth, alias, validator, MtlsServer.TL_SV1_3)) .intercept(new ConcurrencyLimitClientInterceptor(limiter, diff --git a/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsServer.java b/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsServer.java index 3cac8d621..88e79fc34 100644 --- a/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsServer.java +++ b/memberships/src/main/java/com/salesforce/apollo/archipelago/MtlsServer.java @@ -44,6 +44,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; @@ -140,15 +141,15 @@ public static SslContext forServer(ClientAuth clientAuth, String alias, X509Cert public RouterImpl router(ServerConnectionCache.Builder cacheBuilder, Supplier serverLimit, LimitsRegistry limitsRegistry, List interceptors, Predicate validator, ExecutorService executor) { - // if (executor == null) { - // executor = Executors.newVirtualThreadPerTaskExecutor(); - // } + if (executor == null) { + executor = Executors.newVirtualThreadPerTaskExecutor(); + } var limitsBuilder = new GrpcServerLimiterBuilder().limit(serverLimit.get()); if (limitsRegistry != null) { limitsBuilder.metricRegistry(limitsRegistry); } NettyServerBuilder serverBuilder = NettyServerBuilder.forAddress(epProvider.getBindAddress()) - // .executor(executor) + .executor(executor) .withOption(ChannelOption.SO_REUSEADDR, true) .sslContext(supplier.forServer(ClientAuth.REQUIRE, epProvider.getAlias(), diff --git a/memberships/src/main/java/com/salesforce/apollo/context/DynamicContextImpl.java b/memberships/src/main/java/com/salesforce/apollo/context/DynamicContextImpl.java index 43cb35a3d..068804878 100644 --- a/memberships/src/main/java/com/salesforce/apollo/context/DynamicContextImpl.java +++ b/memberships/src/main/java/com/salesforce/apollo/context/DynamicContextImpl.java @@ -730,16 +730,10 @@ public Iterable traverse(int ring, T member) { */ @Override public void uniqueSuccessors(Digest key, Predicate test, Set collector) { - var delegate = ring(0).successor(key, test); - if (delegate == null) { - return; - } for (Ring ring : rings) { - T successor = ring.successor(hashFor(delegate, ring.index), m -> !collector.contains(m) && test.test(m)); + T successor = ring.successor(key, m -> !collector.contains(m) && test.test(m)); if (successor != null) { collector.add(successor); - } else { - collector.add(delegate); } } } diff --git a/memberships/src/main/java/com/salesforce/apollo/context/StaticContext.java b/memberships/src/main/java/com/salesforce/apollo/context/StaticContext.java index 7c78c165c..be43490f9 100644 --- a/memberships/src/main/java/com/salesforce/apollo/context/StaticContext.java +++ b/memberships/src/main/java/com/salesforce/apollo/context/StaticContext.java @@ -449,17 +449,11 @@ public Iterable traverse(int ring, T member) { @Override public void uniqueSuccessors(Digest key, Predicate test, Set collector) { - var delegate = ring(0).successor(key, test); - if (delegate == null) { - return; - } for (int ring = 0; ring < rings.length; ring++) { StaticRing r = ring(ring); - T successor = r.successor(hashFor(delegate, r.index), m -> !collector.contains(m) && test.test(m)); + T successor = r.successor(key, m -> !collector.contains(m) && test.test(m)); if (successor != null) { collector.add(successor); - } else { - collector.add(delegate); } } } diff --git a/memberships/src/test/java/com/salesforce/apollo/context/ContextTests.java b/memberships/src/test/java/com/salesforce/apollo/context/ContextTests.java index f9f5d4dc8..859f06281 100644 --- a/memberships/src/test/java/com/salesforce/apollo/context/ContextTests.java +++ b/memberships/src/test/java/com/salesforce/apollo/context/ContextTests.java @@ -18,6 +18,7 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; +import java.util.SequencedSet; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,6 +27,30 @@ */ public class ContextTests { + @Test + public void bftSubset() throws Exception { + var context = new DynamicContextImpl<>(DigestAlgorithm.DEFAULT.getOrigin().prefix(1), 10, 0.2, 2); + List members = new ArrayList<>(); + var entropy = SecureRandom.getInstance("SHA1PRNG"); + entropy.setSeed(new byte[] { 6, 6, 6 }); + var stereotomy = new StereotomyImpl(new MemKeyStore(), new MemKERL(DigestAlgorithm.DEFAULT), entropy); + + for (int i = 0; i < 7; i++) { + SigningMember m = new ControlledIdentifierMember(stereotomy.newIdentifier()); + members.add(m); + context.activate(m); + } + var testEntropy = SecureRandom.getInstance("SHA1PRNG"); + testEntropy.setSeed(new byte[] { 6, 6, 6 }); + var algo = DigestAlgorithm.DEFAULT; + List> subsets = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + var subset = context.bftSubset(algo.random(testEntropy)); + System.out.println(subset.stream().map(Member::getId).toList()); + subsets.add(subset); + } + } + @Test public void consistency() throws Exception { var context = new DynamicContextImpl<>(DigestAlgorithm.DEFAULT.getOrigin().prefix(1), 10, 0.2, 2);