Skip to content

Commit 941959a

Browse files
committed
Merge branch 'develop' of github.com:tronprotocol/java-tron into discard-inv-below-solid-block
2 parents 930362b + 1f0aa38 commit 941959a

File tree

156 files changed

+8445
-850
lines changed

Some content is hidden

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

156 files changed

+8445
-850
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Please make sure your submission meets the following code style:
151151
152152
### Commit Messages
153153
154-
Commit messages should follow the rule below, we provide a template corresponding instructions.
154+
Commit messages should follow the rule below, we provide a template with corresponding instructions.
155155
156156
Template:
157157
```
@@ -182,7 +182,7 @@ The subject contains a succinct description of the change:
182182
4. Do not end the subject line with a period.
183183
5. Avoid meaningless commits. It is recommended to use the git rebase command.
184184
185-
Message body use the imperative, present tense: "change" not "changed" nor "changes". The body should include the motivation for the change and contrast this with previous behavior.
185+
Message body uses the imperative, present tense: "change" not "changed" nor "changes". The body should include the motivation for the change and contrast this with previous behavior.
186186
187187
Here is an example:
188188
```
@@ -217,7 +217,7 @@ If the purpose of this submission is to modify one issue, you need to refer to t
217217
218218
219219
### Special Situations And How To Deal With Them
220-
As a reviewer, you may find yourself in one of the sitations below. Here’s how to deal with those:
220+
As a reviewer, you may find yourself in one of the situations below. Here’s how to deal with those:
221221
222222
The author doesn’t follow up: ping them after a while (i.e. after a few days). If there is no further response, close the PR or complete the work yourself.
223223

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
## Table of Contents
4444

