Skip to content
Merged
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
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public enum ForkBlockVersionEnum {
VERSION_4_7_5(30, 1596780000000L, 80),
VERSION_4_7_7(31, 1596780000000L, 80),
VERSION_4_8_0(32, 1596780000000L, 80),
VERSION_4_8_1(33, 1596780000000L, 80);
VERSION_4_8_0_1(33, 1596780000000L, 70),
VERSION_4_8_1(34, 1596780000000L, 80);
// if add a version, modify BLOCK_VERSION simultaneously

@Getter
Expand Down Expand Up @@ -76,7 +77,7 @@ public class ChainConstant {
public static final int SINGLE_REPEAT = 1;
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 33;
public static final int BLOCK_VERSION = 34;
public static final long FROZEN_PERIOD = 86_400_000L;
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
public static final long TRX_PRECISION = 1000_000L;
Expand Down
30 changes: 30 additions & 0 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import org.tron.core.capsule.TransactionRetCapsule;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.core.capsule.utils.TransactionUtil;
import org.tron.core.config.Parameter;
import org.tron.core.config.Parameter.ChainConstant;
import org.tron.core.config.args.Args;
import org.tron.core.consensus.ProposalController;
Expand Down Expand Up @@ -876,6 +877,11 @@ public boolean pushTransaction(final TransactionCapsule trx)
return false;
}

if (isExchangeTransaction(trx.getInstance())) {
throw new ContractValidateException("ExchangeTransactionContract is rejected");
}


pushTransactionQueue.add(trx);
Metrics.gaugeInc(MetricKeys.Gauge.MANAGER_QUEUE, 1,
MetricLabels.Gauge.QUEUE_QUEUED);
Expand Down Expand Up @@ -1701,6 +1707,11 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
accountSet.add(ownerAddress);
}
}

if (isExchangeTransaction(transaction)) {
continue;
}

if (ownerAddressSet.contains(ownerAddress)) {
trx.setVerified(false);
}
Expand Down Expand Up @@ -1774,6 +1785,24 @@ private boolean isShieldedTransaction(Transaction transaction) {
}
}

private boolean isExchangeTransaction(Transaction transaction) {
Contract contract = transaction.getRawData().getContract(0);
switch (contract.getType()) {
case ExchangeTransactionContract: {
return true;
}
default:
return false;
}
}

private void rejectExchangeTransaction(Transaction transaction) throws ContractValidateException {
if (isExchangeTransaction(transaction) && chainBaseManager.getForkController()
.pass(Parameter.ForkBlockVersionEnum.VERSION_4_8_0_1)) {
throw new ContractValidateException("ExchangeTransactionContract is rejected");
}
}

