Skip to content

Commit a7def45

Browse files
committed
add new proposal 35 and separate the function, forbid transfer to contract from proposal 32
1 parent b46814a commit a7def45

File tree

9 files changed

+64
-9
lines changed

9 files changed

+64
-9
lines changed

src/main/java/org/tron/core/Wallet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ public Protocol.ChainParameters getChainParameters() {
921921
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059())
922922
.build());
923923

924+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
925+
.setKey("getForbidTransferToContract")
926+
.setValue(dbManager.getDynamicPropertiesStore().getForbidTransferToContract())
927+
.build());
928+
924929
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
925930
.setKey("getAdaptiveResourceLimitTargetRatio")
926931
.setValue(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public boolean validate() throws ContractValidateException {
124124
if (toAccount == null) {
125125
fee = fee + dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract();
126126
}
127-
//after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed.
128-
if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1
127+
//after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed.
128+
if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1
129129
&& toAccount != null
130130
&& toAccount.getType() == AccountType.Contract) {
131131
throw new ContractValidateException("Cannot transfer trx to smartContract.");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ public boolean validate() throws ContractValidateException {
166166

167167
AccountCapsule toAccount = this.dbManager.getAccountStore().get(toAddress);
168168
if (toAccount != null) {
169-
//after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed.
170-
if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1
169+
//after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed.
170+
if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1
171171
&& toAccount.getType() == AccountType.Contract) {
172172
throw new ContractValidateException("Cannot transfer asset to smartContract.");
173173
}

src/main/java/org/tron/core/config/Parameter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ChainConstant {
2323
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
2424
public static final int MAX_VOTE_NUMBER = 30;
2525
public static final int MAX_FROZEN_NUMBER = 1;
26-
public static final int BLOCK_VERSION = 9;
26+
public static final int BLOCK_VERSION = 10;
2727
}
2828

2929
public class NodeConstant {
@@ -84,7 +84,8 @@ public enum ForkBlockVersionEnum {
8484
VERSION_3_2_2(6),
8585
VERSION_3_5(7),
8686
VERSION_3_6(8),
87-
VERSION_3_6_5(9);
87+
VERSION_3_6_5(9),
88+
VERSION_3_6_6(10);
8889

8990
@Getter
9091
private int value;

src/main/java/org/tron/core/config/args/Args.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ public class Args {
361361
@Setter
362362
private long allowTvmSolidity059; //committee parameter
363363

364+
@Getter
365+
@Setter
366+
private long forbidTransferToContract; //committee parameter
367+
364368
@Getter
365369
@Setter
366370
private int tcpNettyWorkThreadNum;
@@ -529,6 +533,7 @@ public static void clearParam() {
529533
INSTANCE.allowDelegateResource = 0;
530534
INSTANCE.allowSameTokenName = 0;
531535
INSTANCE.allowTvmSolidity059 = 0;
536+
INSTANCE.forbidTransferToContract = 0;
532537
INSTANCE.tcpNettyWorkThreadNum = 0;
533538
INSTANCE.udpNettyWorkThreadNum = 0;
534539
INSTANCE.p2pNodeId = "";
@@ -888,6 +893,10 @@ public static void setParam(final String[] args, final String confFileName) {
888893
config.hasPath("committee.allowTvmSolidity059") ? config
889894
.getInt("committee.allowTvmSolidity059") : 0;
890895

896+
INSTANCE.forbidTransferToContract =
897+
config.hasPath("committee.forbidTransferToContract") ? config
898+
.getInt("committee.forbidTransferToContract") : 0;
899+
891900
INSTANCE.tcpNettyWorkThreadNum = config.hasPath("node.tcpNettyWorkThreadNum") ? config
892901
.getInt("node.tcpNettyWorkThreadNum") : 0;
893902

src/main/java/org/tron/core/db/DynamicPropertiesStore.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ private static class DynamicResourceProperties {
170170

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

173+
private static final byte[] FORBID_TRANSFER_TO_CONTRACT = "FORBID_TRANSFER_TO_CONTRACT".getBytes();
174+
173175
//Used only for protobuf data filter , once,value is 0,1
174176
private static final byte[] ALLOW_PROTO_FILTER_NUM = "ALLOW_PROTO_FILTER_NUM"
175177
.getBytes();
@@ -522,6 +524,12 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
522524
this.saveAllowTvmSolidity059(Args.getInstance().getAllowTvmSolidity059());
523525
}
524526

527+
try {
528+
this.getForbidTransferToContract();
529+
} catch (IllegalArgumentException e) {
530+
this.saveForbidTransferToContract(Args.getInstance().getForbidTransferToContract());
531+
}
532+
525533
try {
526534
this.getAvailableContractType();
527535
} catch (IllegalArgumentException e) {
@@ -1378,6 +1386,17 @@ public long getAllowTvmSolidity059() {
13781386
.orElseThrow(() -> new IllegalArgumentException("not found ALLOW_TVM_SOLIDITY_059"));
13791387
}
13801388

1389+
public void saveForbidTransferToContract(long value) {
1390+
this.put(FORBID_TRANSFER_TO_CONTRACT,
1391+
new BytesCapsule(ByteArray.fromLong(value)));
1392+
}
1393+
1394+
public long getForbidTransferToContract() {
1395+
return Optional.ofNullable(getUnchecked(FORBID_TRANSFER_TO_CONTRACT))
1396+
.map(BytesCapsule::getData)
1397+
.map(ByteArray::toLong)
1398+
.orElseThrow(() -> new IllegalArgumentException("not found FORBID_TRANSFER_TO_CONTRACT"));
1399+
}
13811400

13821401

13831402
public void saveAvailableContractType(byte[] value) {

src/main/java/org/tron/core/services/ProposalService.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public enum ProposalType {
5454
ALLOW_CHANGE_DELEGATION(30), //1, 30
5555
WITNESS_127_PAY_PER_BLOCK(31), //drop, 31
5656
ALLOW_TVM_SOLIDITY_059(32), // 1, 32
57-
ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33); // 10, 33
57+
ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33), // 10, 33
58+
FORBID_TRANSFER_TO_CONTRACT(35); // 1, 35
5859

5960
ProposalType(long code) {
6061
this.code = code;
@@ -330,6 +331,22 @@ public static void validator(Manager manager, long code, long value)
330331
}
331332
break;
332333
}
334+
case FORBID_TRANSFER_TO_CONTRACT: {
335+
if (!manager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_6_6)) {
336+
337+
throw new ContractValidateException(BAD_PARAM_ID);
338+
}
339+
if (value != 1) {
340+
throw new ContractValidateException(
341+
"This value[FORBID_TRANSFER_TO_CONTRACT] is only allowed to be 1");
342+
}
343+
if (manager.getDynamicPropertiesStore().getAllowCreationOfContracts() == 0) {
344+
throw new ContractValidateException(
345+
"[ALLOW_CREATION_OF_CONTRACTS] proposal must be approved "
346+
+ "before [ALLOW_TVM_SOLIDITY_059] can be proposed");
347+
}
348+
break;
349+
}
333350
default:
334351
break;
335352
}
@@ -492,6 +509,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
492509
manager.getDynamicPropertiesStore().saveWitness127PayPerBlock(entry.getValue());
493510
break;
494511
}
512+
case FORBID_TRANSFER_TO_CONTRACT: {
513+
manager.getDynamicPropertiesStore().saveForbidTransferToContract(entry.getValue());
514+
break;
515+
}
495516
default:
496517
find = false;
497518
break;

src/test/java/org/tron/core/actuator/TransferActuatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public void insufficientFee() {
466466
@Test
467467
public void transferToSmartContractAddress()
468468
throws ContractExeException, ReceiptCheckErrException, VMIllegalException, ContractValidateException, BalanceInsufficientException {
469-
dbManager.getDynamicPropertiesStore().saveAllowTvmSolidity059(1);
469+
dbManager.getDynamicPropertiesStore().saveForbidTransferToContract(1);
470470
String contractName = "testContract";
471471
byte[] address = Hex.decode(OWNER_ADDRESS);
472472
String ABI =

src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ public void SameTokenNameCloseAssetNameTest() {
13501350
@Test
13511351
public void transferToContractAddress()
13521352
throws ContractExeException, ReceiptCheckErrException, VMIllegalException, ContractValidateException, BalanceInsufficientException {
1353-
dbManager.getDynamicPropertiesStore().saveAllowTvmSolidity059(1);
1353+
dbManager.getDynamicPropertiesStore().saveForbidTransferToContract(1);
13541354
createAssertSameTokenNameActive();
13551355
VMConfig.initAllowMultiSign(1);
13561356
VMConfig.initAllowTvmTransferTrc10(1);

0 commit comments

Comments
 (0)