Search in sources :

Example 6 with NodeAddress

use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method verifyEmptyDeprecatedMemo.

@Test
void verifyEmptyDeprecatedMemo() throws UnknownHostException {
    List<NodeAddress> nodeAddressList = new ArrayList<>();
    int nodeAccountStart = 3;
    int addressBookEntries = 5;
    // service endpoint
    int numEndpointsPerNode = 1;
    for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
        // empty deprecated ip
        nodeAddressList.add(getNodeAddress(i, "", null, List.of(String.format("127.0.%d.0", i))));
    }
    NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
    byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
    update(addressBookBytes, 2L, true);
    assertArrayEquals(addressBookBytes, addressBookService.getCurrent().getFileData());
    // bootstrap and new address book with service endpoints
    assertEquals(2, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
    assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
Also used : ArrayList(java.util.ArrayList) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 7 with NodeAddress

use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method verifyDuplicateEndpointsPerNodeAddressAreCollapsed.

@Test
void verifyDuplicateEndpointsPerNodeAddressAreCollapsed() throws UnknownHostException {
    List<NodeAddress> nodeAddressList = new ArrayList<>();
    int nodeAccountStart = 3;
    int addressBookEntries = 5;
    // 127.0.<nodeId>.0, 127.0.<nodeId>.1, 127.0.<nodeId>.2
    int numEndpointsPerNode = 3;
    for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
        // deprecated ip
        nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("127.0.%d.0", i), List.of()));
        // subset of only service endpoints
        nodeAddressList.add(getNodeAddress(i, baseAccountId + i, null, List.of(String.format("127.0.%d.0", i))));
        // another deprecated ip and more service endpoints
        nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("127.0.%d.0", i), List.of(String.format("127.0.%d.1", i), String.format("127.0.%d.2", i))));
    }
    NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
    byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
    update(addressBookBytes, 2L, true);
    assertArrayEquals(addressBookBytes, addressBookService.getCurrent().getFileData());
    // bootstrap and new address book with service endpoints
    assertEquals(2, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
    assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
Also used : ArrayList(java.util.ArrayList) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 8 with NodeAddress

use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method verifyAddressBookEntriesWithNodeIdAndPortNotSet.

@Test
void verifyAddressBookEntriesWithNodeIdAndPortNotSet() {
    Map<String, Integer> memoToNodeIdMap = Map.of("0.0.3", 0, "0.0.4", 1);
    String[] accountIds = memoToNodeIdMap.keySet().stream().sorted().toArray(String[]::new);
    // nodeId 0, port 0
    NodeAddress nodeAddress1 = NodeAddress.newBuilder().setIpAddress(ByteString.copyFromUtf8("127.0.0.1")).setMemo(ByteString.copyFromUtf8(accountIds[0])).setNodeAccountId(AccountID.newBuilder().setAccountNum(3)).setNodeCertHash(ByteString.copyFromUtf8("nodeCertHash")).setRSAPubKey("rsa+public/key").build();
    // nodeId 0, port 50211
    NodeAddress nodeAddress2 = NodeAddress.newBuilder(nodeAddress1).setIpAddress(ByteString.copyFromUtf8("127.0.0.2")).setMemo(ByteString.copyFromUtf8(accountIds[1])).setNodeAccountId(AccountID.newBuilder().setAccountNum(4)).setPortno(50211).build();
    NodeAddressBook nodeAddressBook = NodeAddressBook.newBuilder().addAllNodeAddress(List.of(nodeAddress1, nodeAddress2)).build();
    byte[] addressBookBytes = nodeAddressBook.toByteArray();
    long addressBookConsensusTimeStamp = 5L;
    update(addressBookBytes, addressBookConsensusTimeStamp, true);
    assertAddressBookData(addressBookBytes, addressBookConsensusTimeStamp + 1);
    AddressBook addressBook = addressBookService.getCurrent();
    ListAssert<AddressBookEntry> listAssert = assertThat(addressBook.getEntries()).hasSize(nodeAddressBook.getNodeAddressCount());
    for (NodeAddress nodeAddress : nodeAddressBook.getNodeAddressList()) {
        int expectedNodeId = memoToNodeIdMap.get(nodeAddress.getMemo().toStringUtf8());
        listAssert.anySatisfy(abe -> {
            assertThat(abe.getMemo()).isEqualTo(nodeAddress.getMemo().toStringUtf8());
            assertThat(abe.getNodeAccountId()).isEqualTo(EntityId.of(nodeAddress.getNodeAccountId()));
            assertThat(abe.getNodeCertHash()).isEqualTo(nodeAddress.getNodeCertHash().toByteArray());
            assertThat(abe.getPublicKey()).isEqualTo(nodeAddress.getRSAPubKey());
            // both entries have null node id
            assertThat(abe.getNodeId()).isEqualTo(expectedNodeId);
            assertAddressBookEndPoints(abe.getServiceEndpoints(), nodeAddress.getServiceEndpointList());
        });
    }
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ByteString(com.google.protobuf.ByteString) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 9 with NodeAddress

use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method verifyAddressBookWithServiceEndpointsOnly.

@Test
void verifyAddressBookWithServiceEndpointsOnly() throws UnknownHostException {
    List<NodeAddress> nodeAddressList = new ArrayList<>();
    int nodeAccountStart = 3;
    int addressBookEntries = 5;
    int numEndpointsPerNode = 4;
    for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
        nodeAddressList.add(getNodeAddress(i, baseAccountId + i, null, List.of(String.format("127.0.%d.1", i), String.format("127.0.%d.2", i), String.format("127.0.%d.3", i), String.format("127.0.%d.4", i))));
    }
    NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
    byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
    update(addressBookBytes, 2L, false);
    assertArrayEquals(initialAddressBookBytes, addressBookService.getCurrent().getFileData());
    // bootstrap and new address book with service endpoints
    assertEquals(2, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
    assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
Also used : ArrayList(java.util.ArrayList) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 10 with NodeAddress

use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.

the class MissingAddressBooksMigrationTest method assertAddressBook.

private void assertAddressBook(AddressBook actual, NodeAddressBook expected) {
    ListAssert<AddressBookEntry> listAssert = assertThat(actual.getEntries()).hasSize(expected.getNodeAddressCount());
    for (NodeAddress nodeAddress : expected.getNodeAddressList()) {
        listAssert.anySatisfy(abe -> {
            assertThat(abe.getMemo()).isEqualTo(nodeAddress.getMemo().toStringUtf8());
            assertThat(abe.getNodeAccountId()).isEqualTo(EntityId.of(nodeAddress.getNodeAccountId()));
            assertThat(abe.getNodeCertHash()).isEqualTo(nodeAddress.getNodeCertHash().toByteArray());
            assertThat(abe.getPublicKey()).isEqualTo(nodeAddress.getRSAPubKey());
            assertThat(abe.getNodeId()).isEqualTo(nodeAddress.getNodeId());
        });
    }
}
Also used : AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress)

Aggregations

NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)13 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)9 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)8 Test (org.junit.jupiter.api.Test)8 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)7 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)7 ArrayList (java.util.ArrayList)6 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)5 ByteString (com.google.protobuf.ByteString)3 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 AddressBookQuery (com.hedera.mirror.api.proto.AddressBookQuery)1 ReactorNetworkServiceGrpc (com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc)1 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)1 ProtoUtil (com.hedera.mirror.grpc.util.ProtoUtil)1 FileID (com.hederahashgraph.api.proto.java.FileID)1 Status (io.grpc.Status)1 InetAddress (java.net.InetAddress)1