Skip to content

Commit d07b0ae

Browse files
committed
Merge branch 'develop' into add_unit_test
2 parents 55ac7f2 + e4eb9a4 commit d07b0ae

74 files changed

Lines changed: 214 additions & 343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/main/java/org/tron/core/db/Manager.java‎

Lines changed: 14 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ public WitnessStore getWitnessStore() {
187187
return this.witnessStore;
188188
}
189189

190-
private void setWitnessStore(final WitnessStore witnessStore) {
191-
this.witnessStore = witnessStore;
192-
}
193-
194190
public DynamicPropertiesStore getDynamicPropertiesStore() {
195191
return this.dynamicPropertiesStore;
196192
}
@@ -285,27 +281,6 @@ public long getHeadBlockTimeStamp() {
285281
return getDynamicPropertiesStore().getLatestBlockHeaderTimestamp();
286282
}
287283

288-
// public PeersStore getPeersStore() {
289-
// return peersStore;
290-
// }
291-
//
292-
// public void setPeersStore(PeersStore peersStore) {
293-
// this.peersStore = peersStore;
294-
// }
295-
//
296-
// public Node getHomeNode() {
297-
// final Args args = Args.getInstance();
298-
// Set<Node> nodes = this.peersStore.get("home".getBytes());
299-
// if (nodes.size() > 0) {
300-
// return nodes.stream().findFirst().get();
301-
// } else {
302-
// Node node =
303-
// new Node(new ECKey().getNodeId(), args.getNodeExternalIp(), args.getNodeListenPort());
304-
// nodes.add(node);
305-
// this.peersStore.put("home".getBytes(), nodes);
306-
// return node;
307-
// }
308-
// }
309284

310285
public void clearAndWriteNeighbours(Set<Node> nodes) {
311286
this.peersStore.put("neighbours".getBytes(), nodes);
@@ -376,14 +351,8 @@ public void init() {
376351
}
377352
forkController.init(this);
378353
revokingStore.enable();
379-
380-
// this.codeStore = CodeStore.create("code");
381-
// this.contractStore = ContractStore.create("contract");
382-
// this.storageStore = StorageStore.create("storage");
383-
384354
validateSignService = Executors
385355
.newFixedThreadPool(Args.getInstance().getValidateSignThreadNum());
386-
387356
repushThread = new Thread(repushLoop);
388357
repushThread.start();
389358
}
@@ -412,7 +381,7 @@ public void initGenesis() {
412381
} else {
413382
logger.info("create genesis block");
414383
Args.getInstance().setChainId(this.genesisBlock.getBlockId().toString());
415-
// this.pushBlock(this.genesisBlock);
384+
416385
blockStore.put(this.genesisBlock.getBlockId().getBytes(), this.genesisBlock);
417386
this.blockIndexStore.put(this.genesisBlock.getBlockId());
418387

@@ -596,7 +565,6 @@ public boolean pushTransaction(final TransactionCapsule trx)
596565
throw new ValidateSignatureException("trans sig validate failed");
597566
}
598567

