Skip to content

Commit 2bfefaf

Browse files
committed
remove redundant check
1 parent 7676699 commit 2bfefaf

2 files changed

Lines changed: 13 additions & 22 deletions

File tree

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,12 +1806,8 @@ public Exchange getExchangeById(ByteString exchangeId) {
18061806
return null;
18071807
}
18081808

1809-
private boolean getAllowShieldedTransactionApi() {
1810-
return Args.getInstance().isAllowShieldedTransactionApi();
1811-
}
1812-
18131809
private void checkAllowShieldedTransactionApi() throws ZksnarkException {
1814-
if (!getAllowShieldedTransactionApi()) {
1810+
if (!Args.getInstance().isAllowShieldedTransactionApi()) {
18151811
throw new ZksnarkException(SHIELDED_ID_NOT_ALLOWED);
18161812
}
18171813
}
@@ -1830,10 +1826,7 @@ public BytesMessage getNullifier(ByteString id) {
18301826
}
18311827

18321828
private long getBlockNumber(OutputPoint outPoint)
1833-
throws BadItemException, ZksnarkException {
1834-
if (!getAllowShieldedTransactionApi()) {
1835-
throw new ZksnarkException(SHIELDED_ID_NOT_ALLOWED);
1836-
}
1829+
throws BadItemException {
18371830
ByteString txId = outPoint.getHash();
18381831

18391832
long blockNum = chainBaseManager.getTransactionStore().getBlockNumber(txId.toByteArray());
@@ -1848,9 +1841,6 @@ private long getBlockNumber(OutputPoint outPoint)
18481841
private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Long blockNumber)
18491842
throws ItemNotFoundException, BadItemException,
18501843
InvalidProtocolBufferException, ZksnarkException {
1851-
if (!getAllowShieldedTransactionApi()) {
1852-
throw new ZksnarkException(SHIELDED_ID_NOT_ALLOWED);
1853-
}
18541844
ByteString txId = outPoint.getHash();
18551845

18561846
//Get the tree in blockNum-1 position
@@ -1946,9 +1936,6 @@ private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Lo
19461936
private void updateWitnesses(List<IncrementalMerkleVoucherContainer> witnessList, long large,
19471937
int synBlockNum) throws ItemNotFoundException, BadItemException,
19481938
InvalidProtocolBufferException, ZksnarkException {
1949-
if (!getAllowShieldedTransactionApi()) {
1950-
throw new ZksnarkException(SHIELDED_ID_NOT_ALLOWED);
1951-
}
19521939
long start = large;
19531940
long end = large + synBlockNum - 1;
19541941

@@ -2022,10 +2009,7 @@ private void updateLowWitness(IncrementalMerkleVoucherContainer witness, long bl
20222009
}
20232010
}
20242011

2025-
private void validateInput(OutputPointInfo request) throws BadItemException, ZksnarkException {
2026-
if (!getAllowShieldedTransactionApi()) {
2027-
throw new ZksnarkException(SHIELDED_ID_NOT_ALLOWED);
2028-
}
2012+
private void validateInput(OutputPointInfo request) throws BadItemException {
20292013
if (request.getBlockNum() < 0 || request.getBlockNum() > 1000) {
20302014
throw new BadItemException("request.BlockNum must be specified with range in [0, 1000]");
20312015
}
@@ -2097,9 +2081,7 @@ public IncrementalMerkleVoucherInfo getMerkleTreeVoucherInfo(OutputPointInfo req
20972081
}
20982082

20992083
public IncrementalMerkleTree getMerkleTreeOfBlock(long blockNum) throws ZksnarkException {
2100-
if (!getAllowShieldedTransactionApi()) {
2101-
throw new ZksnarkException(SHIELDED_ID_NOT_ALLOWED);
2102-
}
2084+
checkAllowShieldedTransactionApi();
21032085
if (blockNum < 0) {
21042086
return null;
21052087
}

framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.io.InputStream;
6+
import java.util.concurrent.atomic.AtomicBoolean;
67
import javax.annotation.PostConstruct;
78
import lombok.extern.slf4j.Slf4j;
89
import org.apache.commons.io.FileUtils;
@@ -16,12 +17,19 @@
1617
@Component
1718
public class ZksnarkInitService {
1819

20+
private static final AtomicBoolean initialized = new AtomicBoolean(false);
21+
1922
@PostConstruct
2023
private void init() {
2124
librustzcashInitZksnarkParams();
2225
}
2326

2427
public static void librustzcashInitZksnarkParams() {
28+
if (initialized.get()) {
29+
logger.info("zk param already initialized");
30+
return;
31+
}
32+
2533
logger.info("init zk param begin");
2634

2735
String spendPath = getParamsFile("sapling-spend.params");
@@ -35,6 +43,7 @@ public static void librustzcashInitZksnarkParams() {
3543
try {
3644
JLibrustzcash.librustzcashInitZksnarkParams(
3745
new LibrustzcashParam.InitZksnarkParams(spendPath, spendHash, outputPath, outputHash));
46+
initialized.set(true);
3847
} catch (ZksnarkException e) {
3948
throw new TronError(e, TronError.ErrCode.ZCASH_INIT);
4049
}

0 commit comments

Comments
 (0)