From d1149d182bfb2417194b51ee66e0ee0d4e450887 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Sat, 13 Apr 2024 08:55:34 -0700 Subject: [PATCH] interim --- .../com/salesforce/apollo/choam/CHOAM.java | 26 ++++++++++--------- .../com/salesforce/apollo/choam/Producer.java | 3 +++ .../com/salesforce/apollo/choam/Session.java | 9 ++++--- 3 files changed, 23 insertions(+), 15 deletions(-) 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 d475aa91b..2b1783083 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java @@ -23,9 +23,11 @@ import com.salesforce.apollo.choam.support.HashedCertifiedBlock.NullBlock; import com.salesforce.apollo.context.Context; import com.salesforce.apollo.context.DelegatedContext; +import com.salesforce.apollo.context.StaticContext; import com.salesforce.apollo.cryptography.*; import com.salesforce.apollo.cryptography.Signer.SignerImpl; import com.salesforce.apollo.cryptography.proto.PubKey; +import com.salesforce.apollo.ethereal.Dag; import com.salesforce.apollo.membership.GroupIterator; import com.salesforce.apollo.membership.Member; import com.salesforce.apollo.membership.RoundScheduler; @@ -44,7 +46,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.security.KeyPair; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -394,12 +399,6 @@ private boolean checkJoin(Digest nextView, Digest from) { source.getId(), params.member().getId()); return false; } - final Set members = Committee.viewMembersOf(nextView, pendingView().get()); - if (!members.contains(params.member())) { - log.debug("Not a member of view: {} invalid join request from: {} members: {} on: {}", nextView, - source.getId(), members.stream().map(m -> m.getId()).toList(), params.member().getId()); - return false; - } return true; } @@ -736,12 +735,12 @@ private void reconfigure(Reconfigure reconfigure) { view.set(h); session.setView(h); if (validators.containsKey(params.member())) { - try { + if (Dag.validate(validators.size())) { current.set(new Associate(h, validators, currentView)); - } catch (IllegalArgumentException e) { + } else { + log.warn("Reconfiguration to associate failed: {} in view: {} on:{}", validators.size(), + new Digest(reconfigure.getId()), params.member().getId()); current.set(new Client(validators, getViewId())); - log.debug("unable to create consensus: {} defaulting to committee: {} on: {}", e.getMessage(), - current.get().getClass().getSimpleName(), params.member().getId()); } } else { current.set(new Client(validators, getViewId())); @@ -1262,6 +1261,8 @@ public SubmitResult submitTxn(Transaction transaction) { log.debug("No link for: {} for submitting txn on: {}", target.getId(), params.member().getId()); return SubmitResult.newBuilder().setResult(Result.UNAVAILABLE).build(); } + log.trace("Submitting txn: {} to: {} in view: {} on: {}", hashOf(transaction, params.digestAlgorithm()), + link.getMember().getId(), viewId, params.member().getId()); return link.submit(transaction); } catch (StatusRuntimeException e) { log.trace("Failed submitting txn: {} status:{} to: {} in: {} on: {}", @@ -1294,7 +1295,8 @@ private class Associate extends Administration { super(validators, new Digest( viewChange.block.hasGenesis() ? viewChange.block.getGenesis().getInitialView().getId() : viewChange.block.getReconfigure().getId())); - var context = Committee.viewFor(viewId, params.context()); + var context = new StaticContext<>(viewId, params.context().getProbabilityByzantine(), 3, + validators.keySet(), params.context().getEpsilon(), validators.size()); log.trace("Using consensus key: {} sig: {} for view: {} on: {}", params.digestAlgorithm().digest(nextView.consensusKeyPair.getPublic().getEncoded()), params.digestAlgorithm().digest(nextView.member.getSignature().toByteString()), viewId, diff --git a/choam/src/main/java/com/salesforce/apollo/choam/Producer.java b/choam/src/main/java/com/salesforce/apollo/choam/Producer.java index d8af594e1..0ff834cb1 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/Producer.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/Producer.java @@ -150,6 +150,9 @@ public void stop() { } public SubmitResult submit(Transaction transaction) { + if (!started.get()) { + return SubmitResult.newBuilder().setResult(Result.NO_COMMITTEE).build(); + } if (ds.offer(transaction)) { return SubmitResult.newBuilder().setResult(Result.PUBLISHED).build(); } else { diff --git a/choam/src/main/java/com/salesforce/apollo/choam/Session.java b/choam/src/main/java/com/salesforce/apollo/choam/Session.java index d7185aea9..99aa48076 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/Session.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/Session.java @@ -89,9 +89,11 @@ public static boolean verify(Transaction transaction, Verifier verifier) { public static CompletableFuture retryNesting(Supplier> supplier, int maxRetries) { CompletableFuture cf = supplier.get(); for (int i = 0; i < maxRetries; i++) { - cf = cf.thenApply(CompletableFuture::completedFuture) - .exceptionally(__ -> supplier.get()) - .thenCompose(java.util.function.Function.identity()); + final var attempt = i; + cf = cf.thenApply(CompletableFuture::completedFuture).exceptionally(__ -> { + log.warn("resubmitting, next attempt: {}", attempt); + return supplier.get(); + }).thenCompose(java.util.function.Function.identity()); } return cf; } @@ -310,6 +312,7 @@ private Submission submit(SubmittedTransaction stx) { return new Submission(SubmitResult.newBuilder().setResult(SubmitResult.Result.RATE_LIMITED).build(), listener); } + log.debug("Submitting txn: {} on: {}", stx.hash(), params.member().getId()); return new Submission(service.apply(stx), listener); }