Skip to content

Commit 959e019

Browse files
authored
Merge pull request #5300 from tronprotocol/release_v4.7.2
Release v4.7.2
2 parents d5da6ae + 28f5c99 commit 959e019

File tree

836 files changed

+8737
-183047
lines changed

Some content is hidden

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

836 files changed

+8737
-183047
lines changed

.circleci/config.yml

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ Wallet
5454

5555
# vm_trace
5656
/vm_trace/
57+
58+
/framework/propPath

DownloadLinks.sh

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

Tron protobuf protocol document.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ Transaction and transaction-related messages.
627627
WithdrawExpireUnfreezeContract = 56;
628628
DelegateResourceContract = 57;
629629
UnDelegateResourceContract = 58;
630+
CancelAllUnfreezeV2Contract = 59;
630631
}
631632
ContractType type = 1;
632633
google.protobuf.Any parameter = 2;
@@ -887,6 +888,7 @@ Contract and contract-related messages.
887888
WithdrawExpireUnfreezeContract = 56;
888889
DelegateResourceContract = 57;
889890
UnDelegateResourceContract = 58;
891+
CancelAllUnfreezeV2Contract = 59;
890892
}
891893
ContractType type = 1;
892894
google.protobuf.Any parameter = 2;

actuator/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description = "actuator – a series of transactions for blockchain."
33
// Dependency versions
44
// ---------------------------------------
55

