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

jdk11 #25

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions actuator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
description = "actuator – a series of transactions for blockchain."

dependencies {
compile project(":chainbase")
compile project(":protocol")
compile project(":crypto")
api project(":chainbase")
api project(":protocol")
api project(":crypto")
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
import org.tron.core.capsule.AccountCapsule;
Expand Down Expand Up @@ -111,7 +112,7 @@ private boolean checkPermission(Permission permission) throws ContractValidateEx
throw new ContractValidateException("key's weight should be greater than 0");
}
try {
weightSum = Math.addExact(weightSum, key.getWeight());
weightSum = MathWrapper.addExact(weightSum, key.getWeight());
} catch (ArithmeticException e) {
throw new ContractValidateException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Arrays;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
Expand Down Expand Up @@ -71,14 +72,14 @@ public boolean execute(Object object) throws ContractExeException {

if (Arrays.equals(tokenID, firstTokenID)) {
anotherTokenID = secondTokenID;
anotherTokenQuant = Math
.floorDiv(Math.multiplyExact(secondTokenBalance, tokenQuant), firstTokenBalance);
anotherTokenQuant = MathWrapper.floorDiv(
MathWrapper.multiplyExact(secondTokenBalance, tokenQuant), firstTokenBalance);
exchangeCapsule.setBalance(firstTokenBalance + tokenQuant,
secondTokenBalance + anotherTokenQuant);
} else {
anotherTokenID = firstTokenID;
anotherTokenQuant = Math
.floorDiv(Math.multiplyExact(firstTokenBalance, tokenQuant), secondTokenBalance);
anotherTokenQuant = MathWrapper.floorDiv(
MathWrapper.multiplyExact(firstTokenBalance, tokenQuant), secondTokenBalance);
exchangeCapsule.setBalance(firstTokenBalance + anotherTokenQuant,
secondTokenBalance + tokenQuant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,12 @@ public boolean execute(Object object) throws ContractExeException {
BigInteger bigTokenQuant = new BigInteger(String.valueOf(tokenQuant));
if (Arrays.equals(tokenID, firstTokenID)) {
anotherTokenID = secondTokenID;
// anotherTokenQuant = Math
// .floorDiv(Math.multiplyExact(secondTokenBalance, tokenQuant), firstTokenBalance);
anotherTokenQuant = bigSecondTokenBalance.multiply(bigTokenQuant)
.divide(bigFirstTokenBalance).longValueExact();
exchangeCapsule.setBalance(firstTokenBalance - tokenQuant,
secondTokenBalance - anotherTokenQuant);
} else {
anotherTokenID = firstTokenID;
// anotherTokenQuant = Math
// .floorDiv(Math.multiplyExact(firstTokenBalance, tokenQuant), secondTokenBalance);
anotherTokenQuant = bigFirstTokenBalance.multiply(bigTokenQuant)
.divide(bigSecondTokenBalance).longValueExact();
exchangeCapsule.setBalance(firstTokenBalance - anotherTokenQuant,
Expand Down Expand Up @@ -210,8 +206,6 @@ public boolean validate() throws ContractValidateException {
BigDecimal bigSecondTokenBalance = new BigDecimal(String.valueOf(secondTokenBalance));
BigDecimal bigTokenQuant = new BigDecimal(String.valueOf(tokenQuant));
if (Arrays.equals(tokenID, firstTokenID)) {
// anotherTokenQuant = Math
// .floorDiv(Math.multiplyExact(secondTokenBalance, tokenQuant), firstTokenBalance);
anotherTokenQuant = bigSecondTokenBalance.multiply(bigTokenQuant)
.divideToIntegralValue(bigFirstTokenBalance).longValueExact();
if (firstTokenBalance < tokenQuant || secondTokenBalance < anotherTokenQuant) {
Expand All @@ -230,8 +224,6 @@ public boolean validate() throws ContractValidateException {
}

} else {
// anotherTokenQuant = Math
// .floorDiv(Math.multiplyExact(firstTokenBalance, tokenQuant), secondTokenBalance);
anotherTokenQuant = bigFirstTokenBalance.multiply(bigTokenQuant)
.divideToIntegralValue(bigSecondTokenBalance).longValueExact();
if (secondTokenBalance < tokenQuant || firstTokenBalance < anotherTokenQuant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
import org.tron.core.capsule.AccountCapsule;
Expand Down Expand Up @@ -244,7 +245,7 @@ public boolean validate() throws ContractValidateException {
long fee = calcFee();

if (Arrays.equals(sellTokenID, "_".getBytes())) {
if (ownerAccount.getBalance() < Math.addExact(sellTokenQuantity, fee)) {
if (ownerAccount.getBalance() < MathWrapper.addExact(sellTokenQuantity, fee)) {
throw new ContractValidateException("No enough balance !");
}
} else {
Expand Down Expand Up @@ -447,7 +448,7 @@ private void matchSingleOrder(MarketOrderCapsule takerOrderCapsule,
takerOrderCapsule.setSellTokenQuantityRemain(0);
MarketUtils.updateOrderState(takerOrderCapsule, State.INACTIVE, marketAccountStore);

makerOrderCapsule.setSellTokenQuantityRemain(Math.subtractExact(
makerOrderCapsule.setSellTokenQuantityRemain(MathWrapper.subtractExact(
makerOrderCapsule.getSellTokenQuantityRemain(), takerBuyTokenQuantityRemain));
} else {
// taker > maker
Expand Down Expand Up @@ -475,7 +476,7 @@ private void matchSingleOrder(MarketOrderCapsule takerOrderCapsule,
return;
} else {
makerOrderCapsule.setSellTokenQuantityRemain(0);
takerOrderCapsule.setSellTokenQuantityRemain(Math.subtractExact(
takerOrderCapsule.setSellTokenQuantityRemain(MathWrapper.subtractExact(
takerOrderCapsule.getSellTokenQuantityRemain(), makerBuyTokenQuantityReceive));
}
}
Expand Down Expand Up @@ -524,7 +525,8 @@ private MarketOrderCapsule createAndSaveOrder(AccountCapsule accountCapsule,

private void transferBalanceOrToken(AccountCapsule accountCapsule) {
if (Arrays.equals(sellTokenID, "_".getBytes())) {
accountCapsule.setBalance(Math.subtractExact(accountCapsule.getBalance(), sellTokenQuantity));
accountCapsule.setBalance(MathWrapper.subtractExact(
accountCapsule.getBalance(), sellTokenQuantity));
} else {
accountCapsule
.reduceAssetAmountV2(sellTokenID, sellTokenQuantity, dynamicStore, assetIssueStore);
Expand All @@ -537,7 +539,7 @@ private void addTrxOrToken(MarketOrderCapsule orderCapsule, long num,

byte[] buyTokenId = orderCapsule.getBuyTokenId();
if (Arrays.equals(buyTokenId, "_".getBytes())) {
accountCapsule.setBalance(Math.addExact(accountCapsule.getBalance(), num));
accountCapsule.setBalance(MathWrapper.addExact(accountCapsule.getBalance(), num));
} else {
accountCapsule
.addAssetAmountV2(buyTokenId, num, dynamicStore, assetIssueStore);
Expand All @@ -550,7 +552,7 @@ private void addTrxOrToken(MarketOrderCapsule orderCapsule, long num) {

byte[] buyTokenId = orderCapsule.getBuyTokenId();
if (Arrays.equals(buyTokenId, "_".getBytes())) {
accountCapsule.setBalance(Math.addExact(accountCapsule.getBalance(), num));
accountCapsule.setBalance(MathWrapper.addExact(accountCapsule.getBalance(), num));
} else {
accountCapsule
.addAssetAmountV2(buyTokenId, num, dynamicStore, assetIssueStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
Expand Down Expand Up @@ -64,8 +65,8 @@ public boolean execute(Object object) throws ContractExeException {
//subtract from owner address
byte[] ownerAddress = participateAssetIssueContract.getOwnerAddress().toByteArray();
AccountCapsule ownerAccount = accountStore.get(ownerAddress);
long balance = Math.subtractExact(ownerAccount.getBalance(), cost);
balance = Math.subtractExact(balance, fee);
long balance = MathWrapper.subtractExact(ownerAccount.getBalance(), cost);
balance = MathWrapper.subtractExact(balance, fee);
ownerAccount.setBalance(balance);
byte[] key = participateAssetIssueContract.getAssetName().toByteArray();

Expand All @@ -74,14 +75,14 @@ public boolean execute(Object object) throws ContractExeException {
assetIssueCapsule = Commons
.getAssetIssueStoreFinal(dynamicStore, assetIssueStore, assetIssueV2Store).get(key);

long exchangeAmount = Math.multiplyExact(cost, assetIssueCapsule.getNum());
exchangeAmount = Math.floorDiv(exchangeAmount, assetIssueCapsule.getTrxNum());
long exchangeAmount = MathWrapper.multiplyExact(cost, assetIssueCapsule.getNum());
exchangeAmount = MathWrapper.floorDiv(exchangeAmount, assetIssueCapsule.getTrxNum());
ownerAccount.addAssetAmountV2(key, exchangeAmount, dynamicStore, assetIssueStore);

//add to to_address
byte[] toAddress = participateAssetIssueContract.getToAddress().toByteArray();
AccountCapsule toAccount = accountStore.get(toAddress);
toAccount.setBalance(Math.addExact(toAccount.getBalance(), cost));
toAccount.setBalance(MathWrapper.addExact(toAccount.getBalance(), cost));
if (!toAccount.reduceAssetAmountV2(key, exchangeAmount, dynamicStore, assetIssueStore)) {
throw new ContractExeException("reduceAssetAmount failed !");
}
Expand Down Expand Up @@ -156,7 +157,7 @@ public boolean validate() throws ContractValidateException {
try {
//Whether the balance is enough
long fee = calcFee();
if (ownerAccount.getBalance() < Math.addExact(amount, fee)) {
if (ownerAccount.getBalance() < MathWrapper.addExact(amount, fee)) {
throw new ContractValidateException("No enough balance !");
}

Expand All @@ -181,8 +182,8 @@ public boolean validate() throws ContractValidateException {

int trxNum = assetIssueCapsule.getTrxNum();
int num = assetIssueCapsule.getNum();
long exchangeAmount = Math.multiplyExact(amount, num);
exchangeAmount = Math.floorDiv(exchangeAmount, trxNum);
long exchangeAmount = MathWrapper.multiplyExact(amount, num);
exchangeAmount = MathWrapper.floorDiv(exchangeAmount, trxNum);
if (exchangeAmount <= 0) {
throw new ContractValidateException("Can not process the exchange!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.tron.common.math.MathWrapper;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
Expand Down Expand Up @@ -97,7 +98,7 @@ public boolean execute(Object result)
//adjust and verify total shielded pool value
try {
Commons.adjustTotalShieldedPoolValue(
Math.addExact(Math.subtractExact(shieldedTransferContract.getToAmount(),
MathWrapper.addExact(MathWrapper.subtractExact(shieldedTransferContract.getToAmount(),
shieldedTransferContract.getFromAmount()), fee), dynamicStore);
} catch (ArithmeticException | BalanceInsufficientException e) {
logger.debug(e.getMessage(), e);
Expand Down Expand Up @@ -327,9 +328,10 @@ private void checkProof(List<SpendDescription> spendDescriptions,
long totalShieldedPoolValue = dynamicStore
.getTotalShieldedPoolValue();
try {
valueBalance = Math.addExact(Math.subtractExact(shieldedTransferContract.getToAmount(),
valueBalance = MathWrapper.addExact(
MathWrapper.subtractExact(shieldedTransferContract.getToAmount(),
shieldedTransferContract.getFromAmount()), fee);
totalShieldedPoolValue = Math.subtractExact(totalShieldedPoolValue, valueBalance);
totalShieldedPoolValue = MathWrapper.subtractExact(totalShieldedPoolValue, valueBalance);
} catch (ArithmeticException e) {
logger.debug(e.getMessage(), e);
throw new ZkProofValidateException(e.getMessage(), true);
Expand Down Expand Up @@ -452,7 +454,7 @@ private void validateTransparent(ShieldedTransferContract shieldedTransferContra
AccountCapsule toAccount = accountStore.get(toAddress);
if (toAccount != null) {
try {
Math.addExact(getZenBalance(toAccount), toAmount);
MathWrapper.addExact(getZenBalance(toAccount), toAmount);
} catch (ArithmeticException e) {
logger.debug(e.getMessage(), e);
throw new ContractValidateException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
import org.tron.common.utils.StringUtil;
Expand Down Expand Up @@ -58,7 +59,7 @@ public boolean execute(Object object) throws ContractExeException {
fee = fee + dynamicStore.getCreateNewAccountFeeInSystemContract();
}

Commons.adjustBalance(accountStore, ownerAddress, -(Math.addExact(fee, amount)));
Commons.adjustBalance(accountStore, ownerAddress, -(MathWrapper.addExact(fee, amount)));
if (dynamicStore.supportBlackHoleOptimization()) {
dynamicStore.burnTrx(fee);
} else {
Expand Down Expand Up @@ -156,15 +157,15 @@ public boolean validate() throws ContractValidateException {
}
}

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

if (toAccount != null) {
Math.addExact(toAccount.getBalance(), amount);
MathWrapper.addExact(toAccount.getBalance(), amount);
}
} catch (ArithmeticException e) {
logger.debug(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Commons;
import org.tron.common.utils.DecodeUtil;
Expand Down Expand Up @@ -177,7 +178,7 @@ public boolean validate() throws ContractValidateException {
assetBalance = toAccount.getAsset(dynamicStore, ByteArray.toStr(assetName));
if (assetBalance != null) {
try {
assetBalance = Math.addExact(assetBalance, amount); //check if overflow
assetBalance = MathWrapper.addExact(assetBalance, amount); //check if overflow
} catch (Exception e) {
logger.debug(e.getMessage(), e);
throw new ContractValidateException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.MathWrapper;
import org.tron.common.utils.DecodeUtil;
import org.tron.common.utils.StringUtil;
import org.tron.core.capsule.AccountCapsule;
Expand Down Expand Up @@ -82,7 +83,7 @@ public boolean execute(Object result) throws ContractExeException {
* ((double) (dynamicStore.getTotalNetLimit()) / dynamicStore.getTotalNetWeight()));
transferUsage = (long) (receiverCapsule.getNetUsage()
* ((double) (unDelegateBalance) / receiverCapsule.getAllFrozenBalanceForBandwidth()));
transferUsage = Math.min(unDelegateMaxUsage, transferUsage);
transferUsage = MathWrapper.min(unDelegateMaxUsage, transferUsage);

receiverCapsule.addAcquiredDelegatedFrozenV2BalanceForBandwidth(-unDelegateBalance);
}
Expand All @@ -105,7 +106,7 @@ public boolean execute(Object result) throws ContractExeException {
* ((double) (dynamicStore.getTotalEnergyCurrentLimit()) / dynamicStore.getTotalEnergyWeight()));
transferUsage = (long) (receiverCapsule.getEnergyUsage()
* ((double) (unDelegateBalance) / receiverCapsule.getAllFrozenBalanceForEnergy()));
transferUsage = Math.min(unDelegateMaxUsage, transferUsage);
transferUsage = MathWrapper.min(unDelegateMaxUsage, transferUsage);

receiverCapsule.addAcquiredDelegatedFrozenV2BalanceForEnergy(-unDelegateBalance);
}
Expand Down
Loading
Loading