Skip to content

Commit

Permalink
Use the compact digest of the view diadem - do'h
Browse files Browse the repository at this point in the history
fix up view listener
  • Loading branch information
Hellblazer committed Jan 28, 2024
1 parent 8c2bad2 commit 695baaa
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 70 deletions.
44 changes: 20 additions & 24 deletions choam/src/main/java/com/salesforce/apollo/choam/CHOAM.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public class CHOAM {
private final Combine.Transitions transitions;
private final TransSubmission txnSubmission = new TransSubmission();
private final AtomicReference<HashedCertifiedBlock> view = new AtomicReference<>();
private final AtomicReference<HexBloom> diadem = new AtomicReference<>();
private final AtomicReference<Digest> diadem = new AtomicReference<>();

public CHOAM(Parameters params) {
this.store = new Store(params.digestAlgorithm(), params.mvBuilder().clone().build());
this.params = params;
diadem.set(new HexBloom(params.digestAlgorithm().getLast()));
diadem.set(params.digestAlgorithm().getLast());
executions = Executors.newVirtualThreadPerTaskExecutor();

nextView();
Expand Down Expand Up @@ -175,7 +175,7 @@ public static Checkpoint checkpoint(DigestAlgorithm algo, File state, int segmen
return cp;
}

public static Block genesis(Digest id, HexBloom diadem, Map<Member, Join> joins, HashedBlock head,
public static Block genesis(Digest id, Digest diadem, Map<Member, Join> joins, HashedBlock head,
Context<Member> context, HashedBlock lastViewChange, Parameters params,
HashedBlock lastCheckpoint, Iterable<Transaction> initialization) {
var reconfigure = reconfigure(id, diadem, joins, context, params, params.checkpointBlockDelta());
Expand All @@ -196,12 +196,12 @@ public static String print(Join join, DigestAlgorithm da) {
+ "certifications: " + join.getEndorsementsList().stream().map(c -> ViewContext.print(c, da)).toList() + "]";
}

public static Reconfigure reconfigure(Digest nextViewId, HexBloom diadem, Map<Member, Join> joins,
public static Reconfigure reconfigure(Digest nextViewId, Digest diadem, Map<Member, Join> joins,
Context<Member> context, Parameters params, int checkpointTarget) {
var builder = Reconfigure.newBuilder()
.setCheckpointTarget(checkpointTarget)
.setId(nextViewId.toDigeste())
.setView(diadem.toHexBloome());
.setView(diadem.toDigeste());

// Canonical labeling of the view members for Ethereal
var remapped = rosterMap(context, joins.keySet());
Expand All @@ -212,7 +212,7 @@ public static Reconfigure reconfigure(Digest nextViewId, HexBloom diadem, Map<Me
return reconfigure;
}

public static Block reconfigure(Digest nextViewId, HexBloom diadem, Map<Member, Join> joins, HashedBlock head,
public static Block reconfigure(Digest nextViewId, Digest diadem, Map<Member, Join> joins, HashedBlock head,
Context<Member> context, HashedBlock lastViewChange, Parameters params,
HashedBlock lastCheckpoint) {
final Block lvc = lastViewChange.block;
Expand Down Expand Up @@ -299,16 +299,16 @@ public String logState() {
params.member().getId());
}

public void setDiadem(HexBloom diadem) {
log.info("Set diadem: {} on: {}", diadem.compact(), params.member().getId());
public void setDiadem(Digest diadem) {
log.info("Set diadem: {} on: {}", diadem, params.member().getId());
this.diadem.set(diadem);
}

public void start() {
if (!started.compareAndSet(false, true)) {
return;
}
log.info("CHOAM startup: {} diadem: {}, majority: {} on: {}", params.context().getId(), diadem.get().compact(),
log.info("CHOAM startup: {} diadem: {}, majority: {} on: {}", params.context().getId(), diadem.get(),
params.majority(), params.member().getId());
combine.start(params.producer().gossipDuration());
transitions.fsm().enterStartState();
Expand Down Expand Up @@ -475,7 +475,7 @@ public Block checkpoint() {
}

@Override
public HexBloom diadem() {
public Digest diadem() {
return diadem.get();
}

Expand All @@ -484,7 +484,7 @@ public Block genesis(Map<Member, Join> joining, Digest nextViewId, HashedBlock p
final HashedCertifiedBlock cp = checkpoint.get();
final HashedCertifiedBlock v = view.get();
var current = diadem.get();
log.info("Create genesis: {}", diadem.get().compact());
log.info("Create genesis: {}", diadem.get());
return CHOAM.genesis(nextViewId, current, joining, previous, params.context(), v, params, cp,
params.genesisData().apply(joining));
}
Expand Down Expand Up @@ -634,8 +634,7 @@ private void nextView() {
var current = diadem.get();
log.trace("Generated next view consensus key: {} sig: {} diadem: {} on: {}",
params.digestAlgorithm().digest(pubKey.getEncoded()),
params.digestAlgorithm().digest(signed.toSig().toByteString()), current.compact(),
params.member().getId());
params.digestAlgorithm().digest(signed.toSig().toByteString()), current, params.member().getId());
next.set(new nextView(ViewMember.newBuilder()
.setId(params.member().getId().toDigeste())
.setConsensusKey(pubKey)
Expand All @@ -652,14 +651,13 @@ private void process() {
case ASSEMBLE: {
params.processor().beginBlock(h.height(), h.hash);
nextViewId.set(Digest.from(h.block.getAssemble().getNextView()));
var ass = HexBloom.from(h.block.getAssemble().getDiadem());
var ass = Digest.from(h.block.getAssemble().getDiadem());
var current = diadem.getAndSet(ass);
if (!current.equivalent(ass)) {
log.info("Next view id: {} diadem: {} does match current: {} on: {}", nextViewId.get(), ass.compact(),
current.compact(), params.member().getId());
if (!current.equals(ass)) {
log.info("Next view id: {} diadem: {} does match current: {} on: {}", nextViewId.get(), ass, current,
params.member().getId());
}
log.info("Next view id: {} diadem: {} on: {}", nextViewId.get(), diadem.get().compact(),
params.member().getId());
log.info("Next view id: {} diadem: {} on: {}", nextViewId.get(), diadem.get(), params.member().getId());
c.assembled();
break;
}
Expand Down Expand Up @@ -963,7 +961,7 @@ private void synchronizedProcess(CertifiedBlock certifiedBlock) {
public interface BlockProducer {
Block checkpoint();

HexBloom diadem();
Digest diadem();

Block genesis(Map<Member, Join> joining, Digest nextViewId, HashedBlock previous);

Expand Down Expand Up @@ -1159,7 +1157,7 @@ public ViewMember join(Digest nextView, Digest from) {
log.debug("Joining view: {} from: {} view member: {} on: {}", nextView, from,
ViewContext.print(c.member, params.digestAlgorithm()), params.member().getId());
}
return ViewMember.newBuilder(c.member).setDiadem(diadem.get().toIdentityHexBloome()).build();
return ViewMember.newBuilder(c.member).setDiadem(diadem.get().toDigeste()).build();
}

@Override
Expand Down Expand Up @@ -1307,13 +1305,11 @@ public ViewMember join(Digest nextView, Digest from) {
}
final var c = next.get();
var cd = diadem.get();
assert cd.equivalent(HexBloom.from(cd.toIdentityHexBloome())) : "Deser: {} not equal to: {}".formatted(
HexBloom.from(cd.toIdentityHexBloome()), cd);
if (log.isDebugEnabled()) {
log.debug("Joining view: {} diadem: {} from: {} view member: {} on: {}", nextView, cd, from,
ViewContext.print(c.member, params.digestAlgorithm()), params.member().getId());
}
return ViewMember.newBuilder(c.member).setDiadem(cd.toIdentityHexBloome()).build();
return ViewMember.newBuilder(c.member).setDiadem(cd.toDigeste()).build();
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions choam/src/main/java/com/salesforce/apollo/choam/Producer.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ private void produceAssemble() {
nextViewId = vlb.hash;
nextAssembly.addAll(Committee.viewMembersOf(nextViewId, params().context()));
var diadem = view.diadem();
log.debug("Assembling: {} diadem: {} on: {}", nextViewId, diadem.compact(), params().member().getId());
log.debug("Assembling: {} diadem: {} on: {}", nextViewId, diadem, params().member().getId());
final var assemble = new HashedBlock(params().digestAlgorithm(), view.produce(vlb.height().add(1), vlb.hash,
Assemble.newBuilder()
.setNextView(
vlb.hash.toDigeste())
.setDiadem(
diadem.toIdentityHexBloome())
diadem.toDigeste())
.build(),
checkpoint.get()));
previousBlock.set(assemble);
Expand Down Expand Up @@ -373,14 +373,14 @@ public void produceAssemble() {

@Override
public void reconfigure() {
log.debug("Starting view reconfiguration: {} diadem: {} on: {}", nextViewId, view.diadem().compact(),
log.debug("Starting view reconfiguration: {} diadem: {} on: {}", nextViewId, view.diadem(),
params().member().getId());
assembly.set(new ViewAssembly(nextViewId, view, Producer.this::addReassemble, comms) {
@Override
public void complete() {
super.complete();
log.debug("View reconfiguration: {} diadem: {} gathered: {} complete on: {}", nextViewId,
view.diadem().compact(), getSlate().size(), params().member().getId());
view.diadem(), getSlate().size(), params().member().getId());
assembled.set(true);
Producer.this.transitions.viewComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.salesforce.apollo.choam.fsm.Reconfiguration.Transitions;
import com.salesforce.apollo.choam.proto.*;
import com.salesforce.apollo.cryptography.Digest;
import com.salesforce.apollo.cryptography.HexBloom;
import com.salesforce.apollo.cryptography.proto.PubKey;
import com.salesforce.apollo.membership.Member;
import com.salesforce.apollo.ring.SliceIterator;
Expand Down Expand Up @@ -199,10 +198,10 @@ private Reassemble join(ViewMember vm) {
}
return null;
}
final var hex = HexBloom.from(vm.getDiadem());
final var hex = Digest.from(vm.getDiadem());
var diadem = view.diadem();
if (!diadem.equivalent(hex)) {
log.warn("Invalid diadem: {} not equivalent to: {} vm: {} on: {}", hex.compact(), diadem.compact(),
if (!diadem.equals(hex)) {
log.warn("Invalid diadem: {} not equivalent to: {} vm: {} on: {}", hex, diadem,
ViewContext.print(vm, params().digestAlgorithm()), params().member().getId());
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public Context<Member> context() {
return context;
}

public HexBloom diadem() {
return blockProducer == null ? new HexBloom() : blockProducer.diadem();
public Digest diadem() {
return blockProducer == null ? DigestAlgorithm.DEFAULT.getLast() : blockProducer.diadem();
}

public Validate generateValidation(HashedBlock block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.salesforce.apollo.choam.support.HashedBlock;
import com.salesforce.apollo.cryptography.Digest;
import com.salesforce.apollo.cryptography.DigestAlgorithm;
import com.salesforce.apollo.cryptography.HexBloom;
import com.salesforce.apollo.cryptography.Signer;
import com.salesforce.apollo.cryptography.proto.PubKey;
import com.salesforce.apollo.membership.Context;
Expand Down Expand Up @@ -138,14 +137,14 @@ public Block checkpoint() {
}

@Override
public HexBloom diadem() {
return new HexBloom();
public Digest diadem() {
return DigestAlgorithm.DEFAULT.getLast();
}

@Override
public Block genesis(Map<Member, Join> joining, Digest nextViewId, HashedBlock previous) {
return CHOAM.genesis(viewId, new HexBloom(), joining, previous, committee, previous, built,
previous, Collections.emptyList());
return CHOAM.genesis(viewId, DigestAlgorithm.DEFAULT.getLast(), joining, previous, committee,
previous, built, previous, Collections.emptyList());
}

@Override
Expand All @@ -169,7 +168,6 @@ public Block reconfigure(Map<Member, Join> joining, Digest nextViewId, HashedBlo
return null;
}
};
HexBloom diadem = new HexBloom();
var view = new GenesisContext(committee, built, sm, reconfigure);

KeyPair keyPair = params.getViewSigAlgorithm().generateKeyPair();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void buildAssemblies() {
public ViewMember answer(InvocationOnMock invocation) throws Throwable {
return ViewMember.newBuilder()
.setId(m.getId().toDigeste())
.setDiadem(new HexBloom().toIdentityHexBloome())
.setDiadem(DigestAlgorithm.DEFAULT.getLast().toDigeste())
.setConsensusKey(consensus)
.setSignature(((Signer) m).sign(consensus.toByteString()).toSig())
.build();
Expand Down Expand Up @@ -161,7 +161,6 @@ public ViewMember answer(InvocationOnMock invocation) throws Throwable {
e -> new Verifier.DefaultVerifier(
e.getValue().getPublic())));
Map<Member, ViewContext> views = new HashMap<>();
HexBloom diadem = new HexBloom(DigestAlgorithm.DEFAULT.getLast());
context.active().forEach(m -> {
SigningMember sm = (SigningMember) m;
Router router = communications.get(m);
Expand Down
21 changes: 10 additions & 11 deletions fireflies/src/main/java/com/salesforce/apollo/fireflies/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,12 @@ void introduced() {
void notifyListeners(List<SelfAddressingIdentifier> joining, List<Digest> leaving) {
final var current = currentView();
viewNotificationQueue.execute(Utils.wrapped(() -> {
var diadem = viewManagement.diadem.get();
lifecycleListeners.forEach(listener -> {
try {
log.trace("Notifying: {} view change: {} diadem: {} cardinality: {} joins: {} leaves: {} on: {} ",
listener, currentView(), diadem, context.totalCount(), joining.size(), leaving.size(),
node.getId());
listener.viewChange(i -> context.getMember(i.getDigest()), diadem, current, joining, leaving);
log.trace("Notifying: {} view change: {} cardinality: {} joins: {} leaves: {} on: {} ", listener,
currentView(), context.totalCount(), joining.size(), leaving.size(), node.getId());
listener.viewChange(i -> context.getMember(i.getDigest()), current, viewManagement.cardinality(),
joining, leaving);
} catch (Throwable e) {
log.error("error in view change listener: {} on: {} ", listener, node.getId(), e);
}
Expand Down Expand Up @@ -1476,13 +1475,13 @@ public interface ViewLifecycleListener {
/**
* Notification of a view change event
*
* @param members - the source of Members for supplied identifiers
* @param diadem - the wrapped diadem of the view
* @param viewId - the Digest identity of the new view
* @param joins - the list of joining member's id
* @param leaves - the list of leaving member's id
* @param members - the source of Members for supplied identifiers
* @param viewId - the compact Digest identifying the new view
* @param cardinality - the cardinality of the new view
* @param joins - the list of joining member's id
* @param leaves - the list of leaving member's id
*/
void viewChange(Function<SelfAddressingIdentifier, Participant> members, HexBloom diadem, Digest viewId,
void viewChange(Function<SelfAddressingIdentifier, Participant> members, Digest viewId, int cardinality,
List<SelfAddressingIdentifier> joins, List<Digest> leaves);

}
Expand Down
6 changes: 3 additions & 3 deletions grpc/src/main/proto/choam.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ message Genesis {

message Reconfigure {
crypto.Digeste id = 1;
crypto.HexBloome view = 2;
crypto.Digeste view = 2;
int32 checkpointTarget = 3;
repeated Join joins = 4;
}
Expand All @@ -87,7 +87,7 @@ message Executions {

message Assemble {
crypto.Digeste nextView = 1;
crypto.HexBloome diadem = 2;
crypto.Digeste diadem = 2;
}

message FoundationSeal {
Expand Down Expand Up @@ -117,7 +117,7 @@ message Join {

message ViewMember {
crypto.Digeste id = 1;
crypto.HexBloome diadem = 2;
crypto.Digeste diadem = 2;
crypto.PubKey consensusKey = 3;
crypto.Sig signature = 4;
}
Expand Down
Loading

0 comments on commit 695baaa

Please sign in to comment.