Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change witness max active num #236

Merged
merged 7 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.tron.common.overlay.discover;

import com.sun.org.apache.xpath.internal.Arg;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
Expand Down
70 changes: 45 additions & 25 deletions dapp-chain/side-chain/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.spongycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -635,7 +634,8 @@ public TransactionApprovedList getTransactionApprovedList(Transaction trx) {
"Signature size is " + sig.size());
}
String base64 = TransactionCapsule.getBase64FromByteString(sig);
byte[] address = ECKey.signatureToAddress(TransactionCapsule.getHashWithSideChainId(hash), base64);
byte[] address = ECKey
.signatureToAddress(TransactionCapsule.getHashWithSideChainId(hash), base64);
approveList.add(ByteString.copyFrom(address)); //out put approve list.
}
tswBuilder.addAllApprovedList(approveList);
Expand Down Expand Up @@ -750,7 +750,8 @@ public Protocol.SideChainParameters getSideChainParameters() {
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getMaintenanceTimeInterval")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getMaintenanceTimeInterval()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getMaintenanceTimeInterval()))
.build());
// ACCOUNT_UPGRADE_COST, //drop ,1
builder.addChainParameter(
Expand All @@ -771,10 +772,11 @@ public Protocol.SideChainParameters getSideChainParameters() {
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getTransactionFee()))
.build());
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getTransactionSunTokenFee")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getTransactionSunTokenFee()))
.build());
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getTransactionSunTokenFee")
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getTransactionSunTokenFee()))
.build());
// ASSET_ISSUE_FEE, //drop ,4
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
Expand All @@ -791,20 +793,23 @@ public Protocol.SideChainParameters getSideChainParameters() {
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getWitnessStandbyAllowance")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getWitnessStandbyAllowance()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getWitnessStandbyAllowance()))
.build());
// CREATE_NEW_ACCOUNT_FEE_IN_SYSTEM_CONTRACT, //drop ,7
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getCreateNewAccountFeeInSystemContract")
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract()))
String.valueOf(
dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract()))
.build());
// CREATE_NEW_ACCOUNT_BANDWIDTH_RATE, // 1 ~ ,8
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getCreateNewAccountBandwidthRate")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getCreateNewAccountBandwidthRate()))
.setValue(String
.valueOf(dbManager.getDynamicPropertiesStore().getCreateNewAccountBandwidthRate()))
.build());
// ALLOW_CREATION_OF_CONTRACTS, // 0 / >0 ,9
// builder.addChainParameter(
Expand All @@ -816,7 +821,8 @@ public Protocol.SideChainParameters getSideChainParameters() {
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getRemoveThePowerOfTheGr")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getRemoveThePowerOfTheGr()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getRemoveThePowerOfTheGr()))
.build());
// ENERGY_FEE, // drop, 11
builder.addChainParameter(
Expand All @@ -840,7 +846,8 @@ public Protocol.SideChainParameters getSideChainParameters() {
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getAllowUpdateAccountName")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getAllowUpdateAccountName()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getAllowUpdateAccountName()))
.build());
// ALLOW_SAME_TOKEN_NAME, // 1, 15
// builder.addChainParameter(
Expand Down Expand Up @@ -870,7 +877,8 @@ public Protocol.SideChainParameters getSideChainParameters() {
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getTotalEnergyCurrentLimit")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getTotalEnergyCurrentLimit()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getTotalEnergyCurrentLimit()))
.build());
// ALLOW_MULTI_SIGN, // 1, 20
builder.addChainParameter(
Expand All @@ -884,7 +892,8 @@ public Protocol.SideChainParameters getSideChainParameters() {
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getAllowAdaptiveEnergy")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getAllowAdaptiveEnergy()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getAllowAdaptiveEnergy()))
.build());
//other chainParameters
builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
Expand All @@ -894,12 +903,14 @@ public Protocol.SideChainParameters getSideChainParameters() {

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getTotalEnergyAverageUsage")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getTotalEnergyAverageUsage()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getTotalEnergyAverageUsage()))
.build());

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getUpdateAccountPermissionFee")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee()))
.build());

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
Expand All @@ -909,7 +920,8 @@ public Protocol.SideChainParameters getSideChainParameters() {

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getUpdateAccountPermissionFee")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee()))
.setValue(
String.valueOf(dbManager.getDynamicPropertiesStore().getUpdateAccountPermissionFee()))
.build());

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
Expand Down Expand Up @@ -937,23 +949,25 @@ public Protocol.SideChainParameters getSideChainParameters() {

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getMainChainGateWayList")
.setValue(convertGateWayListToString(dbManager.getDynamicPropertiesStore().getMainChainGateWayList()))
.setValue(convertGateWayListToString(
dbManager.getDynamicPropertiesStore().getMainChainGateWayList()))
.build());

builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getSideChainGateWayList")
.setValue(convertGateWayListToString(dbManager.getDynamicPropertiesStore().getSideChainGateWayList()))
.setValue(convertGateWayListToString(
dbManager.getDynamicPropertiesStore().getSideChainGateWayList()))
.build());
builder.addChainParameter(Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getSideChainId")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getSideChainId()))
.build());
// PROPOSAL_EXPIRE_TIME, //ms ,259_200_000L
builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getProposalExpireTime")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getProposalExpireTime()))
.build());
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getProposalExpireTime")
.setValue(String.valueOf(dbManager.getDynamicPropertiesStore().getProposalExpireTime()))
.build());

