Skip to content

Commit aee58a8

Browse files
authored
Merge pull request #3608 from tronprotocol/remove-blackhole-account
Optimize blackhole account
2 parents fb78d0d + bb7881b commit aee58a8

File tree

23 files changed

+271
-83
lines changed

23 files changed

+271
-83
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ public boolean execute(Object object) throws ContractExeException {
5353
accountStore.put(ownerAddress, account);
5454

5555
Commons.adjustBalance(accountStore, ownerAddress, -fee);
56-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
56+
if (chainBaseManager.getDynamicPropertiesStore().supportTransactionFeePool()) {
57+
chainBaseManager.getDynamicPropertiesStore().addTransactionFeePool(fee);
58+
} else if (chainBaseManager.getDynamicPropertiesStore().supportOptimizeBlackHole()) {
59+
chainBaseManager.getDynamicPropertiesStore().burnTrx(fee);
60+
} else {
61+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
62+
}
5763

5864
result.setStatus(fee, code.SUCESS);
5965
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ public boolean execute(Object result) throws ContractExeException {
8585
}
8686

8787
Commons.adjustBalance(accountStore, ownerAddress, -fee);
88-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(),
89-
fee);//send to blackhole
90-
88+
if (dynamicStore.supportTransactionFeePool()) {
89+
dynamicStore.addTransactionFeePool(fee);
90+
} else if (dynamicStore.supportOptimizeBlackHole()) {
91+
dynamicStore.burnTrx(fee);
92+
} else {
93+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);//send to blackhole
94+
}
9195
AccountCapsule accountCapsule = accountStore.get(ownerAddress);
9296
List<FrozenSupply> frozenSupplyList = assetIssueContract.getFrozenSupplyList();
9397
Iterator<FrozenSupply> iterator = frozenSupplyList.iterator();

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

Lines changed: 9 additions & 4 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.Objects;
@@ -18,8 +20,6 @@
1820
import org.tron.protos.Protocol.Transaction.Result.code;
1921
import org.tron.protos.contract.AccountContract.AccountCreateContract;
2022

