Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Mar 23, 2024
1 parent 1a1865d commit 548ceb7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 37 deletions.
23 changes: 11 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 @@ -311,9 +311,8 @@ public String logState() {
public void nextView(Context<Member> context, Digest diadem) {
((DelegatedContext<Member>) combine.getContext()).setContext(context);
var c = current.get();
var pv = new PendingView(context, diadem);
if (c != null) {
c.nextView(pv);
c.nextView(new PendingView(context, diadem));
} else {
log.info("Acquiring new diadem: {} size: {} on: {}", diadem, context.size(), params.member().getId());
params.context().setContext(context);
Expand Down Expand Up @@ -881,20 +880,20 @@ private Initial sync(Synchronize request, Digest from) {
private void synchronize(SynchronizedState state) {
transitions.synchronizing();
CertifiedBlock current1;
if (state.lastCheckpoint == null) {
log.info("Synchronizing from genesis: {} on: {}", state.genesis.hash, params.member().getId());
current1 = state.genesis.certifiedBlock;
if (state.lastCheckpoint() == null) {
log.info("Synchronizing from genesis: {} on: {}", state.genesis().hash, params.member().getId());
current1 = state.genesis().certifiedBlock;
} else {
log.info("Synchronizing from checkpoint: {} on: {}", state.lastCheckpoint.hash, params.member().getId());
restoreFrom(state.lastCheckpoint, state.checkpoint);
current1 = store.getCertifiedBlock(state.lastCheckpoint.height().add(1));
log.info("Synchronizing from checkpoint: {} on: {}", state.lastCheckpoint().hash, params.member().getId());
restoreFrom(state.lastCheckpoint(), state.checkpoint());
current1 = store.getCertifiedBlock(state.lastCheckpoint().height().add(1));
}
while (current1 != null) {
synchronizedProcess(current1);
current1 = store.getCertifiedBlock(height(current1.getBlock()).add(1));
}
log.info("Synchronized, resuming view: {} deferred blocks: {} on: {}",
state.lastCheckpoint != null ? state.lastCheckpoint.hash : state.genesis.hash, pending.size(),
state.lastCheckpoint() != null ? state.lastCheckpoint().hash : state.genesis().hash, pending.size(),
params.member().getId());
try {
linear.execute(transitions::regenerated);
Expand Down Expand Up @@ -926,7 +925,7 @@ private void synchronizedProcess(CertifiedBlock certifiedBlock) {
}
} else {
if (hcb.height().compareTo(prevHeight) <= 0) {
log.debug("Discarding previously committed block: {} height: {} current height: {} on: {}",
log.trace("Discarding previously committed block: {} height: {} current height: {} on: {}",
hcb.hash, hcb.height(), prevHeight, params.member().getId());
return;
}
Expand Down Expand Up @@ -1360,7 +1359,7 @@ public void nextView(PendingView pendingView) {
pendingView.context.size(), params.member().getId());
params.context().setContext(pendingView.context);
CHOAM.this.diadem.set(pendingView.diadem);
CHOAM.this.pendingView.set(pendingView);
CHOAM.this.pendingView.set(null);
if (assembly != null) {
assembly.start();
}
Expand Down Expand Up @@ -1429,7 +1428,7 @@ public void nextView(PendingView pendingView) {
params.member().getId());
params.context().setContext(pendingView.context);
CHOAM.this.diadem.set(pendingView.diadem);
CHOAM.this.pendingView.set(pendingView);
CHOAM.this.pendingView.set(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ViewAssembly(Digest nextViewId, ViewContext vc, Consumer<Reassemble> publ
.stream()
.collect(Collectors.toMap(Member::getId, m -> m));
var slice = new ArrayList<>(nextAssembly.values());
committee = new SliceIterator<Terminal>("Committee for " + nextViewId, params().member(), slice, comms);
committee = new SliceIterator<>("Committee for " + nextViewId, params().member(), slice, comms);

final Fsm<Reconfiguration, Transitions> fsm = Fsm.construct(new Recon(), Transitions.class,
Reconfigure.AWAIT_ASSEMBLY, true);
Expand All @@ -78,8 +78,7 @@ public ViewAssembly(Digest nextViewId, ViewContext vc, Consumer<Reassemble> publ
}

public Map<Member, Join> getSlate() {
final var c = slate;
return c;
return slate;
}

public void start() {
Expand Down Expand Up @@ -111,7 +110,7 @@ void complete() {
.stream()
.map(p -> String.format("%s:%s", p.member.getId(),
p.validations.size()))
.toList(), nextViewId, params().member());
.toList(), nextViewId, params().member().getId());
transitions.failed();
}
}
Expand Down Expand Up @@ -316,7 +315,8 @@ public void certify() {
if (proposals.values().stream().filter(p -> p.validations.size() == nextAssembly.size()).count()
== nextAssembly.size()) {
cancelSlice.set(true);
log.debug("Certifying slate: {} of: {} on: {}", proposals.size(), nextViewId, params().member());
log.debug("Certifying slate: {} of: {} on: {}", proposals.size(), nextViewId,
params().member().getId());
transitions.certified();
}
log.debug("Not certifying slate: {} of: {} on: {}", proposals.entrySet()
Expand All @@ -341,7 +341,7 @@ public void elect() {
.forEach(p -> slate.put(p.member(), joinOf(p)));
if (slate.size() >= params().context().majority()) {
cancelSlice.set(true);
log.debug("Electing slate: {} of: {} on: {}", slate.size(), nextViewId, params().member());
log.debug("Electing slate: {} of: {} on: {}", slate.size(), nextViewId, params().member().getId());
transitions.complete();
} else {
log.error("Failed election, required: {} slate: {} of: {} on: {}", params().context().majority() + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,23 +493,12 @@ private void validateViewChain() {
}
}

public record SynchronizedState(HashedCertifiedBlock genesis, HashedCertifiedBlock lastView,
HashedCertifiedBlock lastCheckpoint, CheckpointState checkpoint) {
}

public static class GenesisNotResolved extends Exception {
private static final long serialVersionUID = 1L;

}

public static class SynchronizedState {
public final CheckpointState checkpoint;
public final HashedCertifiedBlock genesis;
public final HashedCertifiedBlock lastCheckpoint;
public final HashedCertifiedBlock lastView;

public SynchronizedState(HashedCertifiedBlock genesis, HashedCertifiedBlock lastView,
HashedCertifiedBlock lastCheckpoint, CheckpointState checkpoint) {
this.genesis = genesis;
this.lastView = lastView;
this.lastCheckpoint = lastCheckpoint;
this.checkpoint = checkpoint;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public void smoke() throws Exception {
CompletableFuture<SynchronizedState> syncFuture = boot.synchronize();
SynchronizedState state = syncFuture.get(10, TimeUnit.SECONDS);
assertNotNull(state);
assertNotNull(state.genesis);
assertNotNull(state.checkpoint);
assertNotNull(state.lastCheckpoint);
assertNotNull(state.lastView);
assertNotNull(state.genesis());
assertNotNull(state.checkpoint());
assertNotNull(state.lastCheckpoint());
assertNotNull(state.lastView());
}

private Terminal mockClient(Member to, Store bootstrapStore, TestChain testChain) {
Expand Down

0 comments on commit 548ceb7

Please sign in to comment.