Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into spend_all_…
Browse files Browse the repository at this point in the history
…energy_when_except
  • Loading branch information
tjchern committed Aug 25, 2018
2 parents c31695c + 7383e13 commit ca1d414
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/org/tron/common/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -432,6 +436,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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ private void validateValue(Map.Entry<Long, Long> 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(
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/tron/core/capsule/AccountCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
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 @@ -240,6 +240,10 @@ public class Args {
@Setter
private long proposalExpireTime; // (ms)

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

@Getter
@Setter
private int tcpNettyWorkThreadNum;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/tron/core/db/DynamicPropertiesStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
try {
this.getAllowCreationOfContracts();
} catch (IllegalArgumentException e) {
this.saveAllowCreationOfContracts(0L);
this.saveAllowCreationOfContracts(Args.getInstance().getAllowCreationOfContracts());
}

try {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,7 @@ block = {
maintenanceTimeInterval = 21600000
proposalExpireTime = 259200000 // 3 day: 259200000(ms)
}

committee = {
allowCreationOfContracts = 0 //mainnet:0 (reset by committee),test:1
}
1 change: 1 addition & 0 deletions src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(1L, args.getAllowCreationOfContracts());
}
}
4 changes: 4 additions & 0 deletions src/test/resources/config-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,7 @@ seed.node = {
block = {
needSyncCheck = true # first node : false, other : true
}

committee = {
allowCreationOfContracts = 1 //mainnet:0 (reset by committee),test:1
}

0 comments on commit ca1d414

Please sign in to comment.