Skip to content

Commit

Permalink
chore: Add missing javadocs in Consensus Service (#15299)
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Tonev <[email protected]>
  • Loading branch information
petreze authored Sep 18, 2024
1 parent 6c987c2 commit 55b01b5
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
* Standard implementation of the {@link ConsensusService} {@link RpcService}.
*/
public final class ConsensusServiceImpl implements ConsensusService {
/**
* Topic running hash
*/
public static final int RUNNING_HASH_BYTE_ARRAY_SIZE = 48;

/**
* Topics state key
*/
public static final String TOPICS_KEY = "TOPICS";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void put(@NonNull final Topic topic) {
* Returns the {@link Topic} with the given number using {@link WritableKVState#getForModify}.
* If no such topic exists, returns {@code Optional.empty()}
* @param topicID - the id of the topic to be retrieved.
* @return the retrieved topic
*/
public Topic getForModify(@NonNull final TopicID topicID) {
requireNonNull(topicID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
*/
@Singleton
public class ConsensusCreateTopicHandler implements TransactionHandler {
/**
* Default constructor for injection.
*/
@Inject
public ConsensusCreateTopicHandler() {
// Exists for injection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
*/
@Singleton
public class ConsensusDeleteTopicHandler implements TransactionHandler {
/**
* Default constructor for injection.
*/
@Inject
public ConsensusDeleteTopicHandler() {
// Exists for injection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
*/
@Singleton
public class ConsensusGetTopicInfoHandler extends PaidQueryHandler {

/**
* Default constructor for injection.
*/
@Inject
public ConsensusGetTopicInfoHandler() {
// Dagger 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class ConsensusHandlers {

/**
* Constructor for ConsensusHandlers.
* @param consensusCreateTopicHandler the handler for create topic
* @param consensusDeleteTopicHandler the handler for delete topic
* @param consensusGetTopicInfoHandler the handler for topic info
* @param consensusSubmitMessageHandler the handler for message submit
* @param consensusUpdateTopicHandler the handler for update topic
*/
@Inject
public ConsensusHandlers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@
*/
@Singleton
public class ConsensusSubmitMessageHandler implements TransactionHandler {
/**
* Running hash version
*/
public static final long RUNNING_HASH_VERSION = 3L;

/**
* Default constructor for injection.
*/
@Inject
public ConsensusSubmitMessageHandler() {
// Exists for injection
Expand Down Expand Up @@ -262,6 +268,10 @@ public Topic updateRunningHashAndSequenceNumber(
return topicBuilder.build();
}

/**
* @param byteArray the byte array to hash
* @return the byte array of the hashed value
*/
public static byte[] noThrowSha384HashOf(final byte[] byteArray) {
try {
return MessageDigest.getInstance("SHA-384").digest(byteArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
public class ConsensusUpdateTopicHandler implements TransactionHandler {
private static final Logger log = LogManager.getLogger(ConsensusUpdateTopicHandler.class);

/**
* Default constructor for injection.
*/
@Inject
public ConsensusUpdateTopicHandler() {
// Exists for injection
Expand Down Expand Up @@ -304,6 +307,10 @@ private void validateMaybeNewSubmitKey(
}
}

/**
* @param op the transaction body of consensus update operation
* @return {@code true} if the operation wants to update a non-expiry field, {@code false} otherwise.
*/
public static boolean wantsToMutateNonExpiryField(@NonNull final ConsensusUpdateTopicTransactionBody op) {
return op.hasMemo()
|| op.hasAdminKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class V0490ConsensusSchema extends Schema {

private static final long MAX_TOPICS = 1_000_000_000L;

/**
* Constructor for this schema.
*/
public V0490ConsensusSchema() {
super(VERSION);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.hedera.node.app.service.consensus.impl.ConsensusServiceImpl;

/**
* Module that provides the implementation of the Hedera Consensus Service.
*/
module com.hedera.node.app.service.consensus.impl {
requires transitive com.hedera.node.app.service.consensus;
requires transitive com.hedera.node.app.spi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Unit tests of Consensus Service
*/
public class ConsensusServiceImplTest {
private ConsensusServiceImpl subject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Base class for consensus service tests.
*/
@ExtendWith(MockitoExtension.class)
public class ConsensusTestBase {
private static final String A_NAME = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
Expand All @@ -64,6 +67,7 @@ public class ConsensusTestBase {
KEY_BUILDER.apply(C_NAME).build())
.build()))
.build();

public static final Key A_COMPLEX_KEY = Key.newBuilder()
.thresholdKey(ThresholdKey.newBuilder()
.threshold(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import com.hedera.node.app.service.token.ReadableAccountStore;
import com.hedera.pbj.runtime.io.buffer.Bytes;

/**
* Util class used in unit tests for Consensus Service
*/
public final class ConsensusTestUtils {

static final Key SIMPLE_KEY_A = Key.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Unit tests for the initial mod-service schema for the consensus service.
*/
@ExtendWith(MockitoExtension.class)
public class V0490ConsensusSchemaTest {
private V0490ConsensusSchema subject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
* Service</a>.
*/
public interface ConsensusService extends RpcService {
/**
* The name of the service
*/
String NAME = "ConsensusService";

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
*/
@SuppressWarnings("java:S6548")
public final class ConsensusServiceDefinition implements RpcServiceDefinition {
/**
* Singleton instance of the Token Service
*/
public static final ConsensusServiceDefinition INSTANCE = new ConsensusServiceDefinition();

private static final Set<RpcMethodDefinition<?, ?>> methods = Set.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Provides the classes necessary to manage Hedera Consensus Service.
*/
module com.hedera.node.app.service.consensus {
exports com.hedera.node.app.service.consensus;

Expand Down

0 comments on commit 55b01b5

Please sign in to comment.