Skip to content

Commit e143dbe

Browse files
committed
refactor & delete the unused code.
1 parent 10ee8ee commit e143dbe

2 files changed

Lines changed: 9 additions & 93 deletions

File tree

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

Lines changed: 8 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);
@@ -1488,22 +1406,21 @@ public void closeAllStore() {
14881406
closeOneStore(recentBlockStore);
14891407
closeOneStore(transactionHistoryStore);
14901408
closeOneStore(votesStore);
1491-
System.err.println("******** end to close db ********");
1409+
logger.info("******** end to close db ********");
14921410
}
14931411

14941412
private void closeOneStore(ITronChainBase database) {
1495-
System.err.println("******** begin to close " + database.getName() + " ********");
1413+
logger.info("******** begin to close " + database.getName() + " ********");
14961414
try {
14971415
database.close();
14981416
} catch (Exception e) {
1499-
System.err.println("failed to close " + database.getName() + ". " + e);
1417+
logger.info("failed to close " + database.getName() + ". " + e);
15001418
} finally {
1501-
System.err.println("******** end to close " + database.getName() + " ********");
1419+
logger.info("******** end to close " + database.getName() + " ********");
15021420
}
15031421
}
15041422

15051423
public boolean isTooManyPending() {
1506-
// if (getPendingTransactions().size() + PendingManager.getTmpTransactions().size()
15071424
if (getPendingTransactions().size() + getRepushTransactions().size()
15081425
> MAX_TRANSACTION_PENDING) {
15091426
return true;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ 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 {
3030
if (tx.getTrxTrace().getTimeResultType().equals(TimeResultType.NORMAL)) {
3131
dbManager.getRepushTransactions().put(tx);
@@ -48,6 +48,5 @@ public void close() {
4848
}
4949
}
5050
dbManager.getPoppedTransactions().clear();
51-
5251
}
5352
}

0 commit comments

Comments
 (0)