Skip to content

Commit 8720e06

Browse files
authored
Merge pull request tronprotocol#5841 from tronprotocol/release_v4.7.5
merge release_v4.7.5 to master
2 parents b1fc2f0 + fcae37a commit 8720e06

File tree

44 files changed

+713
-70
lines changed

Some content is hidden

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

44 files changed

+713
-70
lines changed

.github/ISSUE_TEMPLATE/report-a-bug.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,39 @@ assignees: ''
77

88
---
99

10-
#### System information
11-
12-
java-tron version: `java -jar FullNode.jar -v`
13-
OS & Version: Windows/Linux/OSX
14-
Commit hash : (if `develop`)
10+
<!-- Have you done the following? -->
11+
<!-- * Reproduced the issue in the latest version of the software -->
12+
<!-- * Duplicate Issue check: https://github.com/search?q=+is%3Aissue+repo%3Atronprotocol/java-tron -->
13+
14+
#### Software Versions
15+
<!-- `java -jar FullNode.jar -v` -->
16+
17+
<!--
18+
```
19+
OS : Linux
20+
JVM : Oracle Corporation 1.8.0_161 amd64
21+
Git : b1fc2f0f2bd79527099bc3027b9aba165c2e20c2
22+
Version : 4.7.4
23+
Code : 18260
24+
```
25+
-->
1526

1627
#### Expected behaviour
28+
<!--[What you expect to happen] -->
1729

1830

1931
#### Actual behaviour
32+
<!--[What you expect to happen] -->
33+
2034

35+
#### Frequency
36+
<!-- [What percentage of the time does it occur?] -->
2137

2238
#### Steps to reproduce the behaviour
2339

40+
1. [Step 1]
41+
2. [Step 2]
42+
3. [Step ...]
2443

2544
#### Backtrace
2645

.github/ISSUE_TEMPLATE/request-a-feature.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@ labels: 'type:feature'
66
assignees: ''
77

88
---
9+
# Background
910

1011
# Rationale
1112

1213
Why should this feature exist?
14+
1315
What are the use-cases?
1416

17+
# Specification
18+
19+
# Test Specification
20+
21+
# Scope Of Impact
22+
23+
1524
# Implementation
1625

1726
Do you have ideas regarding the implementation of this feature?
27+
1828
Are you willing to implement this feature?

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ TRON enables large-scale development and engagement. With over 2000 transactions
6363

6464
# Building the source
6565

66-
Building java-tron requires `git` 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.
66+
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

6868
Clone the repo and switch to the `master` branch
6969

@@ -73,7 +73,7 @@ $ cd java-tron
7373
$ git checkout -t origin/master
7474
```
7575

76-
then run the following command to build java-tron, the `FullNode.jar` file can be found in `java-tron/build/libs/` after build successful.
76+
then run the following command to build java-tron, the `FullNode.jar` file can be found in `java-tron/build/libs/` after build successfully.
7777

7878
```bash
7979
$ ./gradlew clean build -x test
@@ -120,7 +120,7 @@ $ nohup java -Xms9G -Xmx9G -XX:ReservedCodeCacheSize=256m \
120120

121121
Adding the `--witness` parameter to the startup command, full node will run as a super representative node. The super representative node supports all the functions of the full node and also supports block production. Before running, make sure you have a super representative account and get votes from others. Once the number of obtained votes ranks in the top 27, your super representative node will participate in block production.
122122

123-
Fill in the private key of super representative address into the `localwitness` list in the `main_net_config.conf`. Here is an example:
123+
Fill in the private key of a super representative address into the `localwitness` list in the `main_net_config.conf`. Here is an example:
124124

