Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feature/optimize…
Browse files Browse the repository at this point in the history
…_stake2_code
  • Loading branch information
lxcmyf committed Aug 23, 2023
2 parents 699c044 + a4100b6 commit 22b1265
Show file tree
Hide file tree
Showing 50 changed files with 1,423 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ private long getTotalWithdrawUnfreeze(List<UnFreezeV2> unfrozenV2List, long now)
}

private List<UnFreezeV2> getTotalWithdrawList(List<UnFreezeV2> unfrozenV2List, long now) {
return unfrozenV2List.stream().filter(unfrozenV2 -> (unfrozenV2.getUnfreezeAmount() > 0
&& unfrozenV2.getUnfreezeExpireTime() <= now)).collect(Collectors.toList());
return unfrozenV2List.stream().filter(unfrozenV2 -> unfrozenV2.getUnfreezeExpireTime() <= now)
.collect(Collectors.toList());
}

private List<UnFreezeV2> getRemainWithdrawList(List<UnFreezeV2> unfrozenV2List, long now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private long getTotalWithdrawUnfreeze(List<Protocol.Account.UnFreezeV2> unfrozen
}

private List<Protocol.Account.UnFreezeV2> getTotalWithdrawList(List<Protocol.Account.UnFreezeV2> unfrozenV2List, long now) {
return unfrozenV2List.stream().filter(unfrozenV2 -> (unfrozenV2.getUnfreezeAmount() > 0
&& unfrozenV2.getUnfreezeExpireTime() <= now)).collect(Collectors.toList());
return unfrozenV2List.stream().filter(unfrozenV2 -> unfrozenV2.getUnfreezeExpireTime() <= now)
.collect(Collectors.toList());
}

public long execute(WithdrawExpireUnfreezeParam param, Repository repo) throws ContractExeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ private static long getTotalWithdrawUnfreeze(List<Protocol.Account.UnFreezeV2> u
}

private static List<Protocol.Account.UnFreezeV2> getTotalWithdrawList(List<Protocol.Account.UnFreezeV2> unfrozenV2List, long now) {
return unfrozenV2List.stream().filter(unfrozenV2 -> (unfrozenV2.getUnfreezeAmount() > 0
&& unfrozenV2.getUnfreezeExpireTime() <= now)).collect(Collectors.toList());
return unfrozenV2List.stream().filter(unfrozenV2 -> unfrozenV2.getUnfreezeExpireTime() <= now)
.collect(Collectors.toList());
}

public static long getV2NetUsage(AccountCapsule ownerCapsule, long netUsage) {
Expand Down
57 changes: 5 additions & 52 deletions chainbase/src/main/java/org/tron/core/ChainBaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.tron.core.db.RecentBlockStore;
import org.tron.core.db.RecentTransactionStore;
import org.tron.core.db.TransactionStore;
import org.tron.core.db2.core.ITronChainBase;
import org.tron.core.exception.BadItemException;
import org.tron.core.exception.HeaderNotFound;
import org.tron.core.exception.ItemNotFoundException;
Expand Down Expand Up @@ -245,54 +244,6 @@ public class ChainBaseManager {
@Setter
private long lowestBlockNum = -1; // except num = 0.

public void closeOneStore(ITronChainBase database) {
logger.info("******** Begin to close {}. ********", database.getName());
try {
database.close();
} catch (Exception e) {
logger.info("Failed to close {}.", database.getName(), e);
} finally {
logger.info("******** End to close {}. ********", database.getName());
}
}

public void closeAllStore() {
dbStatService.shutdown();
closeOneStore(transactionRetStore);
closeOneStore(recentBlockStore);
closeOneStore(transactionHistoryStore);
closeOneStore(transactionStore);
closeOneStore(accountStore);
closeOneStore(blockStore);
closeOneStore(blockIndexStore);
closeOneStore(accountIdIndexStore);
closeOneStore(accountIndexStore);
closeOneStore(witnessScheduleStore);
closeOneStore(assetIssueStore);
closeOneStore(dynamicPropertiesStore);
closeOneStore(abiStore);
closeOneStore(codeStore);
closeOneStore(contractStore);
closeOneStore(contractStateStore);
closeOneStore(storageRowStore);
closeOneStore(exchangeStore);
closeOneStore(proposalStore);
closeOneStore(votesStore);
closeOneStore(delegatedResourceStore);
closeOneStore(delegatedResourceAccountIndexStore);
closeOneStore(assetIssueV2Store);
closeOneStore(exchangeV2Store);
closeOneStore(nullifierStore);
closeOneStore(merkleTreeStore);
closeOneStore(delegationStore);
closeOneStore(proofStore);
closeOneStore(commonStore);
closeOneStore(commonDataBase);
closeOneStore(pbftSignDataStore);
closeOneStore(sectionBloomStore);
closeOneStore(accountAssetStore);
}

// for test only
public List<ByteString> getWitnesses() {
return witnessScheduleStore.getActiveWitnesses();
Expand All @@ -316,9 +267,7 @@ public BlockCapsule getHead() throws HeaderNotFound {
}

public synchronized BlockId getHeadBlockId() {
return new BlockId(
dynamicPropertiesStore.getLatestBlockHeaderHash(),
dynamicPropertiesStore.getLatestBlockHeaderNumber());
return new BlockId(dynamicPropertiesStore.getLatestBlockHeaderHash());
}

public long getHeadBlockNum() {
Expand Down Expand Up @@ -434,6 +383,10 @@ private void init() {
this.nodeType = getLowestBlockNum() > 1 ? NodeType.LITE : NodeType.FULL;
}

public void shutdown() {
dbStatService.shutdown();
}

public boolean isLiteNode() {
return getNodeType() == NodeType.LITE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ public static byte[] getOwner(Transaction.Contract contract) {
}
}
return owner.toByteArray();
} catch (InvalidProtocolBufferException invalidProtocolBufferException) {
logger.warn("InvalidProtocolBufferException occurred because {}, please verify the interface "
+ "input parameters", invalidProtocolBufferException.getMessage());
return new byte[0];
} catch (Exception ex) {
logger.error(ex.getMessage());
return new byte[0];
Expand Down
9 changes: 8 additions & 1 deletion chainbase/src/main/java/org/tron/core/db/TronDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ public void reset() {
*/
@Override
public void close() {
dbSource.closeDB();
logger.info("******** Begin to close {}. ********", getName());
try {
dbSource.closeDB();
} catch (Exception e) {
logger.warn("Failed to close {}.", getName(), e);
} finally {
logger.info("******** End to close {}. ********", getName());
}
}

public abstract void put(byte[] key, T item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@ public String getName() {

@Override
public void close() {
revokingDB.close();
logger.info("******** Begin to close {}. ********", getName());
try {
revokingDB.close();
} catch (Exception e) {
logger.warn("Failed to close {}.", getName(), e);
} finally {
logger.info("******** End to close {}. ********", getName());
}
}

@Override
Expand Down
Loading

0 comments on commit 22b1265

Please sign in to comment.