599-
//validateFreq(trx);
600568
synchronized (this) {
601569
if (!session.valid()) {
602570
session.setValue(revokingStore.buildSession());
@@ -618,39 +586,6 @@ public void consumeBandwidth(TransactionCapsule trx, TransactionTrace trace)
618586
processor.consume(trx, trace);
619587
}
620588

621-
@Deprecated
622-
private void validateFreq(TransactionCapsule trx) throws HighFreqException {
623-
List<org.tron.protos.Protocol.Transaction.Contract> contracts =
624-
trx.getInstance().getRawData().getContractList();
625-
for (Transaction.Contract contract : contracts) {
626-
if (contract.getType() == TransferContract || contract.getType() == TransferAssetContract) {
627-
byte[] address = TransactionCapsule.getOwner(contract);
628-
AccountCapsule accountCapsule = this.getAccountStore().getUnchecked(address);
629-
if (accountCapsule == null) {
630-
throw new HighFreqException("account not exists");
631-
}
632-
long balance = accountCapsule.getBalance();
633-
long latestOperationTime = accountCapsule.getLatestOperationTime();
634-
if (latestOperationTime != 0) {
635-
doValidateFreq(balance, 0, latestOperationTime);
636-
}
637-
accountCapsule.setLatestOperationTime(Time.getCurrentMillis());
638-
this.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
639-
}
640-
}
641-
}
642-
643-
@Deprecated
644-
private void doValidateFreq(long balance, int transNumber, long latestOperationTime)
645-
throws HighFreqException {
646-
long now = Time.getCurrentMillis();
647-
// todo: avoid ddos, design more smoothly formula later.
648-
if (balance < 1000000 * 1000) {
649-
if (now - latestOperationTime < 5 * 60 * 1000) {
650-
throw new HighFreqException("try later");
651-
}
652-
}
653-
}
654589

655590
/**
656591
* when switch fork need erase blocks on fork branch.
@@ -786,10 +721,6 @@ private void switchFork(BlockCapsule newHead)
786721
}
787722
}
788723

789-
// TODO: if error need to rollback.
790-
791-
private synchronized void filterPendingTrx(List<TransactionCapsule> listTrx) {
792-
}
793724

794725
/**
795726
* save a block.
@@ -1138,7 +1069,6 @@ public synchronized BlockCapsule generateBlock(
11381069
// apply transaction
11391070
try (ISession tmpSeesion = revokingStore.buildSession()) {
11401071
processTransaction(trx, blockCapsule);
1141-
// trx.resetResult();
11421072
tmpSeesion.merge();
11431073
// push into block
11441074
blockCapsule.addTransaction(trx);
@@ -1225,33 +1155,22 @@ public synchronized BlockCapsule generateBlock(
12251155
return null;
12261156
}
12271157

1228-
private void setAccountStore(final AccountStore accountStore) {
1229-
this.accountStore = accountStore;
1230-
}
1158+
12311159

12321160
public TransactionStore getTransactionStore() {
12331161
return this.transactionStore;
12341162
}
12351163

1236-
private void setTransactionStore(final TransactionStore transactionStore) {
1237-
this.transactionStore = transactionStore;
1238-
}
1164+
12391165

12401166
public TransactionHistoryStore getTransactionHistoryStore() {
12411167
return this.transactionHistoryStore;
12421168
}
12431169

1244-
private void setTransactionHistoryStore(final TransactionHistoryStore transactionHistoryStore) {
1245-
this.transactionHistoryStore = transactionHistoryStore;
1246-
}
1247-
12481170
public BlockStore getBlockStore() {
12491171
return this.blockStore;
12501172
}
12511173

1252-
private void setBlockStore(final BlockStore blockStore) {
1253-
this.blockStore = blockStore;
1254-
}
12551174

12561175
/**
12571176
* process block.
@@ -1288,7 +1207,6 @@ public void processBlock(BlockCapsule block)
12881207
this.updateLatestSolidifiedBlock();
12891208
this.updateTransHashCache(block);
12901209
updateMaintenanceState(needMaint);
1291-
//witnessController.updateWitnessSchedule();
12921210
updateRecentBlock(block);
12931211

12941212
}
@@ -1468,7 +1386,7 @@ public void setAccountIndexStore(AccountIndexStore indexStore) {
14681386
}
14691387

14701388
public void closeAllStore() {
1471-
System.err.println("******** begin to close db ********");
1389+
logger.info("******** begin to close db ********");
14721390
closeOneStore(accountStore);
14731391
closeOneStore(blockStore);
14741392
closeOneStore(blockIndexStore);
@@ -1482,22 +1400,27 @@ public void closeAllStore() {
14821400
closeOneStore(codeStore);
14831401
closeOneStore(contractStore);
14841402
closeOneStore(storageRowStore);
1485-
System.err.println("******** end to close db ********");
1403+
closeOneStore(exchangeStore);
1404+
closeOneStore(peersStore);
1405+
closeOneStore(proposalStore);
1406+
closeOneStore(recentBlockStore);
1407+
closeOneStore(transactionHistoryStore);
1408+
closeOneStore(votesStore);
1409+
logger.info("******** end to close db ********");
14861410
}
14871411

14881412
private void closeOneStore(ITronChainBase database) {
1489-
System.err.println("******** begin to close " + database.getName() + " ********");
1413+
logger.info("******** begin to close " + database.getName() + " ********");
14901414
try {
14911415
database.close();
14921416
} catch (Exception e) {
1493-
System.err.println("failed to close " + database.getName() + ". " + e);
1417+
logger.info("failed to close " + database.getName() + ". " + e);
14941418
} finally {
1495-
System.err.println("******** end to close " + database.getName() + " ********");
1419+
logger.info("******** end to close " + database.getName() + " ********");
14961420
}
14971421
}
14981422

14991423
public boolean isTooManyPending() {
1500-
// if (getPendingTransactions().size() + PendingManager.getTmpTransactions().size()
15011424
if (getPendingTransactions().size() + getRepushTransactions().size()
15021425
> MAX_TRANSACTION_PENDING) {
15031426
return true;

‎src/main/java/org/tron/core/db/PendingManager.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public PendingManager(Manager db) {
2525
@Override
2626
public void close() {
2727

28-
for (TransactionCapsule tx : this.tmpTransactions) {
28+
for (TransactionCapsule tx : PendingManager.tmpTransactions) {
2929
try {
30-
if (tx.getTrxTrace().getTimeResultType().equals(TimeResultType.NORMAL)) {
30+
if (tx.getTrxTrace() != null &&
31+
tx.getTrxTrace().getTimeResultType().equals(TimeResultType.NORMAL)) {
3132
dbManager.getRepushTransactions().put(tx);
3233
}
3334
} catch (InterruptedException e) {
@@ -39,15 +40,12 @@ public void close() {
3940

4041
for (TransactionCapsule tx : dbManager.getPoppedTransactions()) {
4142
try {
42-
if (tx.getTrxTrace().getTimeResultType().equals(TimeResultType.NORMAL)) {
4343
dbManager.getRepushTransactions().put(tx);
44-
}
4544
} catch (InterruptedException e) {
4645
logger.error(e.getMessage());
4746
Thread.currentThread().interrupt();
4847
}
4948
}
5049
dbManager.getPoppedTransactions().clear();
51-
5250
}
5351
}

‎src/main/java/org/tron/core/net/node/NodeDelegateImpl.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,18 @@ public boolean handleTransaction(TransactionCapsule trx) throws BadTransactionEx
149149
logger.info("AccountResourceInsufficientException" + e.getMessage());
150150
return false;
151151
} catch (DupTransactionException e) {
152-
logger.info("dup trans" + e.getMessage());
152+
logger.info("Dup trans" + e.getMessage());
153153
return false;
154154
} catch (TaposException e) {
155-
logger.info("tapos error" + e.getMessage());
155+
logger.info("Tapos error" + e.getMessage());
156156
return false;
157157
} catch (ReceiptException e) {
158158
logger.info("Receipt exception," + e.getMessage());
159159
} catch (TooBigTransactionException e) {
160-
logger.info("too big transaction" + e.getMessage());
160+
logger.info("Too big transaction" + e.getMessage());
161161
return false;
162162
} catch (TransactionExpirationException e) {
163-
logger.info("expiration transaction" + e.getMessage());
163+
logger.info("Expiration transaction" + e.getMessage());
164164
return false;
165165
} catch (TransactionTraceException e) {
166166
logger.info("TransactionTrace Exception" + e.getMessage());
@@ -172,7 +172,7 @@ public boolean handleTransaction(TransactionCapsule trx) throws BadTransactionEx
172172
logger.warn(e.getMessage());
173173
throw new BadTransactionException();
174174
} catch (TooBigTransactionResultException e) {
175-
logger.info("too big transactionresult" + e.getMessage());
175+
logger.info("Too big transactionresult" + e.getMessage());
176176
return false;
177177
}
178178

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public void inheritanceTest()
130130
@AfterClass
131131
public static void destroy() {
132132
Args.clearParam();
133+
context.destroy();
133134
if (FileUtil.deleteDir(new File(dbPath))) {
134135
logger.info("Release resources successful.");
135136
} else {
136137
logger.info("Release resources failure.");
137138
}
138-
context.destroy();
139139
}
140140

141141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ private byte[] deployCallerContractAndGetItsAddress(byte[] calledContractAddress
168168
@AfterClass
169169
public static void destroy() {
170170
Args.clearParam();
171+
context.destroy();
171172
if (FileUtil.deleteDir(new File(dbPath))) {
172173
logger.info("Release resources successful.");
173174
} else {
174175
logger.info("Release resources failure.");
175176
}
176-
context.destroy();
177177
}
178178

179179
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ public void TransferTrxToContractAccountWhenTriggerAContract()
167167
@AfterClass
168168
public static void destroy() {
169169
Args.clearParam();
170+
context.destroy();
170171
if (FileUtil.deleteDir(new File(dbPath))) {
171172
logger.info("Release resources successful.");
172173
} else {
173174
logger.info("Release resources failure.");
174175
}
175-
context.destroy();
176176
}
177177

178178

‎src/test/java/org/tron/common/runtime/vm/ChargeTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ public void testCreateDepthAndWidth()
338338
@After
339339
public void destroy() {
340340
Args.clearParam();
341+
context.destroy();
341342
if (FileUtil.deleteDir(new File(dbPath))) {
342343
logger.info("Release resources successful.");
343344
} else {
344345
logger.info("Release resources failure.");
345346
}
346-
context.destroy();
347347
}
348348
}

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenAssertStyleTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,12 @@ public void overflowTest()
493493
@After
494494
public void destroy() {
495495
Args.clearParam();
496+
context.destroy();
496497
if (FileUtil.deleteDir(new File(dbPath))) {
497498
logger.info("Release resources successful.");
498499
} else {
499500
logger.info("Release resources failure.");
500501
}
501-
context.destroy();
502502
}
503503
}
504504

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenRequireStyleTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,12 @@ public void reach64CallDepth() {
453453
@After
454454
public void destroy() {
455455
Args.clearParam();
456+
context.destroy();
456457
if (FileUtil.deleteDir(new File(dbPath))) {
457458
logger.info("Release resources successful.");
458459
} else {
459460
logger.info("Release resources failure.");
460461
}
461-
context.destroy();
462462
}
463463
}
464464

‎src/test/java/org/tron/common/runtime/vm/EnergyWhenSendAndTransferTest.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.junit.Test;
88
import org.spongycastle.util.encoders.Hex;
99
import org.testng.Assert;
10+
import org.tron.common.application.Application;
11+
import org.tron.common.application.ApplicationFactory;
1012
import org.tron.common.application.TronApplicationContext;
1113
import org.tron.common.runtime.TVMTestResult;
1214
import org.tron.common.runtime.TVMTestUtils;
@@ -31,7 +33,7 @@ public class EnergyWhenSendAndTransferTest {
3133
private DepositImpl deposit;
3234
private String dbPath = "output_EnergyWhenSendAndTransferTest";
3335
private String OWNER_ADDRESS;
34-
36+
private Application AppT;
3537

3638
/**
3739
* Init data.
@@ -40,6 +42,7 @@ public class EnergyWhenSendAndTransferTest {
4042
public void init() {
4143
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
4244
context = new TronApplicationContext(DefaultConfig.class);
45+
AppT = ApplicationFactory.create(context);
4346
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
4447
dbManager = context.getBean(Manager.class);
4548
deposit = DepositImpl.createRoot(dbManager);
@@ -234,11 +237,12 @@ public TVMTestResult deploySendAndTransferTestContract(long value, long feeLimit
234237
@After
235238
public void destroy() {
236239
Args.clearParam();
240+
AppT.shutdown();
241+
context.destroy();
237242
if (FileUtil.deleteDir(new File(dbPath))) {
238243
logger.info("Release resources successful.");
239244
} else {
240245
logger.info("Release resources failure.");
241246
}
242-
context.destroy();
243247
}
244248
}

0 commit comments

Comments
 (0)