Skip to content

Commit feb946d

Browse files
committed
Merge branch 'tronprotocol:release_v4.7.2' into release_v4.7.2
2 parents b605617 + 0a3f2aa commit feb946d

19 files changed

Lines changed: 111 additions & 44 deletions

framework/src/main/java/org/tron/core/net/service/nodepersist/NodePersistService.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,32 @@
44
import java.util.ArrayList;
55
import java.util.Comparator;
66
import java.util.List;
7+
import java.util.Objects;
78
import java.util.Timer;
89
import java.util.TimerTask;
910
import lombok.extern.slf4j.Slf4j;
1011
import org.springframework.stereotype.Component;
12+
import org.tron.common.parameter.CommonParameter;
1113
import org.tron.common.utils.ByteArray;
1214
import org.tron.common.utils.JsonUtil;
1315
import org.tron.core.ChainBaseManager;
1416
import org.tron.core.capsule.BytesCapsule;
15-
import org.tron.core.config.args.Args;
1617
import org.tron.core.net.TronNetService;
1718
import org.tron.p2p.discover.Node;
1819

1920
@Slf4j(topic = "net")
2021
@Component
2122
public class NodePersistService {
2223
private static final byte[] DB_KEY_PEERS = "peers".getBytes();
23-
private static final long DB_COMMIT_RATE = 1 * 60 * 1000L;
24+
private static final long DB_COMMIT_RATE = 60 * 1000L;
2425
private static final int MAX_NODES_WRITE_TO_DB = 30;
25-
26-
private boolean isNodePersist = Args.getInstance().isNodeDiscoveryPersist();
27-
28-
private ChainBaseManager chainBaseManager = ChainBaseManager.getInstance();
29-
26+
private final boolean isNodePersist = CommonParameter.getInstance().isNodeDiscoveryPersist();
27+
private final ChainBaseManager chainBaseManager = ChainBaseManager.getInstance();
3028
private Timer nodePersistTaskTimer;
3129

3230
public void init() {
33-
nodePersistTaskTimer = new Timer("NodePersistTaskTimer");
3431
if (isNodePersist) {
32+
nodePersistTaskTimer = new Timer("NodePersistTaskTimer");
3533
nodePersistTaskTimer.scheduleAtFixedRate(new TimerTask() {
3634
@Override
3735
public void run() {
@@ -42,6 +40,9 @@ public void run() {
4240
}
4341

4442
public void close() {
43+
if (Objects.isNull(nodePersistTaskTimer)) {
44+
return;
45+
}
4546
try {
4647
nodePersistTaskTimer.cancel();
4748
} catch (Exception e) {

framework/src/test/java/org/tron/common/runtime/InheritanceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class InheritanceTest extends BaseTest {
2222

2323
private static final String OWNER_ADDRESS;
2424
private RepositoryImpl repository;
25+
private static boolean init;
2526

2627
static {
2728
dbPath = "output_InheritanceTest";
@@ -34,9 +35,13 @@ public class InheritanceTest extends BaseTest {
3435
*/
3536
@Before
3637
public void init() {
38+
if (init) {
39+
return;
40+
}
3741
repository = RepositoryImpl.createRoot(StoreFactory.getInstance());
3842
repository.createAccount(Hex.decode(OWNER_ADDRESS), AccountType.Normal);
3943
repository.addBalance(Hex.decode(OWNER_ADDRESS), 100000000);
44+
init = true;
4045
}
4146

4247
/**

framework/src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class InternalTransactionComplexTest extends BaseTest {
2424
private static final String OWNER_ADDRESS;
2525
private static Runtime runtime;
2626
private static RepositoryImpl repository;
27+
private static boolean init;
2728

2829
static {
2930
dbPath = "output_InternalTransactionComplexTest";
@@ -37,9 +38,13 @@ public class InternalTransactionComplexTest extends BaseTest {
3738
*/
3839
@Before
3940
public void init() {
41+
if (init) {
42+
return;
43+
}
4044
repository = RepositoryImpl.createRoot(StoreFactory.getInstance());
4145
repository.createAccount(Hex.decode(OWNER_ADDRESS), AccountType.Normal);
4246
repository.addBalance(Hex.decode(OWNER_ADDRESS), 100000000);
47+
init = true;
4348
}
4449

4550
/**

framework/src/test/java/org/tron/common/runtime/ProgramResultTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class ProgramResultTest extends BaseTest {
4141
private static final String TRANSFER_TO;
4242
private static Runtime runtime;
4343
private static RepositoryImpl repository;
44+
private static boolean init;
4445

4546
static {
4647
dbPath = "output_InternalTransactionComplexTest";
@@ -55,12 +56,16 @@ public class ProgramResultTest extends BaseTest {
5556
*/
5657
@Before
5758
public void init() {
59+
if (init) {
60+
return;
61+
}
5862
repository = RepositoryImpl.createRoot(StoreFactory.getInstance());
5963
repository.createAccount(Hex.decode(OWNER_ADDRESS), AccountType.Normal);
6064
repository.addBalance(Hex.decode(OWNER_ADDRESS), 100000000);
6165
repository.createAccount(Hex.decode(TRANSFER_TO), AccountType.Normal);
6266
repository.addBalance(Hex.decode(TRANSFER_TO), 0);
6367
repository.commit();
68+
init = true;
6469
}
6570

6671
/**

framework/src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class RuntimeTransferComplexTest extends BaseTest {
2929
private static final String TRANSFER_TO;
3030
private static Runtime runtime;
3131
private static RepositoryImpl repository;
32+
private static boolean init;
3233

3334
static {
3435
dbPath = "output_RuntimeTransferComplexTest";
@@ -42,12 +43,16 @@ public class RuntimeTransferComplexTest extends BaseTest {
4243
*/
4344
@Before
4445
public void init() {
46+
if (init) {
47+
return;
48+
}
4549
repository = RepositoryImpl.createRoot(StoreFactory.getInstance());
4650
repository.createAccount(Hex.decode(OWNER_ADDRESS), AccountType.Normal);
4751
repository.addBalance(Hex.decode(OWNER_ADDRESS), 1000000000);
4852
repository.createAccount(Hex.decode(TRANSFER_TO), AccountType.Normal);
4953
repository.addBalance(Hex.decode(TRANSFER_TO), 10);
5054
repository.commit();
55+
init = true;
5156
}
5257

5358
/**

framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
6464

6565
private static final String OwnerAddress = "TCWHANtDDdkZCTo2T2peyEq3Eg9c2XB7ut";
6666
private static final String TriggerOwnerAddress = "TCSgeWapPJhCqgWRxXCKb6jJ5AgNWSGjPA";
67+
private static boolean init;
6768

6869
static {
6970
dbPath = "output_bandwidth_runtime_out_of_time_test";
@@ -84,6 +85,9 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
8485
*/
8586
@Before
8687
public void init() {
88+
if (init) {
89+
return;
90+
}
8791
//init energy
8892
dbManager.getDynamicPropertiesStore().saveLatestBlockHeaderTimestamp(1526647828000L);
8993
dbManager.getDynamicPropertiesStore().saveTotalEnergyWeight(10_000_000L);
@@ -107,6 +111,7 @@ public void init() {
107111
.put(Commons.decodeFromBase58Check(TriggerOwnerAddress), accountCapsule2);
108112
dbManager.getDynamicPropertiesStore()
109113
.saveLatestBlockHeaderTimestamp(System.currentTimeMillis() / 1000);
114+
init = true;
110115
}
111116

112117
@Test

framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {
6565
private static final String indexDirectory = "index_BandWidthRuntimeOutOfTimeTest_test";
6666
private static final String OwnerAddress = "TCWHANtDDdkZCTo2T2peyEq3Eg9c2XB7ut";
6767
private static final String TriggerOwnerAddress = "TCSgeWapPJhCqgWRxXCKb6jJ5AgNWSGjPA";
68+
private static boolean init;
6869

6970
static {
7071
dbPath = "output_bandwidth_runtime_out_of_time_with_check_test";
@@ -85,6 +86,9 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {
8586
*/
8687
@Before
8788
public void init() {
89+
if (init) {
90+
return;
91+
}
8892
//init energy
8993
dbManager.getDynamicPropertiesStore().saveLatestBlockHeaderTimestamp(1526647837000L);
9094
dbManager.getDynamicPropertiesStore().saveTotalEnergyWeight(10_000_000L);
@@ -108,6 +112,7 @@ public void init() {
108112
.put(Commons.decodeFromBase58Check(TriggerOwnerAddress), accountCapsule2);
109113
dbManager.getDynamicPropertiesStore()
110114
.saveLatestBlockHeaderTimestamp(System.currentTimeMillis() / 1000);
115+
init = true;
111116
}
112117

113118
@Test

framework/src/test/java/org/tron/common/utils/Sha256HashTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.util.Arrays;
44
import java.util.concurrent.atomic.AtomicLong;
55
import java.util.stream.IntStream;
6-
import org.testng.Assert;
7-
import org.testng.annotations.Test;
6+
import org.junit.Assert;
7+
import org.junit.Test;
88
import org.tron.common.parameter.CommonParameter;
99

1010
public class Sha256HashTest {
@@ -17,10 +17,10 @@ public void testHash() {
1717
.getInstance().isECKeyCryptoEngine(), input);
1818
byte[] hash1 = Sha256Hash.hash(CommonParameter
1919
.getInstance().isECKeyCryptoEngine(), hash0);
20-
Assert.assertEquals(hash0, ByteArray
21-
.fromHexString("CD5D4A7E8BE869C00E17F8F7712F41DBE2DDBD4D8EC36A7280CD578863717084"));
22-
Assert.assertEquals(hash1, ByteArray
23-
.fromHexString("10AE21E887E8FE30C591A22A5F8BB20EB32B2A739486DC5F3810E00BBDB58C5C"));
20+
Assert.assertEquals(Arrays.toString(hash0), Arrays.toString(ByteArray
21+
.fromHexString("CD5D4A7E8BE869C00E17F8F7712F41DBE2DDBD4D8EC36A7280CD578863717084")));
22+
Assert.assertEquals(Arrays.toString(hash1), Arrays.toString(ByteArray
23+
.fromHexString("10AE21E887E8FE30C591A22A5F8BB20EB32B2A739486DC5F3810E00BBDB58C5C")));
2424

2525
}
2626

@@ -40,7 +40,7 @@ public void testMultiThreadingHash() {
4040
countAll.incrementAndGet();
4141
if (!Arrays.equals(hash, hash0)) {
4242
countFailed.incrementAndGet();
43-
Assert.assertTrue(false);
43+
Assert.fail();
4444
}
4545
}
4646
});

framework/src/test/java/org/tron/core/WalletTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public class WalletTest extends BaseTest {
131131
private static final String OWNER_ADDRESS;
132132
private static final String RECEIVER_ADDRESS;
133133
private static final long initBalance = 43_200_000_000L;
134+
private static boolean init;
134135

135136
static {
136137
dbPath = "output_wallet_test";
@@ -141,11 +142,15 @@ public class WalletTest extends BaseTest {
141142

142143
@Before
143144
public void before() {
145+
initAccountCapsule();
146+
if (init) {
147+
return;
148+
}
144149
initTransaction();
145150
initBlock();
146-
initAccountCapsule();
147151
chainBaseManager.getDynamicPropertiesStore().saveLatestBlockHeaderNumber(5);
148152
chainBaseManager.getDelegatedResourceStore().reset();
153+
init = true;
149154
}
150155

151156
/**

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AccountStoreTest extends BaseTest {
3333
private AssetIssueStore assetIssueStore;
3434
private static byte[] address = TransactionStoreTest.randomBytes(32);
3535
private static byte[] accountName = TransactionStoreTest.randomBytes(32);
36+
private static boolean init;
3637

3738
static {
3839
dbPath = "output_AccountStore_test";
@@ -48,13 +49,17 @@ public class AccountStoreTest extends BaseTest {
4849

4950
@Before
5051
public void init() {
52+
if (init) {
53+
return;
54+
}
5155
assetIssueStore = chainBaseManager.getAssetIssueStore();
5256
dynamicPropertiesStore.saveAllowBlackHoleOptimization(1);
5357
AccountCapsule accountCapsule = new AccountCapsule(ByteString.copyFrom(address),
5458
ByteString.copyFrom(accountName),
5559
AccountType.forNumber(1));
5660

5761
accountStore.put(data, accountCapsule);
62+
init = true;
5863
}
5964

6065
@Test

0 commit comments

Comments
 (0)