Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -3,13 +3,13 @@
import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
import static org.tron.core.actuator.ActuatorConstant.WITNESS_EXCEPTION_STR;
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.DecodeUtil;
import org.tron.common.utils.StringUtil;
import org.tron.core.capsule.ProposalCapsule;
Expand Down Expand Up @@ -53,7 +53,8 @@ public boolean execute(Object result) throws ContractExeException {

long currentMaintenanceTime =
chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
long now3 = now + CommonParameter.getInstance().getProposalExpireTime();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered removing the code related to the deprecated configuration item "proposalExpireTime"?

long now3 = now + chainBaseManager.getDynamicPropertiesStore().getProposalVotingWindow()
* BLOCK_PRODUCED_INTERVAL;
long round = (now3 - currentMaintenanceTime) / maintenanceTimeInterval;
long expirationTime =
currentMaintenanceTime + (round + 1) * maintenanceTimeInterval;
Expand Down
19 changes: 18 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
import static org.tron.core.Constant.MAX_PROPOSAL_VOTING_WINDOW;
import static org.tron.core.Constant.MIN_PROPOSAL_VOTING_WINDOW;
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;

import org.tron.common.utils.ForkController;
Expand Down Expand Up @@ -839,6 +841,20 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case PROPOSAL_VOTING_WINDOW: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
throw new ContractValidateException(
"Bad chain parameter id [PROPOSAL_VOTING_WINDOW]");
}
if (value <= MIN_PROPOSAL_VOTING_WINDOW
|| value > MAX_PROPOSAL_VOTING_WINDOW) {
throw new ContractValidateException(
"This value[PROPOSAL_VOTING_WINDOW] is only allowed to be greater than "
+ MIN_PROPOSAL_VOTING_WINDOW + " and less than or equal to "
+ MAX_PROPOSAL_VOTING_WINDOW + "!");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -921,7 +937,8 @@ public enum ProposalType { // current value, value range
ALLOW_TVM_CANCUN(83), // 0, 1
ALLOW_STRICT_MATH(87), // 0, 1
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
ALLOW_TVM_BLOB(89); // 0, 1
ALLOW_TVM_BLOB(89), // 0, 1
PROPOSAL_VOTING_WINDOW(92); // (0, 10512000]

private long code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] ALLOW_TVM_CANCUN = "ALLOW_TVM_CANCUN".getBytes();

private static final byte[] ALLOW_TVM_BLOB = "ALLOW_TVM_BLOB".getBytes();
private static final byte[] PROPOSAL_VOTING_WINDOW = "PROPOSAL_VOTING_WINDOW".getBytes();

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
Expand Down Expand Up @@ -2946,6 +2947,17 @@ public long getAllowTvmBlob() {
.orElse(CommonParameter.getInstance().getAllowTvmBlob());
}

public void saveProposalVotingWindow(long proposalVotingWindow) {
this.put(PROPOSAL_VOTING_WINDOW, new BytesCapsule(ByteArray.fromLong(proposalVotingWindow)));
}

public long getProposalVotingWindow() {
return Optional.ofNullable(getUnchecked(PROPOSAL_VOTING_WINDOW))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElse(CommonParameter.getInstance().getProposalVotingWindow());
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,14 @@ public class CommonParameter {
@Setter
public long allowTvmBlob;

/**
* Committee parameter.
* Indicate the number of blocks after which the proposal approval window will take effect.
*/
@Getter
@Setter
public long proposalVotingWindow;
Comment thread
lxcmyf marked this conversation as resolved.
Outdated

private static double calcMaxTimeRatio() {
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
return 5.0;
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class Constant {
public static final long MAX_CONTRACT_RESULT_SIZE = 2L;
public static final long PB_DEFAULT_ENERGY_LIMIT = 0L;
public static final long CREATOR_DEFAULT_ENERGY_LIMIT = 1000 * 10_000L;
public static final long MIN_PROPOSAL_VOTING_WINDOW = 0L; // Number of blocks to 0 day
public static final long MAX_PROPOSAL_VOTING_WINDOW = 10512000L; // Number of blocks to 365 days
/**
* default number of blocks to 3 days
*/
public static final long DEFAULT_PROPOSAL_VOTING_WINDOW = 86400L;


// Numbers
Expand Down Expand Up @@ -405,4 +411,5 @@ public class Constant {
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";

public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
public static final String COMMITTEE_PROPOSAL_VOTING_WINDOW = "committee.proposalVotingWindow";
}
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum ForkBlockVersionEnum {
VERSION_4_7_4(29, 1596780000000L, 80),
VERSION_4_7_5(30, 1596780000000L, 80),
VERSION_4_7_7(31, 1596780000000L, 80),
VERSION_4_8_0(32, 1596780000000L, 80);
VERSION_4_8_0(32, 1596780000000L, 80),
VERSION_4_8_1(33, 1596780000000L, 80);
// if add a version, modify BLOCK_VERSION simultaneously

@Getter
Expand Down Expand Up @@ -75,7 +76,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 = 32;
public static final int BLOCK_VERSION = 33;
public static final long FROZEN_PERIOD = 86_400_000L;
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
public static final long TRX_PRECISION = 1000_000L;
Expand Down
5 changes: 5 additions & 0 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,11 @@ public Protocol.ChainParameters getChainParameters() {
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmBlob())
.build());

builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getProposalVotingWindow")
.setValue(dbManager.getDynamicPropertiesStore().getProposalVotingWindow())
.build());

return builder.build();
}

Expand Down
6 changes: 6 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.tron.common.math.Maths.max;
import static org.tron.common.math.Maths.min;
import static org.tron.core.Constant.ADD_PRE_FIX_BYTE_MAINNET;
import static org.tron.core.Constant.DEFAULT_PROPOSAL_VOTING_WINDOW;
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCE_TIMEOUT_PERCENT;
Expand Down Expand Up @@ -247,6 +248,7 @@ public static void clearParam() {
PARAMETER.consensusLogicOptimization = 0;
PARAMETER.allowTvmCancun = 0;
PARAMETER.allowTvmBlob = 0;
PARAMETER.proposalVotingWindow = DEFAULT_PROPOSAL_VOTING_WINDOW;
}

/**
Expand Down Expand Up @@ -1297,6 +1299,10 @@ public static void setParam(final Config config) {
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_BLOB) ? config
.getInt(Constant.COMMITTEE_ALLOW_TVM_BLOB) : 0;

PARAMETER.proposalVotingWindow =
config.hasPath(Constant.COMMITTEE_PROPOSAL_VOTING_WINDOW) ? config
.getInt(Constant.COMMITTEE_PROPOSAL_VOTING_WINDOW) : DEFAULT_PROPOSAL_VOTING_WINDOW;

Comment thread
lxcmyf marked this conversation as resolved.
Outdated
logConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
manager.getDynamicPropertiesStore().saveAllowTvmBlob(entry.getValue());
break;
}
case PROPOSAL_VOTING_WINDOW: {
manager.getDynamicPropertiesStore().saveProposalVotingWindow(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
2 changes: 2 additions & 0 deletions framework/src/test/java/org/tron/common/ParameterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,7 @@ public void testCommonParameter() {
assertEquals(1, parameter.getAllowEnergyAdjustment());
parameter.setMaxCreateAccountTxSize(1000);
assertEquals(1000, parameter.getMaxCreateAccountTxSize());
parameter.setProposalVotingWindow(86400L);
assertEquals(86400L, parameter.getProposalVotingWindow());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.tron.core.services;

import static org.tron.core.Constant.MAX_PROPOSAL_VOTING_WINDOW;
import static org.tron.core.utils.ProposalUtil.ProposalType.CONSENSUS_LOGIC_OPTIMIZATION;
import static org.tron.core.utils.ProposalUtil.ProposalType.ENERGY_FEE;
import static org.tron.core.utils.ProposalUtil.ProposalType.PROPOSAL_VOTING_WINDOW;
import static org.tron.core.utils.ProposalUtil.ProposalType.TRANSACTION_FEE;
import static org.tron.core.utils.ProposalUtil.ProposalType.WITNESS_127_PAY_PER_BLOCK;

Expand All @@ -13,6 +15,7 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.tron.common.BaseTest;
import org.tron.common.parameter.CommonParameter;
import org.tron.core.Constant;
import org.tron.core.capsule.ProposalCapsule;
import org.tron.core.config.args.Args;
Expand Down Expand Up @@ -131,4 +134,21 @@ public void testUpdateConsensusLogicOptimization() {
Assert.assertTrue(dbManager.getDynamicPropertiesStore().disableJavaLangMath());
}

@Test
public void testProposalVotingWindow() {
long defaultWindow = dbManager.getDynamicPropertiesStore().getProposalVotingWindow();
long proposalExpireTime = CommonParameter.getInstance().getProposalExpireTime();
Assert.assertEquals(proposalExpireTime, defaultWindow * 3000);

Proposal proposal = Proposal.newBuilder().putParameters(PROPOSAL_VOTING_WINDOW.getCode(),
MAX_PROPOSAL_VOTING_WINDOW).build();
ProposalCapsule proposalCapsule = new ProposalCapsule(proposal);
proposalCapsule.setExpirationTime(1627279200000L);
boolean result = ProposalService.process(dbManager, proposalCapsule);
Assert.assertTrue(result);

long window = dbManager.getDynamicPropertiesStore().getProposalVotingWindow();
Assert.assertEquals(MAX_PROPOSAL_VOTING_WINDOW, window);
}

}