Search in sources :

Example 1 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class DomainBuilder method addressBookEntry.

public DomainWrapper<AddressBookEntry, AddressBookEntry.AddressBookEntryBuilder> addressBookEntry(int endpoints) {
    long consensusTimestamp = timestamp();
    long nodeId = id();
    var builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).description(text(10)).memo(text(10)).nodeId(nodeId).nodeAccountId(EntityId.of(0L, 0L, nodeId + 3, ACCOUNT)).nodeCertHash(bytes(96)).publicKey(text(64)).stake(0L);
    var serviceEndpoints = new HashSet<AddressBookServiceEndpoint>();
    builder.serviceEndpoints(serviceEndpoints);
    for (int i = 0; i < endpoints; ++i) {
        var endpoint = addressBookServiceEndpoint().customize(a -> a.consensusTimestamp(consensusTimestamp).nodeId(nodeId)).get();
        serviceEndpoints.add(endpoint);
    }
    return new DomainWrapperImpl<>(builder, builder::build);
}
Also used : SCHEDULE(com.hedera.mirror.common.domain.entity.EntityType.SCHEDULE) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) EntityType(com.hedera.mirror.common.domain.entity.EntityType) NodeStake(com.hedera.mirror.common.domain.addressbook.NodeStake) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) InetAddress(java.net.InetAddress) SecureRandom(java.security.SecureRandom) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) Range(com.google.common.collect.Range) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) Instant(java.time.Instant) TINYBARS_IN_ONE_HBAR(com.hedera.mirror.common.util.DomainUtils.TINYBARS_IN_ONE_HBAR) SignaturePair(com.hederahashgraph.api.proto.java.SignaturePair) ZoneId(java.time.ZoneId) FileData(com.hedera.mirror.common.domain.file.FileData) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) ByteString(com.google.protobuf.ByteString) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) TransactionOperations(org.springframework.transaction.support.TransactionOperations) StakingRewardTransfer(com.hedera.mirror.common.domain.transaction.StakingRewardTransfer) LocalDate(java.time.LocalDate) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) Schedule(com.hedera.mirror.common.domain.schedule.Schedule) TOPIC(com.hedera.mirror.common.domain.entity.EntityType.TOPIC) NftId(com.hedera.mirror.common.domain.token.NftId) Contract(com.hedera.mirror.common.domain.contract.Contract) Supplier(java.util.function.Supplier) Scope(org.springframework.context.annotation.Scope) Value(lombok.Value) HashSet(java.util.HashSet) FILE(com.hedera.mirror.common.domain.entity.EntityType.FILE) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) EntityManager(javax.persistence.EntityManager) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) UnknownHostException(java.net.UnknownHostException) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Key(com.hederahashgraph.api.proto.java.Key) Component(org.springframework.stereotype.Component) Log4j2(lombok.extern.log4j.Log4j2) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) EthereumTransaction(com.hedera.mirror.common.domain.transaction.EthereumTransaction) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) HashSet(java.util.HashSet)

Example 2 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImpl method getAddressBookServiceEndpoint.

private static AddressBookServiceEndpoint getAddressBookServiceEndpoint(ServiceEndpoint serviceEndpoint, long consensusTimestamp, long nodeId) throws UnknownHostException {
    var ipAddressByteString = serviceEndpoint.getIpAddressV4();
    if (ipAddressByteString == null || ipAddressByteString.size() != 4) {
        throw new IllegalStateException(String.format("Invalid IpAddressV4: %s", ipAddressByteString));
    }
    var ip = InetAddress.getByAddress(ipAddressByteString.toByteArray()).getHostAddress();
    AddressBookServiceEndpoint addressBookServiceEndpoint = new AddressBookServiceEndpoint();
    addressBookServiceEndpoint.setConsensusTimestamp(consensusTimestamp);
    addressBookServiceEndpoint.setIpAddressV4(ip);
    addressBookServiceEndpoint.setPort(serviceEndpoint.getPort());
    addressBookServiceEndpoint.setNodeId(nodeId);
    return addressBookServiceEndpoint;
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Example 3 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method assertAddressBookEndPoints.

private void assertAddressBookEndPoints(Set<AddressBookServiceEndpoint> actual, List<ServiceEndpoint> expected) {
    if (expected.isEmpty()) {
        return;
    }
    var listAssert = assertThat(actual).hasSize(expected.size());
    for (ServiceEndpoint serviceEndpoint : expected) {
        listAssert.anySatisfy(abe -> {
            AtomicReference<String> ip = new AtomicReference<>("");
            assertDoesNotThrow(() -> {
                ip.set(InetAddress.getByAddress(serviceEndpoint.getIpAddressV4().toByteArray()).getHostAddress());
            });
            assertThat(abe.getId().getPort()).isEqualTo(serviceEndpoint.getPort());
            assertThat(abe.getId().getIpAddressV4()).isEqualTo(ip.get());
        });
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Example 4 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenBothDeprecatedIpAndAddressBookServiceEndpointsAreSet.

@Test
void verifyMigrateWhenBothDeprecatedIpAndAddressBookServiceEndpointsAreSet() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    int endPointPerNode = 3;
    int numEndPoints = nodeIdCount * (endPointPerNode + 1);
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_101_ENTITY_ID, consensusTimestamp, nodeIdCount);
    getAndSaveAddressBookEntries(true, consensusTimestamp, nodeIdCount, endPointPerNode);
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIdCount).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrder(0L, 1L, 2L);
    assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints).extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrder(443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 5 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenOnlyAddressBookServiceEndpointsAreSet.

@Test
void verifyMigrateWhenOnlyAddressBookServiceEndpointsAreSet() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    int endPointPerNode = 3;
    int numEndPoints = nodeIdCount * endPointPerNode;
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, consensusTimestamp, nodeIdCount);
    getAndSaveAddressBookEntries(false, consensusTimestamp, nodeIdCount, endPointPerNode);
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIdCount).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrder(0L, 1L, 2L);
    assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints).extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrder(443, 444, 445, 446, 447, 448, 449, 450, 451);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)13 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)7 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 Test (org.junit.jupiter.api.Test)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 HashSet (java.util.HashSet)3 ByteString (com.google.protobuf.ByteString)2 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)2 Range (com.google.common.collect.Range)1 NodeStake (com.hedera.mirror.common.domain.addressbook.NodeStake)1 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)1 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)1 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)1 CryptoAllowance (com.hedera.mirror.common.domain.entity.CryptoAllowance)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1