Skip to content

Commit

Permalink
Fix parsing ConsensusCreateTopic with existing autorenew account (#502)
Browse files Browse the repository at this point in the history
* Fix parsing ConsensusCreateTopic with existing autorenew account

Signed-off-by: Steven Sheehy <steven.sheehy@hedera.com>

* Fix mirror_api db permissions

Signed-off-by: Steven Sheehy <steven.sheehy@hedera.com>

* Bump versions to v0.5.2

Signed-off-by: Steven Sheehy <steven.sheehy@hedera.com>
  • Loading branch information
steven-sheehy authored Jan 20, 2020
1 parent c02c417 commit ca2aba6
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 24 deletions.
2 changes: 1 addition & 1 deletion hedera-mirror-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-datagenerator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-importer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* ‍
*/

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -54,7 +53,7 @@ public class Entities {
@Column(name = "fk_entity_type_id")
private Integer entityTypeId;

@ManyToOne(cascade = CascadeType.ALL)
@ManyToOne
private Entities autoRenewAccount;

private Long autoRenewPeriod;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.hedera.mirror.importer.domain;

/*-
* ‌
* Hedera Mirror Node
* ​
* Copyright (C) 2019 Hedera Hashgraph, LLC
* ​
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ‍
*/

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum EntityTypeEnum {

ACCOUNT(1),
CONTRACT(2),
FILE(3),
TOPIC(4);

private final int id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public static void storeRecord(Transaction transaction, TransactionRecord txReco
body = TransactionBody.parseFrom(transaction.getBodyBytes());
}

log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body));
long initialBalance = 0;
Entities entity = null;
Entities proxyEntity = null;
Expand Down Expand Up @@ -469,6 +470,7 @@ public static void storeRecord(Transaction transaction, TransactionRecord txReco
if (proxyEntity != null) {
entity.setProxyAccountId(proxyEntity.getId());
}
entity.setAutoRenewAccount(createEntity(entity.getAutoRenewAccount()));
entity = entityRepository.save(entity);
sqlInsertTransaction.setLong(F_TRANSACTION.CUD_ENTITY_ID.ordinal(), entity.getId());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ private boolean loadRecordFile(String fileName, String previousFileHash, String
TransactionRecord txRecord = TransactionRecord.parseFrom(rawBytes);

try {
RecordFileLogger.storeRecord(transaction, txRecord, rawBytes);

if (log.isTraceEnabled()) {
log.trace("Transaction = {}, Record = {}", Utility
.printProtoMessage(transaction), Utility.printProtoMessage(txRecord));
} else {
log.debug("Stored transaction with consensus timestamp {}", () -> Utility
log.debug("Storing transaction with consensus timestamp {}", () -> Utility
.printProtoMessage(txRecord.getConsensusTimestamp()));
}

RecordFileLogger.storeRecord(transaction, txRecord, rawBytes);
} finally {
// TODO: Refactor to not parse TransactionBody twice
DataCase dc = Utility.getTransactionBody(transaction).getDataCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter default privileges in schema public grant select on tables to ${api-user};

grant select on all tables in schema public to ${api-user};
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
import com.hedera.mirror.importer.TestUtils;
import com.hedera.mirror.importer.TopicIdConverter;
import com.hedera.mirror.importer.domain.Entities;
import com.hedera.mirror.importer.domain.EntityTypeEnum;
import com.hedera.mirror.importer.domain.TopicMessage;
import com.hedera.mirror.importer.domain.Transaction;
import com.hedera.mirror.importer.util.Utility;

public class RecordFileLoggerTopicTest extends AbstractRecordFileLoggerTest {

static final String TRANSACTION_MEMO = "transaction memo";
static final int TOPIC_ENTITY_TYPE_ID = 4;
static final String NODE_ID = "0.0.3";
static final String TRANSACTION_ID = "0.0.9999-123456789";

Expand Down Expand Up @@ -110,7 +110,33 @@ void createTopicTestNulls() throws Exception {
.returns("".getBytes(), from(Entities::getSubmitKey))
.returns("", from(Entities::getMemo))
.returns(false, from(Entities::isDeleted))
.returns(TOPIC_ENTITY_TYPE_ID, from(Entities::getEntityTypeId));
.returns(EntityTypeEnum.TOPIC.getId(), from(Entities::getEntityTypeId));
}

// /~https://github.com/hashgraph/hedera-mirror-node/issues/501
@Test
void createTopicTestExistingAutoRenewAccount() throws Exception {
Entities autoRenewAccount = createEntity(100L, EntityTypeEnum.ACCOUNT);
var topicId = 200L;
var consensusTimestamp = 2_000_000L;
var responseCode = ResponseCodeEnum.SUCCESS;
var transaction = createCreateTopicTransaction(null, null, null, autoRenewAccount.getEntityNum(), null);
var transactionRecord = createTransactionRecord(TopicID.newBuilder().setTopicNum(topicId)
.build(), null, null, consensusTimestamp, responseCode);

RecordFileLogger.storeRecord(transaction, transactionRecord);
RecordFileLogger.completeFile("", "");

var entity = entityRepository.findByPrimaryKey(0L, 0L, topicId).get();
assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
assertEquals(4L, entityRepository.count()); // Node, payer, topic, autorenew
assertThat(entity)
.returns("".getBytes(), from(Entities::getKey))
.returns("".getBytes(), from(Entities::getSubmitKey))
.returns("", from(Entities::getMemo))
.returns(false, from(Entities::isDeleted))
.returns(EntityTypeEnum.TOPIC.getId(), from(Entities::getEntityTypeId))
.returns(autoRenewAccount, from(Entities::getAutoRenewAccount));
}

@Test
Expand Down Expand Up @@ -160,6 +186,9 @@ void updateTopicTest(@ConvertWith(TopicIdConverter.class) TopicID topicId, long
// Store topic to be updated.
var topic = createTopicEntity(topicId, expirationTimeSeconds, expirationTimeNanos, adminKey, submitKey, memo,
autoRenewAccount, autoRenewPeriod);
if (topic.getAutoRenewAccount() != null) {
topic.setAutoRenewAccount(entityRepository.save(topic.getAutoRenewAccount()));
}
entityRepository.save(topic);

var responseCode = ResponseCodeEnum.SUCCESS;
Expand Down Expand Up @@ -265,6 +294,9 @@ void updateTopicTestPartialUpdates(@ConvertWith(TopicIdConverter.class) TopicID
// Store topic to be updated.
var topic = createTopicEntity(topicId, expirationTimeSeconds, expirationTimeNanos, adminKey, submitKey, memo,
autoRenewAccount, autoRenewPeriod);
if (topic.getAutoRenewAccount() != null) {
topic.setAutoRenewAccount(entityRepository.save(topic.getAutoRenewAccount()));
}
entityRepository.save(topic);

// Setup the expected entity.
Expand Down Expand Up @@ -561,6 +593,15 @@ private TransactionBody.Builder createTransactionBody() {
.setMemo(TRANSACTION_MEMO);
}

private Entities createEntity(long num, EntityTypeEnum entityType) {
Entities entities = new Entities();
entities.setEntityShard(0L);
entities.setEntityRealm(0L);
entities.setEntityNum(num);
entities.setEntityTypeId(entityType.getId());
return entityRepository.save(entities);
}

private Entities createTopicEntity(TopicID topicId, Long expirationTimeSeconds, Integer expirationTimeNanos,
Key adminKey, Key submitKey, String memo, Long autoRenewAccount,
Long autoRenewPeriod) {
Expand All @@ -573,7 +614,7 @@ private Entities createTopicEntity(TopicID topicId, Long expirationTimeSeconds,
autoRenewEntity.setEntityShard(topic.getEntityShard());
autoRenewEntity.setEntityRealm(topic.getEntityRealm());
autoRenewEntity.setEntityNum(autoRenewAccount);
autoRenewEntity.setEntityTypeId(1);
autoRenewEntity.setEntityTypeId(EntityTypeEnum.ACCOUNT.getId());
topic.setAutoRenewAccount(autoRenewEntity);
}
if (autoRenewPeriod != null) {
Expand All @@ -589,7 +630,7 @@ private Entities createTopicEntity(TopicID topicId, Long expirationTimeSeconds,
topic.setSubmitKey(submitKey.toByteArray());
}
topic.setMemo(memo);
topic.setEntityTypeId(TOPIC_ENTITY_TYPE_ID);
topic.setEntityTypeId(EntityTypeEnum.TOPIC.getId());
return topic;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void findByPrimaryKey() {
autoRenewAccount.setEntityShard(0L);
autoRenewAccount.setEntityRealm(0L);
autoRenewAccount.setEntityNum(101L);
autoRenewAccount = entityRepository.save(autoRenewAccount);

Entities proxyEntity = new Entities();
proxyEntity.setEntityTypeId(entityTypeId);
Expand All @@ -60,11 +61,6 @@ void findByPrimaryKey() {
entity.setSubmitKey("SubmitKey".getBytes());
entity = entityRepository.save(entity);

assertThat(entityRepository.findByPrimaryKey(autoRenewAccount.getEntityShard(),
autoRenewAccount.getEntityRealm(), autoRenewAccount.getEntityNum()))
.get()
.isEqualToIgnoringGivenFields(autoRenewAccount, "id");

assertThat(entityRepository
.findByPrimaryKey(entity.getEntityShard(), entity.getEntityRealm(), entity.getEntityNum()))
.get()
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-rest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hedera-mirror-rest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hedera-mirror-rest",
"version": "0.5.1",
"version": "0.5.2",
"description": "Hedera Mirror Node REST API",
"main": "server.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<build>
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<artifactId>hedera-mirror-node</artifactId>
<groupId>com.hedera</groupId>
<version>0.5.1</version>
<version>0.5.2</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.hedera</groupId>
<artifactId>hedera-mirror-node</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
<description>Hedera Mirror Node mirrors data from Hedera nodes and serves it via an API</description>
<inceptionYear>2019</inceptionYear>
<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit ca2aba6

Please sign in to comment.