Search in sources :

Example 1 with InvalidEntityException

use of com.hedera.mirror.common.exception.InvalidEntityException in project hedera-mirror-node by hashgraph.

the class PubSubRecordItemListener method onItem.

@Override
public void onItem(RecordItem recordItem) throws ImporterException {
    TransactionBody body = recordItem.getTransactionBody();
    TransactionRecord txRecord = recordItem.getRecord();
    TransactionType transactionType = TransactionType.of(recordItem.getTransactionType());
    TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
    log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body));
    long consensusTimestamp = DomainUtils.timeStampInNanos(txRecord.getConsensusTimestamp());
    EntityId entityId;
    try {
        entityId = transactionHandler.getEntity(recordItem);
    } catch (InvalidEntityException e) {
        // transaction can have invalid topic/contract/file id
        log.warn("Invalid entity encountered for consensusTimestamp {} : {}", consensusTimestamp, e.getMessage());
        entityId = null;
    }
    PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entityId, recordItem);
    try {
        sendPubSubMessage(pubSubMessage);
    } catch (Exception e) {
        // greater than that of last correctly sent txn.
        throw new ParserException("Error sending transaction to pubsub", e);
    }
    log.debug("Published transaction : {}", consensusTimestamp);
    if (addressBookService.isAddressBook(entityId)) {
        FileID fileID = null;
        byte[] fileBytes = null;
        if (body.hasFileAppend()) {
            fileID = body.getFileAppend().getFileID();
            fileBytes = body.getFileAppend().getContents().toByteArray();
        } else if (body.hasFileCreate()) {
            fileID = txRecord.getReceipt().getFileID();
            fileBytes = body.getFileCreate().getContents().toByteArray();
        } else if (body.hasFileUpdate()) {
            fileID = body.getFileUpdate().getFileID();
            fileBytes = body.getFileUpdate().getContents().toByteArray();
        }
        FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem.getTransactionType());
        fileDataRepository.save(fileData);
        addressBookService.update(fileData);
    }
}
Also used : ParserException(com.hedera.mirror.importer.exception.ParserException) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) MessageTimeoutException(org.springframework.integration.MessageTimeoutException) ParserException(com.hedera.mirror.importer.exception.ParserException) ImporterException(com.hedera.mirror.importer.exception.ImporterException) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionHandler(com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler) PubSubMessage(com.hedera.mirror.importer.parser.domain.PubSubMessage) FileID(com.hederahashgraph.api.proto.java.FileID) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) FileData(com.hedera.mirror.common.domain.file.FileData)

Example 2 with InvalidEntityException

use of com.hedera.mirror.common.exception.InvalidEntityException in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImpl method notify.

@Override
public void notify(Aliasable aliasable) {
    if (aliasable == null || (aliasable.getDeleted() != null && aliasable.getDeleted())) {
        return;
    }
    ByteString alias = DomainUtils.fromBytes(aliasable.getAlias());
    if (alias == null) {
        return;
    }
    EntityId entityId = aliasable.toEntityId();
    EntityType type = aliasable.getType();
    GeneratedMessageV3.Builder<?> builder;
    switch(type) {
        case ACCOUNT:
            builder = AccountID.newBuilder().setShardNum(entityId.getShardNum()).setRealmNum(entityId.getRealmNum()).setAlias(alias);
            break;
        case CONTRACT:
            builder = ContractID.newBuilder().setShardNum(entityId.getShardNum()).setRealmNum(entityId.getRealmNum()).setEvmAddress(alias);
            break;
        default:
            throw new InvalidEntityException(String.format("%s entity can't have alias", type));
    }
    cache.put(builder.build().hashCode(), entityId);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteString(com.google.protobuf.ByteString) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException)

Example 3 with InvalidEntityException

use of com.hedera.mirror.common.exception.InvalidEntityException in project hedera-mirror-node by hashgraph.

the class ProtoUtilTest method toStatusRuntimeException.

