Search in sources :

Example 11 with NodeAddress

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

the class AddressBookServiceImplTest method verifyAddressBookWithDeprecatedIpAndServiceEndpoints.

@Test
void verifyAddressBookWithDeprecatedIpAndServiceEndpoints() throws UnknownHostException {
    List<NodeAddress> nodeAddressList = new ArrayList<>();
    int nodeAccountStart = 3;
    int addressBookEntries = 5;
    // deprecated ip + service endpoints
    int numEndpointsPerNode = 5;
    for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
        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), 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, 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 12 with NodeAddress

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

the class AddressBookServiceImpl method retrieveNodeAddressesFromAddressBook.

/**
 * Extracts a collection of AddressBookEntry domain objects from NodeAddressBook proto. Sets provided
 * consensusTimestamp as the consensusTimestamp of each address book entry to ensure mapping to a single
 * AddressBook
 *
 * @param nodeAddressBook    node address book proto
 * @param consensusTimestamp transaction consensusTimestamp
 * @return
 */
private static Collection<AddressBookEntry> retrieveNodeAddressesFromAddressBook(NodeAddressBook nodeAddressBook, long consensusTimestamp) throws UnknownHostException {
    // node id to entry
    Map<Long, AddressBookEntry> addressBookEntries = new LinkedHashMap<>();
    for (NodeAddress nodeAddressProto : nodeAddressBook.getNodeAddressList()) {
        Pair<Long, EntityId> nodeIds = getNodeIds(nodeAddressProto);
        AddressBookEntry addressBookEntry = addressBookEntries.computeIfAbsent(nodeIds.getLeft(), k -> getAddressBookEntry(nodeAddressProto, consensusTimestamp, nodeIds));
        Set<AddressBookServiceEndpoint> updatedList = new HashSet<>(addressBookEntry.getServiceEndpoints());
        updatedList.addAll(getAddressBookServiceEndpoints(nodeAddressProto, consensusTimestamp));
        addressBookEntry.setServiceEndpoints(updatedList);
    }
    return addressBookEntries.values();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 13 with NodeAddress

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

the class NetworkControllerTest method nullFields.

@Test
void nullFields() {
    AddressBook addressBook = addressBook();
    AddressBookEntry addressBookEntry = domainBuilder.addressBookEntry().customize(a -> a.consensusTimestamp(CONSENSUS_TIMESTAMP).description(null).memo(null).nodeCertHash(null).publicKey(null).stake(null)).persist();
    AddressBookQuery query = AddressBookQuery.newBuilder().setFileId(FileID.newBuilder().setFileNum(addressBook.getFileId().getEntityNum()).build()).build();
    reactiveService.getNodes(Mono.just(query)).as(StepVerifier::create).thenAwait(Duration.ofMillis(50)).consumeNextWith(n -> assertThat(n).isNotNull().returns("", NodeAddress::getDescription).returns(ByteString.EMPTY, NodeAddress::getMemo).returns(addressBookEntry.getNodeAccountId(), t -> EntityId.of(n.getNodeAccountId())).returns(ByteString.EMPTY, NodeAddress::getNodeCertHash).returns(addressBookEntry.getNodeId(), NodeAddress::getNodeId).returns("", NodeAddress::getRSAPubKey).returns(0L, NodeAddress::getStake)).expectComplete().verify(Duration.ofSeconds(1L));
}
Also used : FileID(com.hederahashgraph.api.proto.java.FileID) AddressBookQuery(com.hedera.mirror.api.proto.AddressBookQuery) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) GrpcClient(net.devh.boot.grpc.client.inject.GrpcClient) StepVerifier(reactor.test.StepVerifier) EntityId(com.hedera.mirror.common.domain.entity.EntityId) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) ProtoUtil(com.hedera.mirror.grpc.util.ProtoUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Mono(reactor.core.publisher.Mono) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test) ReactorNetworkServiceGrpc(com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc) Duration(java.time.Duration) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Log4j2(lombok.extern.log4j.Log4j2) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) Status(io.grpc.Status) AddressBookQuery(com.hedera.mirror.api.proto.AddressBookQuery) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

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