Skip to content

Commit fcdefd5

Browse files
authored
Merge pull request tronprotocol#4454 from tronprotocol/master
master merge to develop
2 parents 00d1caf + 85f7278 commit fcdefd5

File tree

204 files changed

+5647
-3766
lines changed

Some content is hidden

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

204 files changed

+5647
-3766
lines changed

Dockerfile

Lines changed: 0 additions & 43 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ Here are some common use cases of the scripting tool
116116

117117
For more details, please refer to the tool [guide](./shell.md).
118118

119+
## Run inside Docker container
120+
121+
One of the quickest ways to get `java-tron` up and running on your machine is by using Docker:
122+
```shell
123+
$ docker run -d --name="java-tron" \
124+
-v /your_path/output-directory:/java-tron/output-directory \
125+
-v /your_path/logs:/java-tron/logs \
126+
-p 8090:8090 -p 18888:18888 -p 50051:50051 \
127+
tronprotocol/java-tron \
128+
-c /java-tron/config/main_net_config.conf
129+
```
130+
131+
This will mount the `output-directory` and `logs` directories on the host, the docker.sh tool can also be used to simplify the use of docker, see more [here](docker/docker.md).
119132

120133
# Community
121134
[Tron Developers & SRs](https://discord.gg/hqKvyAM) is Tron's official Discord channel. Feel free to join this channel if you have any questions.

Tron protobuf protocol document.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ enum AccountType {
9090

9191
`allowance`: the allowance of this account.
9292

93-
`latest_withdrew_time`: the latest operation time of this account.
93+
`latest_withdraw_time`: the latest operation time of this account.
9494

9595
`code`: reserved
9696

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,7 @@ private void validateTransparent(ShieldedTransferContract shieldedTransferContra
462462
}
463463

464464
private long getZenBalance(AccountCapsule account) {
465-
if (account.getAssetMapV2().get(CommonParameter
466-
.getInstance().getZenTokenId()) == null) {
467-
return 0L;
468-
} else {
469-
return account.getAssetMapV2().get(CommonParameter
470-
.getInstance().getZenTokenId());
471-
}
465+
return account.getAssetV2(CommonParameter.getInstance().getZenTokenId());
472466
}
473467

474468
@Override

actuator/src/main/java/org/tron/core/actuator/TransferAssetActuator.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.protobuf.ByteString;
1919
import com.google.protobuf.InvalidProtocolBufferException;
2020
import java.util.Arrays;
21-
import java.util.Map;
2221
import java.util.Objects;
2322
import lombok.extern.slf4j.Slf4j;
2423
import org.tron.common.utils.ByteArray;
@@ -159,17 +158,7 @@ public boolean validate() throws ContractValidateException {
159158
throw new ContractValidateException("No asset!");
160159
}
161160

162-
Map<String, Long> asset;
163-
if (dynamicStore.getAllowSameTokenName() == 0) {
164-
asset = ownerAccount.getAssetMap();
165-
} else {
166-
asset = ownerAccount.getAssetMapV2();
167-
}
168-
if (asset.isEmpty()) {
169-
throw new ContractValidateException("Owner has no asset!");
170-
}
171-
172-
Long assetBalance = asset.get(ByteArray.toStr(assetName));
161+
Long assetBalance = ownerAccount.getAsset(dynamicStore, ByteArray.toStr(assetName));
173162
if (null == assetBalance || assetBalance <= 0) {
174163
throw new ContractValidateException("assetBalance must be greater than 0.");
175164
}
@@ -185,11 +174,7 @@ public boolean validate() throws ContractValidateException {
185174
throw new ContractValidateException("Cannot transfer asset to smartContract.");
186175
}
187176

188-
if (dynamicStore.getAllowSameTokenName() == 0) {
189-
assetBalance = toAccount.getAssetMap().get(ByteArray.toStr(assetName));
190-
} else {
191-
assetBalance = toAccount.getAssetMapV2().get(ByteArray.toStr(assetName));
192-
}
177+
assetBalance = toAccount.getAsset(dynamicStore, ByteArray.toStr(assetName));
193178
if (assetBalance != null) {
194179
try {
195180
assetBalance = Math.addExact(assetBalance, amount); //check if overflow

actuator/src/main/java/org/tron/core/actuator/UpdateEnergyLimitContractActuator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.tron.core.exception.ContractValidateException;
1616
import org.tron.core.store.AccountStore;
1717
import org.tron.core.store.ContractStore;
18+
import org.tron.core.vm.repository.RepositoryImpl;
1819
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
1920
import org.tron.protos.Protocol.Transaction.Result.code;
2021
import org.tron.protos.contract.SmartContractOuterClass.UpdateEnergyLimitContract;
@@ -44,6 +45,7 @@ public boolean execute(Object object) throws ContractExeException {
4445
contractStore.put(contractAddress, new ContractCapsule(
4546
deployedContract.getInstance().toBuilder().setOriginEnergyLimit(newOriginEnergyLimit)
4647
.build()));
48+
RepositoryImpl.removeLruCache(contractAddress);
4749

4850
ret.setStatus(fee, code.SUCESS);
4951
} catch (InvalidProtocolBufferException e) {

actuator/src/main/java/org/tron/core/actuator/UpdateSettingContractActuator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.tron.core.exception.ContractValidateException;
1717
import org.tron.core.store.AccountStore;
1818
import org.tron.core.store.ContractStore;
19+
import org.tron.core.vm.repository.RepositoryImpl;
1920
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
2021
import org.tron.protos.Protocol.Transaction.Result.code;
2122
import org.tron.protos.contract.SmartContractOuterClass.UpdateSettingContract;
@@ -45,6 +46,7 @@ public boolean execute(Object object) throws ContractExeException {
4546
contractStore.put(contractAddress, new ContractCapsule(
4647
deployedContract.getInstance().toBuilder().setConsumeUserResourcePercent(newPercent)
4748
.build()));
49+
RepositoryImpl.removeLruCache(contractAddress);
4850

4951
ret.setStatus(fee, code.SUCESS);
5052
} catch (InvalidProtocolBufferException e) {

actuator/src/main/java/org/tron/core/actuator/VMActuator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.tron.common.runtime.InternalTransaction.ExecutorType;
2222
import org.tron.common.runtime.InternalTransaction.TrxType;
2323
import org.tron.common.runtime.ProgramResult;
24+
import org.tron.common.runtime.vm.DataWord;
2425
import org.tron.common.utils.StorageUtils;
2526
import org.tron.common.utils.StringUtil;
2627
import org.tron.common.utils.WalletUtil;
@@ -172,7 +173,7 @@ public void execute(Object object) throws ContractExeException {
172173
throw e;
173174
}
174175

175-
VM.play(program, OperationRegistry.getTable(OperationRegistry.Version.TRON_V1));
176+
VM.play(program, OperationRegistry.getTable());
176177
result = program.getResult();
177178

178179
if (TrxType.TRX_CONTRACT_CREATION_TYPE == trxType && !result.isRevert()) {
@@ -235,6 +236,9 @@ public void execute(Object object) throws ContractExeException {
235236
} else {
236237
rootRepository.commit();
237238
}
239+
for (DataWord account : result.getDeleteAccounts()) {
240+
RepositoryImpl.removeLruCache(account.toTronAddress());
241+
}
238242
} catch (JVMStackOverFlowException e) {
239243
program.spendAllEnergy();
240244
result = program.getResult();
@@ -380,7 +384,10 @@ private void create()
380384
.createProgramInvoke(TrxType.TRX_CONTRACT_CREATION_TYPE, executorType, trx,
381385
tokenValue, tokenId, blockCap.getInstance(), rootRepository, vmStartInUs,
382386
vmShouldEndInUs, energyLimit);
383-
this.program = new Program(ops, programInvoke, rootInternalTx);
387+
if (isConstantCall) {
388+
programInvoke.setConstantCall();
389+
}
390+
this.program = new Program(ops, contractAddress, programInvoke, rootInternalTx);
384391
if (VMConfig.allowTvmCompatibleEvm()) {
385392
this.program.setContractVersion(1);
386393
}
@@ -496,7 +503,7 @@ private void call()
496503
programInvoke.setConstantCall();
497504
}
498505
rootInternalTx = new InternalTransaction(trx, trxType);
499-
this.program = new Program(code, programInvoke, rootInternalTx);
506+
this.program = new Program(code, contractAddress, programInvoke, rootInternalTx);
500507
if (VMConfig.allowTvmCompatibleEvm()) {
501508
this.program.setContractVersion(deployedContract.getContractVersion());
502509
}
@@ -715,5 +722,4 @@ private boolean isCheckTransaction() {
715722
.getWitnessSignature().isEmpty();
716723
}
717724

718-
719725
}

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
6767
case EXCHANGE_CREATE_FEE:
6868
break;
6969
case MAX_CPU_TIME_OF_ONE_TX:
70-
if (value < 10 || value > 100) {
71-
throw new ContractValidateException(
72-
"Bad chain parameter value, valid range is [10,100]");
70+
if (dynamicPropertiesStore.getAllowHigherLimitForMaxCpuTimeOfOneTx() == 1) {
71+
if (value < 10 || value > 400) {
72+
throw new ContractValidateException(
73+
"Bad chain parameter value, valid range is [10,400]");
74+
}
75+
} else {
76+
if (value < 10 || value > 100) {
77+
throw new ContractValidateException(
78+
"Bad chain parameter value, valid range is [10,100]");
79+
}
7380
}
7481
break;
7582
case ALLOW_UPDATE_ACCOUNT_NAME: {
@@ -501,11 +508,11 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
501508
case ALLOW_ACCOUNT_ASSET_OPTIMIZATION: {
502509
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_3)) {
503510
throw new ContractValidateException(
504-
"Bad chain parameter id [ALLOW_ACCOUNT_ASSET_OPTIMIZATION]");
511+
"Bad chain parameter id [ALLOW_ACCOUNT_ASSET_OPTIMIZATION]");
505512
}
506513
if (value != 1) {
507514
throw new ContractValidateException(
508-
"This value[ALLOW_ACCOUNT_ASSET_OPTIMIZATION] is only allowed to be 1");
515+
"This value[ALLOW_ACCOUNT_ASSET_OPTIMIZATION] is only allowed to be 1");
509516
}
510517
break;
511518
}
@@ -531,6 +538,28 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
531538
}
532539
break;
533540
}
541+
case ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX: {
542+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_5)) {
543+
throw new ContractValidateException(
544+
"Bad chain parameter id [ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX]");
545+
}
546+
if (value != 1) {
547+
throw new ContractValidateException(
548+
"This value[ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX] is only allowed to be 1");
549+
}
550+
break;
551+
}
552+
case ALLOW_ASSET_OPTIMIZATION: {
553+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_5)) {
554+
throw new ContractValidateException(
555+
"Bad chain parameter id [ALLOW_ASSET_OPTIMIZATION]");
556+
}
557+
if (value != 1) {
558+
throw new ContractValidateException(
559+
"This value[ALLOW_ASSET_OPTIMIZATION] is only allowed to be 1");
560+
}
561+
break;
562+
}
534563
default:
535564
break;
536565
}
@@ -592,7 +621,9 @@ public enum ProposalType { // current value, value range
592621
ALLOW_TVM_COMPATIBLE_EVM(60), // 0, 1
593622
FREE_NET_LIMIT(61), // 5000, [0, 100_000]
594623
TOTAL_NET_LIMIT(62), // 43_200_000_000L, [0, 1000_000_000_000L]
595-
ALLOW_TVM_LONDON(63); // 0, 1
624+
ALLOW_TVM_LONDON(63), // 0, 1
625+
ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX(65), // 0, 1
626+
ALLOW_ASSET_OPTIMIZATION(66); // 0, 1
596627

597628
private long code;
598629

actuator/src/main/java/org/tron/core/utils/TransactionUtil.java

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -205,54 +205,61 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
205205
trxExBuilder.setResult(retBuilder);
206206
tswBuilder.setTransaction(trxExBuilder);
207207
Result.Builder resultBuilder = Result.newBuilder();
208-
try {
209-
Contract contract = trx.getRawData().getContract(0);
210-
byte[] owner = TransactionCapsule.getOwner(contract);
211-
AccountCapsule account = chainBaseManager.getAccountStore().get(owner);
212-
if (Objects.isNull(account)) {
213-
throw new PermissionException("Account does not exist!");
214-
}
215-
int permissionId = contract.getPermissionId();
216-
Permission permission = account.getPermissionById(permissionId);
217-
if (permission == null) {
218-
throw new PermissionException("Permission for this, does not exist!");
219-
}
220-
if (permissionId != 0) {
221-
if (permission.getType() != PermissionType.Active) {
222-
throw new PermissionException("Permission type is wrong!");
208+
209+
if (trx.getRawData().getContractCount() == 0) {
210+
resultBuilder.setCode(Result.response_code.OTHER_ERROR);
211+
resultBuilder.setMessage("Invalid transaction: no valid contract");
212+
} else {
213+
try {
214+
Contract contract = trx.getRawData().getContract(0);
215+
byte[] owner = TransactionCapsule.getOwner(contract);
216+
AccountCapsule account = chainBaseManager.getAccountStore().get(owner);
217+
if (Objects.isNull(account)) {
218+
throw new PermissionException("Account does not exist!");
223219
}
224-
//check operations
225-
if (!checkPermissionOperations(permission, contract)) {
226-
throw new PermissionException("Permission denied!");
220+
int permissionId = contract.getPermissionId();
221+
Permission permission = account.getPermissionById(permissionId);
222+
if (permission == null) {
223+
throw new PermissionException("Permission for this, does not exist!");
227224
}
225+
if (permissionId != 0) {
226+
if (permission.getType() != PermissionType.Active) {
227+
throw new PermissionException("Permission type is wrong!");
228+
}
229+
//check operations
230+
if (!checkPermissionOperations(permission, contract)) {
231+
throw new PermissionException("Permission denied!");
232+
}
233+
}
234+
tswBuilder.setPermission(permission);
235+
if (trx.getSignatureCount() > 0) {
236+
List<ByteString> approveList = new ArrayList<ByteString>();
237+
long currentWeight = TransactionCapsule.checkWeight(permission, trx.getSignatureList(),
238+
Sha256Hash.hash(CommonParameter.getInstance()
239+
.isECKeyCryptoEngine(), trx.getRawData().toByteArray()), approveList);
240+
tswBuilder.addAllApprovedList(approveList);
241+
tswBuilder.setCurrentWeight(currentWeight);
242+
}
243+
if (tswBuilder.getCurrentWeight() >= permission.getThreshold()) {
244+
resultBuilder.setCode(Result.response_code.ENOUGH_PERMISSION);
245+
} else {
246+
resultBuilder.setCode(Result.response_code.NOT_ENOUGH_PERMISSION);
247+
}
248+
} catch (SignatureFormatException signEx) {
249+
resultBuilder.setCode(Result.response_code.SIGNATURE_FORMAT_ERROR);
250+
resultBuilder.setMessage(signEx.getMessage());
251+
} catch (SignatureException signEx) {
252+
resultBuilder.setCode(Result.response_code.COMPUTE_ADDRESS_ERROR);
253+
resultBuilder.setMessage(signEx.getMessage());
254+
} catch (PermissionException permEx) {
255+
resultBuilder.setCode(Result.response_code.PERMISSION_ERROR);
256+
resultBuilder.setMessage(permEx.getMessage());
257+
} catch (Exception ex) {
258+
resultBuilder.setCode(Result.response_code.OTHER_ERROR);
259+
resultBuilder.setMessage(ex.getClass() + " : " + ex.getMessage());
228260
}
229-
tswBuilder.setPermission(permission);
230-
if (trx.getSignatureCount() > 0) {
231-
List<ByteString> approveList = new ArrayList<ByteString>();
232-
long currentWeight = TransactionCapsule.checkWeight(permission, trx.getSignatureList(),
233-
Sha256Hash.hash(CommonParameter.getInstance()
234-
.isECKeyCryptoEngine(), trx.getRawData().toByteArray()), approveList);
235-
tswBuilder.addAllApprovedList(approveList);
236-
tswBuilder.setCurrentWeight(currentWeight);
237-
}
238-
if (tswBuilder.getCurrentWeight() >= permission.getThreshold()) {
239-
resultBuilder.setCode(Result.response_code.ENOUGH_PERMISSION);
240-
} else {
241-
resultBuilder.setCode(Result.response_code.NOT_ENOUGH_PERMISSION);
242-
}
243-
} catch (SignatureFormatException signEx) {
244-
resultBuilder.setCode(Result.response_code.SIGNATURE_FORMAT_ERROR);
245-
resultBuilder.setMessage(signEx.getMessage());
246-
} catch (SignatureException signEx) {
247-
resultBuilder.setCode(Result.response_code.COMPUTE_ADDRESS_ERROR);
248-
resultBuilder.setMessage(signEx.getMessage());
249-
} catch (PermissionException permEx) {
250-
resultBuilder.setCode(Result.response_code.PERMISSION_ERROR);
251-
resultBuilder.setMessage(permEx.getMessage());
252-
} catch (Exception ex) {
253-
resultBuilder.setCode(Result.response_code.OTHER_ERROR);
254-
resultBuilder.setMessage(ex.getClass() + " : " + ex.getMessage());
255261
}
262+
256263
tswBuilder.setResult(resultBuilder);
257264
return tswBuilder.build();
258265
}

0 commit comments

Comments
 (0)