Skip to content

Commit 554e34c

Browse files
authored
Merge pull request #4800 from tronprotocol/release_4.6.0
merge release_4.6.0 to master
2 parents 349116e + f724e05 commit 554e34c

137 files changed

Lines changed: 2962 additions & 1320 deletions

File tree

Some content is hidden

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

.github/workflows/docker-publish.yml

Lines changed: 0 additions & 83 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ If you want to contribute codes to java-tron, please follow the following steps:
103103
104104
Submit a pull request (PR) from your repository to `tronprotocol/java-tron`.
105105
Please be sure to click on the link in the red box shown below. Select the base branch for tronprotocol and the compare branch for your personal fork repository.
106-
![](https://codimd.s3.shivering-isles.com/demo/uploads/e24435ab42e4287d9369a2136.png)
106+
![image](https://raw.githubusercontent.com/tronprotocol/documentation-en/master/images/javatron_pr.png)
107107
108108
109109
110110
## Code Review Guidelines
111-
The only way to get code into java-tron is to send a pull request. Those pull requests need to be reviewed by someone. there a guide that explains our expectations around PRs for both authors and reviewers.
111+
The only way to get code into java-tron is to send a pull request. Those pull requests need to be reviewed by someone. The following guide explains our expectations around PRs for both authors and reviewers.
112112
113113
### Terminology
114114
- The author of a pull request is the entity who wrote the diff and submitted it to GitHub.
@@ -186,10 +186,10 @@ Message body use the imperative, present tense: "change" not "changed" nor "chan
186186
187187
Here is an example:
188188
```
189-
feat(block): optimize product block
189+
feat(block): optimize the block-producing logic
190190

191-
1. optimize the block production threads
192-
2. improve transaction entry speed
191+
1. increase the priority that block producing thread acquires synchronization lock
192+
2. add the interruption exception handling in block-producing thread
193193

194194
Closes #1234
195195
```

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

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

3+
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
4+
35
import com.google.protobuf.ByteString;
46
import com.google.protobuf.InvalidProtocolBufferException;
57
import java.util.Arrays;
@@ -16,13 +18,10 @@
1618
import org.tron.core.store.AbiStore;
1719
import org.tron.core.store.AccountStore;
1820
import org.tron.core.store.ContractStore;
19-
import org.tron.core.vm.config.VMConfig;
2021
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
2122
import org.tron.protos.Protocol.Transaction.Result.code;
22-
import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI;
2323
import org.tron.protos.contract.SmartContractOuterClass.ClearABIContract;
24-
25-
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
24+
import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI;
2625

2726
@Slf4j(topic = "actuator")
2827
public class ClearABIContractActuator extends AbstractActuator {
@@ -57,17 +56,16 @@ public boolean execute(Object result) throws ContractExeException {
5756

5857
@Override
5958
public boolean validate() throws ContractValidateException {
60-
if (!VMConfig.allowTvmConstantinople()) {
61-
throw new ContractValidateException(
62-
"contract type error,unexpected type [ClearABIContract]");
63-
}
64-
6559
if (this.any == null) {
6660
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
6761
}
6862
if (chainBaseManager == null) {
6963
throw new ContractValidateException("No account store or contract store!");
7064
}
65+
if (chainBaseManager.getDynamicPropertiesStore().getAllowTvmConstantinople() == 0) {
66+
throw new ContractValidateException(
67+
"contract type error,unexpected type [ClearABIContract]");
68+
}
7169
AccountStore accountStore = chainBaseManager.getAccountStore();
7270
ContractStore contractStore = chainBaseManager.getContractStore();
7371
if (!this.any.is(ClearABIContract.class)) {

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

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
44
import static org.tron.core.config.Parameter.ChainConstant.FROZEN_PERIOD;
55
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
6+
import static org.tron.protos.contract.Common.ResourceCode;
7+
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
8+
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
9+
import static org.tron.protos.contract.Common.ResourceCode.TRON_POWER;
610

711
import com.google.protobuf.ByteString;
812
import com.google.protobuf.InvalidProtocolBufferException;
@@ -72,44 +76,48 @@ public boolean execute(Object result) throws ContractExeException {
7276
byte[] ownerAddress = freezeBalanceContract.getOwnerAddress().toByteArray();
7377
byte[] receiverAddress = freezeBalanceContract.getReceiverAddress().toByteArray();
7478

79+
long increment;
7580
switch (freezeBalanceContract.getResource()) {
7681
case BANDWIDTH:
7782
if (!ArrayUtils.isEmpty(receiverAddress)
7883
&& dynamicStore.supportDR()) {
79-
delegateResource(ownerAddress, receiverAddress, true,
80-
frozenBalance, expireTime);
84+
increment = delegateResource(ownerAddress, receiverAddress, true,
85+
frozenBalance, expireTime);
8186
accountCapsule.addDelegatedFrozenBalanceForBandwidth(frozenBalance);
8287
} else {
88+
long oldNetWeight = accountCapsule.getFrozenBalance() / TRX_PRECISION;
8389
long newFrozenBalanceForBandwidth =
8490
frozenBalance + accountCapsule.getFrozenBalance();
8591
accountCapsule.setFrozenForBandwidth(newFrozenBalanceForBandwidth, expireTime);
92+
long newNetWeight = accountCapsule.getFrozenBalance() / TRX_PRECISION;
93+
increment = newNetWeight - oldNetWeight;
8694
}
87-
dynamicStore
88-
.addTotalNetWeight(frozenBalance / TRX_PRECISION);
95+
addTotalWeight(BANDWIDTH, dynamicStore, frozenBalance, increment);
8996
break;
9097
case ENERGY:
9198
if (!ArrayUtils.isEmpty(receiverAddress)
9299
&& dynamicStore.supportDR()) {
93-
delegateResource(ownerAddress, receiverAddress, false,
94-
frozenBalance, expireTime);
100+
increment = delegateResource(ownerAddress, receiverAddress, false,
101+
frozenBalance, expireTime);
95102
accountCapsule.addDelegatedFrozenBalanceForEnergy(frozenBalance);
96103
} else {
104+
long oldEnergyWeight = accountCapsule.getEnergyFrozenBalance() / TRX_PRECISION;
97105
long newFrozenBalanceForEnergy =
98-
frozenBalance + accountCapsule.getAccountResource()
99-
.getFrozenBalanceForEnergy()
100-
.getFrozenBalance();
106+
frozenBalance + accountCapsule.getEnergyFrozenBalance();
101107
accountCapsule.setFrozenForEnergy(newFrozenBalanceForEnergy, expireTime);
108+
long newEnergyWeight = accountCapsule.getEnergyFrozenBalance() / TRX_PRECISION;
109+
increment = newEnergyWeight - oldEnergyWeight;
102110
}
103-
dynamicStore
104-
.addTotalEnergyWeight(frozenBalance / TRX_PRECISION);
111+
addTotalWeight(ENERGY, dynamicStore, frozenBalance, increment);
105112
break;
106113
case TRON_POWER:
114+
long oldTPWeight = accountCapsule.getTronPowerFrozenBalance() / TRX_PRECISION;
107115
long newFrozenBalanceForTronPower =
108116
frozenBalance + accountCapsule.getTronPowerFrozenBalance();
109117
accountCapsule.setFrozenForTronPower(newFrozenBalanceForTronPower, expireTime);
110-
111-
dynamicStore
112-
.addTotalTronPowerWeight(frozenBalance / TRX_PRECISION);
118+
long newTPWeight = accountCapsule.getTronPowerFrozenBalance() / TRX_PRECISION;
119+
increment = newTPWeight - oldTPWeight;
120+
addTotalWeight(TRON_POWER, dynamicStore, frozenBalance, increment);
113121
break;
114122
default:
115123
logger.debug("Resource Code Error.");
@@ -123,6 +131,23 @@ public boolean execute(Object result) throws ContractExeException {
123131
return true;
124132
}
125133

134+
private void addTotalWeight(ResourceCode resourceCode, DynamicPropertiesStore dynamicStore,
135+
long frozenBalance, long increment) {
136+
long weight = dynamicStore.allowNewReward() ? increment : frozenBalance / TRX_PRECISION;
137+
switch (resourceCode) {
138+
case BANDWIDTH:
139+
dynamicStore.addTotalNetWeight(weight);
140+
break;
141+
case ENERGY:
142+
dynamicStore.addTotalEnergyWeight(weight);
143+
break;
144+
case TRON_POWER:
145+
dynamicStore.addTotalTronPowerWeight(weight);
146+
break;
147+
default:
148+
logger.debug("Resource Code Error.");
149+
}
150+
}
126151

127152
@Override
128153
public boolean validate() throws ContractValidateException {
@@ -175,11 +200,6 @@ public boolean validate() throws ContractValidateException {
175200
throw new ContractValidateException("frozenBalance must be less than accountBalance");
176201
}
177202

178-
// long maxFrozenNumber = dbManager.getDynamicPropertiesStore().getMaxFrozenNumber();
179-
// if (accountCapsule.getFrozenCount() >= maxFrozenNumber) {
180-
// throw new ContractValidateException("max frozen number is: " + maxFrozenNumber);
181-
// }
182-
183203
long frozenDuration = freezeBalanceContract.getFrozenDuration();
184204
long minFrozenTime = dynamicStore.getMinFrozenTime();
185205
long maxFrozenTime = dynamicStore.getMaxFrozenTime();
@@ -262,9 +282,10 @@ public long calcFee() {
262282
return 0;
263283
}
264284

265-
private void delegateResource(byte[] ownerAddress, byte[] receiverAddress, boolean isBandwidth,
285+
private long delegateResource(byte[] ownerAddress, byte[] receiverAddress, boolean isBandwidth,
266286
long balance, long expireTime) {
267287
AccountStore accountStore = chainBaseManager.getAccountStore();
288+
DynamicPropertiesStore dynamicPropertiesStore = chainBaseManager.getDynamicPropertiesStore();
268289
DelegatedResourceStore delegatedResourceStore = chainBaseManager.getDelegatedResourceStore();
269290
DelegatedResourceAccountIndexStore delegatedResourceAccountIndexStore = chainBaseManager
270291
.getDelegatedResourceAccountIndexStore();
@@ -292,46 +313,56 @@ private void delegateResource(byte[] ownerAddress, byte[] receiverAddress, boole
292313
delegatedResourceStore.put(key, delegatedResourceCapsule);
293314

294315
//modify DelegatedResourceAccountIndexStore
295-
{
296-
DelegatedResourceAccountIndexCapsule delegatedResourceAccountIndexCapsule = delegatedResourceAccountIndexStore
297-
.get(ownerAddress);
298-
if (delegatedResourceAccountIndexCapsule == null) {
299-
delegatedResourceAccountIndexCapsule = new DelegatedResourceAccountIndexCapsule(
316+
if (!dynamicPropertiesStore.supportAllowDelegateOptimization()) {
317+
318+
DelegatedResourceAccountIndexCapsule ownerIndexCapsule =
319+
delegatedResourceAccountIndexStore.get(ownerAddress);
320+
if (ownerIndexCapsule == null) {
321+
ownerIndexCapsule = new DelegatedResourceAccountIndexCapsule(
300322
ByteString.copyFrom(ownerAddress));
301323
}
302-
List<ByteString> toAccountsList = delegatedResourceAccountIndexCapsule.getToAccountsList();
324+
List<ByteString> toAccountsList = ownerIndexCapsule.getToAccountsList();
303325
if (!toAccountsList.contains(ByteString.copyFrom(receiverAddress))) {
304-
delegatedResourceAccountIndexCapsule.addToAccount(ByteString.copyFrom(receiverAddress));
326+
ownerIndexCapsule.addToAccount(ByteString.copyFrom(receiverAddress));
305327
}
306-
delegatedResourceAccountIndexStore
307-
.put(ownerAddress, delegatedResourceAccountIndexCapsule);
308-
}
328+
delegatedResourceAccountIndexStore.put(ownerAddress, ownerIndexCapsule);
309329

310-
{
311-
DelegatedResourceAccountIndexCapsule delegatedResourceAccountIndexCapsule = delegatedResourceAccountIndexStore
312-
.get(receiverAddress);
313-
if (delegatedResourceAccountIndexCapsule == null) {
314-
delegatedResourceAccountIndexCapsule = new DelegatedResourceAccountIndexCapsule(
330+
DelegatedResourceAccountIndexCapsule receiverIndexCapsule
331+
= delegatedResourceAccountIndexStore.get(receiverAddress);
332+
if (receiverIndexCapsule == null) {
333+
receiverIndexCapsule = new DelegatedResourceAccountIndexCapsule(
315334
ByteString.copyFrom(receiverAddress));
316335
}
317-
List<ByteString> fromAccountsList = delegatedResourceAccountIndexCapsule
336+
List<ByteString> fromAccountsList = receiverIndexCapsule
318337
.getFromAccountsList();
319338
if (!fromAccountsList.contains(ByteString.copyFrom(ownerAddress))) {
320-
delegatedResourceAccountIndexCapsule.addFromAccount(ByteString.copyFrom(ownerAddress));
339+
receiverIndexCapsule.addFromAccount(ByteString.copyFrom(ownerAddress));
321340
}
322-
delegatedResourceAccountIndexStore
323-
.put(receiverAddress, delegatedResourceAccountIndexCapsule);
341+
delegatedResourceAccountIndexStore.put(receiverAddress, receiverIndexCapsule);
342+
343+
} else {
344+
// modify DelegatedResourceAccountIndexStore new
345+
delegatedResourceAccountIndexStore.convert(ownerAddress);
346+
delegatedResourceAccountIndexStore.convert(receiverAddress);
347+
delegatedResourceAccountIndexStore.delegate(ownerAddress, receiverAddress,
348+
dynamicPropertiesStore.getLatestBlockHeaderTimestamp());
324349
}
325350

326351
//modify AccountStore
327352
AccountCapsule receiverCapsule = accountStore.get(receiverAddress);
353+
long oldWeight;
354+
long newWeight;
328355
if (isBandwidth) {
356+
oldWeight = receiverCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth() / TRX_PRECISION;
329357
receiverCapsule.addAcquiredDelegatedFrozenBalanceForBandwidth(balance);
358+
newWeight = receiverCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth() / TRX_PRECISION;
330359
} else {
360+
oldWeight = receiverCapsule.getAcquiredDelegatedFrozenBalanceForEnergy() / TRX_PRECISION;
331361
receiverCapsule.addAcquiredDelegatedFrozenBalanceForEnergy(balance);
362+
newWeight = receiverCapsule.getAcquiredDelegatedFrozenBalanceForEnergy() / TRX_PRECISION;
332363
}
333-
334364
accountStore.put(receiverCapsule.createDbKey(), receiverCapsule);
365+
return newWeight - oldWeight;
335366
}
336367

337368
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import lombok.extern.slf4j.Slf4j;
1010
import org.tron.common.utils.Commons;
1111
import org.tron.common.utils.DecodeUtil;
12+
import org.tron.common.utils.StringUtil;
1213
import org.tron.core.capsule.AccountCapsule;
1314
import org.tron.core.capsule.ContractCapsule;
1415
import org.tron.core.capsule.TransactionResultCapsule;
@@ -156,6 +157,8 @@ public boolean validate() throws ContractValidateException {
156157
}
157158

158159
if (balance < Math.addExact(amount, fee)) {
160+
logger.warn("Balance is not sufficient. Account: {}, balance: {}, amount: {}, fee: {}.",
161+
StringUtil.encode58Check(ownerAddress), balance, amount, fee);
159162
throw new ContractValidateException(
160163
"Validate TransferContract error, balance is not sufficient.");
161164
}

0 commit comments

Comments
 (0)