Skip to content

Commit

Permalink
Merge pull request tronprotocol#3608 from tronprotocol/remove-blackho…
Browse files Browse the repository at this point in the history
…le-account

Optimize blackhole account
  • Loading branch information
lvs007 authored Jan 7, 2021
2 parents fb78d0d + bb7881b commit aee58a8
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ public boolean execute(Object object) throws ContractExeException {
accountStore.put(ownerAddress, account);

Commons.adjustBalance(accountStore, ownerAddress, -fee);
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
if (chainBaseManager.getDynamicPropertiesStore().supportTransactionFeePool()) {
chainBaseManager.getDynamicPropertiesStore().addTransactionFeePool(fee);
} else if (chainBaseManager.getDynamicPropertiesStore().supportOptimizeBlackHole()) {
chainBaseManager.getDynamicPropertiesStore().burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}

result.setStatus(fee, code.SUCESS);
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ public boolean execute(Object result) throws ContractExeException {
}

Commons.adjustBalance(accountStore, ownerAddress, -fee);
Commons.adjustBalance(accountStore, accountStore.getBlackhole(),
fee);//send to blackhole

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);//send to blackhole
}
AccountCapsule accountCapsule = accountStore.get(ownerAddress);
List<FrozenSupply> frozenSupplyList = assetIssueContract.getFrozenSupplyList();
Iterator<FrozenSupply> iterator = frozenSupplyList.iterator();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.tron.core.actuator;

import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.Objects;
Expand All @@ -18,8 +20,6 @@
import org.tron.protos.Protocol.Transaction.Result.code;
import org.tron.protos.contract.AccountContract.AccountCreateContract;

import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;

@Slf4j(topic = "actuator")
public class CreateAccountActuator extends AbstractActuator {

Expand Down Expand Up @@ -51,8 +51,13 @@ public boolean execute(Object result)
Commons
.adjustBalance(accountStore, accountCreateContract.getOwnerAddress().toByteArray(), -fee);
// Add to blackhole address
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}
ret.setStatus(fee, code.SUCESS);
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
logger.debug(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.tron.core.store.DynamicPropertiesStore;
import org.tron.core.store.ExchangeStore;
import org.tron.core.store.ExchangeV2Store;
import org.tron.core.utils.TransactionUtil;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.Transaction.Result.code;
import org.tron.protos.contract.ExchangeContract.ExchangeCreateContract;
Expand Down Expand Up @@ -119,9 +118,13 @@ public boolean execute(Object object) throws ContractExeException {

accountStore.put(accountCapsule.createDbKey(), accountCapsule);
dynamicStore.saveLatestExchangeNum(id);

Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}
ret.setExchangeId(id);
ret.setStatus(fee, code.SUCESS);
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

package org.tron.core.actuator;

import static org.tron.core.actuator.ActuatorConstant.CONTRACT_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.TX_RESULT_NULL;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.Objects;
Expand Down Expand Up @@ -43,10 +47,6 @@
import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract;
import org.tron.protos.contract.MarketContract.MarketCancelOrderContract;

import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.CONTRACT_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.TX_RESULT_NULL;

@Slf4j(topic = "actuator")
public class MarketCancelOrderActuator extends AbstractActuator {

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

// fee
accountCapsule.setBalance(accountCapsule.getBalance() - fee);
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}
// 1. return balance and token
MarketUtils.returnSellTokenRemain(orderCapsule, accountCapsule, dynamicStore, assetIssueStore);
MarketUtils
.returnSellTokenRemain(orderCapsule, accountCapsule, dynamicStore, assetIssueStore);

MarketUtils.updateOrderState(orderCapsule, State.CANCELED, marketAccountStore);
accountStore.put(orderCapsule.getOwnerAddress().toByteArray(), accountCapsule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package org.tron.core.actuator;

import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.CONTRACT_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.STORE_NOT_EXIST;
import static org.tron.core.actuator.ActuatorConstant.TX_RESULT_NULL;
import static org.tron.core.capsule.utils.TransactionUtil.isNumber;

Expand Down Expand Up @@ -126,8 +126,13 @@ public boolean execute(Object object) throws ContractExeException {
// fee
accountCapsule.setBalance(accountCapsule.getBalance() - fee);
// add to blackhole address
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}
// 1. transfer of balance
transferBalanceOrToken(accountCapsule);

Expand Down Expand Up @@ -290,7 +295,7 @@ public long calcFee() {

/**
* return marketPrice if matched, otherwise null
* */
*/
private MarketPrice hasMatch(List<byte[]> priceKeysList, MarketPrice takerPrice) {
if (priceKeysList.isEmpty()) {
return null;
Expand Down Expand Up @@ -320,7 +325,7 @@ private void matchOrder(MarketOrderCapsule takerCapsule, MarketPrice takerPrice,
// get maker price list
List<byte[]> priceKeysList = pairPriceToOrderStore
.getPriceKeysList(MarketUtils.getPairPriceHeadKey(makerSellTokenID, makerBuyTokenID),
(long)(MAX_MATCH_NUM + 1), makerPriceNumber, true);
(long) (MAX_MATCH_NUM + 1), makerPriceNumber, true);

int matchOrderCount = 0;
// match different price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public boolean execute(Object object) throws ContractExeException {
}

Commons.adjustBalance(accountStore, ownerAddress, -(Math.addExact(fee, amount)));
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}
Commons.adjustBalance(accountStore, toAddress, amount);
ret.setStatus(fee, code.SUCESS);
} catch (BalanceInsufficientException | ArithmeticException | InvalidProtocolBufferException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public boolean execute(Object result) throws ContractExeException {
ByteString assetName = transferAssetContract.getAssetName();
long amount = transferAssetContract.getAmount();


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

Commons.adjustBalance(accountStore, ownerAccountCapsule, -fee);
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(fee);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), fee);
}
ret.setStatus(fee, code.SUCESS);
} catch (BalanceInsufficientException e) {
logger.debug(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public boolean validate() throws ContractValidateException {
} */

if (witnessStore.has(ownerAddress)) {
throw new ContractValidateException(WITNESS_EXCEPTION_STR + readableOwnerAddress + "] has existed");
throw new ContractValidateException(
WITNESS_EXCEPTION_STR + readableOwnerAddress + "] has existed");
}

if (accountCapsule.getBalance() < dynamicStore
Expand Down Expand Up @@ -141,9 +142,13 @@ private void createWitness(final WitnessCreateContract witnessCreateContract)
long cost = dynamicStore.getAccountUpgradeCost();
Commons
.adjustBalance(accountStore, witnessCreateContract.getOwnerAddress().toByteArray(), -cost);

Commons.adjustBalance(accountStore, accountStore.getBlackhole(), +cost);

if (dynamicStore.supportTransactionFeePool()) {
dynamicStore.addTransactionFeePool(cost);
} else if (dynamicStore.supportOptimizeBlackHole()) {
dynamicStore.burnTrx(cost);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole(), +cost);
}
dynamicStore.addTotalCreateWitnessCost(cost);
}
}
14 changes: 13 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_OPTIMIZE_BLACKHOLE: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_1_2)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_REMOVE_BLACKHOLE]");
}
if (value != 1 && value != 0) {
throw new ContractValidateException(
"This value[ALLOW_REMOVE_BLACKHOLE] is only allowed to be 1 or 0");
}
break;
}


