Skip to content

Commit

Permalink
Merge pull request #5841 from tronprotocol/release_v4.7.5
Browse files Browse the repository at this point in the history
merge release_v4.7.5 to master
  • Loading branch information
lvs007 authored May 30, 2024
2 parents b1fc2f0 + fcae37a commit 8720e06
Show file tree
Hide file tree
Showing 44 changed files with 713 additions and 70 deletions.
29 changes: 24 additions & 5 deletions .github/ISSUE_TEMPLATE/report-a-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,39 @@ assignees: ''

---

#### System information

java-tron version: `java -jar FullNode.jar -v`
OS & Version: Windows/Linux/OSX
Commit hash : (if `develop`)
<!-- Have you done the following? -->
<!-- * Reproduced the issue in the latest version of the software -->
<!-- * Duplicate Issue check: https://github.com/search?q=+is%3Aissue+repo%3Atronprotocol/java-tron -->

#### Software Versions
<!-- `java -jar FullNode.jar -v` -->

<!--
```
OS : Linux
JVM : Oracle Corporation 1.8.0_161 amd64
Git : b1fc2f0f2bd79527099bc3027b9aba165c2e20c2
Version : 4.7.4
Code : 18260
```
-->

#### Expected behaviour
<!--[What you expect to happen] -->


#### Actual behaviour
<!--[What you expect to happen] -->


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

#### Steps to reproduce the behaviour

1. [Step 1]
2. [Step 2]
3. [Step ...]

#### Backtrace

Expand Down
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/request-a-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ labels: 'type:feature'
assignees: ''

---
# Background

# Rationale

Why should this feature exist?

What are the use-cases?

# Specification

# Test Specification

# Scope Of Impact


# Implementation

Do you have ideas regarding the implementation of this feature?

Are you willing to implement this feature?
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TRON enables large-scale development and engagement. With over 2000 transactions

# Building the source

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.
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.

Clone the repo and switch to the `master` branch