@Test
void toStatusRuntimeException() {
    var entityId = EntityId.of(1L, EntityType.ACCOUNT);
    var message = "boom";
    assertException(Exceptions.failWithOverflow(message), Status.DEADLINE_EXCEEDED, OVERFLOW_ERROR);
    assertException(new ConstraintViolationException(message, null), Status.INVALID_ARGUMENT, message);
    assertException(new IllegalArgumentException(message), Status.INVALID_ARGUMENT, message);
    assertException(new InvalidEntityException(message), Status.INVALID_ARGUMENT, message);
    assertException(new EntityNotFoundException(entityId), Status.NOT_FOUND, "Account 0.0.1 does not exist");
    assertException(new NonTransientDataAccessResourceException(message), Status.UNAVAILABLE, DB_ERROR);
    assertException(new QueryTimeoutException(message), Status.RESOURCE_EXHAUSTED, DB_ERROR);
    assertException(new TimeoutException(message), Status.RESOURCE_EXHAUSTED, DB_ERROR);
    assertException(new RuntimeException(message), Status.UNKNOWN, UNKNOWN_ERROR);
}
Also used : QueryTimeoutException(org.springframework.dao.QueryTimeoutException) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) StatusRuntimeException(io.grpc.StatusRuntimeException) ConstraintViolationException(javax.validation.ConstraintViolationException) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) QueryTimeoutException(org.springframework.dao.QueryTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with InvalidEntityException

use of com.hedera.mirror.common.exception.InvalidEntityException in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListener method onItem.

@Override
public void onItem(RecordItem recordItem) throws ImporterException {
    TransactionRecord txRecord = recordItem.getRecord();
    TransactionBody body = recordItem.getTransactionBody();
    int transactionTypeValue = recordItem.getTransactionType();
    TransactionType transactionType = TransactionType.of(transactionTypeValue);
    TransactionHandler transactionHandler = transactionHandlerFactory.get(transactionType);
    long consensusTimestamp = DomainUtils.timeStampInNanos(txRecord.getConsensusTimestamp());
    EntityId entityId;
    try {
        entityId = transactionHandler.getEntity(recordItem);
    } catch (InvalidEntityException e) {
        // transaction can have invalid topic/contract/file id
        log.warn("Invalid entity encountered for consensusTimestamp {} : {}", consensusTimestamp, e.getMessage());
        entityId = null;
    }
    log.debug("Processing {} transaction {} for entity {}", transactionType, consensusTimestamp, entityId);
    // to:do - exclude Freeze from Filter transaction type
    TransactionFilterFields transactionFilterFields = new TransactionFilterFields(entityId, transactionType);
    if (!transactionFilter.test(transactionFilterFields)) {
        log.debug("Ignoring transaction. consensusTimestamp={}, transactionType={}, entityId={}", consensusTimestamp, transactionType, entityId);
        return;
    }
    Transaction transaction = buildTransaction(consensusTimestamp, recordItem);
    transaction.setEntityId(entityId);
    transactionHandler.updateTransaction(transaction, recordItem);
    if (txRecord.hasTransferList() && entityProperties.getPersist().isCryptoTransferAmounts()) {
        insertTransferList(recordItem);
    }
    // insert staking reward transfers even on failure
    insertStakingRewardTransfers(recordItem);
    // handle scheduled transaction, even on failure
    if (transaction.isScheduled()) {
        onScheduledTransaction(recordItem);
    }
    if (recordItem.isSuccessful()) {
        if (entityProperties.getPersist().getTransactionSignatures().contains(transactionType)) {
            insertTransactionSignatures(transaction.getEntityId(), recordItem.getConsensusTimestamp(), recordItem.getSignatureMap().getSigPairList());
        }
        // Only add non-fee transfers on success as the data is assured to be valid
        processNonFeeTransfers(consensusTimestamp, recordItem);
        if (body.hasConsensusSubmitMessage()) {
            insertConsensusTopicMessage(recordItem);
        } else if (body.hasCryptoAddLiveHash()) {
            insertCryptoAddLiveHash(consensusTimestamp, body.getCryptoAddLiveHash());
        } else if (body.hasFileAppend()) {
            insertFileAppend(consensusTimestamp, body.getFileAppend(), transactionTypeValue);
        } else if (body.hasFileCreate()) {
            insertFileData(consensusTimestamp, DomainUtils.toBytes(body.getFileCreate().getContents()), txRecord.getReceipt().getFileID(), transactionTypeValue);
        } else if (body.hasFileUpdate()) {
            insertFileUpdate(consensusTimestamp, body.getFileUpdate(), transactionTypeValue);
        } else if (body.hasTokenAssociate()) {
            insertTokenAssociate(recordItem);
        } else if (body.hasTokenBurn()) {
            insertTokenBurn(recordItem);
        } else if (body.hasTokenCreation()) {
            insertTokenCreate(recordItem);
        } else if (body.hasTokenDissociate()) {
            insertTokenDissociate(recordItem);
        } else if (body.hasTokenFeeScheduleUpdate()) {
            insertTokenFeeScheduleUpdate(recordItem);
        } else if (body.hasTokenFreeze()) {
            insertTokenAccountFreezeBody(recordItem);
        } else if (body.hasTokenGrantKyc()) {
            insertTokenAccountGrantKyc(recordItem);
        } else if (body.hasTokenMint()) {
            insertTokenMint(recordItem);
        } else if (body.hasTokenPause()) {
            insertTokenPause(recordItem);
        } else if (body.hasTokenRevokeKyc()) {
            insertTokenAccountRevokeKyc(recordItem);
        } else if (body.hasTokenUnfreeze()) {
            insertTokenAccountUnfreeze(recordItem);
        } else if (body.hasTokenUnpause()) {
            insertTokenUnpause(recordItem);
        } else if (body.hasTokenUpdate()) {
            insertTokenUpdate(recordItem);
        } else if (body.hasTokenWipe()) {
            insertTokenAccountWipe(recordItem);
        }
        // Record token transfers can be populated for multiple transaction types
        insertTokenTransfers(recordItem);
        insertAssessedCustomFees(recordItem);
        insertAutomaticTokenAssociations(recordItem);
    }
    contractResultService.process(recordItem, transaction);
    entityListener.onTransaction(transaction);
    log.debug("Storing transaction: {}", transaction);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody) TokenRevokeKycTransactionBody(com.hederahashgraph.api.proto.java.TokenRevokeKycTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TokenPauseTransactionBody(com.hederahashgraph.api.proto.java.TokenPauseTransactionBody) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) TokenGrantKycTransactionBody(com.hederahashgraph.api.proto.java.TokenGrantKycTransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) TokenUnfreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenUnfreezeAccountTransactionBody) TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) TokenDissociateTransactionBody(com.hederahashgraph.api.proto.java.TokenDissociateTransactionBody) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) TokenFreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenFreezeAccountTransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TransactionHandler(com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler) TransactionFilterFields(com.hedera.mirror.importer.domain.TransactionFilterFields) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException)