// vote witness switch
builder.addChainParameter(
Expand Down Expand Up @@ -1005,6 +1019,12 @@ public Protocol.SideChainParameters getSideChainParameters() {
.valueOf(dbManager.getDynamicPropertiesStore().getPercentToPayWitness()))
.build());

builder.addChainParameter(
Protocol.SideChainParameters.SideChainParameter.newBuilder()
.setKey("getWitnessMaxActiveNum")
.setValue(String
.valueOf(dbManager.getDynamicPropertiesStore().getWitnessMaxActiveNum()))
.build());
return builder.build();
}

Expand Down Expand Up @@ -1568,8 +1588,8 @@ public ExchangeList getPaginatedExchangeList(long offset, long limit) {
public String convertGateWayListToString(List<byte[]> list) {
String gateWayStr = "";
int i = 0;
while(i < list.size() - 1){
gateWayStr+= Wallet.encode58Check(list.get(i)) + ",";
while (i < list.size() - 1) {
gateWayStr += Wallet.encode58Check(list.get(i)) + ",";
i++;
}
if (i == list.size() - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public boolean validate() throws ContractValidateException {
}
if (!this.contract.is(SideChainProposalCreateContract.class)) {
throw new ContractValidateException(
"contract type error,expected type [SideChainProposalCreateContract],real type[" + contract
"contract type error,expected type [SideChainProposalCreateContract],real type["
+ contract
.getClass() + "]");
}
final SideChainProposalCreateContract contract;
Expand Down Expand Up @@ -148,7 +149,8 @@ private void validateValue(Map.Entry<Long, String> entry) throws ContractValidat

switch (entry.getKey().intValue()) {
case (0): {
if (Long.valueOf(entry.getValue()) < 3 * Args.getInstance().getWitnessMaxActiveNum() * 1000
if (Long.valueOf(entry.getValue()) < 3 * dbManager.getDynamicPropertiesStore()
.getWitnessMaxActiveNum() * 1000
|| Long.valueOf(entry.getValue()) > 24 * 3600 * 1000) {
throw new ContractValidateException(
"Bad chain parameter value,valid range is [3 * 27 * 1000,24 * 3600 * 1000]");
Expand Down Expand Up @@ -337,7 +339,7 @@ private void validateValue(Map.Entry<Long, String> entry) throws ContractValidat
// }
// break;
// }
case (1_000_007):{
case (1_000_007): {
try {
byte[] address = Wallet.decodeFromBase58Check(entry.getValue());
if (!Wallet.addressValid(address)) {
Expand All @@ -358,20 +360,21 @@ private void validateValue(Map.Entry<Long, String> entry) throws ContractValidat
throw new ContractValidateException("target Fund Inject Address should not "
+ "be a contract");
}
} catch (Exception e){
} catch (Exception e) {
throw new ContractValidateException(
"Invalid Fund Inject Address");
}

break;
}
case (1_000_008):{
case (1_000_008): {
if (Long.valueOf(entry.getValue()) != 1 && Long.valueOf(entry.getValue()) != 0) {
throw new ContractValidateException(
"Bad chain parameter value,valid value is {0,1}");
}
if (Long.valueOf(entry.getValue()) == 1 && ByteUtil.equals(this.dbManager.getDynamicPropertiesStore().getFundInjectAddress(),
Hex.decode(Constant.TRON_ZERO_ADDRESS_HEX))) {
if (Long.valueOf(entry.getValue()) == 1 && ByteUtil
.equals(this.dbManager.getDynamicPropertiesStore().getFundInjectAddress(),
Hex.decode(Constant.TRON_ZERO_ADDRESS_HEX))) {
throw new ContractValidateException(
"Fund Inject Address should not be default T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"
+ " to enable Fund distribution switch"
Expand All @@ -393,9 +396,23 @@ private void validateValue(Map.Entry<Long, String> entry) throws ContractValidat
}
break;
}
case (1_000_011): {
if (Integer.parseInt(entry.getValue()) < 5 || Integer.parseInt(entry.getValue()) > 27) {
throw new ContractValidateException(
"Bad chain parameter value, valid range is [5,27]");
} else if (Integer.parseInt(entry.getValue()) > Args.getInstance().getGenesisBlock()
.getWitnesses().size()) {
throw new ContractValidateException(
"Bad chain parameter value, must Less than Genesis Block Witnesses size");
} else if (Integer.parseInt(entry.getValue()) <= dbManager.getDynamicPropertiesStore()
.getWitnessMaxActiveNum()) {
throw new ContractValidateException(
"Bad chain parameter value, must greater than current value {}");
}
break;
}
default:
throw new ContractValidateException(
"non-exist proposal number");
throw new ContractValidateException("non-exist proposal number");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import lombok.extern.slf4j.Slf4j;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.StringUtil;
import org.tron.core.config.Parameter.ChainConstant;
import org.tron.core.config.args.Args;
import org.tron.protos.Protocol.SideChainProposal;
import org.tron.protos.Protocol.SideChainProposal.State;

Expand Down Expand Up @@ -162,9 +160,7 @@ public boolean hasMostApprovals(List<ByteString> activeWitnesses) {
.filter(witness -> !activeWitnesses.contains(witness)).collect(Collectors.toList());
logger.info("InvalidApprovalList:" + StringUtil.getAddressStringList(InvalidApprovalList));
}
if (activeWitnesses.size() != Args.getInstance().getWitnessMaxActiveNum()) {
logger.info("activeWitnesses size = {}", activeWitnesses.size());
}
logger.info("activeWitnesses size = {}", activeWitnesses.size());
return count >= activeWitnesses.size() * 7 / 10;
}
}
Loading