Skip to content

Commit

Permalink
feat: Replaced AddressBook based NetworkInfo implementations (#15781)
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
  • Loading branch information
Neeharika-Sompalli authored Oct 4, 2024
1 parent 3db0fc9 commit 9951157
Show file tree
Hide file tree
Showing 63 changed files with 641 additions and 980 deletions.
3 changes: 2 additions & 1 deletion hedera-node/hedera-addressbook-service-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ plugins {

description = "Default Hedera AddressBook Service Implementation"

dependencies { implementation(project(":swirlds-platform-core")) }

mainModuleInfo { annotationProcessor("dagger.compiler") }

testModuleInfo {
Expand All @@ -29,7 +31,6 @@ testModuleInfo {
requires("com.hedera.node.app.service.token.impl")
requires("com.hedera.node.config.test.fixtures")
requires("com.swirlds.config.extensions.test.fixtures")
requires("com.swirlds.platform.core")
requires("com.swirlds.platform.core.test.fixtures")
requires("com.swirlds.state.api.test.fixtures")
requires("com.hedera.node.app.spi.test.fixtures")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hedera.node.app.service.addressbook.impl.schemas;

import static com.hedera.node.app.service.addressbook.AddressBookHelper.NODES_KEY;
import static com.swirlds.platform.roster.RosterUtils.formatNodeName;
import static java.util.Objects.requireNonNull;

import com.hedera.hapi.node.base.AccountID;
Expand All @@ -41,7 +42,6 @@
import com.swirlds.state.spi.StateDefinition;
import com.swirlds.state.spi.WritableKVState;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
Expand Down Expand Up @@ -78,11 +78,12 @@ public Set<StateDefinition> statesToCreate() {
@Override
public void migrate(@NonNull final MigrationContext ctx) {
requireNonNull(ctx);
final var networkInfo = ctx.genesisNetworkInfo();
if (networkInfo == null) {
throw new IllegalStateException("Genesis network info is not found");
}
final WritableKVState<EntityNumber, Node> writableNodes =
ctx.newStates().get(NODES_KEY);

final var networkInfo = ctx.networkInfo();
final var addressBook = networkInfo.addressBook();
final var bootstrapConfig = ctx.configuration().getConfigData(BootstrapConfig.class);

log.info("Started migrating nodes from address book");
Expand All @@ -93,14 +94,14 @@ public void migrate(@NonNull final MigrationContext ctx) {
? Key.newBuilder().ed25519(bootstrapConfig.genesisPublicKey()).build()
: adminKey;
NodeAddress nodeDetail;
final var addressBook = networkInfo.addressBook();
for (final var nodeInfo : addressBook) {
final var nodeBuilder = Node.newBuilder()
.nodeId(nodeInfo.nodeId())
.accountId(nodeInfo.accountId())
.description(nodeInfo.selfName())
.gossipEndpoint(List.of(
endpointFor(nodeInfo.internalHostName(), nodeInfo.internalPort()),
endpointFor(nodeInfo.externalHostName(), nodeInfo.externalPort())))
// Default node description hard coded to the values used currently
.description(formatNodeName(nodeInfo.nodeId()))
.gossipEndpoint(nodeInfo.gossipEndpoints())
.gossipCaCertificate(nodeInfo.sigCertBytes())
.weight(nodeInfo.stake())
.adminKey(finalAdminKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
requires transitive dagger;
requires transitive javax.inject;
requires com.hedera.node.app.service.token;
requires com.swirlds.platform.core;
requires org.apache.logging.log4j;
requires static transitive java.compiler;
requires static com.github.spotbugs.annotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ void migrateAsExpected2() {
Node.newBuilder()
.nodeId(1)
.accountId(payerId)
.description("memo1")
.gossipEndpoint(List.of(endpointFor("127.0.0.1", 123), endpointFor("23.45.34.245", 22)))
.description("node2")
.gossipEndpoint(List.of(endpointFor("23.45.34.245", 22), endpointFor("127.0.0.1", 123)))
.gossipCaCertificate(Bytes.wrap(gossipCaCertificate))
.weight(0)
.adminKey(anotherKey)
Expand All @@ -131,8 +131,8 @@ void migrateAsExpected2() {
Node.newBuilder()
.nodeId(2)
.accountId(accountId)
.description("memo2")
.gossipEndpoint(List.of(endpointFor("127.0.0.2", 123), endpointFor("23.45.34.240", 23)))
.description("node3")
.gossipEndpoint(List.of(endpointFor("23.45.34.240", 23), endpointFor("127.0.0.2", 123)))
.gossipCaCertificate(Bytes.wrap(grpcCertificateHash))
.weight(1)
.adminKey(anotherKey)
Expand All @@ -142,8 +142,8 @@ void migrateAsExpected2() {
Node.newBuilder()
.nodeId(3)
.accountId(accountId)
.description("memo3")
.gossipEndpoint(List.of(endpointFor("127.0.0.3", 124), endpointFor("23.45.34.243", 45)))
.description("node4")
.gossipEndpoint(List.of(endpointFor("23.45.34.243", 45), endpointFor("127.0.0.3", 124)))
.gossipCaCertificate(Bytes.wrap(grpcCertificateHash))
.weight(10)
.adminKey(anotherKey)
Expand All @@ -162,8 +162,8 @@ void migrateAsExpected3() {
Node.newBuilder()
.nodeId(1)
.accountId(payerId)
.description("memo1")
.gossipEndpoint(List.of(endpointFor("127.0.0.1", 123), endpointFor("23.45.34.245", 22)))
.description("node2")
.gossipEndpoint(List.of(endpointFor("23.45.34.245", 22), endpointFor("127.0.0.1", 123)))
.gossipCaCertificate(Bytes.wrap(gossipCaCertificate))
.weight(0)
.adminKey(anotherKey)
Expand All @@ -173,8 +173,8 @@ void migrateAsExpected3() {
Node.newBuilder()
.nodeId(2)
.accountId(accountId)
.description("memo2")
.gossipEndpoint(List.of(endpointFor("127.0.0.2", 123), endpointFor("23.45.34.240", 23)))
.description("node3")
.gossipEndpoint(List.of(endpointFor("23.45.34.240", 23), endpointFor("127.0.0.2", 123)))
.gossipCaCertificate(Bytes.wrap(grpcCertificateHash))
.weight(1)
.adminKey(anotherKey)
Expand All @@ -186,8 +186,8 @@ void migrateAsExpected3() {
Node.newBuilder()
.nodeId(3)
.accountId(accountId)
.description("memo3")
.gossipEndpoint(List.of(endpointFor("127.0.0.3", 124), endpointFor("23.45.34.243", 45)))
.description("node4")
.gossipEndpoint(List.of(endpointFor("23.45.34.243", 45), endpointFor("127.0.0.3", 124)))
.gossipCaCertificate(Bytes.wrap(grpcCertificateHash))
.weight(10)
.adminKey(anotherKey)
Expand All @@ -212,8 +212,8 @@ void migrateAsExpected4() {
Node.newBuilder()
.nodeId(1)
.accountId(payerId)
.description("memo1")
.gossipEndpoint(List.of(endpointFor("127.0.0.1", 123), endpointFor("23.45.34.245", 22)))
.description("node2")
.gossipEndpoint(List.of(endpointFor("23.45.34.245", 22), endpointFor("127.0.0.1", 123)))
.gossipCaCertificate(Bytes.wrap(gossipCaCertificate))
.weight(0)
.adminKey(anotherKey)
Expand All @@ -223,8 +223,8 @@ void migrateAsExpected4() {
Node.newBuilder()
.nodeId(2)
.accountId(accountId)
.description("memo2")
.gossipEndpoint(List.of(endpointFor("127.0.0.2", 123), endpointFor("23.45.34.240", 23)))
.description("node3")
.gossipEndpoint(List.of(endpointFor("23.45.34.240", 23), endpointFor("127.0.0.2", 123)))
.gossipCaCertificate(Bytes.wrap(grpcCertificateHash))
.weight(1)
.adminKey(anotherKey)
Expand All @@ -234,8 +234,8 @@ void migrateAsExpected4() {
Node.newBuilder()
.nodeId(3)
.accountId(accountId)
.description("memo3")
.gossipEndpoint(List.of(endpointFor("127.0.0.3", 124), endpointFor("23.45.34.243", 45)))
.description("node4")
.gossipEndpoint(List.of(endpointFor("23.45.34.243", 45), endpointFor("127.0.0.3", 124)))
.gossipCaCertificate(Bytes.wrap(grpcCertificateHash))
.weight(10)
.adminKey(anotherKey)
Expand All @@ -251,40 +251,22 @@ private void setupMigrationContext() {
1,
payerId,
0,
"23.45.34.245",
22,
"127.0.0.1",
123,
"pubKey1",
"memo1",
Bytes.wrap(gossipCaCertificate),
"memo1");
List.of(endpointFor("23.45.34.245", 22), endpointFor("127.0.0.1", 123)),
Bytes.wrap(gossipCaCertificate));
final var nodeInfo2 = new NodeInfoImpl(
2,
accountId,
1,
"23.45.34.240",
23,
"127.0.0.2",
123,
"pubKey2",
"memo2",
Bytes.wrap(grpcCertificateHash),
"memo2");
List.of(endpointFor("23.45.34.240", 23), endpointFor("127.0.0.2", 123)),
Bytes.wrap(grpcCertificateHash));
final var nodeInfo3 = new NodeInfoImpl(
3,
accountId,
10,
"23.45.34.243",
45,
"127.0.0.3",
124,
"pubKey3",
"memo3",
Bytes.wrap(grpcCertificateHash),
"memo3");
List.of(endpointFor("23.45.34.243", 45), endpointFor("127.0.0.3", 124)),
Bytes.wrap(grpcCertificateHash));
given(networkInfo.addressBook()).willReturn(List.of(nodeInfo1, nodeInfo2, nodeInfo3));
given(migrationContext.networkInfo()).willReturn(networkInfo);
given(migrationContext.genesisNetworkInfo()).willReturn(networkInfo);
final var config = HederaTestConfigBuilder.create()
.withValue("bootstrap.genesisPublicKey", defauleAdminKeyBytes)
.getOrCreateConfig();
Expand Down
Loading

0 comments on commit 9951157

Please sign in to comment.