Example 5 with InvalidEntityException

use of com.hedera.mirror.common.exception.InvalidEntityException in project hedera-mirror-node by hashgraph.

the class NonFeeTransferExtractionStrategyImplTest method extractNonFeeTransfersContractCallFailedThrows.

@Test
void extractNonFeeTransfersContractCallFailedThrows() {
    var amount = 123456L;
    var transactionBody = getContractCallTransactionBody(TestUtils.generateRandomByteArray(20), amount);
    var transactionRecord = getSimpleTransactionRecord();
    when(entityIdService.lookup(ContractID.getDefaultInstance(), transactionBody.getContractCall().getContractID())).thenThrow(new InvalidEntityException(""));
    assertThrows(InvalidEntityException.class, () -> extractionStrategy.extractNonFeeTransfers(transactionBody, transactionRecord));
}
Also used : InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidEntityException (com.hedera.mirror.common.exception.InvalidEntityException)5 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 TransactionType (com.hedera.mirror.common.domain.transaction.TransactionType)2 TransactionHandler (com.hedera.mirror.importer.parser.record.transactionhandler.TransactionHandler)2 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)2 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)2 Test (org.junit.jupiter.api.Test)2 ByteString (com.google.protobuf.ByteString)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 FileData (com.hedera.mirror.common.domain.file.FileData)1 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)1 EntityNotFoundException (com.hedera.mirror.grpc.exception.EntityNotFoundException)1 TransactionFilterFields (com.hedera.mirror.importer.domain.TransactionFilterFields)1 ImporterException (com.hedera.mirror.importer.exception.ImporterException)1 ParserException (com.hedera.mirror.importer.exception.ParserException)1 PubSubMessage (com.hedera.mirror.importer.parser.domain.PubSubMessage)1 ConsensusSubmitMessageTransactionBody (com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)1 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)1 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)1