Skip to content

Commit 436ab69

Browse files
committed
optimize the log for configuration without Blackhole account
1 parent 1e35f79 commit 436ab69

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

chainbase/src/main/java/org/tron/core/store/AccountStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.tron.core.capsule.BlockCapsule;
1313
import org.tron.core.db.TronStoreWithRevoking;
1414
import org.tron.core.db.accountstate.AccountStateCallBackUtils;
15+
import org.tron.core.exception.TronError;
1516
import org.tron.protos.contract.BalanceContract.TransactionBalanceTrace;
1617
import org.tron.protos.contract.BalanceContract.TransactionBalanceTrace.Operation;
1718

@@ -50,6 +51,9 @@ public static void setAccount(com.typesafe.config.Config config) {
5051
byte[] address = Commons.decodeFromBase58Check(obj.get("address").unwrapped().toString());
5152
assertsAddress.put(accountName, address);
5253
}
54+
if (assertsAddress.get("Blackhole") == null) {
55+
throw new TronError("Account[Blackhole] is not configured.", TronError.ErrCode.GENESIS_BLOCK_INIT);
56+
}
5357
}
5458

5559
@Override

common/src/main/java/org/tron/common/exit/ExitManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static Optional<TronError> findTronError(Throwable e) {
4646

4747
public static void logAndExit(TronError exit) {
4848
final int code = exit.getErrCode().getCode();
49-
logger.error("Shutting down with code: {}.", exit.getErrCode(), exit);
49+
logger.error("Shutting down with code: {}, reason: {}", exit.getErrCode(), exit.getMessage());
5050
Thread exitThread = exitThreadFactory.newThread(() -> System.exit(code));
5151
exitThread.start();
5252
}

framework/src/test/java/org/tron/core/db/AccountStoreTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
package org.tron.core.db;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.mockito.Mockito.mock;
45

56
import com.google.protobuf.ByteString;
7+
import com.typesafe.config.Config;
8+
import java.lang.reflect.Field;
9+
import java.util.ArrayList;
10+
import java.util.Collections;
611
import java.util.HashMap;
12+
import java.util.List;
713
import java.util.Map;
814
import javax.annotation.Resource;
915
import org.junit.Assert;
1016
import org.junit.Before;
1117
import org.junit.Test;
18+
import org.mockito.Mockito;
1219
import org.tron.common.BaseTest;
1320
import org.tron.common.utils.ByteArray;
1421
import org.tron.core.Constant;
1522
import org.tron.core.capsule.AccountCapsule;
1623
import org.tron.core.config.args.Args;
1724
import org.tron.core.db2.ISession;
25+
import org.tron.core.exception.TronError;
26+
import org.tron.core.net.peer.PeerManager;
1827
import org.tron.core.store.AccountStore;
1928
import org.tron.core.store.AssetIssueStore;
2029
import org.tron.core.store.DynamicPropertiesStore;
@@ -61,6 +70,21 @@ public void init() {
6170
init = true;
6271
}
6372

73+
@Test
74+
public void setAccountTest() throws Exception {
75+
Field field = AccountStore.class.getDeclaredField("assertsAddress");
76+
field.setAccessible(true);
77+
field.set(AccountStore.class, new HashMap<>());
78+
Config config = mock(Config.class);
79+
Mockito.when(config.getObjectList("genesis.block.assets")).thenReturn(new ArrayList<>());
80+
try {
81+
AccountStore.setAccount(config);
82+
Assert.fail();
83+
} catch (Throwable e) {
84+
Assert.assertTrue(e instanceof TronError);
85+
}
86+
}
87+
6488
@Test
6589
public void get() {
6690
//test get and has Method

framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ public void testBroadcastBeforeAllowZksnark()
320320
}
321321

322322
/*
323-
* generate spendproof, dataToBeSigned, outputproof example dynamically according to the params file
323+
* generate spendproof, dataToBeSigned, outputproof example dynamically according to
324+
* the params file.
324325
*/
325326
public String[] generateSpendAndOutputParams() throws ZksnarkException, BadItemException {
326327
librustzcashInitZksnarkParams();

0 commit comments

Comments
 (0)