Skip to content

Commit

Permalink
feat: Added states for TssService (#15622)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Moran <[email protected]>
Signed-off-by: Neeharika-Sompalli <[email protected]>
Signed-off-by: Neeharika Sompalli <[email protected]>
Co-authored-by: Thomas Moran <[email protected]>
Co-authored-by: Joseph S. <[email protected]>
Co-authored-by: Matt Hess <[email protected]>
  • Loading branch information
4 people authored Oct 3, 2024
1 parent a086d3b commit b19b06f
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 11 deletions.
4 changes: 2 additions & 2 deletions hapi/hedera-protobufs/services/transaction_body.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ import "node_create.proto";
import "node_update.proto";
import "node_delete.proto";

import "tss_message_transaction.proto";
import "tss_vote_transaction.proto";
import "tss_message.proto";
import "tss_vote.proto";

/**
* A single transaction. All transaction types are possible here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ message TssVoteTransactionBody {

/**
* A bit vector of message statuses.<br/>
* Each bit in this vector indicates receipt (1) or non-receipt (0) of a
* _valid_ `TssMessage` for a corresponding `TssMessageTransaction`.
* <p>
* #### Example<br/>
* <ul><li>The least significant bit of byte[0] SHALL be the 0th item in the sequence.</li>
* <li>The most significant bit of byte[0] SHALL be the 7th item in the sequence.</li>
* <li>The least significant bit of byte[1] SHALL be the 8th item in the sequence.</li>
* <li>The most significant bit of byte[1] SHALL be the 15th item in the sequence.</li>
* <ul><li>The least significant bit of byte[0] SHALL be sequence 0.</li>
* <li>The most significant bit of byte[0] SHALL be sequence 7.</li>
* <li>The least significant bit of byte[1] SHALL be sequence 8.</li>
* <li>The most significant bit of byte[0] SHALL be sequence 15.</li>
* </ul>
* A bit SHALL be set if the `TssMessage` for the `TssMessageTransaction`
* with a sequence number matching that bit index has been
Expand Down
4 changes: 4 additions & 0 deletions hapi/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
exports com.hedera.hapi.node.token;
exports com.hedera.hapi.node.token.codec;
exports com.hedera.hapi.node.token.schema;
exports com.hedera.hapi.node.tss;
exports com.hedera.hapi.node.tss.codec;
exports com.hedera.hapi.node.tss.schema;
exports com.hedera.hapi.node.transaction;
exports com.hedera.hapi.node.transaction.codec;
exports com.hedera.hapi.node.transaction.schema;
Expand Down Expand Up @@ -62,6 +65,7 @@
exports com.hedera.hapi.platform.state;
exports com.hedera.hapi.node.state.roster;
exports com.hedera.hapi.block.stream.schema;
exports com.hedera.hapi.node.state.tss;

requires transitive com.google.common;
requires transitive com.google.protobuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.hedera.node.config.data.TokensConfig;
import com.hedera.node.config.data.TopicsConfig;
import com.hedera.node.config.data.TraceabilityConfig;
import com.hedera.node.config.data.TssConfig;
import com.hedera.node.config.data.UtilPrngConfig;
import com.hedera.node.config.data.VersionConfig;
import com.hedera.node.config.types.CongestionMultipliers;
Expand Down Expand Up @@ -126,7 +127,8 @@ public Set<Class<? extends Record>> getConfigDataTypes() {
TopicsConfig.class,
TraceabilityConfig.class,
UtilPrngConfig.class,
VersionConfig.class);
VersionConfig.class,
TssConfig.class);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static java.util.Objects.requireNonNull;

import com.hedera.node.app.tss.TssBaseService;
import com.hedera.node.app.tss.schemas.V0560TSSSchema;
import com.swirlds.common.utility.CommonUtils;
import com.swirlds.state.spi.SchemaRegistry;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -54,7 +55,8 @@ public void setExecutor(@NonNull final ExecutorService executor) {

@Override
public void registerSchemas(@NonNull final SchemaRegistry registry) {
// FUTURE - add required schemas
requireNonNull(registry);
registry.register(new V0560TSSSchema());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.tss.schemas;

import com.hedera.hapi.node.base.SemanticVersion;
import com.hedera.hapi.node.state.tss.TssMessageMapKey;
import com.hedera.hapi.node.state.tss.TssVoteMapKey;
import com.hedera.hapi.node.tss.TssMessageTransactionBody;
import com.hedera.hapi.node.tss.TssVoteTransactionBody;
import com.swirlds.state.spi.Schema;
import com.swirlds.state.spi.StateDefinition;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Schema for the TSS service.
*/
public class V0560TSSSchema extends Schema {
private static final Logger log = LogManager.getLogger(V0560TSSSchema.class);
public static final String TSS_MESSAGE_MAP_KEY = "TSS_MESSAGES";
public static final String TSS_VOTE_MAP_KEY = "TSS_VOTES";
/**
* This will at most be equal to the number of nodes in the network.
*/
private static final long MAX_TSS_MESSAGES = 65_536L;
/**
* This will at most be equal to the number of nodes in the network.
*/
private static final long MAX_TSS_VOTES = 65_536L;

/**
* The version of the schema.
*/
private static final SemanticVersion VERSION =
SemanticVersion.newBuilder().major(0).minor(56).patch(0).build();
/**
* Create a new instance
*/
public V0560TSSSchema() {
super(VERSION);
}

@NonNull
@Override
public Set<StateDefinition> statesToCreate() {
return Set.of(
StateDefinition.onDisk(
TSS_MESSAGE_MAP_KEY,
TssMessageMapKey.PROTOBUF,
TssMessageTransactionBody.PROTOBUF,
MAX_TSS_MESSAGES),
StateDefinition.onDisk(
TSS_VOTE_MAP_KEY, TssVoteMapKey.PROTOBUF, TssVoteTransactionBody.PROTOBUF, MAX_TSS_VOTES));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.hedera.node.app.tss.impl;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.verify;

import com.hedera.node.app.tss.schemas.V0560TSSSchema;
import com.swirlds.state.spi.SchemaRegistry;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -80,8 +82,8 @@ void onlyRegisteredConsumerReceiveCallbacks() throws InterruptedException {
}

@Test
void placeholderRegistersNoSchemasYet() {
void placeholderRegistersSchemas() {
subject.registerSchemas(registry);
verifyNoInteractions(registry);
verify(registry).register(argThat(s -> s instanceof V0560TSSSchema));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.tss.schemas;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.swirlds.state.spi.StateDefinition;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class V0560TSSSchemaTest {
private V0560TSSSchema subject;

@BeforeEach
void setUp() {
subject = new V0560TSSSchema();
}

@Test
void registersExpectedSchema() {
final var statesToCreate = subject.statesToCreate();
assertThat(statesToCreate.size()).isEqualTo(2);
final var iter =
statesToCreate.stream().map(StateDefinition::stateKey).sorted().iterator();
assertEquals(V0560TSSSchema.TSS_MESSAGE_MAP_KEY, iter.next());
assertEquals(V0560TSSSchema.TSS_VOTE_MAP_KEY, iter.next());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.config.data;

import com.hedera.node.config.NetworkProperty;
import com.swirlds.config.api.ConfigData;
import com.swirlds.config.api.ConfigProperty;

/**
* Configuration for the TSS service.
* @param maxSharesPerNode The maximum number of shares that can be assigned to a node.
* @param keyActiveRoster A test-only configuration; set this to true to enable the process that will key the candidate roster with TSS key material.
*/
@ConfigData("tss")
public record TssConfig(
@ConfigProperty(defaultValue = "3") @NetworkProperty long maxSharesPerNode,
@ConfigProperty(defaultValue = "false") @NetworkProperty boolean keyActiveRoster,
@ConfigProperty(defaultValue = "false") @NetworkProperty boolean enableLedgerId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.hedera.node.config.data.TokensConfig;
import com.hedera.node.config.data.TopicsConfig;
import com.hedera.node.config.data.TraceabilityConfig;
import com.hedera.node.config.data.TssConfig;
import com.hedera.node.config.data.UtilPrngConfig;
import com.hedera.node.config.data.VersionConfig;
import com.hedera.node.config.types.CongestionMultipliers;
Expand Down Expand Up @@ -186,6 +187,7 @@ public static TestConfigBuilder create() {
.withConfigDataType(UtilPrngConfig.class)
.withConfigDataType(VersionConfig.class)
.withConfigDataType(NodesConfig.class)
.withConfigDataType(TssConfig.class)
.withConfigDataType(BlockStreamConfig.class)
.withConverter(CongestionMultipliers.class, new CongestionMultipliersConverter())
.withConverter(EntityScaleFactors.class, new EntityScaleFactorsConverter())
Expand Down

0 comments on commit b19b06f

Please sign in to comment.