Skip to content

Commit e27c862

Browse files
committed
Merge remote-tracking branch 'origin/release_v4.7.2' into release_v4.7.2
2 parents cfbfec5 + feb946d commit e27c862

16 files changed

Lines changed: 77 additions & 8 deletions

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import java.util.Timer;
99
import java.util.TimerTask;
1010
import lombok.extern.slf4j.Slf4j;
11+
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.stereotype.Component;
1213
import org.tron.common.parameter.CommonParameter;
1314
import org.tron.common.utils.ByteArray;
1415
import org.tron.common.utils.JsonUtil;
15-
import org.tron.core.ChainBaseManager;
1616
import org.tron.core.capsule.BytesCapsule;
17+
import org.tron.core.db.CommonStore;
1718
import org.tron.core.net.TronNetService;
1819
import org.tron.p2p.discover.Node;
1920

@@ -24,7 +25,8 @@ public class NodePersistService {
2425
private static final long DB_COMMIT_RATE = 60 * 1000L;
2526
private static final int MAX_NODES_WRITE_TO_DB = 30;
2627
private final boolean isNodePersist = CommonParameter.getInstance().isNodeDiscoveryPersist();
27-
private final ChainBaseManager chainBaseManager = ChainBaseManager.getInstance();
28+
@Autowired
29+
private CommonStore commonStore;
2830
private Timer nodePersistTaskTimer;
2931

3032
public void init() {
@@ -53,7 +55,7 @@ public void close() {
5355
public List<InetSocketAddress> dbRead() {
5456
List<InetSocketAddress> nodes = new ArrayList<>();
5557
try {
56-
byte[] nodeBytes = chainBaseManager.getCommonStore().get(DB_KEY_PEERS).getData();
58+
byte[] nodeBytes = commonStore.get(DB_KEY_PEERS).getData();
5759
if (ByteArray.isEmpty(nodeBytes)) {
5860
return nodes;
5961
}
@@ -85,8 +87,7 @@ private void dbWrite() {
8587

8688
logger.info("Write nodes to store: {}/{} nodes", batch.size(), tableNodes.size());
8789

88-
chainBaseManager.getCommonStore()
89-
.put(DB_KEY_PEERS, new BytesCapsule(JsonUtil.obj2Json(dbNodes).getBytes()));
90+
commonStore.put(DB_KEY_PEERS, new BytesCapsule(JsonUtil.obj2Json(dbNodes).getBytes()));
9091
} catch (Exception e) {
9192
logger.warn("DB write nodes failed, {}", e.getMessage());
9293
}

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/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

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

Whitespace-only changes.

0 commit comments

Comments
 (0)