21-
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
22-
2323
@Slf4j(topic = "actuator")
2424
public class CreateAccountActuator extends AbstractActuator {
2525

@@ -51,8 +51,13 @@ public boolean execute(Object result)
5151
Commons
5252
.adjustBalance(accountStore, accountCreateContract.getOwnerAddress().toByteArray(), -fee);
5353
// Add to blackhole address
54-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
55-
54+
if (dynamicStore.supportTransactionFeePool()) {
55+
dynamicStore.addTransactionFeePool(fee);
56+
} else if (dynamicStore.supportOptimizeBlackHole()) {
57+
dynamicStore.burnTrx(fee);
58+
} else {
59+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
60+
}
5661
ret.setStatus(fee, code.SUCESS);
5762
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
5863
logger.debug(e.getMessage(), e);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.tron.core.store.DynamicPropertiesStore;
2424
import org.tron.core.store.ExchangeStore;
2525
import org.tron.core.store.ExchangeV2Store;
26-
import org.tron.core.utils.TransactionUtil;
2726
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
2827
import org.tron.protos.Protocol.Transaction.Result.code;
2928
import org.tron.protos.contract.ExchangeContract.ExchangeCreateContract;
@@ -119,9 +118,13 @@ public boolean execute(Object object) throws ContractExeException {
119118

120119
accountStore.put(accountCapsule.createDbKey(), accountCapsule);
121120
dynamicStore.saveLatestExchangeNum(id);
122-
123-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
124-
121+
if (dynamicStore.supportTransactionFeePool()) {
122+
dynamicStore.addTransactionFeePool(fee);
123+
} else if (dynamicStore.supportOptimizeBlackHole()) {
124+
dynamicStore.burnTrx(fee);
125+
} else {
126+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
127+
}
125128
ret.setExchangeId(id);
126129
ret.setStatus(fee, code.SUCESS);
127130
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
package org.tron.core.actuator;
1717

18+
import static org.tron.core.actuator.ActuatorConstant.CONTRACT_NOT_EXIST;
19+
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
20+
import static org.tron.core.actuator.ActuatorConstant.TX_RESULT_NULL;
21+
1822
import com.google.protobuf.ByteString;
1923
import com.google.protobuf.InvalidProtocolBufferException;
2024
import java.util.Objects;
@@ -43,10 +47,6 @@
4347
import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract;
4448
import org.tron.protos.contract.MarketContract.MarketCancelOrderContract;
4549

46-
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
47-
import static org.tron.core.actuator.ActuatorConstant.CONTRACT_NOT_EXIST;
48-
import static org.tron.core.actuator.ActuatorConstant.TX_RESULT_NULL;
49-
5050
@Slf4j(topic = "actuator")
5151
public class MarketCancelOrderActuator extends AbstractActuator {
5252

@@ -97,10 +97,16 @@ public boolean execute(Object object) throws ContractExeException {
9797

9898
// fee
9999
accountCapsule.setBalance(accountCapsule.getBalance() - fee);
100-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
101-
100+
if (dynamicStore.supportTransactionFeePool()) {
101+
dynamicStore.addTransactionFeePool(fee);
102+
} else if (dynamicStore.supportOptimizeBlackHole()) {
103+
dynamicStore.burnTrx(fee);
104+
} else {
105+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
106+
}
102107
// 1. return balance and token
103-
MarketUtils.returnSellTokenRemain(orderCapsule, accountCapsule, dynamicStore, assetIssueStore);
108+
MarketUtils
109+
.returnSellTokenRemain(orderCapsule, accountCapsule, dynamicStore, assetIssueStore);
104110

105111
MarketUtils.updateOrderState(orderCapsule, State.CANCELED, marketAccountStore);
106112
accountStore.put(orderCapsule.getOwnerAddress().toByteArray(), accountCapsule);

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
package org.tron.core.actuator;
1717

18-
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
1918
import static org.tron.core.actuator.ActuatorConstant.CONTRACT_NOT_EXIST;
19+
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
2020
import static org.tron.core.actuator.ActuatorConstant.TX_RESULT_NULL;
2121
import static org.tron.core.capsule.utils.TransactionUtil.isNumber;
2222

@@ -126,8 +126,13 @@ public boolean execute(Object object) throws ContractExeException {
126126
// fee
127127
accountCapsule.setBalance(accountCapsule.getBalance() - fee);
128128
// add to blackhole address
129-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
130-
129+
if (dynamicStore.supportTransactionFeePool()) {
130+
dynamicStore.addTransactionFeePool(fee);
131+
} else if (dynamicStore.supportOptimizeBlackHole()) {
132+
dynamicStore.burnTrx(fee);
133+
} else {
134+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
135+
}
131136
// 1. transfer of balance
132137
transferBalanceOrToken(accountCapsule);
133138

@@ -290,7 +295,7 @@ public long calcFee() {
290295

291296
/**
292297
* return marketPrice if matched, otherwise null
293-
* */
298+
*/
294299
private MarketPrice hasMatch(List<byte[]> priceKeysList, MarketPrice takerPrice) {
295300
if (priceKeysList.isEmpty()) {
296301
return null;
@@ -320,7 +325,7 @@ private void matchOrder(MarketOrderCapsule takerCapsule, MarketPrice takerPrice,
320325
// get maker price list
321326
List<byte[]> priceKeysList = pairPriceToOrderStore
322327
.getPriceKeysList(MarketUtils.getPairPriceHeadKey(makerSellTokenID, makerBuyTokenID),
323-
(long)(MAX_MATCH_NUM + 1), makerPriceNumber, true);
328+
(long) (MAX_MATCH_NUM + 1), makerPriceNumber, true);
324329

325330
int matchOrderCount = 0;
326331
// match different price

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ public boolean execute(Object object) throws ContractExeException {
5757
}
5858

5959
Commons.adjustBalance(accountStore, ownerAddress, -(Math.addExact(fee, amount)));
60-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
60+
if (dynamicStore.supportTransactionFeePool()) {
61+
dynamicStore.addTransactionFeePool(fee);
62+
} else if (dynamicStore.supportOptimizeBlackHole()) {
63+
dynamicStore.burnTrx(fee);
64+
} else {
65+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
66+
}
6167
Commons.adjustBalance(accountStore, toAddress, amount);
6268
ret.setStatus(fee, code.SUCESS);
6369
} catch (BalanceInsufficientException | ArithmeticException | InvalidProtocolBufferException e) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public boolean execute(Object result) throws ContractExeException {
7373
ByteString assetName = transferAssetContract.getAssetName();
7474
long amount = transferAssetContract.getAmount();
7575

76-
7776
AccountCapsule ownerAccountCapsule = accountStore.get(ownerAddress);
7877
if (!ownerAccountCapsule
7978
.reduceAssetAmountV2(assetName.toByteArray(), amount, dynamicStore, assetIssueStore)) {
@@ -86,8 +85,13 @@ public boolean execute(Object result) throws ContractExeException {
8685
accountStore.put(toAddress, toAccountCapsule);
8786

8887
Commons.adjustBalance(accountStore, ownerAccountCapsule, -fee);
89-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
90-
88+
if (dynamicStore.supportTransactionFeePool()) {
89+
dynamicStore.addTransactionFeePool(fee);
90+
} else if (dynamicStore.supportOptimizeBlackHole()) {
91+
dynamicStore.burnTrx(fee);
92+
} else {
93+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
94+
}
9195
ret.setStatus(fee, code.SUCESS);
9296
} catch (BalanceInsufficientException e) {
9397
logger.debug(e.getMessage(), e);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public boolean validate() throws ContractValidateException {
9797
} */
9898

9999
if (witnessStore.has(ownerAddress)) {
100-
throw new ContractValidateException(WITNESS_EXCEPTION_STR + readableOwnerAddress + "] has existed");
100+
throw new ContractValidateException(
101+
WITNESS_EXCEPTION_STR + readableOwnerAddress + "] has existed");
101102
}
102103

103104
if (accountCapsule.getBalance() < dynamicStore
@@ -141,9 +142,13 @@ private void createWitness(final WitnessCreateContract witnessCreateContract)
141142
long cost = dynamicStore.getAccountUpgradeCost();
142143
Commons
143144
.adjustBalance(accountStore, witnessCreateContract.getOwnerAddress().toByteArray(), -cost);
144-
145-
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), +cost);
146-
145+
if (dynamicStore.supportTransactionFeePool()) {
146+
dynamicStore.addTransactionFeePool(cost);
147+
} else if (dynamicStore.supportOptimizeBlackHole()) {
148+
dynamicStore.burnTrx(cost);
149+
} else {
150+
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), +cost);
151+
}
147152
dynamicStore.addTotalCreateWitnessCost(cost);
148153
}
149154
}

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
422422
}
423423
break;
424424
}
425+
case ALLOW_OPTIMIZE_BLACKHOLE: {
426+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1_2)) {
427+
throw new ContractValidateException(
428+
"Bad chain parameter id [ALLOW_REMOVE_BLACKHOLE]");
429+
}
430+
if (value != 1 && value != 0) {
431+
throw new ContractValidateException(
432+
"This value[ALLOW_REMOVE_BLACKHOLE] is only allowed to be 1 or 0");
433+
}
434+
break;
435+
}
425436

426437

427438
default:
@@ -475,7 +486,8 @@ public enum ProposalType { // current value, value range
475486
MARKET_SELL_FEE(45), // 0 [0,10_000_000_000]
476487
MARKET_CANCEL_FEE(46), // 0 [0,10_000_000_000]
477488
MAX_FEE_LIMIT(47), // [0, 10_000_000_000]
478-
ALLOW_TRANSACTION_FEE_POOL(48); // 0, 1
489+
ALLOW_TRANSACTION_FEE_POOL(48), // 0, 1
490+
ALLOW_OPTIMIZE_BLACKHOLE(49);// 0,1
479491

480492
private long code;
481493

0 commit comments

Comments
 (0)