Skip to content

Commit

Permalink
interim
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Apr 13, 2024
1 parent 58552cb commit d1149d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
26 changes: 14 additions & 12 deletions choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -394,12 +399,6 @@ private boolean checkJoin(Digest nextView, Digest from) {
source.getId(), params.member().getId());
return false;
}
final Set<Member> 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;
}

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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: {}",
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions choam/src/main/java/com/salesforce/apollo/choam/Producer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions choam/src/main/java/com/salesforce/apollo/choam/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ public static boolean verify(Transaction transaction, Verifier verifier) {
public static <T> CompletableFuture<T> retryNesting(Supplier<CompletableFuture<T>> supplier, int maxRetries) {
CompletableFuture<T> 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;
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit d1149d1

Please sign in to comment.