diff --git a/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/actuator/VMActuator.java b/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/actuator/VMActuator.java index d3d5a20aa..5c385f856 100644 --- a/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/actuator/VMActuator.java +++ b/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/actuator/VMActuator.java @@ -84,6 +84,9 @@ public class VMActuator implements Actuator2 { @Setter private boolean isConstantCall = false; + @Getter + private boolean isSideChainGateWayContractCall; + @Setter private boolean enableEventLinstener; @@ -117,6 +120,10 @@ public void validate(Object object) throws ContractValidateException { //Load Config ConfigLoader.load(context.getStoreFactory()); + if (context.getTrxCap().checkIfSideChainGateWayContractCall(context.getStoreFactory() + .getChainBaseManager().getDynamicPropertiesStore())) { + isSideChainGateWayContractCall = true; + } trx = context.getTrxCap().getInstance(); blockCap = context.getBlockCap(); //Route Type @@ -490,7 +497,9 @@ private void call() if (isConstantCall) { energyLimit = Constant.ENERGY_LIMIT_IN_CONSTANT_TX; } else if (!VMConfig.isVmResourceChargingOn()) { - energyLimit = 10_000_000; + energyLimit = Constant.ENERGY_LIMIT_IN_CHARGING_OFF; + } else if (VMConfig.isAllowDapp152() && isSideChainGateWayContractCall()) { + energyLimit = Constant.ENERGY_LIMIT_ALLOW_DAPP_152; } else { AccountCapsule creator = repository .getAccount(deployedContract.getInstance().getOriginAddress().toByteArray()); diff --git a/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java b/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java index 6b6760456..590aaf522 100644 --- a/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java +++ b/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java @@ -302,7 +302,7 @@ public static void validator(ChainBaseManager manager, ForkUtils forkUtils, * Side Chain proposals */ case ALLOW_CHARGING_FEE: { - if (value != 1 && Long.valueOf(value) != 0) { + if (value != 1 && value != 0) { throw new ContractValidateException( "this value[ENERGY_CHARGING_SWITCH] is only allowed to be 1 or 0"); } @@ -471,6 +471,16 @@ public static void validator(ChainBaseManager manager, ForkUtils forkUtils, } break; } + case ALLOW_DAPP_152: { + if (!forkUtils.pass(ForkBlockVersionEnum.DAPP_CHAIN_1_5_2)) { + throw new ContractValidateException(BAD_PARAM_ID); + } + if (value != 1) { + throw new ContractValidateException( + "this value[ALLOW_DAPP_152] is only allowed to be 1"); + } + break; + } default: break; } @@ -528,7 +538,8 @@ public enum ProposalType { FUND_DISTRIBUTION_DAYS(1_000_009), // 1, 1_000_009 WITNESS_REWARD_PERCENTAGE(1_000_010), // number, 1_000_010 WITNESS_MAX_NUMBER(1_000_011), // number, 1_000_011 - ALLOW_UPDATE_GATEWAY102(1_000_012); // 1 (hard fork), 1_000_012 + ALLOW_UPDATE_GATEWAY102(1_000_012), // 1 (hard fork), 1_000_012 + ALLOW_DAPP_152(1_000_013); //ALLOW_UPDATE_SUN_NETWORK_150(1_000_013); // 1 (hard fork), 1_000_013 private long code; @@ -618,6 +629,7 @@ public static long validateStringContent(ProposalType proposalType, String conte case WITNESS_REWARD_PERCENTAGE: case WITNESS_MAX_NUMBER: case ALLOW_UPDATE_GATEWAY102: + case ALLOW_DAPP_152: //case ALLOW_UPDATE_SUN_NETWORK_150: try { value = Long.valueOf(content); diff --git a/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/vm/config/VMConfig.java b/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/vm/config/VMConfig.java index 63a21b48d..cd2de777e 100644 --- a/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/vm/config/VMConfig.java +++ b/dapp-chain/side-chain/actuator/src/main/java/org/tron/core/vm/config/VMConfig.java @@ -58,6 +58,10 @@ public class VMConfig { @Setter public static boolean isAllowUpdateGateway102 = false; + @Getter + @Setter + public static boolean isAllowDapp152 = false; + private VMConfig() { } @@ -76,6 +80,7 @@ public static boolean vmTraceCompressed() { public static void handleProposalInVM(DynamicPropertiesStore dynamicPropertiesStore) { isVmResourceChargingOn = isChargingResourceProposalOn(dynamicPropertiesStore); isAllowUpdateGateway102 = isAllowUpdateGatewayV102(dynamicPropertiesStore); + isAllowDapp152 = isAllowDapp152(dynamicPropertiesStore); } public static void initVmHardFork(boolean pass) { @@ -131,4 +136,8 @@ private static boolean isAllowUpdateGatewayV102(DynamicPropertiesStore dynamicPr return dynamicPropertiesStore.getAllowUpdateGatewayV102() == 1; } + private static boolean isAllowDapp152(DynamicPropertiesStore dynamicPropertiesStore) { + return dynamicPropertiesStore.getAllowDappV152() == 1; + } + } \ No newline at end of file diff --git a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/common/utils/DBConfig.java b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/common/utils/DBConfig.java index 94a37b87f..d73e37575 100644 --- a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/common/utils/DBConfig.java +++ b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/common/utils/DBConfig.java @@ -197,6 +197,10 @@ public class DBConfig { @Setter private static long updateGateway_v1_0_2; //committee parameter + @Getter + @Setter + private static long allowDapp_v1_5_2; + public static boolean getEnergyLimitHardFork() { return ENERGY_LIMIT_HARD_FORK; diff --git a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/Parameter.java b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/Parameter.java index 812d01ca2..4e55102e7 100644 --- a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/Parameter.java +++ b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/Parameter.java @@ -18,7 +18,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 = 10001; + public static final int BLOCK_VERSION = 10002; } public class NodeConstant { diff --git a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/args/Parameter.java b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/args/Parameter.java index 23ae82506..41528bff7 100644 --- a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/args/Parameter.java +++ b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/config/args/Parameter.java @@ -10,7 +10,8 @@ public enum ForkBlockVersionEnum { VERSION_3_5(7), VERSION_3_6(8), DAPP_CHAIN_1_0_2(10000), - DAPP_CHAIN_1_5_0(10001); + DAPP_CHAIN_1_5_0(10001), + DAPP_CHAIN_1_5_2(10002); @Getter private int value; diff --git a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java index 5d5d43b60..d1b3e832d 100644 --- a/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java +++ b/dapp-chain/side-chain/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import java.util.stream.IntStream; import lombok.extern.slf4j.Slf4j; import org.joda.time.DateTime; @@ -234,6 +235,9 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking private static final byte[] UPDATE_GATEWAY_V_1_0_2 = "UPDATE_GATEWAY_V_1_0_2" .getBytes(); + // for 1_000_013 proposl + private static final byte[] ALLOW_DAPP_V_1_5_2 = "ALLOW_DAPP_V_1_5_2".getBytes(); + @Autowired private DynamicPropertiesStore(@Value("properties") String dbName) { super(dbName); @@ -888,6 +892,12 @@ private DynamicPropertiesStore(@Value("properties") String dbName) { this.saveAllowUpdateGatewayV102(DBConfig.getUpdateGateway_v1_0_2()); } + try { + this.getAllowDappV152(); + } catch (IllegalArgumentException e) { + this.saveAllowDappV152(DBConfig.getAllowDapp_v1_5_2()); + } + } public String intArrayToString(int[] a) { @@ -2476,6 +2486,19 @@ public long getAllowUpdateGatewayV102() { .orElseThrow(() -> new IllegalArgumentException("not found UPDATE_GATEWAY_V_1_0_2")); } + public void saveAllowDappV152(long value) { + this.put(ALLOW_DAPP_V_1_5_2, + new BytesCapsule(ByteArray.fromLong(value))); + } + + public long getAllowDappV152() { + return Optional.ofNullable(getUnchecked(ALLOW_DAPP_V_1_5_2)) + .map(BytesCapsule::getData) + .map(ByteArray::toLong) + + .orElseThrow(() -> new IllegalArgumentException("not found UPDATE_GATEWAY_V_1_0_2")); + } + public void saveProposalExpireTime(long proposalExpireTime) { logger.debug("PROPOSAL_EXPIRE_TIME:" + proposalExpireTime); this.put(PROPOSAL_EXPIRE_TIME, diff --git a/dapp-chain/side-chain/common/src/main/java/org/tron/core/Constant.java b/dapp-chain/side-chain/common/src/main/java/org/tron/core/Constant.java index 067fcf1d9..664195805 100644 --- a/dapp-chain/side-chain/common/src/main/java/org/tron/core/Constant.java +++ b/dapp-chain/side-chain/common/src/main/java/org/tron/core/Constant.java @@ -35,6 +35,9 @@ public class Constant { public static final long MAX_RESULT_SIZE_IN_TX = 64; // max 8 * 8 items in result public static final long PB_DEFAULT_ENERGY_LIMIT = 0L; public static final long CREATOR_DEFAULT_ENERGY_LIMIT = 1000 * 10_000L; + public static final long ENERGY_LIMIT_IN_CHARGING_OFF = 10_000_000L; + public static final long ENERGY_LIMIT_ALLOW_DAPP_152 = 100 * 1_000_000L; + // Numbers diff --git a/dapp-chain/side-chain/framework/src/main/java/org/tron/core/Wallet.java b/dapp-chain/side-chain/framework/src/main/java/org/tron/core/Wallet.java index 363a48886..e523b3870 100644 --- a/dapp-chain/side-chain/framework/src/main/java/org/tron/core/Wallet.java +++ b/dapp-chain/side-chain/framework/src/main/java/org/tron/core/Wallet.java @@ -1065,6 +1065,12 @@ public Protocol.SideChainParameters getSideChainParameters() { .setValue(String .valueOf(dbManager.getDynamicPropertiesStore().getAllowUpdateGatewayV102())) .build()); + builder.addChainParameter( + Protocol.SideChainParameters.SideChainParameter.newBuilder() + .setKey("getAllowDapp_v1_0_5") + .setValue(String + .valueOf(dbManager.getDynamicPropertiesStore().getAllowDappV152())) + .build()); builder.addChainParameter( Protocol.SideChainParameters.SideChainParameter.newBuilder() .setKey("getAllowTvmSolidity059") diff --git a/dapp-chain/side-chain/framework/src/main/java/org/tron/core/config/args/Args.java b/dapp-chain/side-chain/framework/src/main/java/org/tron/core/config/args/Args.java index 16fc3c8cf..3a71853ea 100644 --- a/dapp-chain/side-chain/framework/src/main/java/org/tron/core/config/args/Args.java +++ b/dapp-chain/side-chain/framework/src/main/java/org/tron/core/config/args/Args.java @@ -600,6 +600,10 @@ public class Args extends CommonParameter { @Setter private long updateGateway_v1_0_2; //committee parameter + @Getter + @Setter + private int allowDapp_v1_0_5; + @Autowired(required = false) @Getter private static ConcurrentHashMap> @@ -708,6 +712,7 @@ public static void clearParam() { INSTANCE.voteSwitch = 0; INSTANCE.witnessMaxActiveNum = 27; INSTANCE.updateGateway_v1_0_2 = 0; + INSTANCE.allowDapp_v1_0_5 = 0; } /** @@ -1212,6 +1217,10 @@ public static void setParam(final String[] args, final String confFileName) { config.hasPath("committee.chargingSwitchOn") ? config .getInt("committee.chargingSwitchOn") : 0; + INSTANCE.allowDapp_v1_0_5 = + config.hasPath("committee.allowDapp152") ? config + .getInt("committee.allowDapp152") : 0; + INSTANCE.sideChainChargingType = config.hasPath("sidechain.chargingType") ? config .getInt("sidechain.chargingType") : 0; @@ -1702,7 +1711,7 @@ public static void initDBConfig(Args cfgArgs) { DBConfig.setVoteSwitch(cfgArgs.getVoteSwitch()); DBConfig.setWitnessMaxActiveNum(cfgArgs.getWitnessMaxActiveNum()); DBConfig.setUpdateGateway_v1_0_2(cfgArgs.getUpdateGateway_v1_0_2()); - + DBConfig.setAllowDapp_v1_5_2(cfgArgs.getAllowDapp_v1_0_5()); } diff --git a/dapp-chain/side-chain/framework/src/main/java/org/tron/core/consensus/ProposalService.java b/dapp-chain/side-chain/framework/src/main/java/org/tron/core/consensus/ProposalService.java index 225897beb..4e76d64ef 100644 --- a/dapp-chain/side-chain/framework/src/main/java/org/tron/core/consensus/ProposalService.java +++ b/dapp-chain/side-chain/framework/src/main/java/org/tron/core/consensus/ProposalService.java @@ -275,6 +275,11 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule) .savePercentToPayWitness(Long.valueOf(entry.getValue())); break; } + case ALLOW_DAPP_152: { + manager.getDynamicPropertiesStore() + .saveAllowDappV152(Long.valueOf(entry.getValue())); + break; + } case WITNESS_MAX_NUMBER: { int oldNum = manager.getDynamicPropertiesStore().getWitnessMaxActiveNum(); int newNum = Integer.parseInt(entry.getValue());