From 36dbc3d5685fc94906f5d1caffd0b9f332c3ed90 Mon Sep 17 00:00:00 2001 From: sean-liu55 Date: Fri, 24 Aug 2018 16:19:27 +0800 Subject: [PATCH 1/4] using ALLOW_CREATION_OF_CONTRACTS --- src/main/java/org/tron/common/runtime/Runtime.java | 9 +++++++++ .../org/tron/core/actuator/ProposalCreateActuator.java | 6 ++++++ src/main/java/org/tron/core/config/args/Args.java | 9 +++++++++ .../java/org/tron/core/db/DynamicPropertiesStore.java | 2 +- src/main/resources/config.conf | 4 ++++ src/test/java/org/tron/core/config/args/ArgsTest.java | 1 + 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/tron/common/runtime/Runtime.java b/src/main/java/org/tron/common/runtime/Runtime.java index 35fa37b4b86..f284b41bd8e 100644 --- a/src/main/java/org/tron/common/runtime/Runtime.java +++ b/src/main/java/org/tron/common/runtime/Runtime.java @@ -348,6 +348,10 @@ private long getEnergyLimit(AccountCapsule creator, AccountCapsule caller, **/ private void create() throws ContractExeException, ContractValidateException { + if(!deposit.getDbManager().getDynamicPropertiesStore().supportVM()){ + throw new ContractExeException("VM work is off, need to be opened by the committee"); + } + CreateSmartContract contract = ContractCapsule.getSmartContractFromTransaction(trx); SmartContract newSmartContract = contract.getNewContract(); @@ -436,6 +440,11 @@ private void create() private void call() throws ContractExeException, ContractValidateException { + + if(!deposit.getDbManager().getDynamicPropertiesStore().supportVM()){ + throw new ContractExeException("VM work is off, need to be opened by the committee"); + } + Contract.TriggerSmartContract contract = ContractCapsule.getTriggerContractFromTransaction(trx); if (contract == null) { return; diff --git a/src/main/java/org/tron/core/actuator/ProposalCreateActuator.java b/src/main/java/org/tron/core/actuator/ProposalCreateActuator.java index 46f1da38ccb..21baf848d41 100755 --- a/src/main/java/org/tron/core/actuator/ProposalCreateActuator.java +++ b/src/main/java/org/tron/core/actuator/ProposalCreateActuator.java @@ -129,6 +129,12 @@ private void validateValue(Map.Entry entry) throws ContractValidateE } return; } + case (9):{ + if(entry.getValue() != 1){ + throw new ContractValidateException( + "This value[ALLOW_CREATION_OF_CONTRACTS] is only allowed to be 1"); + } + } case (10):{ if(dbManager.getDynamicPropertiesStore().getRemoveThePowerOfTheGr() == -1){ throw new ContractValidateException( diff --git a/src/main/java/org/tron/core/config/args/Args.java b/src/main/java/org/tron/core/config/args/Args.java index 09248fd33ae..e06737c4b6a 100644 --- a/src/main/java/org/tron/core/config/args/Args.java +++ b/src/main/java/org/tron/core/config/args/Args.java @@ -240,6 +240,10 @@ public class Args { @Setter private long proposalExpireTime; // (ms) + @Getter + @Setter + private long allowCreationOfContracts; //committee parameter + @Getter @Setter private int tcpNettyWorkThreadNum; @@ -336,6 +340,7 @@ public static void clearParam() { INSTANCE.solidityHttpPort = 0; INSTANCE.maintenanceTimeInterval = 0; INSTANCE.proposalExpireTime = 0; + INSTANCE.allowCreationOfContracts = 0; INSTANCE.tcpNettyWorkThreadNum = 0; INSTANCE.udpNettyWorkThreadNum = 0; INSTANCE.p2pNodeId = ""; @@ -546,6 +551,10 @@ public static void setParam(final String[] args, final String confFileName) { config.hasPath("block.proposalExpireTime") ? config .getInt("block.proposalExpireTime") : 259200000L; + INSTANCE.allowCreationOfContracts = + config.hasPath("committee.allowCreationOfContracts") ? config + .getInt("committee.allowCreationOfContracts") : 0; + INSTANCE.tcpNettyWorkThreadNum = config.hasPath("node.tcpNettyWorkThreadNum") ? config .getInt("node.tcpNettyWorkThreadNum") : 0; diff --git a/src/main/java/org/tron/core/db/DynamicPropertiesStore.java b/src/main/java/org/tron/core/db/DynamicPropertiesStore.java index 881b35ca296..1d4e397ab56 100755 --- a/src/main/java/org/tron/core/db/DynamicPropertiesStore.java +++ b/src/main/java/org/tron/core/db/DynamicPropertiesStore.java @@ -359,7 +359,7 @@ private DynamicPropertiesStore(@Value("properties") String dbName) { try { this.getAllowCreationOfContracts(); } catch (IllegalArgumentException e) { - this.saveAllowCreationOfContracts(0L); + this.saveAllowCreationOfContracts(Args.getInstance().getAllowCreationOfContracts()); } try { diff --git a/src/main/resources/config.conf b/src/main/resources/config.conf index 81f9856ad9a..5660498ec2e 100644 --- a/src/main/resources/config.conf +++ b/src/main/resources/config.conf @@ -367,3 +367,7 @@ block = { maintenanceTimeInterval = 21600000 proposalExpireTime = 259200000 // 3 day: 259200000(ms) } + +committee = { + allowCreationOfContracts = 0; //mainnet:0 (reset by committee),test:1 +} \ No newline at end of file diff --git a/src/test/java/org/tron/core/config/args/ArgsTest.java b/src/test/java/org/tron/core/config/args/ArgsTest.java index fe14f55249c..31999487717 100644 --- a/src/test/java/org/tron/core/config/args/ArgsTest.java +++ b/src/test/java/org/tron/core/config/args/ArgsTest.java @@ -75,5 +75,6 @@ public void get() { Assert.assertEquals(Long.MAX_VALUE, args.getMaxConnectionAgeInMillis()); Assert.assertEquals(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE, args.getMaxMessageSize()); Assert.assertEquals(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, args.getMaxHeaderListSize()); + Assert.assertEquals(0L, args.getAllowCreationOfContracts()); } } From b68de6eb24971d8b9ca5fa31b1f0d42d2edceb09 Mon Sep 17 00:00:00 2001 From: sean-liu55 Date: Fri, 24 Aug 2018 16:40:01 +0800 Subject: [PATCH 2/4] minor change --- src/main/resources/config.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config.conf b/src/main/resources/config.conf index 5660498ec2e..517c81642f0 100644 --- a/src/main/resources/config.conf +++ b/src/main/resources/config.conf @@ -369,5 +369,5 @@ block = { } committee = { - allowCreationOfContracts = 0; //mainnet:0 (reset by committee),test:1 + allowCreationOfContracts = 0 //mainnet:0 (reset by committee),test:1 } \ No newline at end of file From b1518bcb079bb85d87d736c6f4ade9d3d524f966 Mon Sep 17 00:00:00 2001 From: sean-liu55 Date: Fri, 24 Aug 2018 17:06:59 +0800 Subject: [PATCH 3/4] fix unitTest --- src/test/java/org/tron/core/config/args/ArgsTest.java | 2 +- src/test/resources/config-test.conf | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/tron/core/config/args/ArgsTest.java b/src/test/java/org/tron/core/config/args/ArgsTest.java index 31999487717..2e5779f9290 100644 --- a/src/test/java/org/tron/core/config/args/ArgsTest.java +++ b/src/test/java/org/tron/core/config/args/ArgsTest.java @@ -75,6 +75,6 @@ public void get() { Assert.assertEquals(Long.MAX_VALUE, args.getMaxConnectionAgeInMillis()); Assert.assertEquals(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE, args.getMaxMessageSize()); Assert.assertEquals(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, args.getMaxHeaderListSize()); - Assert.assertEquals(0L, args.getAllowCreationOfContracts()); + Assert.assertEquals(1L, args.getAllowCreationOfContracts()); } } diff --git a/src/test/resources/config-test.conf b/src/test/resources/config-test.conf index 03b6ee47cb7..677bca99aad 100644 --- a/src/test/resources/config-test.conf +++ b/src/test/resources/config-test.conf @@ -252,3 +252,7 @@ seed.node = { block = { needSyncCheck = true # first node : false, other : true } + +committee = { + allowCreationOfContracts = 1 //mainnet:0 (reset by committee),test:1 +} \ No newline at end of file From 16c92dd8f9aff016178a739924433e5d653273dd Mon Sep 17 00:00:00 2001 From: sean-liu55 Date: Fri, 24 Aug 2018 17:19:16 +0800 Subject: [PATCH 4/4] Optimized display --- src/main/java/org/tron/core/Wallet.java | 10 ++++++++++ .../java/org/tron/core/capsule/AccountCapsule.java | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/org/tron/core/Wallet.java b/src/main/java/org/tron/core/Wallet.java index 3bb2ecd3a3c..b33f81bb949 100755 --- a/src/main/java/org/tron/core/Wallet.java +++ b/src/main/java/org/tron/core/Wallet.java @@ -71,6 +71,7 @@ import org.tron.core.capsule.TransactionCapsule; import org.tron.core.capsule.TransactionResultCapsule; import org.tron.core.capsule.WitnessCapsule; +import org.tron.core.config.Parameter.ChainConstant; import org.tron.core.config.Parameter.ChainParameters; import org.tron.core.db.AccountIdIndexStore; import org.tron.core.db.AccountStore; @@ -278,9 +279,18 @@ public Account getAccount(Account account) { EnergyProcessor energyProcessor = new EnergyProcessor(dbManager); energyProcessor.updateUsage(accountCapsule); + long genesisTimeStamp = dbManager.getGenesisBlock().getTimeStamp(); + accountCapsule.setLatestConsumeTime(genesisTimeStamp + + ChainConstant.BLOCK_PRODUCED_INTERVAL * accountCapsule.getLatestConsumeTime()); + accountCapsule.setLatestConsumeFreeTime(genesisTimeStamp + + ChainConstant.BLOCK_PRODUCED_INTERVAL * accountCapsule.getLatestConsumeFreeTime()); + accountCapsule.setLatestConsumeTimeForEnergy(genesisTimeStamp + + ChainConstant.BLOCK_PRODUCED_INTERVAL * accountCapsule.getLatestConsumeTimeForEnergy()); + return accountCapsule.getInstance(); } + public Account getAccountById(Account account) { AccountStore accountStore = dbManager.getAccountStore(); AccountIdIndexStore accountIdIndexStore = dbManager.getAccountIdIndexStore(); diff --git a/src/main/java/org/tron/core/capsule/AccountCapsule.java b/src/main/java/org/tron/core/capsule/AccountCapsule.java index 05cc545f169..1d535072b30 100644 --- a/src/main/java/org/tron/core/capsule/AccountCapsule.java +++ b/src/main/java/org/tron/core/capsule/AccountCapsule.java @@ -484,6 +484,10 @@ public void setLatestConsumeTimeForEnergy(long latest_time) { .build()).build(); } + public long getLatestConsumeTimeForEnergy() { + return this.account.getAccountResource().getLatestConsumeTimeForEnergy(); + } + public long getFreeNetUsage() { return this.account.getFreeNetUsage(); }