125125
```
126126
localwitness = [

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.tron.core.utils.TransactionUtil;
3939
import org.tron.core.vm.EnergyCost;
4040
import org.tron.core.vm.LogInfoTriggerParser;
41+
import org.tron.core.vm.Op;
4142
import org.tron.core.vm.OperationRegistry;
4243
import org.tron.core.vm.VM;
4344
import org.tron.core.vm.VMConstant;
@@ -189,6 +190,13 @@ public void execute(Object object) throws ContractExeException {
189190
VM.play(program, OperationRegistry.getTable());
190191
result = program.getResult();
191192

193+
if (VMConfig.allowEnergyAdjustment()) {
194+
// If the last op consumed too much execution time, the CPU time limit for the whole tx can be exceeded.
195+
// This is not fair for other txs in the same block.
196+
// So when allowFairEnergyAdjustment is on, the CPU time limit will be checked at the end of tx execution.
197+
program.checkCPUTimeLimit(Op.getNameOf(program.getLastOp()) + "(TX_LAST_OP)");
198+
}
199+
192200
if (TrxType.TRX_CONTRACT_CREATION_TYPE == trxType && !result.isRevert()) {
193201
byte[] code = program.getResult().getHReturn();
194202
if (code.length != 0 && VMConfig.allowTvmLondon() && code[0] == (byte) 0xEF) {

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.tron.core.utils;
22

3+
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE;
4+
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
35
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
46
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
57
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;
@@ -748,6 +750,35 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
748750
}
749751
break;
750752
}
753+
case ALLOW_ENERGY_ADJUSTMENT: {
754+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_5)) {
755+
throw new ContractValidateException(
756+
"Bad chain parameter id [ALLOW_ENERGY_ADJUSTMENT]");
757+
}
758+
if (dynamicPropertiesStore.getAllowEnergyAdjustment() == 1) {
759+
throw new ContractValidateException(
760+
"[ALLOW_ENERGY_ADJUSTMENT] has been valid, no need to propose again");
761+
}
762+
if (value != 1) {
763+
throw new ContractValidateException(
764+
"This value[ALLOW_ENERGY_ADJUSTMENT] is only allowed to be 1");
765+
}
766+
break;
767+
}
768+
case MAX_CREATE_ACCOUNT_TX_SIZE: {
769+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_5)) {
770+
throw new ContractValidateException(
771+
"Bad chain parameter id [MAX_CREATE_ACCOUNT_TX_SIZE]");
772+
}
773+
if (value < CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE
774+
|| value > CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE) {
775+
throw new ContractValidateException(
776+
"This value[MAX_CREATE_ACCOUNT_TX_SIZE] is only allowed to be greater than or equal "
777+
+ "to " + CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE + " and less than or equal to "
778+
+ CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE + "!");
779+
}
780+
break;
781+
}
751782
default:
752783
break;
753784
}
@@ -824,7 +855,9 @@ public enum ProposalType { // current value, value range
824855
ALLOW_TVM_SHANGHAI(76), // 0, 1
825856
ALLOW_CANCEL_ALL_UNFREEZE_V2(77), // 0, 1
826857
MAX_DELEGATE_LOCK_PERIOD(78), // (86400, 10512000]
827-
ALLOW_OLD_REWARD_OPT(79); // 0, 1
858+
ALLOW_OLD_REWARD_OPT(79), // 0, 1
859+
ALLOW_ENERGY_ADJUSTMENT(81), // 0, 1
860+
MAX_CREATE_ACCOUNT_TX_SIZE(82); // [500, 10000]
828861

829862
private long code;
830863

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,19 @@ public static long getSuicideCost(Program ignored) {
259259
return SUICIDE;
260260
}
261261

262+
public static long getSuicideCost2(Program program) {
263+
DataWord inheritorAddress = program.getStack().peek();
264+
if (isDeadAccount(program, inheritorAddress)) {
265+
return getSuicideCost(program) + NEW_ACCT_CALL;
266+
}
267+
return getSuicideCost(program);
268+
}
269+
262270
public static long getBalanceCost(Program ignored) {
263271
return BALANCE;
264272
}
265273

266274
public static long getFreezeCost(Program program) {
267-
268275
Stack stack = program.getStack();
269276
DataWord receiverAddressWord = stack.get(stack.size() - 3);
270277
if (isDeadAccount(program, receiverAddressWord)) {
@@ -306,7 +313,27 @@ public static long getUnDelegateResourceCost(Program ignored) {
306313
}
307314

308315
public static long getVoteWitnessCost(Program program) {
316+
Stack stack = program.getStack();
317+
long oldMemSize = program.getMemSize();
318+
DataWord amountArrayLength = stack.get(stack.size() - 1).clone();
319+
DataWord amountArrayOffset = stack.get(stack.size() - 2);
320+
DataWord witnessArrayLength = stack.get(stack.size() - 3).clone();
321+
DataWord witnessArrayOffset = stack.get(stack.size() - 4);
322+
323+
DataWord wordSize = new DataWord(DataWord.WORD_SIZE);
324+
325+
amountArrayLength.mul(wordSize);
326+
BigInteger amountArrayMemoryNeeded = memNeeded(amountArrayOffset, amountArrayLength);
327+
328+
witnessArrayLength.mul(wordSize);
329+
BigInteger witnessArrayMemoryNeeded = memNeeded(witnessArrayOffset, witnessArrayLength);
330+
331+
return VOTE_WITNESS + calcMemEnergy(oldMemSize,
332+
(amountArrayMemoryNeeded.compareTo(witnessArrayMemoryNeeded) > 0
333+
? amountArrayMemoryNeeded : witnessArrayMemoryNeeded), 0, Op.VOTEWITNESS);
334+
}
309335

336+
public static long getVoteWitnessCost2(Program program) {
310337
Stack stack = program.getStack();
311338
long oldMemSize = program.getMemSize();
312339
DataWord amountArrayLength = stack.get(stack.size() - 1).clone();
@@ -317,9 +344,11 @@ public static long getVoteWitnessCost(Program program) {
317344
DataWord wordSize = new DataWord(DataWord.WORD_SIZE);
318345

319346
amountArrayLength.mul(wordSize);
347+
amountArrayLength.add(wordSize); // dynamic array length is at least 32 bytes
320348
BigInteger amountArrayMemoryNeeded = memNeeded(amountArrayOffset, amountArrayLength);
321349

322350
witnessArrayLength.mul(wordSize);
351+
witnessArrayLength.add(wordSize); // dynamic array length is at least 32 bytes
323352
BigInteger witnessArrayMemoryNeeded = memNeeded(witnessArrayOffset, witnessArrayLength);
324353

325354
return VOTE_WITNESS + calcMemEnergy(oldMemSize,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public static JumpTable getTable() {
6767
adjustMemOperations(table);
6868
}
6969

70+
if (VMConfig.allowEnergyAdjustment()) {
71+
adjustForFairEnergy(table);
72+
}
73+
7074
return table;
7175
}
7276

@@ -635,4 +639,17 @@ public static void appendShangHaiOperations(JumpTable table) {
635639
OperationActions::push0Action,
636640
proposal));
637641
}
642+
643+
public static void adjustForFairEnergy(JumpTable table) {
644+
table.set(new Operation(
645+
Op.VOTEWITNESS, 4, 1,
646+
EnergyCost::getVoteWitnessCost2,
647+
OperationActions::voteWitnessAction,
648+
VMConfig::allowTvmVote));
649+
650+
table.set(new Operation(
651+
Op.SUICIDE, 1, 0,
652+
EnergyCost::getSuicideCost2,
653+
OperationActions::suicideAction));
654+
}
638655
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import java.io.InputStream;
1313
import java.io.OutputStream;
1414
import java.util.Arrays;
15-
import java.util.Map;
1615
import java.util.zip.Deflater;
1716
import java.util.zip.DeflaterOutputStream;
1817
import lombok.extern.slf4j.Slf4j;
1918
import org.tron.common.utils.ByteArray;
2019
import org.tron.common.utils.ByteUtil;
2120
import org.tron.common.utils.Commons;
2221
import org.tron.common.utils.DecodeUtil;
22+
import org.tron.core.Constant;
2323
import org.tron.core.capsule.AccountCapsule;
2424
import org.tron.core.exception.ContractValidateException;
2525
import org.tron.core.vm.config.VMConfig;
@@ -33,6 +33,11 @@ public final class VMUtils {
3333
private VMUtils() {
3434
}
3535

36+
public static int getAddressSize() {
37+
return VMConfig.allowEnergyAdjustment() ?
38+
Constant.TRON_ADDRESS_SIZE : Constant.STANDARD_ADDRESS_SIZE;
39+
}
40+
3641
public static void closeQuietly(Closeable closeable) {
3742
try {
3843
if (closeable != null) {

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
@@ -39,6 +39,7 @@ public static void load(StoreFactory storeFactory) {
3939
VMConfig.initDynamicEnergyIncreaseFactor(ds.getDynamicEnergyIncreaseFactor());
4040
VMConfig.initDynamicEnergyMaxFactor(ds.getDynamicEnergyMaxFactor());
4141
VMConfig.initAllowTvmShangHai(ds.getAllowTvmShangHai());
42+
VMConfig.initAllowEnergyAdjustment(ds.getAllowEnergyAdjustment());
4243
}
4344
}
4445
}

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
@@ -49,6 +49,8 @@ public class VMConfig {
4949

5050
private static boolean ALLOW_TVM_SHANGHAI = false;
5151

52+
private static boolean ALLOW_ENERGY_ADJUSTMENT = false;
53+
5254
private VMConfig() {
5355
}
5456

@@ -136,6 +138,10 @@ public static void initAllowTvmShangHai(long allow) {
136138
ALLOW_TVM_SHANGHAI = allow == 1;
137139
}
138140

141+
public static void initAllowEnergyAdjustment(long allow) {
142+
ALLOW_ENERGY_ADJUSTMENT = allow == 1;
143+
}
144+
139145
public static boolean getEnergyLimitHardFork() {
140146
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
141147
}
@@ -211,4 +217,8 @@ public static long getDynamicEnergyMaxFactor() {
211217
public static boolean allowTvmShanghai() {
212218
return ALLOW_TVM_SHANGHAI;
213219
}
220+
221+
public static boolean allowEnergyAdjustment() {
222+
return ALLOW_ENERGY_ADJUSTMENT;
223+
}
214224
}

actuator/src/main/java/org/tron/core/vm/program/Program.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ public void setLastOp(byte op) {
275275
this.lastOp = op;
276276
}
277277

278+
public byte getLastOp() {
279+
return this.lastOp;
280+
}
281+
278282
/**
279283
* Returns the last fully executed OP.
280284
*/
@@ -457,7 +461,8 @@ public void suicide(DataWord obtainerAddress) {
457461
InternalTransaction internalTx = addInternalTx(null, owner, obtainer, balance, null,
458462
"suicide", nonce, getContractState().getAccount(owner).getAssetMapV2());
459463

460-
if (FastByteComparisons.compareTo(owner, 0, 20, obtainer, 0, 20) == 0) {
464+
int ADDRESS_SIZE = VMUtils.getAddressSize();
465+
if (FastByteComparisons.compareTo(owner, 0, ADDRESS_SIZE, obtainer, 0, ADDRESS_SIZE) == 0) {
461466
// if owner == obtainer just zeroing account according to Yellow Paper
462467
getContractState().addBalance(owner, -balance);
463468
byte[] blackHoleAddress = getContractState().getBlackHoleAddress();

0 commit comments

Comments
 (0)