Skip to content

Commit

Permalink
Merge pull request tronprotocol#300 from tronprotocol/withdrawAllBalance
Browse files Browse the repository at this point in the history
 add proposal ALLOW_DAPP_152(1000013)
  • Loading branch information
taihaofu authored Sep 3, 2020
2 parents bcee98f + 11556de commit 35d4d72
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class VMActuator implements Actuator2 {
@Setter
private boolean isConstantCall = false;

@Getter
private boolean isSideChainGateWayContractCall;

@Setter
private boolean enableEventLinstener;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class VMConfig {
@Setter
public static boolean isAllowUpdateGateway102 = false;

@Getter
@Setter
public static boolean isAllowDapp152 = false;

private VMConfig() {
}

Expand All @@ -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) {
Expand Down Expand Up @@ -131,4 +136,8 @@ private static boolean isAllowUpdateGatewayV102(DynamicPropertiesStore dynamicPr
return dynamicPropertiesStore.getAllowUpdateGatewayV102() == 1;
}

private static boolean isAllowDapp152(DynamicPropertiesStore dynamicPropertiesStore) {
return dynamicPropertiesStore.getAllowDappV152() == 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -234,6 +235,9 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, List<ContractLogTrigger>>
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 35d4d72

Please sign in to comment.