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 a7f6c0b7e..870dafcbe 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java @@ -311,9 +311,8 @@ public String logState() { public void nextView(Context context, Digest diadem) { ((DelegatedContext) 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); @@ -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); @@ -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; } @@ -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(); } @@ -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 diff --git a/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java b/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java index ceaf8e783..2f0f91d00 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java @@ -66,7 +66,7 @@ public ViewAssembly(Digest nextViewId, ViewContext vc, Consumer publ .stream() .collect(Collectors.toMap(Member::getId, m -> m)); var slice = new ArrayList<>(nextAssembly.values()); - committee = new SliceIterator("Committee for " + nextViewId, params().member(), slice, comms); + committee = new SliceIterator<>("Committee for " + nextViewId, params().member(), slice, comms); final Fsm fsm = Fsm.construct(new Recon(), Transitions.class, Reconfigure.AWAIT_ASSEMBLY, true); @@ -78,8 +78,7 @@ public ViewAssembly(Digest nextViewId, ViewContext vc, Consumer publ } public Map getSlate() { - final var c = slate; - return c; + return slate; } public void start() { @@ -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(); } } @@ -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() @@ -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, diff --git a/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java b/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java index d7a70d594..915c82978 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/support/Bootstrapper.java @@ -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; - } - } } diff --git a/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java b/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java index 587278cc1..0275f948c 100644 --- a/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java +++ b/choam/src/test/java/com/salesforce/apollo/choam/support/BootstrapperTest.java @@ -111,10 +111,10 @@ public void smoke() throws Exception { CompletableFuture 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) {