Skip to content

Commit 3a03c1f

Browse files
chore: Integrate PBJ lib prereq to tss.wrapsEnabled=true (#22478)
Signed-off-by: Michael Tinker <[email protected]>
1 parent 976bbea commit 3a03c1f

File tree

38 files changed

+1385
-469
lines changed

38 files changed

+1385
-469
lines changed

hedera-node/hapi-utils/src/main/java/com/hedera/node/app/hapi/utils/CommonPbjConverters.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.hedera.node.app.hapi.utils;
33

44
import static com.hedera.node.app.hapi.utils.ByteStringUtils.unwrapUnsafelyIfPossible;
5+
import static com.hedera.pbj.runtime.Codec.DEFAULT_MAX_DEPTH;
56
import static com.hederahashgraph.api.proto.java.HederaFunctionality.*;
67
import static java.util.Objects.requireNonNull;
78

@@ -47,6 +48,8 @@
4748
import java.util.List;
4849

4950
public class CommonPbjConverters {
51+
public static final int MAX_PBJ_RECORD_SIZE = 33554432;
52+
5053
public static @NonNull com.hederahashgraph.api.proto.java.Query fromPbj(@NonNull Query query) {
5154
requireNonNull(query);
5255
try {
@@ -427,7 +430,8 @@ public static Timestamp toPbj(@NonNull com.hederahashgraph.api.proto.java.Timest
427430
requireNonNull(txBody);
428431
try {
429432
final var bytes = txBody.toByteArray();
430-
return TransactionBody.PROTOBUF.parse(BufferedData.wrap(bytes));
433+
return TransactionBody.PROTOBUF.parse(
434+
BufferedData.wrap(bytes), false, false, DEFAULT_MAX_DEPTH, MAX_PBJ_RECORD_SIZE);
431435
} catch (ParseException e) {
432436
throw new RuntimeException(e);
433437
}

hedera-node/hapi-utils/src/main/java/com/hedera/node/app/hapi/utils/blocks/BlockStreamAccess.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package com.hedera.node.app.hapi.utils.blocks;
33

4+
import static com.hedera.node.app.hapi.utils.CommonPbjConverters.MAX_PBJ_RECORD_SIZE;
45
import static com.hedera.node.app.hapi.utils.exports.recordstreaming.RecordStreamingUtils.SIDECAR_ONLY_TOKEN;
6+
import static com.hedera.pbj.runtime.Codec.DEFAULT_MAX_DEPTH;
57
import static java.util.Comparator.comparing;
68

79
import com.hedera.hapi.block.stream.Block;
@@ -159,10 +161,20 @@ public static Block blockFrom(@NonNull final Path path) {
159161
try {
160162
if (fileName.endsWith(".gz")) {
161163
try (final GZIPInputStream in = new GZIPInputStream(Files.newInputStream(path))) {
162-
return Block.PROTOBUF.parse(Bytes.wrap(in.readAllBytes()));
164+
return Block.PROTOBUF.parse(
165+
Bytes.wrap(in.readAllBytes()).toReadableSequentialData(),
166+
false,
167+
false,
168+
DEFAULT_MAX_DEPTH,
169+
MAX_PBJ_RECORD_SIZE);
163170
}
164171
} else {
165-
return Block.PROTOBUF.parse(Bytes.wrap(Files.readAllBytes(path)));
172+
return Block.PROTOBUF.parse(
173+
Bytes.wrap(Files.readAllBytes(path)).toReadableSequentialData(),
174+
false,
175+
false,
176+
DEFAULT_MAX_DEPTH,
177+
MAX_PBJ_RECORD_SIZE);
166178
}
167179
} catch (IOException | ParseException e) {
168180
throw new RuntimeException("Failed reading block @ " + path, e);

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/HistoryLibrary.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public interface HistoryLibrary {
2525
*/
2626
Bytes EMPTY_PUBLIC_KEY = Bytes.wrap(new byte[32]);
2727

28+
/**
29+
* A placeholder metadata for the genesis WRAPS proof.
30+
*/
31+
byte[] GENESIS_WRAPS_METADATA = new byte[1280];
32+
2833
/**
2934
* An address book for use in the history library.
3035
* @param weights the weights of the nodes in the address book
@@ -252,4 +257,9 @@ Proof constructIncrementalWrapsProof(
252257
* @return true if the proof is valid; false otherwise
253258
*/
254259
boolean isValidWraps(byte[] compressedProof);
260+
261+
/**
262+
* Returns whether the library is ready to be used.
263+
*/
264+
boolean wrapsProverReady();
255265
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/handlers/HistoryProofKeyPublicationHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.hedera.node.app.spi.workflows.PreHandleContext;
1414
import com.hedera.node.app.spi.workflows.PureChecksContext;
1515
import com.hedera.node.app.spi.workflows.TransactionHandler;
16-
import com.hedera.node.config.data.TssConfig;
1716
import edu.umd.cs.findbugs.annotations.NonNull;
1817
import javax.inject.Inject;
1918
import javax.inject.Singleton;
@@ -63,8 +62,7 @@ public void handle(@NonNull final HandleContext context) throws HandleException
6362
controllers.getAnyInProgress().ifPresent(controller -> {
6463
final var publication =
6564
new WrapsMessagePublication(nodeId, message, op.phase(), context.consensusNow());
66-
if (controller.addWrapsMessagePublication(
67-
publication, historyStore, context.configuration().getConfigData(TssConfig.class))) {
65+
if (controller.addWrapsMessagePublication(publication, historyStore)) {
6866
historyStore.addWrapsMessage(controller.constructionId(), publication);
6967
}
7068
});

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/impl/HistoryLibraryImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* Default implementation of the {@link HistoryLibrary}.
2020
*/
2121
public class HistoryLibraryImpl implements HistoryLibrary {
22-
private static final byte[] DUMMY_HINTS_KEY = new byte[1280];
2322
public static final SplittableRandom RANDOM = new SplittableRandom();
2423
public static final WRAPSLibraryBridge WRAPS = WRAPSLibraryBridge.getInstance();
2524

@@ -131,7 +130,7 @@ public Proof constructGenesisWrapsProof(
131130
addressBook.publicKeys(),
132131
addressBook.weights(),
133132
null,
134-
DUMMY_HINTS_KEY,
133+
GENESIS_WRAPS_METADATA,
135134
aggregatedSignature,
136135
addressBook.signersMask(signers));
137136
}
@@ -169,4 +168,9 @@ public boolean isValidWraps(@NonNull final byte[] compressedProof) {
169168
requireNonNull(compressedProof);
170169
return WRAPS.verifyCompressedProof(compressedProof);
171170
}
171+
172+
@Override
173+
public boolean wrapsProverReady() {
174+
return WRAPSLibraryBridge.isProofSupported();
175+
}
172176
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/impl/HistoryProver.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package com.hedera.node.app.history.impl;
33

4-
import static java.util.Objects.requireNonNull;
5-
64
import com.hedera.hapi.node.state.history.HistoryProof;
75
import com.hedera.hapi.node.state.history.HistoryProofConstruction;
6+
import com.hedera.hapi.node.state.history.HistoryProofVote;
87
import com.hedera.hapi.node.state.history.ProofKey;
98
import com.hedera.node.app.history.HistoryLibrary;
109
import com.hedera.node.app.history.ReadableHistoryStore.WrapsMessagePublication;
@@ -31,7 +30,7 @@
3130
* </ul>
3231
* <p>
3332
* Implementations are allowed to be completely asynchronous internally, and most implementations will likely converge
34-
* to an outcome by submitting votes via {@link HistorySubmissions#submitProofVote(long, HistoryProof)}. However, a
33+
* to an outcome by submitting votes via {@link HistorySubmissions#submitExplicitProofVote(long, HistoryProof)}. However, a
3534
* simple implementation could also return a completed proof from a synchronous call to {@link #advance}.
3635
* <p>
3736
* Since implementations are expected to also be stateful, a {@link ProofController} will have a {@link HistoryProver}
@@ -44,6 +43,7 @@ public interface HistoryProver {
4443
interface Factory {
4544
HistoryProver create(
4645
long selfId,
46+
@NonNull TssConfig tssConfig,
4747
@NonNull SchnorrKeyPair schnorrKeyPair,
4848
@Nullable HistoryProof sourceProof,
4949
@NonNull RosterTransitionWeights weights,
@@ -119,24 +119,28 @@ Outcome advance(
119119
* @param constructionId the construction ID
120120
* @param publication the WRAPS message publication
121121
* @param writableHistoryStore the writable history store
122-
* @param tssConfig the TSS configuration
123122
* @return true if the publication was needed by this prover, false otherwise
124123
*/
125124
boolean addWrapsSigningMessage(
126125
long constructionId,
127126
@NonNull WrapsMessagePublication publication,
128-
@NonNull WritableHistoryStore writableHistoryStore,
129-
@NonNull TssConfig tssConfig);
127+
@NonNull WritableHistoryStore writableHistoryStore);
130128

131129
/**
132130
* Replays a WRAPS message publication that previously reached consensus.
133131
* @param constructionId the construction ID
134132
* @param publication the WRAPS message publication
135133
*/
136-
default void replayWrapsSigningMessage(
137-
final long constructionId, @NonNull final WrapsMessagePublication publication) {
138-
requireNonNull(publication);
139-
}
134+
void replayWrapsSigningMessage(long constructionId, @NonNull WrapsMessagePublication publication);
135+
136+
/**
137+
* Observes a proof vote.
138+
*
139+
* @param nodeId the node ID
140+
* @param vote the vote
141+
* @param proofFinalized whether this vote finalized the proof
142+
*/
143+
void observeProofVote(long nodeId, @NonNull HistoryProofVote vote, boolean proofFinalized);
140144

141145
/**
142146
* Returns a list of proof keys from the given map.

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/impl/HistoryServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public void reconcile(
9090
construction,
9191
historyStore,
9292
activeHintsConstruction,
93-
historyStore.getActiveConstruction());
93+
historyStore.getActiveConstruction(),
94+
tssConfig);
9495
controller.advanceConstruction(now, metadata, historyStore, isActive, tssConfig);
9596
}
9697
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/impl/HistorySubmissions.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,26 @@ public CompletableFuture<Void> submitWrapsSigningMessage(
7676
* @param proof history proof to vote for
7777
* @return a future that completes with the submission
7878
*/
79-
public CompletableFuture<Void> submitProofVote(final long constructionId, @NonNull final HistoryProof proof) {
79+
public CompletableFuture<Void> submitExplicitProofVote(
80+
final long constructionId, @NonNull final HistoryProof proof) {
8081
requireNonNull(proof);
8182
logger.info("Submitting proof vote for construction #{}", constructionId);
8283
final var vote = HistoryProofVote.newBuilder().proof(proof).build();
8384
return submitIfActive(
8485
b -> b.historyProofVote(new HistoryProofVoteTransactionBody(constructionId, vote)), onFailure);
8586
}
87+
88+
/**
89+
* Submits a history proof vote to the network.
90+
* @param constructionId the construction id to vote on
91+
* @param congruentNodeId the node id that has already voted for the same proof
92+
* @return a future that completes with the submission
93+
*/
94+
public CompletableFuture<Void> submitCongruentProofVote(final long constructionId, final long congruentNodeId) {
95+
logger.info("Submitting proof vote congruent to node{} for construction #{}", congruentNodeId, constructionId);
96+
final var vote =
97+
HistoryProofVote.newBuilder().congruentNodeId(congruentNodeId).build();
98+
return submitIfActive(
99+
b -> b.historyProofVote(new HistoryProofVoteTransactionBody(constructionId, vote)), onFailure);
100+
}
86101
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/impl/InertProofController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ public void addProofVote(
6060
@Override
6161
public boolean addWrapsMessagePublication(
6262
@NonNull final WrapsMessagePublication publication,
63-
@NonNull final WritableHistoryStore writableHistoryStore,
64-
@NonNull final TssConfig tssConfig) {
63+
@NonNull final WritableHistoryStore writableHistoryStore) {
6564
requireNonNull(publication);
6665
requireNonNull(writableHistoryStore);
67-
requireNonNull(tssConfig);
6866
return false;
6967
}
7068

hedera-node/hedera-app/src/main/java/com/hedera/node/app/history/impl/ProofController.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ void advanceConstruction(
5858
*
5959
* @param publication the proof key publication
6060
* @param writableHistoryStore the writable history store
61-
* @param tssConfig the TSS configuration
6261
*/
6362
boolean addWrapsMessagePublication(
64-
@NonNull WrapsMessagePublication publication,
65-
@NonNull WritableHistoryStore writableHistoryStore,
66-
@NonNull TssConfig tssConfig);
63+
@NonNull WrapsMessagePublication publication, @NonNull WritableHistoryStore writableHistoryStore);
6764

6865
/**
6966
* If this controller's construction is not already complete, considers updating its state with this history

0 commit comments

Comments
 (0)