Skip to content

Commit 9d13f9c

Browse files
authored
Merge pull request #5552 from tronprotocol/release_v4.7.3
Release v4.7.3 merge to master
2 parents 9e95599 + d18597f commit 9d13f9c

File tree

1,596 files changed

+9773
-102774
lines changed

Some content is hidden

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

1,596 files changed

+9773
-102774
lines changed

.github/ISSUE_TEMPLATE/ask-a-question.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,9 @@
22
name: Ask a question
33
about: Something is unclear
44
title: ''
5-
labels: ''
5+
labels: 'type:docs'
66
assignees: ''
77

88
---
9-
10-
<!-- Please answer these questions before submitting your issue. Thanks! -->
11-
12-
### System information
13-
14-
java-tron version: `java -jar FullNode.jar -v`
15-
OS & Version: Windows/Linux/OSX
16-
17-
18-
### 1. What did you do?
19-
<!--If possible, provide a recipe for reproducing the error. -->
20-
21-
22-
### 2. What did you expect to see?
23-
24-
25-
26-
### 3. What did you see instead?
27-
9+
This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation. For general questions please use [Discord](https://discord.gg/cGKSsRVCGm) or [Telegram](https://t.me/TronOfficialDevelopersGroupEn).
2810

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Report a bug
33
about: Create a report to help us improve
44
title: ''
5-
labels: ''
5+
labels: 'type:bug'
66
assignees: ''
77

88
---

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: Request a feature
33
about: Suggest an idea for this project
44
title: ''
5-
labels: ''
5+
labels: 'type:feature'
66
assignees: ''
77

88
---

.github/workflows/codeql.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ 'develop', 'master', 'release_**' ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ 'develop' ]
9+
schedule:
10+
- cron: '6 10 * * 0'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
security-events: write
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
language: [ 'java' ]
25+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
26+
# Use only 'java' to analyze code written in Java, Kotlin or both
27+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
28+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v3
33+
34+
# Initializes the CodeQL tools for scanning.
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v2
37+
with:
38+
languages: ${{ matrix.language }}
39+
# If you wish to specify custom queries, you can do so here or in a config file.
40+
# By default, queries listed here will override any specified in a config file.
41+
# Prefix the list here with "+" to use these queries and those in the config file.
42+
43+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
44+
# queries: security-extended,security-and-quality
45+
46+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
47+
# If this step fails, then you should remove it and run the build manually (see below)
48+
- name: Autobuild
49+
uses: github/codeql-action/autobuild@v2
50+
51+
# ℹ️ Command-line programs to run using the OS shell.
52+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
53+
54+
# If the Autobuild fails above, remove it and uncomment the following three lines.
55+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
56+
57+
# - run: |
58+
# echo "Run, Build Application using script"
59+
# ./location_of_script_within_repo/buildscript.sh
60+
61+
- name: Perform CodeQL Analysis
62+
uses: github/codeql-action/analyze@v2
63+
with:
64+
category: "/language:${{matrix.language}}"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ Wallet
5656
/vm_trace/
5757

5858
/framework/propPath
59+
.cache

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242
</p>
4343