4545
- [What’s TRON?](#whats-tron)
46-
- [Building the Source Code](#building-the-source)
46+
- [Building the Source Code](#building-the-source-code)
4747
- [Running java-tron](#running-java-tron)
4848
- [Community](#community)
4949
- [Contribution](#contribution)
5050
- [Resources](#resources)
5151
- [Integrity Check](#integrity-check)
5252
- [License](#license)
5353

54-
## What's TRON?
54+
# What's TRON?
5555

5656
TRON is a project dedicated to building the infrastructure for a truly decentralized Internet.
5757

@@ -61,7 +61,7 @@ TRON is a project dedicated to building the infrastructure for a truly decentral
6161

6262
TRON enables large-scale development and engagement. With over 2000 transactions per second (TPS), high concurrency, low latency, and massive data transmission. It is ideal for building decentralized entertainment applications. Free features and incentive systems allow developers to create premium app experiences for users.
6363

64-
# Building the source
64+
# Building the Source Code
6565

6666
Building java-tron requires `git` package and 64-bit version of `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
6767

@@ -91,18 +91,18 @@ Minimum:
9191

9292
- CPU with 8 cores
9393
- 16GB RAM
94-
- 2TB free storage space to sync the Mainnet
94+
- 3TB free storage space to sync the Mainnet
9595

9696
Recommended:
9797

9898
- CPU with 16+ cores(32+ cores for a super representative)
9999
- 32GB+ RAM(64GB+ for a super representative)
100-
- High Performance SSD with at least 2.5TB free space
100+
- High Performance SSD with at least 4TB free space
101101
- 100+ MB/s download Internet service
102102

103103
## Running a full node for mainnet
104104

105-
Full node has full historical data, it is the entry point into the TRON network , it can be used by other processes as a gateway into the TRON network via HTTP and GRPC endpoints. You can interact with the TRON network through full node:transfer assets, deploy contracts, interact with contracts and so on. `-c` parameter specifies a configuration file to run a full node:
105+
Full node has full historical data, it is the entry point into the TRON network, it can be used by other processes as a gateway into the TRON network via HTTP and GRPC endpoints. You can interact with the TRON network through full node:transfer assets, deploy contracts, interact with contracts and so on. `-c` parameter specifies a configuration file to run a full node:
106106

107107
```bash
108108
$ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \

Tron protobuf protocol document.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ Contract and contract-related messages.
975975

976976
- message `VoteAssetContract`
977977

978-
`owner_address`: assress of contract owner.
978+
`owner_address`: address of contract owner.
979979

980980
`vote_address`: voted address of asset.
981981

@@ -1059,7 +1059,7 @@ Contract and contract-related messages.
10591059

10601060
`total_supply`: maximum of asset.
10611061

1062-
`frozen_supply`: frozen supplt of asset.
1062+
`frozen_supply`: frozen supply of asset.
10631063

10641064
`trx_num`: trx num defines token price.
10651065

@@ -1079,11 +1079,11 @@ Contract and contract-related messages.
10791079

10801080
`free_asset_net_limit`: free bandwidth limit each account owns when transfers asset.
10811081

1082-
`public_free_asset_net_limit`: free bandwidth limit for all acoounts.
1082+
`public_free_asset_net_limit`: free bandwidth limit for all accounts.
10831083

10841084
`public_free_asset_net_usage`: free bandwidth usage of all accounts.
10851085

1086-
`public_latest_free_net_time`: the latest bandwidth consumption time fo token transfer.
1086+
`public_latest_free_net_time`: the latest bandwidth consumption time for token transfer.
10871087

10881088
```java
10891089
message AssetIssueContract {
@@ -1131,7 +1131,7 @@ Contract and contract-related messages.
11311131

11321132
`owner_address`: owner address.
11331133

1134-
`to_address`: reveiver address.
1134+
`to_address`: receiver address.
11351135

11361136
`asset_name`: target asset name.
11371137

@@ -1461,7 +1461,7 @@ Contract and contract-related messages.
14611461
14621462
`owner_address`: address of owner.
14631463
1464-
`owner`: autuority to execute all contracts.
1464+
`owner`: authority to execute all contracts.
14651465
14661466
`witness`: used by SR for generating blocks.
14671467
@@ -1514,7 +1514,7 @@ Contract and contract-related messages.
15141514
15151515
`binding_signature`: signature to verify transaction.
15161516
1517-
`transparent_to_address`: transparent address of reveiver.
1517+
`transparent_to_address`: transparent address of receiver.
15181518
15191519
`to_amount`: amount to transparent to_address
15201520
@@ -1536,7 +1536,7 @@ Contract and contract-related messages.
15361536

15371537
### <span id="smartc">Smart Contract</span>
15381538

1539-
message `SmartContract` has mutiple attributes and nested message `ABI`
1539+
message `SmartContract` has multiple attributes and nested message `ABI`
15401540

15411541
- message `SmartContract`
15421542

@@ -1559,7 +1559,7 @@ message `SmartContract` has mutiple attributes and nested message `ABI`
15591559

15601560
- message `Param`
15611561

1562-
`indexed`: `true` if the field is part of the log’s topics, `false` if it one of the log’s data segment.
1562+
`indexed`: `true` if the field is part of the log’s topics, `false` if it is one of the log’s data segment.
15631563

15641564
`name`: name of the parameter.
15651565

@@ -1757,7 +1757,7 @@ message `SmartContract` has mutiple attributes and nested message `ABI`
17571757

17581758
`tree`: incremental merkle tree.
17591759

1760-
`filled`: this is a array, it contains the root of the subtree which can be combined with the param tree to be a new merkle tree.
1760+
`filled`: this is an array, it contains the root of the subtree which can be combined with the param tree to be a new merkle tree.
17611761

17621762
`cursor`: the node that can be combined to a subtree, when they are combined to a subtree, compute its root and put it into the filled.
17631763

@@ -1782,7 +1782,7 @@ message `SmartContract` has mutiple attributes and nested message `ABI`
17821782

17831783
`vouchers`: this is an array, each items represents the merklevoucher of the outputpoint.
17841784

1785-
`paths`: his is an array each items represents the path of the outputpoint.
1785+
`paths`: this is an array each items represents the path of the outputpoint.
17861786

17871787
```java
17881788
message IncrementalMerkleVoucherInfo {
@@ -2124,13 +2124,13 @@ message `SmartContract` has mutiple attributes and nested message `ABI`
21242124

21252125
- #### Node Information
21262126

2127-
Node information is separaed into several parts and implemented by nested messages.
2127+
Node information is separated into several parts and implemented by nested messages.
21282128

21292129

21302130

21312131
- message `NodeInfo`
21322132

2133-
`beginSyncNum`: beginning block height for synchornize.
2133+
`beginSyncNum`: beginning block height for synchronize.
21342134

21352135
`block`: head block id.
21362136

@@ -2154,13 +2154,13 @@ message `SmartContract` has mutiple attributes and nested message `ABI`
21542154

21552155
- message `PeerInfo`:
21562156

2157-
`lastSyncBlock`: last block id for synchornize.
2157+
`lastSyncBlock`: last block id for synchronize.
21582158

21592159
`remainNum`: number of remaining blocks.
21602160

21612161
`lastBlockUpdateTime`: latest block update time .
21622162

2163-
`syncFlag`: is synchroniing or not.
2163+
`syncFlag`: is synchronizing or not.
21642164

21652165
`headBlockTimeWeBothHave`: timestamp of common head block.
21662166

@@ -2172,7 +2172,7 @@ message `SmartContract` has mutiple attributes and nested message `ABI`
21722172

21732173
`port`: listening port.
21742174

2175-
`nodeId`: ramdomly generated node ID
2175+
`nodeId`: randomly generated node ID
21762176

21772177
`connectTime`: connection time period from established.
21782178

actuator/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
description = "actuator – a series of transactions for blockchain."
22

33
dependencies {
4-
compile project(":chainbase")
5-
compile project(":protocol")
6-
compile project(":crypto")
4+
api project(":chainbase")
5+
api project(":protocol")
6+
api project(":crypto")
77
}
88

99
test {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public boolean execute(Object object) throws ContractExeException {
6666
long tokenQuant = exchangeTransactionContract.getQuant();
6767

6868
byte[] anotherTokenID;
69-
long anotherTokenQuant = exchangeCapsule.transaction(tokenID, tokenQuant);
69+
long anotherTokenQuant = exchangeCapsule.transaction(tokenID, tokenQuant,
70+
dynamicStore.allowStrictMath());
7071

7172
if (Arrays.equals(tokenID, firstTokenID)) {
7273
anotherTokenID = secondTokenID;
@@ -205,7 +206,8 @@ public boolean validate() throws ContractValidateException {
205206
}
206207
}
207208

208-
long anotherTokenQuant = exchangeCapsule.transaction(tokenID, tokenQuant);
209+
long anotherTokenQuant = exchangeCapsule.transaction(tokenID, tokenQuant,
210+
dynamicStore.allowStrictMath());
209211
if (anotherTokenQuant < tokenExpected) {
210212
throw new ContractValidateException("token required must greater than expected");
211213
}

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,36 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
779779
}
780780
break;
781781
}
782+
case ALLOW_STRICT_MATH: {
783+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_7)) {
784+
throw new ContractValidateException(
785+
"Bad chain parameter id [ALLOW_STRICT_MATH]");
786+
}
787+
if (dynamicPropertiesStore.allowStrictMath()) {
788+
throw new ContractValidateException(
789+
"[ALLOW_STRICT_MATH] has been valid, no need to propose again");
790+
}
791+
if (value != 1) {
792+
throw new ContractValidateException(
793+
"This value[ALLOW_STRICT_MATH] is only allowed to be 1");
794+
}
795+
break;
796+
}
797+
case CONSENSUS_LOGIC_OPTIMIZATION: {
798+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_0)) {
799+
throw new ContractValidateException(
800+
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
801+
}
802+
if (dynamicPropertiesStore.getConsensusLogicOptimization() == 1) {
803+
throw new ContractValidateException(
804+
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again");
805+
}
806+
if (value != 1) {
807+
throw new ContractValidateException(
808+
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
809+
}
810+
break;
811+
}
782812
default:
783813
break;
784814
}
@@ -857,7 +887,9 @@ public enum ProposalType { // current value, value range
857887
MAX_DELEGATE_LOCK_PERIOD(78), // (86400, 10512000]
858888
ALLOW_OLD_REWARD_OPT(79), // 0, 1
859889
ALLOW_ENERGY_ADJUSTMENT(81), // 0, 1
860-
MAX_CREATE_ACCOUNT_TX_SIZE(82); // [500, 10000]
890+
MAX_CREATE_ACCOUNT_TX_SIZE(82), // [500, 10000]
891+
ALLOW_STRICT_MATH(87), // 0, 1
892+
CONSENSUS_LOGIC_OPTIMIZATION(88); // 0, 1
861893

862894
private long code;
863895

actuator/src/main/java/org/tron/core/vm/OperationActions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,9 @@ public static void exeCall(Program program, DataWord adjustedCallEnergy,
989989
PrecompiledContracts.PrecompiledContract contract =
990990
PrecompiledContracts.getContractForAddress(codeAddress);
991991
if (contract != null) {
992+
if (program.isConstantCall()) {
993+
contract = PrecompiledContracts.getOptimizedContractForConstant(contract);
994+
}
992995
program.callToPrecompiledAddress(msg, contract);
993996
} else {
994997
program.callToAddress(msg);

actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
1717

1818
import com.google.protobuf.ByteString;
19+
20+
import java.lang.reflect.Constructor;
1921
import java.math.BigInteger;
2022
import java.security.MessageDigest;
2123
import java.util.ArrayList;
@@ -194,6 +196,14 @@ public class PrecompiledContracts {
194196
private static final DataWord blake2FAddr = new DataWord(
195197
"0000000000000000000000000000000000000000000000000000000000020009");
196198

199+
public static PrecompiledContract getOptimizedContractForConstant(PrecompiledContract contract) {
200+
try {
201+
Constructor<?> constructor = contract.getClass().getDeclaredConstructor();
202+
return (PrecompiledContracts.PrecompiledContract) constructor.newInstance();
203+
} catch (Exception e) {
204+
throw new RuntimeException(e);
205+
}
206+
}
197207

198208
public static PrecompiledContract getContractForAddress(DataWord address) {
199209

actuator/src/main/java/org/tron/core/vm/config/ConfigLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static void load(StoreFactory storeFactory) {
4040
VMConfig.initDynamicEnergyMaxFactor(ds.getDynamicEnergyMaxFactor());
4141
VMConfig.initAllowTvmShangHai(ds.getAllowTvmShangHai());
4242
VMConfig.initAllowEnergyAdjustment(ds.getAllowEnergyAdjustment());
43+
VMConfig.initAllowStrictMath(ds.getAllowStrictMath());
4344
}
4445
}
4546
}

actuator/src/main/java/org/tron/core/vm/config/VMConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class VMConfig {
5151

5252
private static boolean ALLOW_ENERGY_ADJUSTMENT = false;
5353

54+
private static boolean ALLOW_STRICT_MATH = false;
55+
5456
private VMConfig() {
5557
}
5658

@@ -142,6 +144,10 @@ public static void initAllowEnergyAdjustment(long allow) {
142144
ALLOW_ENERGY_ADJUSTMENT = allow == 1;
143145
}
144146

147+
public static void initAllowStrictMath(long allow) {
148+
ALLOW_STRICT_MATH = allow == 1;
149+
}
150+
145151
public static boolean getEnergyLimitHardFork() {
146152
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
147153
}
@@ -221,4 +227,8 @@ public static boolean allowTvmShanghai() {
221227
public static boolean allowEnergyAdjustment() {
222228
return ALLOW_ENERGY_ADJUSTMENT;
223229
}
230+
231+
public static boolean allowStrictMath() {
232+
return ALLOW_STRICT_MATH;
233+
}
224234
}

0 commit comments

Comments
 (0)