Skip to content

Commit

Permalink
Merge pull request #2824 from tronprotocol/Hotfix/split_proposal32_to_35
Browse files Browse the repository at this point in the history
add new proposal 35 and separate the functionality to forbid transfer asset to smart contract using system contract
  • Loading branch information
taihaofu authored Jan 2, 2020
2 parents b46814a + a60443d commit 1ef144e
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getForbidTransferToContract")
.setValue(dbManager.getDynamicPropertiesStore().getForbidTransferToContract())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAdaptiveResourceLimitTargetRatio")
.setValue(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/tron/core/actuator/TransferActuator.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public boolean validate() throws ContractValidateException {
if (toAccount == null) {
fee = fee + dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract();
}
//after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed.
if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1
//after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed.
if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1
&& toAccount != null
&& toAccount.getType() == AccountType.Contract) {
throw new ContractValidateException("Cannot transfer trx to smartContract.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public boolean validate() throws ContractValidateException {

AccountCapsule toAccount = this.dbManager.getAccountStore().get(toAddress);
if (toAccount != null) {
//after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed.
if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1
//after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed.
if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1
&& toAccount.getType() == AccountType.Contract) {
throw new ContractValidateException("Cannot transfer asset to smartContract.");
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/tron/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ChainConstant {
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_VOTE_NUMBER = 30;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 9;
public static final int BLOCK_VERSION = 10;
}

public class NodeConstant {
Expand Down Expand Up @@ -84,7 +84,8 @@ public enum ForkBlockVersionEnum {
VERSION_3_2_2(6),
VERSION_3_5(7),
VERSION_3_6(8),
VERSION_3_6_5(9);
VERSION_3_6_5(9),
VERSION_3_6_6(10);

@Getter
private int value;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ public class Args {
@Setter
private long allowTvmSolidity059; //committee parameter

@Getter
@Setter
private long forbidTransferToContract; //committee parameter

@Getter
@Setter
private int tcpNettyWorkThreadNum;
Expand Down Expand Up @@ -529,6 +533,7 @@ public static void clearParam() {
INSTANCE.allowDelegateResource = 0;
INSTANCE.allowSameTokenName = 0;
INSTANCE.allowTvmSolidity059 = 0;
INSTANCE.forbidTransferToContract = 0;
INSTANCE.tcpNettyWorkThreadNum = 0;
INSTANCE.udpNettyWorkThreadNum = 0;
INSTANCE.p2pNodeId = "";
Expand Down Expand Up @@ -888,6 +893,10 @@ public static void setParam(final String[] args, final String confFileName) {
config.hasPath("committee.allowTvmSolidity059") ? config
.getInt("committee.allowTvmSolidity059") : 0;

INSTANCE.forbidTransferToContract =
config.hasPath("committee.forbidTransferToContract") ? config
.getInt("committee.forbidTransferToContract") : 0;

INSTANCE.tcpNettyWorkThreadNum = config.hasPath("node.tcpNettyWorkThreadNum") ? config
.getInt("node.tcpNettyWorkThreadNum") : 0;

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/tron/core/db/DynamicPropertiesStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ private static class DynamicResourceProperties {

private static final byte[] ALLOW_TVM_SOLIDITY_059 = "ALLOW_TVM_SOLIDITY_059".getBytes();

private static final byte[] FORBID_TRANSFER_TO_CONTRACT = "FORBID_TRANSFER_TO_CONTRACT".getBytes();

//Used only for protobuf data filter , once,value is 0,1
private static final byte[] ALLOW_PROTO_FILTER_NUM = "ALLOW_PROTO_FILTER_NUM"
.getBytes();
Expand Down Expand Up @@ -522,6 +524,12 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
this.saveAllowTvmSolidity059(Args.getInstance().getAllowTvmSolidity059());
}

try {
this.getForbidTransferToContract();
} catch (IllegalArgumentException e) {
this.saveForbidTransferToContract(Args.getInstance().getForbidTransferToContract());
}

try {
this.getAvailableContractType();
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -1378,6 +1386,17 @@ public long getAllowTvmSolidity059() {
.orElseThrow(() -> new IllegalArgumentException("not found ALLOW_TVM_SOLIDITY_059"));
}

public void saveForbidTransferToContract(long value) {
this.put(FORBID_TRANSFER_TO_CONTRACT,
new BytesCapsule(ByteArray.fromLong(value)));
}

public long getForbidTransferToContract() {
return Optional.ofNullable(getUnchecked(FORBID_TRANSFER_TO_CONTRACT))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElseThrow(() -> new IllegalArgumentException("not found FORBID_TRANSFER_TO_CONTRACT"));
}


public void saveAvailableContractType(byte[] value) {
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/org/tron/core/services/ProposalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public enum ProposalType {
ALLOW_CHANGE_DELEGATION(30), //1, 30
WITNESS_127_PAY_PER_BLOCK(31), //drop, 31
ALLOW_TVM_SOLIDITY_059(32), // 1, 32
ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33); // 10, 33
ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33), // 10, 33
FORBID_TRANSFER_TO_CONTRACT(35); // 1, 35

ProposalType(long code) {
this.code = code;
Expand Down Expand Up @@ -330,6 +331,22 @@ public static void validator(Manager manager, long code, long value)
}
break;
}
case FORBID_TRANSFER_TO_CONTRACT: {
if (!manager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_6_6)) {

throw new ContractValidateException(BAD_PARAM_ID);
}
if (value != 1) {
throw new ContractValidateException(
"This value[FORBID_TRANSFER_TO_CONTRACT] is only allowed to be 1");
}
if (manager.getDynamicPropertiesStore().getAllowCreationOfContracts() == 0) {
throw new ContractValidateException(
"[ALLOW_CREATION_OF_CONTRACTS] proposal must be approved "
+ "before [FORBID_TRANSFER_TO_CONTRACT] can be proposed");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -492,6 +509,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveWitness127PayPerBlock(entry.getValue());
break;
}
case FORBID_TRANSFER_TO_CONTRACT: {
manager.getDynamicPropertiesStore().saveForbidTransferToContract(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public void insufficientFee() {
@Test
public void transferToSmartContractAddress()
throws ContractExeException, ReceiptCheckErrException, VMIllegalException, ContractValidateException, BalanceInsufficientException {
dbManager.getDynamicPropertiesStore().saveAllowTvmSolidity059(1);
dbManager.getDynamicPropertiesStore().saveForbidTransferToContract(1);
String contractName = "testContract";
byte[] address = Hex.decode(OWNER_ADDRESS);
String ABI =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ public void SameTokenNameCloseAssetNameTest() {
@Test
public void transferToContractAddress()
throws ContractExeException, ReceiptCheckErrException, VMIllegalException, ContractValidateException, BalanceInsufficientException {
dbManager.getDynamicPropertiesStore().saveAllowTvmSolidity059(1);
dbManager.getDynamicPropertiesStore().saveForbidTransferToContract(1);
createAssertSameTokenNameActive();
VMConfig.initAllowMultiSign(1);
VMConfig.initAllowTvmTransferTrc10(1);
Expand Down

0 comments on commit 1ef144e

Please sign in to comment.