4444
## Table of Contents
45-
- [What’s TRON?](#What’s-TRON)
46-
- [Building the Source Code](#Building-the-source)
47-
- [Getting the Source Code](#Getting-the-Source-Code)
48-
- [Build](#Build)
49-
- [Running java-tron](#Running-java-tron)
50-
- [Community](#Community)
51-
- [Contribution](#Contribution)
52-
- [Resources](#Resources)
53-
- [License](#License)
45+
- [What’s TRON?](#whats-tron)
46+
- [Building the Source Code](#building-the-source)
47+
- [Running java-tron](#running-java-tron)
48+
- [Community](#community)
49+
- [Contribution](#contribution)
50+
- [Resources](#resources)
51+
- [Integrity Check](#integrity-check)
52+
- [License](#license)
5453

5554
## What's TRON?
5655

@@ -63,7 +62,7 @@ TRON is a project dedicated to building the infrastructure for a truly decentral
6362
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.
6463

6564
# Building the source
66-
Building java-tron requires `git` and `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
65+
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.
6766

6867
Clone the repo and switch to the `master` branch
6968

@@ -79,7 +78,7 @@ $ ./gradlew clean build -x test
7978

8079

8180
# Running java-tron
82-
Running java-tron requires `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
81+
Running java-tron requires 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.
8382

8483
Get the mainnet configuration file: [main_net_config.conf](https://github.com/tronprotocol/tron-deployment/blob/master/main_net_config.conf), other network configuration files can be find [here](https://github.com/tronprotocol/tron-deployment).
8584
## Hardware Requirements

SECURITY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Supported Versions
2+
Please see [Releases](https://github.com/tronprotocol/java-tron/releases). We recommend using the [most recently released version](https://github.com/tronprotocol/java-tron/releases/latest).
3+
4+
## Reporting a Vulnerability
5+
**Please do not file a public ticket** mentioning the vulnerability.
6+
To find out how to report a vulnerability in TRON, visit [https://hackerone.com/tron_dao](https://hackerone.com/tron_dao?type=team) or email [[email protected]](mailto:[email protected]).
7+
Please read the [disclosure policy](https://www.hackerone.com/disclosure-guidelines) for more information about publicly disclosed security vulnerabilities.

actuator/build.gradle

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ dependencies {
1616
testImplementation "junit:junit:$junitVersion"
1717
testImplementation "org.mockito:mockito-core:$mockitoVersion"
1818

19-
testImplementation "org.testng:testng:$testNgVersion"
20-
2119
compile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
2220
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
2321
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
@@ -49,34 +47,15 @@ test {
4947
}
5048
}
5149

52-
task testng(type: Test) {
53-
useTestNG()
54-
testLogging {
55-
events = ["skipped", "failed"]
56-
exceptionFormat = "full"
57-
58-
debug.events = ["skipped", "failed"]
59-
debug.exceptionFormat = "full"
60-
61-
info.events = ["failed", "skipped"]
62-
info.exceptionFormat = "full"
63-
64-
warn.events = ["failed", "skipped"]
65-
warn.exceptionFormat = "full"
66-
}
67-
}
68-
6950
jacocoTestReport {
7051
reports {
7152
xml.enabled = true
7253
html.enabled = true
7354
}
74-
executionData.from = '../framework/build/jacoco/jacocoTest.exec'
55+
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
7556
afterEvaluate {
7657
classDirectories.from = classDirectories.files.collect {
7758
fileTree(dir: it,)
7859
}
7960
}
8061
}
81-
82-
check.dependsOn testng

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public boolean execute(Object result) throws ContractExeException {
5858
List<UnFreezeV2> unfrozenV2List = ownerCapsule.getUnfrozenV2List();
5959
long now = dynamicStore.getLatestBlockHeaderTimestamp();
6060
AtomicLong atomicWithdrawExpireBalance = new AtomicLong(0L);
61+
/* The triple object is defined by resource type, with left representing the pair object
62+
corresponding to bandwidth, middle representing the pair object corresponding to energy, and
63+
right representing the pair object corresponding to tron power. The pair object for each
64+
resource type, left represents resource weight, and right represents the number of unfreeze
65+
resources for that resource type. */
6166
Triple<Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>>
6267
triple = Triple.of(
6368
Pair.of(new AtomicLong(0L), new AtomicLong(0L)),

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

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package org.tron.core.actuator;
22

33
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
4+
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
45
import static org.tron.core.config.Parameter.ChainConstant.DELEGATE_PERIOD;
56
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
67
import static org.tron.protos.contract.Common.ResourceCode;
78
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
89
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
10+
import static org.tron.core.vm.utils.FreezeV2Util.getV2EnergyUsage;
11+
import static org.tron.core.vm.utils.FreezeV2Util.getV2NetUsage;
912

1013
import com.google.protobuf.ByteString;
1114
import com.google.protobuf.InvalidProtocolBufferException;
@@ -64,7 +67,8 @@ public boolean execute(Object result) throws ContractExeException {
6467
DynamicPropertiesStore dynamicStore = chainBaseManager.getDynamicPropertiesStore();
6568
long delegateBalance = delegateResourceContract.getBalance();
6669
boolean lock = delegateResourceContract.getLock();
67-
long lockPeriod = getLockPeriod(dynamicStore, delegateResourceContract);
70+
long lockPeriod = getLockPeriod(dynamicStore.supportMaxDelegateLockPeriod(),
71+
delegateResourceContract);
6872
byte[] receiverAddress = delegateResourceContract.getReceiverAddress().toByteArray();
6973

7074
// delegate resource to receiver
@@ -143,7 +147,7 @@ public boolean validate() throws ContractValidateException {
143147

144148
long delegateBalance = delegateResourceContract.getBalance();
145149
if (delegateBalance < TRX_PRECISION) {
146-
throw new ContractValidateException("delegateBalance must be more than 1TRX");
150+
throw new ContractValidateException("delegateBalance must be greater than or equal to 1 TRX");
147151
}
148152

149153
switch (delegateResourceContract.getResource()) {
@@ -153,22 +157,15 @@ public boolean validate() throws ContractValidateException {
153157

154158
long accountNetUsage = ownerCapsule.getNetUsage();
155159
if (null != this.getTx() && this.getTx().isTransactionCreate()) {
156-
accountNetUsage += TransactionUtil.estimateConsumeBandWidthSize(ownerCapsule,
157-
chainBaseManager);
160+
accountNetUsage += TransactionUtil.estimateConsumeBandWidthSize(dynamicStore,
161+
ownerCapsule.getFrozenV2BalanceForBandwidth());
158162
}
159163
long netUsage = (long) (accountNetUsage * TRX_PRECISION * ((double)
160164
(dynamicStore.getTotalNetWeight()) / dynamicStore.getTotalNetLimit()));
161-
162-
long remainNetUsage = netUsage
163-
- ownerCapsule.getFrozenBalance()
164-
- ownerCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth()
165-
- ownerCapsule.getAcquiredDelegatedFrozenV2BalanceForBandwidth();
166-
167-
remainNetUsage = Math.max(0, remainNetUsage);
168-
169-
if (ownerCapsule.getFrozenV2BalanceForBandwidth() - remainNetUsage < delegateBalance) {
165+
long v2NetUsage = getV2NetUsage(ownerCapsule, netUsage);
166+
if (ownerCapsule.getFrozenV2BalanceForBandwidth() - v2NetUsage < delegateBalance) {
170167
throw new ContractValidateException(
171-
"delegateBalance must be less than available FreezeBandwidthV2 balance");
168+
"delegateBalance must be less than or equal to available FreezeBandwidthV2 balance");
172169
}
173170
}
174171
break;
@@ -178,17 +175,10 @@ public boolean validate() throws ContractValidateException {
178175

179176
long energyUsage = (long) (ownerCapsule.getEnergyUsage() * TRX_PRECISION * ((double)
180177
(dynamicStore.getTotalEnergyWeight()) / dynamicStore.getTotalEnergyCurrentLimit()));
181-
182-
long remainEnergyUsage = energyUsage
183-
- ownerCapsule.getEnergyFrozenBalance()
184-
- ownerCapsule.getAcquiredDelegatedFrozenBalanceForEnergy()
185-
- ownerCapsule.getAcquiredDelegatedFrozenV2BalanceForEnergy();
186-
187-
remainEnergyUsage = Math.max(0, remainEnergyUsage);
188-
189-
if (ownerCapsule.getFrozenV2BalanceForEnergy() - remainEnergyUsage < delegateBalance) {
178+
long v2EnergyUsage = getV2EnergyUsage(ownerCapsule, energyUsage);
179+
if (ownerCapsule.getFrozenV2BalanceForEnergy() - v2EnergyUsage < delegateBalance) {
190180
throw new ContractValidateException(
191-
"delegateBalance must be less than available FreezeEnergyV2 balance");
181+
"delegateBalance must be less than or equal to available FreezeEnergyV2 balance");
192182
}
193183
}
194184
break;
@@ -199,7 +189,7 @@ public boolean validate() throws ContractValidateException {
199189

200190
byte[] receiverAddress = delegateResourceContract.getReceiverAddress().toByteArray();
201191

202-
if (ArrayUtils.isEmpty(receiverAddress) || !DecodeUtil.addressValid(receiverAddress)) {
192+
if (!DecodeUtil.addressValid(receiverAddress)) {
203193
throw new ContractValidateException("Invalid receiverAddress");
204194
}
205195

@@ -219,7 +209,7 @@ public boolean validate() throws ContractValidateException {
219209

220210
boolean lock = delegateResourceContract.getLock();
221211
if (lock && dynamicStore.supportMaxDelegateLockPeriod()) {
222-
long lockPeriod = getLockPeriod(dynamicStore, delegateResourceContract);
212+
long lockPeriod = getLockPeriod(true, delegateResourceContract);
223213
long maxDelegateLockPeriod = dynamicStore.getMaxDelegateLockPeriod();
224214
if (lockPeriod < 0 || lockPeriod > maxDelegateLockPeriod) {
225215
throw new ContractValidateException(
@@ -257,20 +247,20 @@ public boolean validate() throws ContractValidateException {
257247
return true;
258248
}
259249

260-
private long getLockPeriod(DynamicPropertiesStore dynamicStore,
250+
private long getLockPeriod(boolean supportMaxDelegateLockPeriod,
261251
DelegateResourceContract delegateResourceContract) {
262252
long lockPeriod = delegateResourceContract.getLockPeriod();
263-
if (dynamicStore.supportMaxDelegateLockPeriod()) {
264-
return lockPeriod == 0 ? DELEGATE_PERIOD / 3000 : lockPeriod;
253+
if (supportMaxDelegateLockPeriod) {
254+
return lockPeriod == 0 ? DELEGATE_PERIOD / BLOCK_PRODUCED_INTERVAL : lockPeriod;
265255
} else {
266-
return 0;
256+
return DELEGATE_PERIOD / BLOCK_PRODUCED_INTERVAL;
267257
}
268258
}
269259

270260
private void validRemainTime(ResourceCode resourceCode, long lockPeriod, long expireTime,
271261
long now) throws ContractValidateException {
272262
long remainTime = expireTime - now;
273-
if (lockPeriod * 3 * 1000 < remainTime) {
263+
if (lockPeriod * BLOCK_PRODUCED_INTERVAL < remainTime) {
274264
throw new ContractValidateException(
275265
"The lock period for " + resourceCode.name() + " this time cannot be less than the "
276266
+ "remaining time[" + remainTime + "ms] of the last lock period for "
@@ -303,11 +293,7 @@ private void delegateResource(byte[] ownerAddress, byte[] receiverAddress, boole
303293
//modify DelegatedResourceStore
304294
long expireTime = 0;
305295
if (lock) {
306-
if (dynamicPropertiesStore.supportMaxDelegateLockPeriod()) {
307-
expireTime = now + lockPeriod * 3 * 1000;
308-
} else {
309-
expireTime = now + DELEGATE_PERIOD;
310-
}
296+
expireTime = now + lockPeriod * BLOCK_PRODUCED_INTERVAL;
311297
}
312298
byte[] key = DelegatedResourceCapsule.createDbKeyV2(ownerAddress, receiverAddress, lock);
313299
DelegatedResourceCapsule delegatedResourceCapsule = delegatedResourceStore.get(key);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ public boolean validate() throws ContractValidateException {
189189
throw new ContractValidateException("frozenBalance must be positive");
190190
}
191191
if (frozenBalance < TRX_PRECISION) {
192-
throw new ContractValidateException("frozenBalance must be more than 1TRX");
192+
throw new ContractValidateException("frozenBalance must be greater than or equal to 1 TRX");
193193
}
194194

195195
int frozenCount = accountCapsule.getFrozenCount();
196196
if (!(frozenCount == 0 || frozenCount == 1)) {
197197
throw new ContractValidateException("frozenCount must be 0 or 1");
198198
}
199199
if (frozenBalance > accountCapsule.getBalance()) {
200-
throw new ContractValidateException("frozenBalance must be less than accountBalance");
200+
throw new ContractValidateException("frozenBalance must be less than or equal to accountBalance");
201201
}
202202

203203
long frozenDuration = freezeBalanceContract.getFrozenDuration();

0 commit comments

Comments
 (0)