From d1f97ac28ec829cfb0e5d1f2ac5e10675a95af7c Mon Sep 17 00:00:00 2001 From: Iris Simon <122310714+iwsimon@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:22:29 -0400 Subject: [PATCH] fix: Fixed 101, 102 protobuf files generation at Genesis (#13746) Signed-off-by: Iris Simon --- .../file/impl/schemas/V0490FileSchema.java | 42 ++++++++++++++----- .../file/ProtectedFilesUpdateSuite.java | 41 ++++++++++++++++-- 2 files changed, 69 insertions(+), 14 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 c7ced8428a4f..ebf534d71745 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 @@ -240,16 +240,17 @@ private void createGenesisAddressBookAndNodeDetails( final var nodeAddresses = new ArrayList(); for (final var nodeInfo : networkInfo.addressBook()) { nodeAddresses.add(NodeAddress.newBuilder() - .ipAddress(Bytes.wrap(nodeInfo.externalHostName())) - .rsaPubKey(nodeInfo.hexEncodedPublicKey()) .nodeId(nodeInfo.nodeId()) - .stake(nodeInfo.stake()) - .memo(Bytes.wrap(nodeInfo.memo())) - .serviceEndpoint(ServiceEndpoint.newBuilder() - .ipAddressV4(Bytes.wrap(nodeInfo.externalHostName())) - .port(nodeInfo.externalPort()) - .build()) - .nodeAccountId(nodeInfo.accountId()) + .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. + ServiceEndpoint.newBuilder() + .ipAddressV4(Bytes.wrap("1.0.0.0")) + .port(1) + .build()) .build()); } @@ -282,7 +283,26 @@ private void createGenesisAddressBookAndNodeDetails( .expirationSecond(bootstrapConfig.systemEntityExpiry()) .build()); - // Create the node details + // Create the node details for file 102, their fields are different from 101, addressBook + final var nodeDetail = new ArrayList(); + for (final var nodeInfo : networkInfo.addressBook()) { + nodeDetail.add(NodeAddress.newBuilder() + .stake(nodeInfo.stake()) + .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(ServiceEndpoint.newBuilder() + .ipAddressV4(Bytes.wrap("1.0.0.0")) + .port(1) + .build()) + .build()); + } + + final var nodeDetails = + NodeAddressBook.newBuilder().nodeAddress(nodeAddresses).build(); + final var nodeDetailsProto = NodeAddressBook.PROTOBUF.toBytes(nodeDetails); final var nodeInfoFileNum = filesConfig.nodeDetails(); final var nodeInfoFileId = FileID.newBuilder() .shardNum(hederaConfig.shard()) @@ -294,7 +314,7 @@ private void createGenesisAddressBookAndNodeDetails( files.put( nodeInfoFileId, File.newBuilder() - .contents(nodeAddressBookProto) + .contents(nodeDetailsProto) .fileId(nodeInfoFileId) .keys(masterKey) .expirationSecond(bootstrapConfig.systemEntityExpiry()) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/ProtectedFilesUpdateSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/ProtectedFilesUpdateSuite.java index 21d841819cb7..c27d0c3a6632 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/ProtectedFilesUpdateSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/ProtectedFilesUpdateSuite.java @@ -17,6 +17,7 @@ package com.hedera.services.bdd.suites.file; import static com.hedera.services.bdd.spec.HapiSpec.defaultHapiSpec; +import static com.hedera.services.bdd.spec.PropertySource.asAccount; import static com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.changeFromSnapshot; import static com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance; import static com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents; @@ -41,7 +42,6 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.services.bdd.junit.HapiTest; import com.hedera.services.bdd.junit.OrderedInIsolation; -import com.hedera.services.bdd.spec.HapiPropertySource; import com.hedera.services.bdd.spec.HapiSpecOperation; import com.hedera.services.bdd.spec.queries.file.HapiGetFileContents; import com.hedera.services.bdd.spec.utilops.CustomSpecAssert; @@ -108,6 +108,12 @@ final Stream account2CanUpdateAddressBook() { GENESIS, ADDRESS_BOOK, true, contents -> extendedBioAddressBook(contents, TARGET_MEMO, REPLACE_MEMO)); } + @HapiTest + final Stream account2CanUpdateAddressBookAccount() { + return specialAccountCanUpdateSpecialFile( + GENESIS, ADDRESS_BOOK, true, contents -> extendedBioAddressBook2(contents, TARGET_MEMO, REPLACE_MEMO)); + } + @HapiTest final Stream account50CanUpdateAddressBook() { return specialAccountCanUpdateSpecialFile(SYSTEM_ADMIN, ADDRESS_BOOK, TARGET_MEMO, REPLACE_MEMO); @@ -305,8 +311,7 @@ private byte[] extendedBioAddressBook(byte[] contents, String targetMemo, String node.setNodeId(nodeId++); r.nextBytes(randCertHash); node.setNodeCertHash(ByteString.copyFrom(randCertHash)); - node.setNodeAccountId( - HapiPropertySource.asAccount(new String(node.getMemo().toByteArray()))); + node.setNodeAccountId(node.getNodeAccountId()); if (new String(node.getMemo().toByteArray()).equals(targetMemo)) { node.setMemo(ByteString.copyFrom(replaceMemo.getBytes())); } @@ -325,6 +330,36 @@ private byte[] extendedBioAddressBook(byte[] contents, String targetMemo, String } } + private byte[] extendedBioAddressBook2(byte[] contents, String targetAccount, String replaceAccount) { + var r = new SplittableRandom(); + try { + var book = NodeAddressBook.parseFrom(contents); + var builder = book.toBuilder(); + byte[] randCertHash = new byte[32]; + long nodeId = 0; + for (NodeAddress.Builder node : builder.getNodeAddressBuilderList()) { + node.setNodeId(nodeId++); + r.nextBytes(randCertHash); + node.setNodeCertHash(ByteString.copyFrom(randCertHash)); + node.setNodeAccountId(node.getNodeAccountId()); + if (node.getNodeAccountId().equals(asAccount(targetAccount))) { + node.setNodeAccountId(asAccount(replaceAccount)); + } + } + var newBook = builder.build(); + var bookJson = mapper.writerWithDefaultPrettyPrinter() + .writeValueAsString(AddressBookPojo.addressBookFrom(newBook)); + log.info("New address book w/ extended bio: {}", bookJson); + return builder.build().toByteArray(); + } catch (InvalidProtocolBufferException e) { + log.error("Basic address book could not be parsed", e); + throw new AssertionError("Unparseable address book!"); + } catch (JsonProcessingException e) { + log.error("Extended address book could not be serialized", e); + throw new AssertionError("Unserializable address book!"); + } + } + private byte[] extendedBioNodeDetails(byte[] contents, String targetMemo, String replaceMemo) { var r = new SplittableRandom(); try {