Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v4.7.3 merge to master #5552

Merged
merged 139 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 137 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
3628b9c
Refactor Credentials.equal method and add unit tests
DoctorLai Jul 10, 2021
36b5caa
Update docker.md
zer0init1 Jan 18, 2023
406c13d
feat(net):update com.google.protobuf and io.grpc version
317787106 Jun 1, 2023
fc1d238
feat(net): update protocol/build.gradle
317787106 Jun 1, 2023
9260293
fix(net):remove forced io.netty
317787106 Jun 5, 2023
ad0b108
Merge pull request #5254 from 317787106/hotfix/grpc_v2
317787106 Jun 5, 2023
c352b34
feat(test): replace testng with junit
halibobo1205 Jun 12, 2023
d4b1636
feat(test): add check and logPeerStats in SyncServiceTest
317787106 Jun 16, 2023
ce285fd
Merge pull request #5271 from halibobo1205/feat/dependencies_clear_up
halibobo1205 Jun 19, 2023
7894ef3
Merge pull request #4929 from zer0init1/patch-1
forfreeday Jun 20, 2023
f5ab656
Merge pull request #3898 from DoctorLai/Credential
halibobo1205 Jun 20, 2023
a10cfd6
feat(test): remove solidity file
Jun 20, 2023
4b6e0a5
Merge pull request #5285 from forfreeday/feature/remove_solidity_file
forfreeday Jun 21, 2023
5c9ca49
feat(monitor): Optimize http interface monitoring
xxo1shine Jun 26, 2023
82ed309
Merge branch 'release_v4.7.2' of https://github.com/tronprotocol/java…
xxo1shine Jun 26, 2023
dcd0ebd
Merge pull request #5325 from tronprotocol/master
forfreeday Jul 1, 2023
08cc798
Merge branch 'develop' of https://github.com/tronprotocol/java-tron i…
xxo1shine Jul 3, 2023
6ed9db4
feat(test): optimize NodeInfoServiceTest
317787106 Jul 3, 2023
e1b9a0b
feat(monitor): remove unused filed
xxo1shine Jul 3, 2023
0b67b1a
feat(test):optimize NodeInfoServiceTest
317787106 Jul 3, 2023
1a66522
feat(monitor): optimize http interface monitor
xxo1shine Jul 4, 2023
c43370a
feat(monitor): optimize monitoring logic for different http code
xxo1shine Jul 4, 2023
353587d
feat(monitor): optimize monitoring logic for http interface
xxo1shine Jul 4, 2023
e8a921f
feat(monitor): optimize code
xxo1shine Jul 4, 2023
7c6c89e
Merge pull request #5333 from 317787106/test_node_info
317787106 Jul 4, 2023
5a515c1
fix(readme): update description of JDK 1.8 version in use
lxcmyf Jul 4, 2023
757c15c
feat(monitor): modify monitoring key
xxo1shine Jul 4, 2023
929dfd9
Merge branch 'develop' of https://github.com/tronprotocol/java-tron i…
xxo1shine Jul 5, 2023
291d9fc
feat(unit): optimize AdvServiceTest
xxo1shine Jul 5, 2023
8950d62
Merge pull request #5338 from lxcmyf/fix/update_readme
halibobo1205 Jul 5, 2023
5007067
Merge pull request #5332 from wubin01/resolve_http_metrics_problem
xxo1shine Jul 5, 2023
043265e
docs(plugins/read_me): fix examples for db lite (#5347)
halibobo1205 Jul 12, 2023
586601f
CI:Add CodeQL workflow (#5331)
jorgectf Jul 19, 2023
040ea41
feat(issue): Add labels to issue templates (#5358)
forfreeday Jul 19, 2023
a1968e5
feat(issue): Optimize ask-a-question.md (#5361)
forfreeday Jul 20, 2023
3ad08d1
feat(config): Update seed node ip list in config.conf (#5360)
forfreeday Jul 20, 2023
f15b2d9
feat(issue): Add SECURITY.md (#5363)
forfreeday Jul 20, 2023
57d1185
fix(docs): fix doc links for README (#5364)
forfreeday Jul 20, 2023
9a65bb6
docs(README.md): fix catalogue links (#5365)
forfreeday Jul 20, 2023
10223cc
docs(ISSUE_TEMPLATE): fix invitation URL for Discord (#5387)
Jake151987 Aug 1, 2023
5ce3ff0
fix(db): fix getHeadBlockId abnormal return problem
xxo1shine Aug 8, 2023
56efc4e
feat(log): optimize checkpointV2 check tips (#5383)
lurais Aug 9, 2023
2bbc0fd
feat(sign): optimize default signature verification efficiency (#5396)
lurais Aug 9, 2023
1a33965
feat(log): optimize error log output for Wallet.java (#5366)
lurais Aug 9, 2023
61c6177
feat(log): optimize error tips for db open(#5385)
lurais Aug 10, 2023
f33c169
Merge pull request #5403 from wubin01/fix_getHeadBlockId
xxo1shine Aug 11, 2023
a9c4f43
feat(all): tune single Thread into SingleThreadExecutor (#5410)
halibobo1205 Aug 15, 2023
83151aa
feat(net):improve chain inventory generating logic (#5393)
jwrct Aug 17, 2023
f18864c
feat(http): optimize getAddress method (#5367)
forfreeday Aug 18, 2023
f20e11b
feat(db): optimize for bloomFilter initialization (#5394)
halibobo1205 Aug 21, 2023
563af93
feat(net): optimize transaction execution logic
xxo1shine Aug 22, 2023
6a1e001
delete four unused paramaters in Args
317787106 Aug 22, 2023
ac90c45
feat(api): optimize compatibility (#5408)
lxcmyf Aug 22, 2023
e1d096b
feat(all):make @PreDestroy work (#5421)
halibobo1205 Aug 23, 2023
a4100b6
feat(db):tune the databases closure (#5429)
halibobo1205 Aug 23, 2023
45cbda0
feat(net):optimzie code
317787106 Aug 23, 2023
3b2b60e
feat(net):optimzie code
317787106 Aug 23, 2023
a02fbb0
feat(freezeV2): optimize Stake2.0 code (#5426)
lxcmyf Aug 23, 2023
1e1cd57
feat(shell): optimize startup scripts
Aug 24, 2023
e70ef1b
feat(*):delelte some unuseful code
317787106 Aug 24, 2023
0bf4bbc
feat(api): add gRPC implementation for certain interfaces
lxcmyf Aug 10, 2023
d535eb2
Merge remote-tracking branch 'upstream/develop' into feature/add_grpc…
lxcmyf Aug 24, 2023
13bab5a
Merge branch 'develop' of github.com:tronprotocol/java-tron into opti…
xxo1shine Aug 25, 2023
bb8362e
Merge pull request #5449 from forfreeday/feature/fix_shell
forfreeday Aug 25, 2023
93454a2
chore(gitignore): ignore .cache (#5448)
halibobo1205 Aug 25, 2023
9ffdf97
Merge pull request #5440 from wubin01/optimize_transaction
xxo1shine Aug 25, 2023
3005246
feat(api): add resource price for solidity and PBFT (#5451)
lxcmyf Aug 28, 2023
8efbd87
add test case of WalletTest
317787106 Aug 28, 2023
bd9ed62
Merge branch 'tronprotocol:develop' into feature/add_grpc_api
lxcmyf Aug 28, 2023
2548300
Merge branch 'develop' into hotfix/delete_unused_args
317787106 Aug 29, 2023
703cf87
add test case of WalletTest
317787106 Aug 29, 2023
1536bc9
Merge pull request #5441 from 317787106/hotfix/delete_unused_args
317787106 Aug 30, 2023
4ada90e
feat(sign): optimize sign exception log (#5446)
lurais Aug 30, 2023
4d5f05a
fix(freezeV2): fix estimateConsumeBandWidthSize (#5450)
CarlChaoCarl Aug 30, 2023
f9c42d6
feat(net): get external IPv4 from libp2p (#5407)
317787106 Aug 30, 2023
03e903e
feat(all):name thread pools (#5425)
halibobo1205 Aug 30, 2023
91b6f33
test(net):add message handler test
jwrct Aug 31, 2023
cc5488b
Merge remote-tracking branch 'upstream/develop' into feature/add_grpc…
lxcmyf Aug 31, 2023
04b1826
test(net):fix checkstyle issues
jwrct Aug 31, 2023
868faec
Revert "test(net):fix checkstyle issues"
jwrct Aug 31, 2023
6fdfd01
test(net):fix checkstyle issues
jwrct Aug 31, 2023
e2fd664
feat(net): fix failure to process FETCH_INV_DATA message
xxo1shine Aug 31, 2023
68b5faf
Merge pull request #5412 from lxcmyf/feature/add_grpc_api
jwrct Aug 31, 2023
ad728fa
feat(all):tune the sequence of resources closure (#5447)
halibobo1205 Aug 31, 2023
42635a8
Merge branch 'develop_upstream' into add_test
jwrct Aug 31, 2023
c175194
test(case): fix code style
Aug 28, 2023
068764b
feature(db): optimize properties query (#5378)
CarlChaoCarl Sep 4, 2023
d6ff733
feat(mechanism): add stake info for log trigger (#5419)
CarlChaoCarl Sep 4, 2023
b9ab07a
feat(net):supplement disconnect reasons (#5392)
317787106 Sep 5, 2023
7e2b7fc
Merge branch 'develop' of github.com:tronprotocol/java-tron into fix_…
xxo1shine Sep 5, 2023
cec13b2
feat(zksnark): delete sapling tmp file on exit (#5467)
halibobo1205 Sep 5, 2023
437c12e
test(rpc): add test for RPC (#5471)
lxcmyf Sep 6, 2023
6748bce
test(net):optimize test code
jwrct Sep 7, 2023
c0cd4e4
Merge branch 'develop_upstream' into add_test
jwrct Sep 7, 2023
1e500f0
feat(config): update jacoco config
Sep 7, 2023
17558c5
test(case): add WitnessScheduleStoreTest test case
Sep 7, 2023
9f8cebd
Merge pull request #5460 from ss3344520/fix_msg_process
xxo1shine Sep 8, 2023
b54912a
test(plugins): add test for plugins (#5482)
halibobo1205 Sep 12, 2023
0fbbc7a
test(refactor): create folders with temporaryFolder (#5477)
halibobo1205 Sep 12, 2023
660917a
Merge branch 'release_v4.7.3' into add_test
jwrct Sep 12, 2023
dc6f2d0
Merge branch 'develop' into feature/update_jacoco_config
Sep 12, 2023
2ce1fa7
Merge branch 'release_v4.7.3' into feature/update_jacoco_config
Sep 12, 2023
7b6dfe4
feat(net):update libp2p version to test-v2.0.2
jwrct Sep 13, 2023
fa8d8cf
Merge pull request #5487 from jwrct/update_libp2p
jwrct Sep 13, 2023
31e499d
Merge branch 'release_v4.7.3' into add_test
jwrct Sep 13, 2023
9d089e7
test(net):create folder with temporaryFolder
jwrct Sep 13, 2023
326b782
fix(db):avoid dumping a wrong cached data (#5491)
halibobo1205 Sep 13, 2023
99bef82
feat(api): change log level from error to warn for url parsing (#5496)
halibobo1205 Sep 14, 2023
b81a63e
feat(http): optimize parameter parsing (#5483)
forfreeday Sep 14, 2023
9750847
Merge pull request #5475 from forfreeday/feature/update_jacoco_config
forfreeday Sep 15, 2023
5e420e4
Merge pull request #5463 from forfreeday/feature/optimize_test_case
forfreeday Sep 18, 2023
47fe702
feat(db/checkPointV2Store): change log level from info to debug for c…
halibobo1205 Sep 18, 2023
c97617c
fix(test\db): fix wrong output path (#5501)
forfreeday Sep 19, 2023
6703d13
feat(api): add http/grpc interface rate limit
xxo1shine Sep 19, 2023
b4d1a6b
Merge branch 'release_v4.7.3' of github.com:tronprotocol/java-tron in…
xxo1shine Sep 19, 2023
290753a
fix(api): optimize API call compatibility
lxcmyf Sep 19, 2023
7ffd2fc
fix(event/mechanism): fix NPE in TransactionLogTriggerCapsule (#5500)
CarlChaoCarl Sep 19, 2023
0bacdaa
Merge remote-tracking branch 'upstream/release_v4.7.3' into release_v…
lxcmyf Sep 19, 2023
52283dc
Merge pull request #5502 from ss3344520/api
xxo1shine Sep 20, 2023
3e6eb02
Merge pull request #5504 from lxcmyf/release_v4.7.3
jwrct Sep 20, 2023
703a866
fix(db/trans-cache): avoid recovering a wrong cached data (#5505)
halibobo1205 Sep 20, 2023
9842b3f
fix(freezeV2): remove duplicate judgments (#5508)
lxcmyf Sep 21, 2023
6802f34
feat(test): add db test (#5461)
lurais Sep 22, 2023
c78c42e
test(db): add test case (#5503)
lurais Sep 22, 2023
9406d24
fix(api): add resource price query API for soliditynode (#5516)
lxcmyf Sep 25, 2023
962a3db
feat(net):update libp2p (#5517)
317787106 Sep 26, 2023
fe7715d
feat(LiteFullNodeTool): mark LiteFullNodeTool as deprecated (#5509)
forfreeday Oct 7, 2023
c623940
feat(db/trans-cache): verify cached files with crc32c (#5523)
halibobo1205 Oct 8, 2023
94e1a84
test(db): fix org.iq80.leveldb.DBException: Closed (#5528)
halibobo1205 Oct 11, 2023
419570c
Merge pull request #5459 from jwrct/add_test
jwrct Oct 11, 2023
283230a
test(api): add test cases of Wallet (#5442)
317787106 Oct 11, 2023
e987efb
feat(net): fix bug of getting head block concurrently (#5532)
317787106 Oct 12, 2023
2ab2677
fix(api):rollback due to insufficient compatibility (#5537)
lxcmyf Oct 16, 2023
1cb7f2c
feat(version): update version
Oct 16, 2023
46ea631
Merge pull request #5538 from forfreeday/feature/update_version
forfreeday Oct 16, 2023
87db52a
update libp2p version to release 2.1.0 (#5539)
317787106 Oct 16, 2023
d1f0ff3
add switch for transaction cache initialization optimization (#5543)
halibobo1205 Oct 17, 2023
5bafc0c
Add block height check when processing PBFT messages (#5548)
jwrct Oct 25, 2023
d18597f
Merge pull request #5554 from tronprotocol/release_v4.7.3.1
lvs007 Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 2 additions & 20 deletions .github/ISSUE_TEMPLATE/ask-a-question.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@
name: Ask a question
about: Something is unclear
title: ''
labels: ''
labels: 'type:docs'
assignees: ''

---

<!-- Please answer these questions before submitting your issue. Thanks! -->

### System information

java-tron version: `java -jar FullNode.jar -v`
OS & Version: Windows/Linux/OSX


### 1. What did you do?
<!--If possible, provide a recipe for reproducing the error. -->


### 2. What did you expect to see?



### 3. What did you see instead?

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

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/report-a-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Report a bug
about: Create a report to help us improve
title: ''
labels: ''
labels: 'type:bug'
assignees: ''

---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/request-a-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Request a feature
about: Suggest an idea for this project
title: ''
labels: ''
labels: 'type:feature'
assignees: ''

---
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "CodeQL"

on:
push:
branches: [ 'develop', 'master', 'release_**' ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ 'develop' ]
schedule:
- cron: '6 10 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# 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
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ Wallet
/vm_trace/

/framework/propPath
.cache
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@
</p>

## Table of Contents
- [What’s TRON?](#What’s-TRON)
- [Building the Source Code](#Building-the-source)
- [Getting the Source Code](#Getting-the-Source-Code)
- [Build](#Build)
- [Running java-tron](#Running-java-tron)
- [Community](#Community)
- [Contribution](#Contribution)
- [Resources](#Resources)
- [License](#License)
- [What’s TRON?](#whats-tron)
- [Building the Source Code](#building-the-source)
- [Running java-tron](#running-java-tron)
- [Community](#community)
- [Contribution](#contribution)
- [Resources](#resources)
- [Integrity Check](#integrity-check)
- [License](#license)

## What's TRON?

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

# Building the source
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.
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.

Clone the repo and switch to the `master` branch

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


# Running java-tron
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.
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.

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).
## Hardware Requirements
Expand Down
7 changes: 7 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Supported Versions
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).

## Reporting a Vulnerability
**Please do not file a public ticket** mentioning the vulnerability.
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]).
Please read the [disclosure policy](https://www.hackerone.com/disclosure-guidelines) for more information about publicly disclosed security vulnerabilities.
23 changes: 1 addition & 22 deletions actuator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ dependencies {
testImplementation "junit:junit:$junitVersion"
testImplementation "org.mockito:mockito-core:$mockitoVersion"

testImplementation "org.testng:testng:$testNgVersion"

compile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
Expand Down Expand Up @@ -49,34 +47,15 @@ test {
}
}

task testng(type: Test) {
useTestNG()
testLogging {
events = ["skipped", "failed"]
exceptionFormat = "full"

debug.events = ["skipped", "failed"]
debug.exceptionFormat = "full"

info.events = ["failed", "skipped"]
info.exceptionFormat = "full"

warn.events = ["failed", "skipped"]
warn.exceptionFormat = "full"
}
}

jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
executionData.from = '../framework/build/jacoco/jacocoTest.exec'
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
classDirectories.from = classDirectories.files.collect {
fileTree(dir: it,)
}
}
}

check.dependsOn testng
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public boolean execute(Object result) throws ContractExeException {
List<UnFreezeV2> unfrozenV2List = ownerCapsule.getUnfrozenV2List();
long now = dynamicStore.getLatestBlockHeaderTimestamp();
AtomicLong atomicWithdrawExpireBalance = new AtomicLong(0L);
/* The triple object is defined by resource type, with left representing the pair object
corresponding to bandwidth, middle representing the pair object corresponding to energy, and
right representing the pair object corresponding to tron power. The pair object for each
resource type, left represents resource weight, and right represents the number of unfreeze
resources for that resource type. */
Triple<Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>>
triple = Triple.of(
Pair.of(new AtomicLong(0L), new AtomicLong(0L)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.tron.core.actuator;

import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
import static org.tron.core.config.Parameter.ChainConstant.DELEGATE_PERIOD;
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
import static org.tron.protos.contract.Common.ResourceCode;
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
import static org.tron.core.vm.utils.FreezeV2Util.getV2EnergyUsage;
import static org.tron.core.vm.utils.FreezeV2Util.getV2NetUsage;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
Expand Down Expand Up @@ -64,7 +67,8 @@ public boolean execute(Object result) throws ContractExeException {
DynamicPropertiesStore dynamicStore = chainBaseManager.getDynamicPropertiesStore();
long delegateBalance = delegateResourceContract.getBalance();
boolean lock = delegateResourceContract.getLock();
long lockPeriod = getLockPeriod(dynamicStore, delegateResourceContract);
long lockPeriod = getLockPeriod(dynamicStore.supportMaxDelegateLockPeriod(),
delegateResourceContract);
byte[] receiverAddress = delegateResourceContract.getReceiverAddress().toByteArray();

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

long delegateBalance = delegateResourceContract.getBalance();
if (delegateBalance < TRX_PRECISION) {
throw new ContractValidateException("delegateBalance must be more than 1TRX");
throw new ContractValidateException("delegateBalance must be greater than or equal to 1 TRX");
}

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

long accountNetUsage = ownerCapsule.getNetUsage();
if (null != this.getTx() && this.getTx().isTransactionCreate()) {
accountNetUsage += TransactionUtil.estimateConsumeBandWidthSize(ownerCapsule,
chainBaseManager);
accountNetUsage += TransactionUtil.estimateConsumeBandWidthSize(dynamicStore,
ownerCapsule.getFrozenV2BalanceForBandwidth());
}
long netUsage = (long) (accountNetUsage * TRX_PRECISION * ((double)
(dynamicStore.getTotalNetWeight()) / dynamicStore.getTotalNetLimit()));

long remainNetUsage = netUsage
- ownerCapsule.getFrozenBalance()
- ownerCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth()
- ownerCapsule.getAcquiredDelegatedFrozenV2BalanceForBandwidth();

remainNetUsage = Math.max(0, remainNetUsage);

if (ownerCapsule.getFrozenV2BalanceForBandwidth() - remainNetUsage < delegateBalance) {
long v2NetUsage = getV2NetUsage(ownerCapsule, netUsage);
if (ownerCapsule.getFrozenV2BalanceForBandwidth() - v2NetUsage < delegateBalance) {
throw new ContractValidateException(
"delegateBalance must be less than available FreezeBandwidthV2 balance");
"delegateBalance must be less than or equal to available FreezeBandwidthV2 balance");
}
}
break;
Expand All @@ -178,17 +175,10 @@ public boolean validate() throws ContractValidateException {

long energyUsage = (long) (ownerCapsule.getEnergyUsage() * TRX_PRECISION * ((double)
(dynamicStore.getTotalEnergyWeight()) / dynamicStore.getTotalEnergyCurrentLimit()));

long remainEnergyUsage = energyUsage
- ownerCapsule.getEnergyFrozenBalance()
- ownerCapsule.getAcquiredDelegatedFrozenBalanceForEnergy()
- ownerCapsule.getAcquiredDelegatedFrozenV2BalanceForEnergy();

remainEnergyUsage = Math.max(0, remainEnergyUsage);

if (ownerCapsule.getFrozenV2BalanceForEnergy() - remainEnergyUsage < delegateBalance) {
long v2EnergyUsage = getV2EnergyUsage(ownerCapsule, energyUsage);
if (ownerCapsule.getFrozenV2BalanceForEnergy() - v2EnergyUsage < delegateBalance) {
throw new ContractValidateException(
"delegateBalance must be less than available FreezeEnergyV2 balance");
"delegateBalance must be less than or equal to available FreezeEnergyV2 balance");
}
}
break;
Expand All @@ -199,7 +189,7 @@ public boolean validate() throws ContractValidateException {

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

if (ArrayUtils.isEmpty(receiverAddress) || !DecodeUtil.addressValid(receiverAddress)) {
if (!DecodeUtil.addressValid(receiverAddress)) {
throw new ContractValidateException("Invalid receiverAddress");
}

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

boolean lock = delegateResourceContract.getLock();
if (lock && dynamicStore.supportMaxDelegateLockPeriod()) {
long lockPeriod = getLockPeriod(dynamicStore, delegateResourceContract);
long lockPeriod = getLockPeriod(true, delegateResourceContract);
long maxDelegateLockPeriod = dynamicStore.getMaxDelegateLockPeriod();
if (lockPeriod < 0 || lockPeriod > maxDelegateLockPeriod) {
throw new ContractValidateException(
Expand Down Expand Up @@ -257,20 +247,20 @@ public boolean validate() throws ContractValidateException {
return true;
}

private long getLockPeriod(DynamicPropertiesStore dynamicStore,
private long getLockPeriod(boolean supportMaxDelegateLockPeriod,
DelegateResourceContract delegateResourceContract) {
long lockPeriod = delegateResourceContract.getLockPeriod();
if (dynamicStore.supportMaxDelegateLockPeriod()) {
return lockPeriod == 0 ? DELEGATE_PERIOD / 3000 : lockPeriod;
if (supportMaxDelegateLockPeriod) {
return lockPeriod == 0 ? DELEGATE_PERIOD / BLOCK_PRODUCED_INTERVAL : lockPeriod;
} else {
return 0;
return DELEGATE_PERIOD / BLOCK_PRODUCED_INTERVAL;
}
}

private void validRemainTime(ResourceCode resourceCode, long lockPeriod, long expireTime,
long now) throws ContractValidateException {
long remainTime = expireTime - now;
if (lockPeriod * 3 * 1000 < remainTime) {
if (lockPeriod * BLOCK_PRODUCED_INTERVAL < remainTime) {
throw new ContractValidateException(
"The lock period for " + resourceCode.name() + " this time cannot be less than the "
+ "remaining time[" + remainTime + "ms] of the last lock period for "
Expand Down Expand Up @@ -303,11 +293,7 @@ private void delegateResource(byte[] ownerAddress, byte[] receiverAddress, boole
//modify DelegatedResourceStore
long expireTime = 0;
if (lock) {
if (dynamicPropertiesStore.supportMaxDelegateLockPeriod()) {
expireTime = now + lockPeriod * 3 * 1000;
} else {
expireTime = now + DELEGATE_PERIOD;
}
expireTime = now + lockPeriod * BLOCK_PRODUCED_INTERVAL;
}
byte[] key = DelegatedResourceCapsule.createDbKeyV2(ownerAddress, receiverAddress, lock);
DelegatedResourceCapsule delegatedResourceCapsule = delegatedResourceStore.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ public boolean validate() throws ContractValidateException {
throw new ContractValidateException("frozenBalance must be positive");
}
if (frozenBalance < TRX_PRECISION) {
throw new ContractValidateException("frozenBalance must be more than 1TRX");
throw new ContractValidateException("frozenBalance must be greater than or equal to 1 TRX");
}

int frozenCount = accountCapsule.getFrozenCount();
if (!(frozenCount == 0 || frozenCount == 1)) {
throw new ContractValidateException("frozenCount must be 0 or 1");
}
if (frozenBalance > accountCapsule.getBalance()) {
throw new ContractValidateException("frozenBalance must be less than accountBalance");
throw new ContractValidateException("frozenBalance must be less than or equal to accountBalance");
}

long frozenDuration = freezeBalanceContract.getFrozenDuration();
Expand Down
Loading