6-
def junitVersion = "4.12"
6+
def junitVersion = "4.13.2"
77
def mockitoVersion = "2.1.0"
88
def testNgVersion = "6.11"
99
def slf4jVersion = "1.7.25"
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
package org.tron.core.actuator;
2+
3+
import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;
4+
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
5+
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
6+
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
7+
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
8+
import static org.tron.protos.contract.Common.ResourceCode.TRON_POWER;
9+
10+
import com.google.protobuf.ByteString;
11+
import com.google.protobuf.InvalidProtocolBufferException;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
import java.util.Objects;
16+
import java.util.concurrent.atomic.AtomicLong;
17+
import lombok.extern.slf4j.Slf4j;
18+
import org.apache.commons.lang3.tuple.Pair;
19+
import org.apache.commons.lang3.tuple.Triple;
20+
import org.tron.common.utils.DecodeUtil;
21+
import org.tron.common.utils.StringUtil;
22+
import org.tron.core.capsule.AccountCapsule;
23+
import org.tron.core.capsule.TransactionResultCapsule;
24+
import org.tron.core.exception.ContractExeException;
25+
import org.tron.core.exception.ContractValidateException;
26+
import org.tron.core.store.AccountStore;
27+
import org.tron.core.store.DynamicPropertiesStore;
28+
import org.tron.protos.Protocol.Account.UnFreezeV2;
29+
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
30+
import org.tron.protos.Protocol.Transaction.Result.code;
31+
import org.tron.protos.contract.BalanceContract.CancelAllUnfreezeV2Contract;
32+
33+
@Slf4j(topic = "actuator")
34+
public class CancelAllUnfreezeV2Actuator extends AbstractActuator {
35+
36+
public CancelAllUnfreezeV2Actuator() {
37+
super(ContractType.CancelAllUnfreezeV2Contract, CancelAllUnfreezeV2Contract.class);
38+
}
39+
40+
@Override
41+
public boolean execute(Object result) throws ContractExeException {
42+
TransactionResultCapsule ret = (TransactionResultCapsule) result;
43+
if (Objects.isNull(ret)) {
44+
throw new RuntimeException(ActuatorConstant.TX_RESULT_NULL);
45+
}
46+
long fee = calcFee();
47+
AccountStore accountStore = chainBaseManager.getAccountStore();
48+
DynamicPropertiesStore dynamicStore = chainBaseManager.getDynamicPropertiesStore();
49+
byte[] ownerAddress;
50+
try {
51+
ownerAddress = getOwnerAddress().toByteArray();
52+
} catch (InvalidProtocolBufferException e) {
53+
logger.debug(e.getMessage(), e);
54+
ret.setStatus(fee, code.FAILED);
55+
throw new ContractExeException(e.getMessage());
56+
}
57+
AccountCapsule ownerCapsule = accountStore.get(ownerAddress);
58+
List<UnFreezeV2> unfrozenV2List = ownerCapsule.getUnfrozenV2List();
59+
long now = dynamicStore.getLatestBlockHeaderTimestamp();
60+
AtomicLong atomicWithdrawExpireBalance = new AtomicLong(0L);
61+
Triple<Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>>
62+
triple = Triple.of(
63+
Pair.of(new AtomicLong(0L), new AtomicLong(0L)),
64+
Pair.of(new AtomicLong(0L), new AtomicLong(0L)),
65+
Pair.of(new AtomicLong(0L), new AtomicLong(0L)));
66+
for (UnFreezeV2 unFreezeV2 : unfrozenV2List) {
67+
updateAndCalculate(triple, ownerCapsule, now, atomicWithdrawExpireBalance, unFreezeV2);
68+
}
69+
ownerCapsule.clearUnfrozenV2();
70+
addTotalResourceWeight(dynamicStore, triple);
71+
72+
long withdrawExpireBalance = atomicWithdrawExpireBalance.get();
73+
if (withdrawExpireBalance > 0) {
74+
ownerCapsule.setBalance(ownerCapsule.getBalance() + withdrawExpireBalance);
75+
}
76+
77+
accountStore.put(ownerCapsule.createDbKey(), ownerCapsule);
78+
ret.setWithdrawExpireAmount(withdrawExpireBalance);
79+
Map<String, Long> cancelUnfreezeV2AmountMap = new HashMap<>();
80+
cancelUnfreezeV2AmountMap.put(BANDWIDTH.name(), triple.getLeft().getRight().get());
81+
cancelUnfreezeV2AmountMap.put(ENERGY.name(), triple.getMiddle().getRight().get());
82+
cancelUnfreezeV2AmountMap.put(TRON_POWER.name(), triple.getRight().getRight().get());
83+
ret.putAllCancelUnfreezeV2AmountMap(cancelUnfreezeV2AmountMap);
84+
ret.setStatus(fee, code.SUCESS);
85+
return true;
86+
}
87+
88+
private void addTotalResourceWeight(DynamicPropertiesStore dynamicStore,
89+
Triple<Pair<AtomicLong, AtomicLong>,
90+
Pair<AtomicLong, AtomicLong>,
91+
Pair<AtomicLong, AtomicLong>> triple) {
92+
dynamicStore.addTotalNetWeight(triple.getLeft().getLeft().get());
93+
dynamicStore.addTotalEnergyWeight(triple.getMiddle().getLeft().get());
94+
dynamicStore.addTotalTronPowerWeight(triple.getRight().getLeft().get());
95+
}
96+
97+
private void updateAndCalculate(Triple<Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>,
98+
Pair<AtomicLong, AtomicLong>> triple,
99+
AccountCapsule ownerCapsule, long now, AtomicLong atomicLong, UnFreezeV2 unFreezeV2) {
100+
if (unFreezeV2.getUnfreezeExpireTime() > now) {
101+
updateFrozenInfoAndTotalResourceWeight(ownerCapsule, unFreezeV2, triple);
102+
} else {
103+
atomicLong.addAndGet(unFreezeV2.getUnfreezeAmount());
104+
}
105+
}
106+
107+
@Override
108+
public boolean validate() throws ContractValidateException {
109+
if (Objects.isNull(this.any)) {
110+
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
111+
}
112+
113+
if (Objects.isNull(chainBaseManager)) {
114+
throw new ContractValidateException(ActuatorConstant.STORE_NOT_EXIST);
115+
}
116+
117+
AccountStore accountStore = chainBaseManager.getAccountStore();
118+
DynamicPropertiesStore dynamicStore = chainBaseManager.getDynamicPropertiesStore();
119+
120+
if (!this.any.is(CancelAllUnfreezeV2Contract.class)) {
121+
throw new ContractValidateException("contract type error, expected type " +
122+
"[CancelAllUnfreezeV2Contract], real type[" + any.getClass() + "]");
123+
}
124+
125+
if (!dynamicStore.supportAllowCancelAllUnfreezeV2()) {
126+
throw new ContractValidateException("Not support CancelAllUnfreezeV2 transaction,"
127+
+ " need to be opened by the committee");
128+
}
129+
130+
byte[] ownerAddress;
131+
try {
132+
ownerAddress = getOwnerAddress().toByteArray();
133+
} catch (InvalidProtocolBufferException e) {
134+
logger.debug(e.getMessage(), e);
135+
throw new ContractValidateException(e.getMessage());
136+
}
137+
138+
if (!DecodeUtil.addressValid(ownerAddress)) {
139+
throw new ContractValidateException("Invalid address");
140+
}
141+
AccountCapsule accountCapsule = accountStore.get(ownerAddress);
142+
String readableOwnerAddress = StringUtil.createReadableString(ownerAddress);
143+
if (Objects.isNull(accountCapsule)) {
144+
throw new ContractValidateException(ACCOUNT_EXCEPTION_STR
145+
+ readableOwnerAddress + NOT_EXIST_STR);
146+
}
147+
148+
List<UnFreezeV2> unfrozenV2List = accountCapsule.getUnfrozenV2List();
149+
if (unfrozenV2List.isEmpty()) {
150+
throw new ContractValidateException("No unfreezeV2 list to cancel");
151+
}
152+
153+
return true;
154+
}
155+
156+
@Override
157+
public ByteString getOwnerAddress() throws InvalidProtocolBufferException {
158+
return getCancelAllUnfreezeV2Contract().getOwnerAddress();
159+
}
160+
161+
private CancelAllUnfreezeV2Contract getCancelAllUnfreezeV2Contract()
162+
throws InvalidProtocolBufferException {
163+
return any.unpack(CancelAllUnfreezeV2Contract.class);
164+
}
165+
166+
@Override
167+
public long calcFee() {
168+
return 0;
169+
}
170+
171+
public void updateFrozenInfoAndTotalResourceWeight(
172+
AccountCapsule accountCapsule, UnFreezeV2 unFreezeV2,
173+
Triple<Pair<AtomicLong, AtomicLong>, Pair<AtomicLong, AtomicLong>,
174+
Pair<AtomicLong, AtomicLong>> triple) {
175+
switch (unFreezeV2.getType()) {
176+
case BANDWIDTH:
177+
long oldNetWeight = accountCapsule.getFrozenV2BalanceWithDelegated(BANDWIDTH) / TRX_PRECISION;
178+
accountCapsule.addFrozenBalanceForBandwidthV2(unFreezeV2.getUnfreezeAmount());
179+
long newNetWeight = accountCapsule.getFrozenV2BalanceWithDelegated(BANDWIDTH) / TRX_PRECISION;
180+
triple.getLeft().getLeft().addAndGet(newNetWeight - oldNetWeight);
181+
triple.getLeft().getRight().addAndGet(unFreezeV2.getUnfreezeAmount());
182+
break;
183+
case ENERGY:
184+
long oldEnergyWeight = accountCapsule.getFrozenV2BalanceWithDelegated(ENERGY) / TRX_PRECISION;
185+
accountCapsule.addFrozenBalanceForEnergyV2(unFreezeV2.getUnfreezeAmount());
186+
long newEnergyWeight = accountCapsule.getFrozenV2BalanceWithDelegated(ENERGY) / TRX_PRECISION;
187+
triple.getMiddle().getLeft().addAndGet(newEnergyWeight - oldEnergyWeight);
188+
triple.getMiddle().getRight().addAndGet(unFreezeV2.getUnfreezeAmount());
189+
break;
190+
case TRON_POWER:
191+
long oldTPWeight = accountCapsule.getTronPowerFrozenV2Balance() / TRX_PRECISION;
192+
accountCapsule.addFrozenForTronPowerV2(unFreezeV2.getUnfreezeAmount());
193+
long newTPWeight = accountCapsule.getTronPowerFrozenV2Balance() / TRX_PRECISION;
194+
triple.getRight().getLeft().addAndGet(newTPWeight - oldTPWeight);
195+
triple.getRight().getRight().addAndGet(unFreezeV2.getUnfreezeAmount());
196+
break;
197+
default:
198+
break;
199+
}
200+
}
201+
}

0 commit comments

Comments
 (0)