default:
Expand Down Expand Up @@ -475,7 +486,8 @@ public enum ProposalType { // current value, value range
MARKET_SELL_FEE(45), // 0 [0,10_000_000_000]
MARKET_CANCEL_FEE(46), // 0 [0,10_000_000_000]
MAX_FEE_LIMIT(47), // [0, 10_000_000_000]
ALLOW_TRANSACTION_FEE_POOL(48); // 0, 1
ALLOW_TRANSACTION_FEE_POOL(48), // 0, 1
ALLOW_OPTIMIZE_BLACKHOLE(49);// 0,1

private long code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ private void payEnergyBill(

if (dynamicPropertiesStore.supportTransactionFeePool() &&
!contractResult.equals(contractResult.OUT_OF_TIME)) {
dynamicPropertiesStore
.saveTransactionFeePool(dynamicPropertiesStore.getTransactionFeePool() + energyFee);
dynamicPropertiesStore.addTransactionFeePool(energyFee);
} else if (dynamicPropertiesStore.supportOptimizeBlackHole()) {
dynamicPropertiesStore.burnTrx(energyFee);
} else {
//send to blackHole
Commons.adjustBalance(accountStore, accountStore.getBlackhole(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public TransactionInfoCapsule() {
this.transactionInfo = TransactionInfo.newBuilder().build();
}


public long getPunishment() {
return transactionInfo.getPunishment();
}

public long getFee() {
return transactionInfo.getFee();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.capsule.TransactionInfoCapsule;
import org.tron.core.db.TransactionTrace;
import org.tron.core.store.DynamicPropertiesStore;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract;
Expand Down Expand Up @@ -75,6 +76,19 @@ public static TransactionInfoCapsule buildTransactionInfoInstance(TransactionCap
long fee =
programResult.getRet().getFee() + traceReceipt.getEnergyFee()
+ traceReceipt.getNetFee() + traceReceipt.getMultiSignFee();

boolean supportPunishmentAmount = trace.getTransactionContext().getStoreFactory()
.getChainBaseManager().getDynamicPropertiesStore().supportPunishmentAmount();
if (supportPunishmentAmount) {
long punishment = 0L;
if (traceReceipt.getResult().equals(Transaction.Result.contractResult.OUT_OF_TIME)) {
fee = programResult.getRet().getFee() + traceReceipt.getNetFee() +
traceReceipt.getMultiSignFee();
punishment += traceReceipt.getEnergyFee();
}
builder.setPunishment(punishment);
}

ByteString contractResult = ByteString.copyFrom(programResult.getHReturn());
ByteString ContractAddress = ByteString.copyFrom(programResult.getContractAddress());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ protected boolean consumeFee(AccountCapsule accountCapsule, long fee) {
accountCapsule.setLatestOperationTime(latestOperationTime);
Commons.adjustBalance(accountStore, accountCapsule, -fee);
if (dynamicPropertiesStore.supportTransactionFeePool()) {
dynamicPropertiesStore
.saveTransactionFeePool(dynamicPropertiesStore.getTransactionFeePool() + fee);
dynamicPropertiesStore.addTransactionFeePool(fee);
} else if (dynamicPropertiesStore.supportOptimizeBlackHole()) {
dynamicPropertiesStore.burnTrx(fee);
} else {
Commons.adjustBalance(accountStore, accountStore.getBlackhole().createDbKey(), +fee);
}
Expand Down
Loading

0 comments on commit aee58a8

Please sign in to comment.