From b208f7c15dd8a3924c88983ffeb56c8bccdca08b Mon Sep 17 00:00:00 2001 From: Iris Simon <122310714+iwsimon@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:28:28 -0500 Subject: [PATCH] feat: cherry-pick: Generated Files 101 & 102 Sequentially Ordered by Node ID (#17289) --- .../file/impl/schemas/V0490FileSchema.java | 49 +++++++++---------- .../suites/hip993/SystemFileExportsTest.java | 11 ++++- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/hedera-node/hedera-file-service-impl/src/main/java/com/hedera/node/app/service/file/impl/schemas/V0490FileSchema.java b/hedera-node/hedera-file-service-impl/src/main/java/com/hedera/node/app/service/file/impl/schemas/V0490FileSchema.java index a1f014a8d427..79c8eb03a354 100644 --- a/hedera-node/hedera-file-service-impl/src/main/java/com/hedera/node/app/service/file/impl/schemas/V0490FileSchema.java +++ b/hedera-node/hedera-file-service-impl/src/main/java/com/hedera/node/app/service/file/impl/schemas/V0490FileSchema.java @@ -42,6 +42,7 @@ import com.hedera.hapi.node.base.TransactionFeeSchedule; import com.hedera.hapi.node.file.FileCreateTransactionBody; import com.hedera.hapi.node.file.FileUpdateTransactionBody; +import com.hedera.hapi.node.state.addressbook.Node; import com.hedera.hapi.node.state.common.EntityNumber; import com.hedera.hapi.node.state.file.File; import com.hedera.hapi.node.state.primitives.ProtoBytes; @@ -64,6 +65,7 @@ import com.swirlds.state.lifecycle.Schema; import com.swirlds.state.lifecycle.StateDefinition; import com.swirlds.state.lifecycle.info.NetworkInfo; +import com.swirlds.state.lifecycle.info.NodeInfo; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.ByteArrayInputStream; @@ -202,36 +204,31 @@ public void createGenesisAddressBookAndNodeDetails(@NonNull final SystemContext } public Bytes genesisAddressBook(@NonNull final NetworkInfo networkInfo) { - final var nodeAddresses = new ArrayList(); - for (final var nodeInfo : networkInfo.addressBook()) { - nodeAddresses.add(NodeAddress.newBuilder() - .nodeId(nodeInfo.nodeId()) - .rsaPubKey(nodeInfo.hexEncodedPublicKey()) - .nodeAccountId(nodeInfo.accountId()) // don't use memo as it is deprecated. - .serviceEndpoint( - // we really don't have grpc proxy name and port for now. Temporary values are set. - // After Dynamic Address Book Phase 2 release, we will have the correct values.Then update - // here. - V053AddressBookSchema.endpointFor("1.0.0.0", 1)) - .build()); - } + final var nodeAddresses = networkInfo.addressBook().stream() + .sorted(Comparator.comparingLong(NodeInfo::nodeId)) + .map(nodeInfo -> NodeAddress.newBuilder() + .nodeId(nodeInfo.nodeId()) + .nodeAccountId(nodeInfo.accountId()) + .rsaPubKey(nodeInfo.hexEncodedPublicKey()) + .serviceEndpoint(V053AddressBookSchema.endpointFor("1.0.0.0", 1)) + .build()) + .toList(); return NodeAddressBook.PROTOBUF.toBytes( NodeAddressBook.newBuilder().nodeAddress(nodeAddresses).build()); } public Bytes genesisNodeDetails(@NonNull final NetworkInfo networkInfo) { - final var nodeDetails = new ArrayList(); - for (final var nodeInfo : networkInfo.addressBook()) { - nodeDetails.add(NodeAddress.newBuilder() - .stake(nodeInfo.weight()) - .nodeAccountId(nodeInfo.accountId()) - .nodeId(nodeInfo.nodeId()) - .rsaPubKey(nodeInfo.hexEncodedPublicKey()) - // we really don't have grpc proxy name and port for now.Temporary values are set. - // After Dynamic Address Book Phase 2 release, we will have the correct values. Then update here. - .serviceEndpoint(V053AddressBookSchema.endpointFor("1.0.0.0", 1)) - .build()); - } + final var nodeDetails = networkInfo.addressBook().stream() + .sorted(Comparator.comparingLong(NodeInfo::nodeId)) + .map(nodeInfo -> NodeAddress.newBuilder() + .stake(nodeInfo.weight()) + .nodeAccountId(nodeInfo.accountId()) + .nodeId(nodeInfo.nodeId()) + .rsaPubKey(nodeInfo.hexEncodedPublicKey()) + .serviceEndpoint(V053AddressBookSchema.endpointFor("1.0.0.0", 1)) + .build()) + .toList(); + return NodeAddressBook.PROTOBUF.toBytes( NodeAddressBook.newBuilder().nodeAddress(nodeDetails).build()); } @@ -271,6 +268,7 @@ private Bytes nodeStoreNodeDetails(@NonNull final ReadableNodeStore nodeStore) { .mapToLong(EntityNumber::number) .mapToObj(nodeStore::get) .filter(node -> node != null && !node.deleted()) + .sorted(Comparator.comparingLong(Node::nodeId)) .forEach(node -> nodeDetails.add(NodeAddress.newBuilder() .nodeId(node.nodeId()) .nodeAccountId(node.accountId()) @@ -296,6 +294,7 @@ private Bytes nodeStoreAddressBook(@NonNull final ReadableNodeStore nodeStore) { .mapToLong(EntityNumber::number) .mapToObj(nodeStore::get) .filter(node -> node != null && !node.deleted()) + .sorted(Comparator.comparingLong(Node::nodeId)) .forEach(node -> nodeAddresses.add(NodeAddress.newBuilder() .nodeId(node.nodeId()) .nodeCertHash(getHexStringBytesFromBytes(node.grpcCertificateHash())) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip993/SystemFileExportsTest.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip993/SystemFileExportsTest.java index 811c7e7095f0..222e3f7fd42d 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip993/SystemFileExportsTest.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/hip993/SystemFileExportsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2024-2025 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. @@ -75,6 +75,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.protobuf.ByteString; @@ -478,7 +479,9 @@ private static VisibleItemsValidator nodeDetailsExportValidator( try { final var updatedAddressBook = NodeAddressBook.PROTOBUF.parse( Bytes.wrap(synthOp.getContents().toByteArray())); + var prevNodeId = -1L; for (final var address : updatedAddressBook.nodeAddress()) { + assertTrue(address.nodeId() > prevNodeId, "Node IDs must be in ascending order"); final var expectedCert = gossipCertificates.get().get(address.nodeId()); final var expectedPubKey = expectedCert.getPublicKey().getEncoded(); final var actualPubKey = unhex(address.rsaPubKey()); @@ -495,6 +498,7 @@ private static VisibleItemsValidator nodeDetailsExportValidator( final var expectedServiceEndpoint = endpointsFor((int) address.nodeId()); assertEquals(expectedServiceEndpoint, address.serviceEndpoint()); + prevNodeId = address.nodeId(); } } catch (ParseException e) { Assertions.fail("Update contents was not protobuf " + e.getMessage()); @@ -523,12 +527,14 @@ private static VisibleItemsValidator addressBookExportValidator( assertNotNull(updateItem, "No update for " + fileNumProperty + " found in post-upgrade txn"); final var synthOp = updateItem.body().getFileUpdate(); final var addressBookId = - new FileID(0, 0, Long.parseLong(spec.startupProperties().get("files.addressBook"))); + new FileID(0, 0, Long.parseLong(spec.startupProperties().get(fileNumProperty))); assertEquals(addressBookId, toPbj(synthOp.getFileID())); try { final var updatedAddressBook = NodeAddressBook.PROTOBUF.parse( Bytes.wrap(synthOp.getContents().toByteArray())); + var prevNodeId = -1L; for (final var address : updatedAddressBook.nodeAddress()) { + assertTrue(address.nodeId() > prevNodeId, "Node IDs must be in ascending order"); final var actualCertHash = address.nodeCertHash().toByteArray(); assertArrayEquals( getHexStringBytesFromBytes(grpcCertHashes[(int) address.nodeId()]), @@ -537,6 +543,7 @@ private static VisibleItemsValidator addressBookExportValidator( final var expectedServiceEndpoint = endpointsFor((int) address.nodeId()); assertEquals(expectedServiceEndpoint, address.serviceEndpoint()); + prevNodeId = address.nodeId(); } } catch (ParseException e) { Assertions.fail("Update contents was not protobuf " + e.getMessage());