Expand All @@ -73,7 +73,7 @@ $ cd java-tron
$ git checkout -t origin/master
```

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

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

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.

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

```
localwitness = [
Expand Down
8 changes: 8 additions & 0 deletions actuator/src/main/java/org/tron/core/actuator/VMActuator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.tron.core.utils.TransactionUtil;
import org.tron.core.vm.EnergyCost;
import org.tron.core.vm.LogInfoTriggerParser;
import org.tron.core.vm.Op;
import org.tron.core.vm.OperationRegistry;
import org.tron.core.vm.VM;
import org.tron.core.vm.VMConstant;
Expand Down Expand Up @@ -189,6 +190,13 @@ public void execute(Object object) throws ContractExeException {
VM.play(program, OperationRegistry.getTable());
result = program.getResult();

if (VMConfig.allowEnergyAdjustment()) {
// If the last op consumed too much execution time, the CPU time limit for the whole tx can be exceeded.
// This is not fair for other txs in the same block.
// So when allowFairEnergyAdjustment is on, the CPU time limit will be checked at the end of tx execution.
program.checkCPUTimeLimit(Op.getNameOf(program.getLastOp()) + "(TX_LAST_OP)");
}

if (TrxType.TRX_CONTRACT_CREATION_TYPE == trxType && !result.isRevert()) {
byte[] code = program.getResult().getHReturn();
if (code.length != 0 && VMConfig.allowTvmLondon() && code[0] == (byte) 0xEF) {
Expand Down
35 changes: 34 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.tron.core.utils;

import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE;
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;
Expand Down Expand Up @@ -748,6 +750,35 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_ENERGY_ADJUSTMENT: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_5)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_ENERGY_ADJUSTMENT]");
}
if (dynamicPropertiesStore.getAllowEnergyAdjustment() == 1) {
throw new ContractValidateException(
"[ALLOW_ENERGY_ADJUSTMENT] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_ENERGY_ADJUSTMENT] is only allowed to be 1");
}
break;
}
case MAX_CREATE_ACCOUNT_TX_SIZE: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_5)) {
throw new ContractValidateException(
"Bad chain parameter id [MAX_CREATE_ACCOUNT_TX_SIZE]");
}
if (value < CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE
|| value > CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE) {
throw new ContractValidateException(
"This value[MAX_CREATE_ACCOUNT_TX_SIZE] is only allowed to be greater than or equal "
+ "to " + CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE + " and less than or equal to "
+ CREATE_ACCOUNT_TRANSACTION_MAX_BYTE_SIZE + "!");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -824,7 +855,9 @@ public enum ProposalType { // current value, value range
ALLOW_TVM_SHANGHAI(76), // 0, 1
ALLOW_CANCEL_ALL_UNFREEZE_V2(77), // 0, 1
MAX_DELEGATE_LOCK_PERIOD(78), // (86400, 10512000]
ALLOW_OLD_REWARD_OPT(79); // 0, 1
ALLOW_OLD_REWARD_OPT(79), // 0, 1
ALLOW_ENERGY_ADJUSTMENT(81), // 0, 1
MAX_CREATE_ACCOUNT_TX_SIZE(82); // [500, 10000]

private long code;

Expand Down
31 changes: 30 additions & 1 deletion actuator/src/main/java/org/tron/core/vm/EnergyCost.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,19 @@ public static long getSuicideCost(Program ignored) {
return SUICIDE;
}

public static long getSuicideCost2(Program program) {
DataWord inheritorAddress = program.getStack().peek();
if (isDeadAccount(program, inheritorAddress)) {
return getSuicideCost(program) + NEW_ACCT_CALL;
}
return getSuicideCost(program);
}

public static long getBalanceCost(Program ignored) {
return BALANCE;
}

public static long getFreezeCost(Program program) {

Stack stack = program.getStack();
DataWord receiverAddressWord = stack.get(stack.size() - 3);
if (isDeadAccount(program, receiverAddressWord)) {
Expand Down Expand Up @@ -306,7 +313,27 @@ public static long getUnDelegateResourceCost(Program ignored) {
}

public static long getVoteWitnessCost(Program program) {
Stack stack = program.getStack();
long oldMemSize = program.getMemSize();
DataWord amountArrayLength = stack.get(stack.size() - 1).clone();
DataWord amountArrayOffset = stack.get(stack.size() - 2);
DataWord witnessArrayLength = stack.get(stack.size() - 3).clone();
DataWord witnessArrayOffset = stack.get(stack.size() - 4);

DataWord wordSize = new DataWord(DataWord.WORD_SIZE);

amountArrayLength.mul(wordSize);
BigInteger amountArrayMemoryNeeded = memNeeded(amountArrayOffset, amountArrayLength);

witnessArrayLength.mul(wordSize);
BigInteger witnessArrayMemoryNeeded = memNeeded(witnessArrayOffset, witnessArrayLength);

return VOTE_WITNESS + calcMemEnergy(oldMemSize,
(amountArrayMemoryNeeded.compareTo(witnessArrayMemoryNeeded) > 0
? amountArrayMemoryNeeded : witnessArrayMemoryNeeded), 0, Op.VOTEWITNESS);
}

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

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

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

return VOTE_WITNESS + calcMemEnergy(oldMemSize,
Expand Down
17 changes: 17 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/OperationRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public static JumpTable getTable() {
adjustMemOperations(table);
}

if (VMConfig.allowEnergyAdjustment()) {
adjustForFairEnergy(table);
}

return table;
}

Expand Down Expand Up @@ -635,4 +639,17 @@ public static void appendShangHaiOperations(JumpTable table) {
OperationActions::push0Action,
proposal));
}

public static void adjustForFairEnergy(JumpTable table) {
table.set(new Operation(
Op.VOTEWITNESS, 4, 1,
EnergyCost::getVoteWitnessCost2,
OperationActions::voteWitnessAction,
VMConfig::allowTvmVote));

table.set(new Operation(
Op.SUICIDE, 1, 0,
EnergyCost::getSuicideCost2,
OperationActions::suicideAction));
}
}
7 changes: 6 additions & 1 deletion actuator/src/main/java/org/tron/core/vm/VMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
import org.tron.core.Constant;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.vm.config.VMConfig;
Expand All @@ -33,6 +33,11 @@ public final class VMUtils {
private VMUtils() {
}

public static int getAddressSize() {
return VMConfig.allowEnergyAdjustment() ?
Constant.TRON_ADDRESS_SIZE : Constant.STANDARD_ADDRESS_SIZE;
}

public static void closeQuietly(Closeable closeable) {
try {
if (closeable != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static void load(StoreFactory storeFactory) {
VMConfig.initDynamicEnergyIncreaseFactor(ds.getDynamicEnergyIncreaseFactor());
VMConfig.initDynamicEnergyMaxFactor(ds.getDynamicEnergyMaxFactor());
VMConfig.initAllowTvmShangHai(ds.getAllowTvmShangHai());
VMConfig.initAllowEnergyAdjustment(ds.getAllowEnergyAdjustment());
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/config/VMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class VMConfig {

private static boolean ALLOW_TVM_SHANGHAI = false;

private static boolean ALLOW_ENERGY_ADJUSTMENT = false;

private VMConfig() {
}

Expand Down Expand Up @@ -136,6 +138,10 @@ public static void initAllowTvmShangHai(long allow) {
ALLOW_TVM_SHANGHAI = allow == 1;
}

public static void initAllowEnergyAdjustment(long allow) {
ALLOW_ENERGY_ADJUSTMENT = allow == 1;
}

public static boolean getEnergyLimitHardFork() {
return CommonParameter.ENERGY_LIMIT_HARD_FORK;
}
Expand Down Expand Up @@ -211,4 +217,8 @@ public static long getDynamicEnergyMaxFactor() {
public static boolean allowTvmShanghai() {
return ALLOW_TVM_SHANGHAI;
}

public static boolean allowEnergyAdjustment() {
return ALLOW_ENERGY_ADJUSTMENT;
}
}
7 changes: 6 additions & 1 deletion actuator/src/main/java/org/tron/core/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ public void setLastOp(byte op) {
this.lastOp = op;
}

public byte getLastOp() {
return this.lastOp;
}

/**
* Returns the last fully executed OP.
*/
Expand Down Expand Up @@ -457,7 +461,8 @@ public void suicide(DataWord obtainerAddress) {
InternalTransaction internalTx = addInternalTx(null, owner, obtainer, balance, null,
"suicide", nonce, getContractState().getAccount(owner).getAssetMapV2());

if (FastByteComparisons.compareTo(owner, 0, 20, obtainer, 0, 20) == 0) {
int ADDRESS_SIZE = VMUtils.getAddressSize();
if (FastByteComparisons.compareTo(owner, 0, ADDRESS_SIZE, obtainer, 0, ADDRESS_SIZE) == 0) {
// if owner == obtainer just zeroing account according to Yellow Paper
getContractState().addBalance(owner, -balance);
byte[] blackHoleAddress = getContractState().getBlackHoleAddress();
Expand Down
Loading

0 comments on commit 8720e06

Please sign in to comment.