Skip to content

Commit 42c40c0

Browse files
committed
refacto allowShieldedTransaction and fullNodeAllowShieldedTransaction
1 parent 6ff3ddd commit 42c40c0

22 files changed

Lines changed: 596 additions & 624 deletions

‎src/main/java/org/tron/common/zksnark/JLibrustzcash.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public static void librustzcash_tree_uncommitted(byte[] result) throws ZksnarkEx
282282
}
283283

284284
private static boolean isOpenZen() {
285-
return Args.getInstance().isAllowShieldedTransaction();
285+
return Args.getInstance().isFullNodeAllowShieldedTransaction();
286286
}
287287

288288
}

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,8 @@ public Protocol.ChainParameters getChainParameters() {
10181018
// ALLOW_ZKSNARK_TRANSACTION
10191019
builder.addChainParameter(
10201020
Protocol.ChainParameters.ChainParameter.newBuilder()
1021-
.setKey("getAllowZksnarkTransaction")
1022-
.setValue(dbManager.getDynamicPropertiesStore().getAllowZksnarkTransaction())
1021+
.setKey("getAllowShieldedTransaction")
1022+
.setValue(dbManager.getDynamicPropertiesStore().getAllowShieldedTransaction())
10231023
.build());
10241024

10251025
// SHIELDED_TRANSACTION_FEE
@@ -1388,8 +1388,8 @@ public Exchange getExchangeById(ByteString exchangeId) {
13881388
return null;
13891389
}
13901390

1391-
public boolean getAllowShieldedTransactionApi() {
1392-
return Args.getInstance().isAllowShieldedTransaction();
1391+
public boolean getFullNodeAllowShieldedTransaction() {
1392+
return Args.getInstance().isFullNodeAllowShieldedTransaction();
13931393
}
13941394

13951395
public BytesMessage getNullifier(ByteString id) {
@@ -1408,7 +1408,7 @@ public BytesMessage getNullifier(ByteString id) {
14081408

14091409
private long getBlockNumber(OutputPoint outPoint)
14101410
throws BadItemException, ZksnarkException {
1411-
if (!getAllowShieldedTransactionApi()) {
1411+
if (!getFullNodeAllowShieldedTransaction()) {
14121412
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
14131413
}
14141414
ByteString txId = outPoint.getHash();
@@ -1424,7 +1424,7 @@ private long getBlockNumber(OutputPoint outPoint)
14241424
//in:outPoint,out:blockNumber
14251425
private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Long blockNumber)
14261426
throws ItemNotFoundException, BadItemException, InvalidProtocolBufferException, ZksnarkException {
1427-
if (!getAllowShieldedTransactionApi()) {
1427+
if (!getFullNodeAllowShieldedTransaction()) {
14281428
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
14291429
}
14301430
ByteString txId = outPoint.getHash();
@@ -1518,7 +1518,7 @@ private IncrementalMerkleVoucherContainer createWitness(OutputPoint outPoint, Lo
15181518
private void updateWitnesses(List<IncrementalMerkleVoucherContainer> witnessList, long large,
15191519
int synBlockNum) throws ItemNotFoundException, BadItemException,
15201520
InvalidProtocolBufferException, ZksnarkException {
1521-
if (!getAllowShieldedTransactionApi()) {
1521+
if (!getFullNodeAllowShieldedTransaction()) {
15221522
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
15231523
}
15241524
long start = large;
@@ -1595,7 +1595,7 @@ private void updateLowWitness(IncrementalMerkleVoucherContainer witness, long bl
15951595
}
15961596

15971597
private void validateInput(OutputPointInfo request) throws BadItemException, ZksnarkException {
1598-
if (!getAllowShieldedTransactionApi()) {
1598+
if (!getFullNodeAllowShieldedTransaction()) {
15991599
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
16001600
}
16011601
if (request.getBlockNum() < 0 || request.getBlockNum() > 1000) {
@@ -1623,7 +1623,7 @@ private void validateInput(OutputPointInfo request) throws BadItemException, Zks
16231623
public IncrementalMerkleVoucherInfo getMerkleTreeVoucherInfo(OutputPointInfo request)
16241624
throws ItemNotFoundException, BadItemException,
16251625
InvalidProtocolBufferException, ZksnarkException {
1626-
if (!getAllowShieldedTransactionApi()) {
1626+
if (!getFullNodeAllowShieldedTransaction()) {
16271627
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
16281628
}
16291629
validateInput(request);
@@ -1669,7 +1669,7 @@ public IncrementalMerkleVoucherInfo getMerkleTreeVoucherInfo(OutputPointInfo req
16691669
}
16701670

16711671
public IncrementalMerkleTree getMerkleTreeOfBlock(long blockNum) throws ZksnarkException {
1672-
if (!getAllowShieldedTransactionApi()) {
1672+
if (!getFullNodeAllowShieldedTransaction()) {
16731673
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
16741674
}
16751675
if (blockNum < 0) {
@@ -1693,7 +1693,7 @@ public long getShieldedTransactionFee() {
16931693

16941694
public TransactionCapsule createShieldedTransaction(PrivateParameters request)
16951695
throws ContractValidateException, RuntimeException, ZksnarkException {
1696-
if (!getAllowShieldedTransactionApi()) {
1696+
if (!getFullNodeAllowShieldedTransaction()) {
16971697
throw new ZksnarkException("createshieldedtransaction is not allowed");
16981698
}
16991699
ZenTransactionBuilder builder = new ZenTransactionBuilder(this);
@@ -1786,7 +1786,7 @@ public TransactionCapsule createShieldedTransaction(PrivateParameters request)
17861786
public TransactionCapsule createShieldedTransactionWithoutSpendAuthSig(
17871787
PrivateParametersWithoutAsk request)
17881788
throws ContractValidateException, ZksnarkException {
1789-
if (!getAllowShieldedTransactionApi()) {
1789+
if (!getFullNodeAllowShieldedTransaction()) {
17901790
throw new ZksnarkException("createshieldedtransactionwithoutspendauthsig is not allowed");
17911791
}
17921792

@@ -1879,7 +1879,7 @@ public TransactionCapsule createShieldedTransactionWithoutSpendAuthSig(
18791879
}
18801880

18811881
public BytesMessage getSpendingKey() throws ZksnarkException {
1882-
if (!getAllowShieldedTransactionApi()) {
1882+
if (!getFullNodeAllowShieldedTransaction()) {
18831883
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
18841884
}
18851885
byte[] sk = SpendingKey.random().getValue();
@@ -1888,7 +1888,7 @@ public BytesMessage getSpendingKey() throws ZksnarkException {
18881888

18891889
public ExpandedSpendingKeyMessage getExpandedSpendingKey(ByteString spendingKey)
18901890
throws BadItemException, ZksnarkException {
1891-
if (!getAllowShieldedTransactionApi()) {
1891+
if (!getFullNodeAllowShieldedTransaction()) {
18921892
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
18931893
}
18941894
if (Objects.isNull(spendingKey)) {
@@ -1914,7 +1914,7 @@ public ExpandedSpendingKeyMessage getExpandedSpendingKey(ByteString spendingKey)
19141914

19151915
public BytesMessage getAkFromAsk(ByteString ask) throws
19161916
BadItemException, ZksnarkException {
1917-
if (!getAllowShieldedTransactionApi()) {
1917+
if (!getFullNodeAllowShieldedTransaction()) {
19181918
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
19191919
}
19201920
if (Objects.isNull(ask)) {
@@ -1931,7 +1931,7 @@ public BytesMessage getAkFromAsk(ByteString ask) throws
19311931

19321932
public BytesMessage getNkFromNsk(ByteString nsk) throws
19331933
BadItemException, ZksnarkException {
1934-
if (!getAllowShieldedTransactionApi()) {
1934+
if (!getFullNodeAllowShieldedTransaction()) {
19351935
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
19361936
}
19371937
if (Objects.isNull(nsk)) {
@@ -1948,7 +1948,7 @@ public BytesMessage getNkFromNsk(ByteString nsk) throws
19481948

19491949
public IncomingViewingKeyMessage getIncomingViewingKey(byte[] ak, byte[] nk)
19501950
throws ZksnarkException {
1951-
if (!getAllowShieldedTransactionApi()) {
1951+
if (!getFullNodeAllowShieldedTransaction()) {
19521952
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
19531953
}
19541954
// if (ak.length != 32 || nk.length != 32) {
@@ -1963,7 +1963,7 @@ public IncomingViewingKeyMessage getIncomingViewingKey(byte[] ak, byte[] nk)
19631963
}
19641964

19651965
public DiversifierMessage getDiversifier() throws ZksnarkException {
1966-
if (!getAllowShieldedTransactionApi()) {
1966+
if (!getFullNodeAllowShieldedTransaction()) {
19671967
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
19681968
}
19691969
byte[] d;
@@ -1982,7 +1982,7 @@ public DiversifierMessage getDiversifier() throws ZksnarkException {
19821982
}
19831983

19841984
public BytesMessage getRcm() throws ZksnarkException {
1985-
if (!getAllowShieldedTransactionApi()) {
1985+
if (!getFullNodeAllowShieldedTransaction()) {
19861986
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
19871987
}
19881988
byte[] rcm = Note.generateR();
@@ -1992,7 +1992,7 @@ public BytesMessage getRcm() throws ZksnarkException {
19921992

19931993
public PaymentAddressMessage getPaymentAddress(IncomingViewingKey ivk,
19941994
DiversifierT d) throws BadItemException, ZksnarkException {
1995-
if (!getAllowShieldedTransactionApi()) {
1995+
if (!getFullNodeAllowShieldedTransaction()) {
19961996
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
19971997
}
19981998

@@ -2021,7 +2021,7 @@ public PaymentAddressMessage getPaymentAddress(IncomingViewingKey ivk,
20212021

20222022
public SpendResult isSpend(NoteParameters noteParameters) throws
20232023
ZksnarkException {
2024-
if (!getAllowShieldedTransactionApi()) {
2024+
if (!getFullNodeAllowShieldedTransaction()) {
20252025
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
20262026
}
20272027
GrpcAPI.Note note = noteParameters.getNote();
@@ -2059,7 +2059,7 @@ public SpendResult isSpend(NoteParameters noteParameters) throws
20592059

20602060
public BytesMessage createSpendAuthSig(SpendAuthSigParameters spendAuthSigParameters)
20612061
throws ZksnarkException {
2062-
if (!getAllowShieldedTransactionApi()) {
2062+
if (!getFullNodeAllowShieldedTransaction()) {
20632063
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
20642064
}
20652065
byte[] result = new byte[64];
@@ -2076,7 +2076,7 @@ public BytesMessage createSpendAuthSig(SpendAuthSigParameters spendAuthSigParame
20762076
}
20772077

20782078
public BytesMessage createShieldNullifier(NfParameters nfParameters) throws ZksnarkException {
2079-
if (!getAllowShieldedTransactionApi()) {
2079+
if (!getFullNodeAllowShieldedTransaction()) {
20802080
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
20812081
}
20822082
byte[] ak = nfParameters.getAk().toByteArray();
@@ -2411,7 +2411,7 @@ public ExchangeList getPaginatedExchangeList(long offset, long limit) {
24112411
*/
24122412
public GrpcAPI.DecryptNotes scanNoteByIvk(long startNum, long endNum,
24132413
byte[] ivk) throws BadItemException, ZksnarkException {
2414-
if (!getAllowShieldedTransactionApi()) {
2414+
if (!getFullNodeAllowShieldedTransaction()) {
24152415
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
24162416
}
24172417
GrpcAPI.DecryptNotes.Builder builder = GrpcAPI.DecryptNotes
@@ -2498,7 +2498,7 @@ public GrpcAPI.DecryptNotes scanNoteByIvk(long startNum, long endNum,
24982498
*/
24992499
public GrpcAPI.DecryptNotes scanNoteByOvk(long startNum, long endNum,
25002500
byte[] ovk) throws BadItemException, ZksnarkException {
2501-
if (!getAllowShieldedTransactionApi()) {
2501+
if (!getFullNodeAllowShieldedTransaction()) {
25022502
throw new ZksnarkException("ShieldedTransactionApi is not allowed");
25032503
}
25042504
GrpcAPI.DecryptNotes.Builder builder = GrpcAPI.DecryptNotes

‎src/main/java/org/tron/core/actuator/ProposalCreateActuator.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,17 @@ private void validateValue(Map.Entry<Long, Long> entry) throws ContractValidateE
326326
}
327327
if (entry.getValue() != 1) {
328328
throw new ContractValidateException(
329-
"This value[ALLOW_ZKSNARK_TRANSACTION] is only allowed to be 1");
329+
"This value[ALLOW_SHIELDED_TRANSACTION] is only allowed to be 1");
330330
}
331331
break;
332332
}
333333
case (28): {
334334
if (!dbManager.getForkController().pass(ForkBlockVersionEnum.VERSION_4_0)) {
335335
throw new ContractValidateException("Bad chain parameter id");
336336
}
337-
if (!dbManager.getDynamicPropertiesStore().supportZKSnarkTransaction()) {
337+
if (!dbManager.getDynamicPropertiesStore().supportShieldedTransaction()) {
338338
throw new ContractValidateException(
339-
"ZKSnark Transaction is not activated,Can't set ZKSnark Transaction fee");
339+
"Shielded Transaction is not activated,Can't set Shielded Transaction fee");
340340
}
341341
if (entry.getValue() < 0 || entry.getValue() > 10_000_000_000L) {
342342
throw new ContractValidateException(

‎src/main/java/org/tron/core/actuator/ShieldedTransferActuator.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private void executeShielded(List<SpendDescription> spends, List<ReceiveDescript
141141
}
142142
dbManager.getNullfierStore().put(new BytesCapsule(spend.getNullifier().toByteArray()));
143143
}
144-
if (Args.getInstance().isAllowShieldedTransaction()) {
144+
if (Args.getInstance().isFullNodeAllowShieldedTransaction()) {
145145
MerkleContainer merkleContainer = dbManager.getMerkleContainer();
146146
IncrementalMerkleTreeContainer currentMerkle = merkleContainer.getCurrentMerkle();
147147
try {
@@ -184,7 +184,7 @@ public boolean validate() throws ContractValidateException {
184184
+ "ALLOW_SAME_TOKEN_NAME is opened by the committee");
185185
}
186186

187-
if (!dbManager.getDynamicPropertiesStore().supportZKSnarkTransaction()) {
187+
if (!dbManager.getDynamicPropertiesStore().supportShieldedTransaction()) {
188188
throw new ContractValidateException("Not support ZKSnarkTransaction, need to be opened by" +
189189
" the committee");
190190
}
@@ -203,7 +203,8 @@ public boolean validate() throws ContractValidateException {
203203
throw new ContractValidateException("duplicate sapling nullifiers in this transaction");
204204
}
205205
nfSet.add(spendDescription.getNullifier());
206-
if (Args.getInstance().isAllowShieldedTransaction() && !dbManager.getMerkleContainer()
206+
if (Args.getInstance().isFullNodeAllowShieldedTransaction() && !dbManager
207+
.getMerkleContainer()
207208
.merkleRootExist(spendDescription.getAnchor().toByteArray())) {
208209
throw new ContractValidateException("Rt is invalid.");
209210
}

‎src/main/java/org/tron/core/config/Parameter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public enum ChainParameters {
100100
ALLOW_PROTO_FILTER_NUM, // 1, 24
101101
ALLOW_ACCOUNT_STATE_ROOT, // 1, 25
102102
ALLOW_TVM_CONSTANTINOPLE, // 1, 26
103-
ALLOW_ZKSNARK_TRANSACTION, // 1, 27
103+
ALLOW_SHIELDED_TRANSACTION, // 1, 27
104104
SHIELDED_TRANSACTION_FEE, // sun, 28
105105
}
106106

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,15 @@ public class Args {
429429
@Getter
430430
@Setter
431431
private int minEffectiveConnection;
432+
433+
@Getter
434+
@Setter
435+
private long allowShieldedTransaction; //committee parameter
436+
437+
// full node used this parameter to close shielded transaction
432438
@Getter
433439
@Setter
434-
private long allowZKSnarkTransaction; //committee parameter
440+
private boolean fullNodeAllowShieldedTransaction;
435441

436442
@Getter
437443
@Setter
@@ -461,9 +467,6 @@ public class Args {
461467
@Parameter(names = {"-v", "--version"}, description = "output code version", help = true)
462468
private boolean version;
463469

464-
@Getter
465-
@Setter
466-
private boolean allowShieldedTransaction;
467470

468471
@Getter
469472
@Setter
@@ -552,11 +555,11 @@ public static void clearParam() {
552555
INSTANCE.minTimeRatio = 0.0;
553556
INSTANCE.maxTimeRatio = 5.0;
554557
INSTANCE.longRunningTime = 10;
555-
INSTANCE.allowZKSnarkTransaction = 0;
558+
INSTANCE.allowShieldedTransaction = 0;
556559
INSTANCE.maxHttpConnectNumber = 50;
557560
INSTANCE.allowMultiSign = 0;
558561
INSTANCE.trxExpirationTimeInMilliseconds = 0;
559-
INSTANCE.allowShieldedTransaction = true;
562+
INSTANCE.fullNodeAllowShieldedTransaction = true;
560563
INSTANCE.zenTokenId = "000000";
561564
INSTANCE.allowProtoFilterNum = 0;
562565
INSTANCE.allowAccountStateRoot = 0;
@@ -943,11 +946,11 @@ public static void setParam(final String[] args, final String confFileName) {
943946
.getBoolean("vm.vmTrace") : false;
944947

945948
INSTANCE.saveInternalTx =
946-
947949
config.hasPath("vm.saveInternalTx") && config.getBoolean("vm.saveInternalTx");
948-
INSTANCE.allowZKSnarkTransaction =
949-
config.hasPath("committee.allowZKSnarkTransaction") ? config
950-
.getInt("committee.allowZKSnarkTransaction") : 0;
950+
951+
INSTANCE.allowShieldedTransaction =
952+
config.hasPath("committee.allowShieldedTransaction") ? config
953+
.getInt("committee.allowShieldedTransaction") : 0;
951954

952955
INSTANCE.eventPluginConfig =
953956
config.hasPath("event.subscribe") ?
@@ -956,8 +959,9 @@ public static void setParam(final String[] args, final String confFileName) {
956959
INSTANCE.eventFilter =
957960
config.hasPath("event.subscribe.filter") ? getEventFilter(config) : null;
958961

959-
INSTANCE.allowShieldedTransaction = config.hasPath("node.allowShieldedTransaction") ?
960-
config.getBoolean("node.allowShieldedTransaction") : true;
962+
INSTANCE.fullNodeAllowShieldedTransaction =
963+
config.hasPath("node.fullNodeAllowShieldedTransaction") ?
964+
config.getBoolean("node.fullNodeAllowShieldedTransaction") : true;
961965

962966
INSTANCE.zenTokenId = config.hasPath("node.zenTokenId") ?
963967
config.getString("node.zenTokenId") : "000000";
@@ -976,7 +980,7 @@ public static void setParam(final String[] args, final String confFileName) {
976980
: Runtime.getRuntime().availableProcessors();
977981

978982
if (INSTANCE.isWitness()) {
979-
INSTANCE.allowShieldedTransaction = true;
983+
INSTANCE.fullNodeAllowShieldedTransaction = true;
980984
}
981985

982986
initBackupProperty(config);

0 commit comments

Comments
 (0)