diff --git a/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java b/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java index 8e8eef109..fcc7d5784 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java @@ -1205,7 +1205,8 @@ public Logger log() { public void nextView(PendingView pendingView) { var previous = CHOAM.this.pendingView.getAndSet(pendingView); log.info("Pending view: {} size: {} previous: {} size: {} on: {}", pendingView.diadem, - pendingView.context.size(), previous.diadem, previous.context.size(), params.member().getId()); + pendingView.context.size(), previous == null ? "" : previous.diadem, + previous == null ? "" : previous.context.size(), params.member().getId()); } @Override @@ -1371,7 +1372,9 @@ public void nextView(PendingView pendingView) { params.context().setContext(pendingView.context); CHOAM.this.diadem.set(pendingView.diadem); CHOAM.this.pendingView.set(pendingView); - assembly.stop(); + if (assembly != null) { + assembly.start(); + } transitions.nextView(); } diff --git a/choam/src/main/java/com/salesforce/apollo/choam/GenesisAssembly.java b/choam/src/main/java/com/salesforce/apollo/choam/GenesisAssembly.java index 1fe24c06a..717264729 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/GenesisAssembly.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/GenesisAssembly.java @@ -68,8 +68,6 @@ public GenesisAssembly(ViewContext vc, CommonCommunications comms, .stream() .collect(Collectors.toMap(Member::getId, m -> m)); if (!Dag.validate(nextAssembly.size())) { - log.error("Invalid cardinality: {} for: {} on: {}", nextAssembly.size(), view.context().getId(), - params().member().getId()); throw new IllegalStateException("Invalid BFT cardinality: " + nextAssembly.size()); } this.genesisMember = genesisMember; @@ -151,13 +149,19 @@ public void gather() { @Override public void gather(List preblock, boolean last) { - preblock.stream().map(bs -> { - try { - return Join.parseFrom(bs); - } catch (InvalidProtocolBufferException e) { - return null; - } - }).filter(Objects::nonNull).filter(j -> !j.equals(Join.getDefaultInstance())).forEach(this::join); + preblock.stream() + .map(bs -> { + try { + return Join.parseFrom(bs); + } catch (InvalidProtocolBufferException e) { + return null; + } + }) + .filter(Objects::nonNull) + .filter(j -> !j.equals(Join.getDefaultInstance())) + .peek( + j -> log.info("Gathering: {} on: {}", Digest.from(j.getMember().getId()), params().member().getId())) + .forEach(this::join); } @Override @@ -170,6 +174,8 @@ public void nominate() { .map(p -> view.generateValidation(p.join.getMember())) .forEach(validations::addValidations); ds.setValue(validations.build().toByteString()); + log.info("Nominations of: {} validations: {} on: {}", params().context().getId(), + validations.getValidationsCount(), params().member().getId()); } @Override diff --git a/choam/src/main/java/com/salesforce/apollo/choam/support/OneShot.java b/choam/src/main/java/com/salesforce/apollo/choam/support/OneShot.java index fc60a4b6b..d96246e8d 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/support/OneShot.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/support/OneShot.java @@ -33,7 +33,7 @@ public ByteString get() { } public void setValue(ByteString value) { - log.trace("resetting value: " + value); + log.trace("resetting value: " + (value == null ? "null" : String.valueOf(value.size()))); this.value = value; latch.countDown(); } diff --git a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/jks/JksKeyStore.java b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/jks/JksKeyStore.java index 00dd1e65d..4fac2b88f 100644 --- a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/jks/JksKeyStore.java +++ b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/jks/JksKeyStore.java @@ -6,6 +6,9 @@ */ package com.salesforce.apollo.stereotomy.jks; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.RemovalCause; import com.salesforce.apollo.cryptography.cert.BcX500NameDnImpl; import com.salesforce.apollo.cryptography.cert.CertExtension; import com.salesforce.apollo.cryptography.cert.Certificates; @@ -18,6 +21,7 @@ import java.security.*; import java.security.cert.Certificate; import java.security.cert.X509Certificate; +import java.time.Duration; import java.time.Instant; import java.util.Collections; import java.util.List; @@ -33,14 +37,22 @@ * @author hal.hildebrand */ public class JksKeyStore implements StereotomyKeyStore { - private static final Logger log = LoggerFactory.getLogger(JksKeyStore.class); - protected final KeyStore keyStore; - protected final Supplier passwordProvider; - private final Lock lock = new ReentrantLock(); + private static final Logger log = LoggerFactory.getLogger(JksKeyStore.class); + + protected final KeyStore keyStore; + protected final Supplier passwordProvider; + private final Lock lock = new ReentrantLock(); + private final Cache cached; public JksKeyStore(KeyStore keyStore, Supplier passwordProvider) { this.keyStore = keyStore; this.passwordProvider = passwordProvider; + cached = Caffeine.newBuilder() + .maximumSize(4) + .expireAfterWrite(Duration.ofMinutes(10)) + .removalListener( + (String alias, KeyPair ks, RemovalCause cause) -> log.trace("KeyPair was removed ({})", cause)) + .build(); } public static String coordinateOrdering(KeyCoordinates coords) { @@ -134,15 +146,15 @@ public void storeNextKey(KeyCoordinates keyCoordinates, KeyPair keyPair) { } } - private Optional get(String alias, KeyCoordinates keyCoordinates) { + private KeyPair fetch(String alias, KeyCoordinates keyCoordinates) { try { if (!keyStore.containsAlias(alias)) { - return Optional.empty(); + return null; } } catch (KeyStoreException e) { log.error("Unable to query keystore for: {} : {}", keyCoordinates != null ? keyCoordinates : alias, e.getMessage()); - return Optional.empty(); + return null; } Certificate cert; try { @@ -150,7 +162,7 @@ private Optional get(String alias, KeyCoordinates keyCoordinates) { } catch (KeyStoreException e) { log.error("Unable to retrieve certificate for: {} : {}", keyCoordinates != null ? keyCoordinates : alias, e.getMessage()); - return Optional.empty(); + return null; } var publicKey = cert.getPublicKey(); PrivateKey privateKey; @@ -159,8 +171,12 @@ private Optional get(String alias, KeyCoordinates keyCoordinates) { } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException e) { log.error("Unable to retrieve certificate for: {} : {}", keyCoordinates != null ? keyCoordinates : alias, e.getMessage()); - return Optional.empty(); + return null; } - return Optional.of(new KeyPair(publicKey, privateKey)); + return new KeyPair(publicKey, privateKey); + } + + private Optional get(String alias, KeyCoordinates keyCoordinates) { + return Optional.ofNullable(cached.get(alias, key -> fetch(key, keyCoordinates))); } } diff --git a/thoth/src/main/java/com/salesforce/apollo/thoth/KerlDHT.java b/thoth/src/main/java/com/salesforce/apollo/thoth/KerlDHT.java index 519a24a58..bc88b3d1d 100644 --- a/thoth/src/main/java/com/salesforce/apollo/thoth/KerlDHT.java +++ b/thoth/src/main/java/com/salesforce/apollo/thoth/KerlDHT.java @@ -824,7 +824,7 @@ private void completeIt(CompletableFuture result, HashMultiset gathere } private boolean failedMajority(CompletableFuture result, int maxAgree, String operation) { - log.error("Unable to achieve majority read: {}, max: {} required: {} on: {}", operation, maxAgree, + log.debug("Unable to achieve majority read: {}, max: {} required: {} on: {}", operation, maxAgree, context.majority(true), member.getId()); return result.completeExceptionally(new CompletionException( "Unable to achieve majority read: " + operation + ", max: " + maxAgree + " required: " + context.majority(true)