public TransactionStore getTransactionStore() {
return chainBaseManager.getTransactionStore();
}
Expand Down Expand Up @@ -1828,6 +1857,7 @@ private void processBlock(BlockCapsule block, List<TransactionCapsule> txs)
List<TransactionInfo> results = new ArrayList<>();
long num = block.getNum();
for (TransactionCapsule transactionCapsule : block.getTransactions()) {
rejectExchangeTransaction(transactionCapsule.getInstance());
if (chainBaseManager.getDynamicPropertiesStore().allowConsensusLogicOptimization()
&& transactionCapsule.retCountIsGreatThanContractCount()) {
throw new BadBlockException(String.format("The result count %d of this transaction %s is "
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/java/org/tron/program/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class Version {

public static final String VERSION_NAME = "GreatVoyage-v4.7.7-243-gb3555dd655";
public static final String VERSION_CODE = "18631";
public static final String VERSION_NAME = "GreatVoyage-v4.8.0-1-g45e3bf88ca";
public static final String VERSION_CODE = "18634";
private static final String VERSION = "4.8.1";

public static String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.tron.core.actuator;

import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import static org.tron.core.config.Parameter.ChainSymbol.TRX_SYMBOL_BYTES;

import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import junit.framework.TestCase;
Expand All @@ -13,18 +16,30 @@
import org.junit.Before;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.crypto.ECKey;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ForkController;
import org.tron.common.utils.PublicMethod;
import org.tron.consensus.base.Param;
import org.tron.consensus.base.Param.Miner;
import org.tron.core.Constant;
import org.tron.core.Wallet;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.AssetIssueCapsule;
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.ExchangeCapsule;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.capsule.TransactionResultCapsule;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.core.config.Parameter;
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
import org.tron.core.config.args.Args;
import org.tron.core.db.Manager;
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.exception.ItemNotFoundException;
import org.tron.protos.Protocol.AccountType;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.Transaction.Result.code;
import org.tron.protos.contract.AssetIssueContractOuterClass;
import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract;
Expand Down Expand Up @@ -1674,7 +1689,7 @@ public void noContract() {
public void invalidContractType() {
ExchangeTransactionActuator actuator = new ExchangeTransactionActuator();
// create AssetIssueContract, not a valid ClearABI contract , which will throw e expectipon
Any invalidContractTypes = Any.pack(AssetIssueContractOuterClass.AssetIssueContract.newBuilder()
Any invalidContractTypes = Any.pack(AssetIssueContract.newBuilder()
.build());
actuator.setChainBaseManager(dbManager.getChainBaseManager())
.setAny(invalidContractTypes);
Expand Down Expand Up @@ -1725,4 +1740,92 @@ private void processAndCheckInvalid(ExchangeTransactionActuator actuator,
}
}

/**
* isExchangeTransaction
*/
@Test
public void isExchangeTransactionPush() {
try {
TransactionCapsule transactionCap = new TransactionCapsule(
ExchangeTransactionContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS_SECOND)))
.setExchangeId(1)
.setTokenId(ByteString.copyFrom("_".getBytes()))
.setQuant(1)
.setExpected(1)
.build(), ContractType.ExchangeTransactionContract);
dbManager.pushTransaction(transactionCap);

} catch (Exception e) {
Assert.assertTrue(true);
}
}

@Test
public void isExchangeTransactionGenerate() {
try {

String key = PublicMethod.getRandomPrivateKey();
byte[] privateKey = ByteArray.fromHexString(key);
final ECKey ecKey = ECKey.fromPrivate(privateKey);
byte[] address = ecKey.getAddress();
WitnessCapsule witnessCapsule = new WitnessCapsule(ByteString.copyFrom(address));

String OWNER_ADDRESS_SECOND =
Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
TransactionCapsule transactionCap = new TransactionCapsule(
ExchangeTransactionContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS_SECOND)))
.setExchangeId(1)
.setTokenId(ByteString.copyFrom("_".getBytes()))
.setQuant(1)
.setExpected(1)
.build(), ContractType.ExchangeTransactionContract);
dbManager.getPendingTransactions().add(transactionCap);
Param param = Param.getInstance();
Miner miner = param.new Miner(privateKey, witnessCapsule.getAddress(),
witnessCapsule.getAddress());
BlockCapsule blockCapsule = dbManager
.generateBlock(miner, 1533529947843L, System.currentTimeMillis() + 1000);
} catch (Exception e) {
Assert.assertTrue(false);
}
}

@Test
public void rejectExchangeTransaction() {
try {
long maintenanceTimeInterval = dbManager.getDynamicPropertiesStore()
.getMaintenanceTimeInterval();
long hardForkTime =
((ForkBlockVersionEnum.VERSION_4_0_1.getHardForkTime() - 1) / maintenanceTimeInterval + 1)
* maintenanceTimeInterval;
dbManager.getDynamicPropertiesStore()
.saveLatestBlockHeaderTimestamp(hardForkTime + 1);
byte[] stats = new byte[27];
Arrays.fill(stats, (byte) 1);
dbManager.getDynamicPropertiesStore()
.statsByVersion(ForkBlockVersionEnum.VERSION_4_8_0_1.getValue(), stats);
boolean flag = ForkController.instance().pass(ForkBlockVersionEnum.VERSION_4_8_0_1);
Assert.assertTrue(flag);
String OWNER_ADDRESS_SECOND =
Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
TransactionCapsule transactionCap = new TransactionCapsule(
ExchangeTransactionContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS_SECOND)))
.setExchangeId(1)
.setTokenId(ByteString.copyFrom("_".getBytes()))
.setQuant(1)
.setExpected(1)
.build(), ContractType.ExchangeTransactionContract);
Method rejectExchangeTransaction = Manager.class.getDeclaredMethod(
"rejectExchangeTransaction", org.tron.protos.Protocol.Transaction.class);
rejectExchangeTransaction.setAccessible(true);
Exception ex = assertThrows(InvocationTargetException.class, () -> {
rejectExchangeTransaction.invoke(dbManager, transactionCap.getInstance());
});
} catch (Exception e) {
fail();
}
}
}