Skip to content

Commit e3f9b52

Browse files
committed
feat(conf): make compatible with old configurations
1 parent 399d159 commit e3f9b52

File tree

10 files changed

+61
-58
lines changed

10 files changed

+61
-58
lines changed

actuator/src/main/java/org/tron/core/actuator/ProposalCreateActuator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.tron.core.actuator.ActuatorConstant.ACCOUNT_EXCEPTION_STR;
44
import static org.tron.core.actuator.ActuatorConstant.NOT_EXIST_STR;
55
import static org.tron.core.actuator.ActuatorConstant.WITNESS_EXCEPTION_STR;
6-
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
76

87
import com.google.protobuf.ByteString;
98
import com.google.protobuf.InvalidProtocolBufferException;
@@ -53,8 +52,7 @@ public boolean execute(Object result) throws ContractExeException {
5352

5453
long currentMaintenanceTime =
5554
chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
56-
long now3 = now + chainBaseManager.getDynamicPropertiesStore().getProposalVotingWindow()
57-
* BLOCK_PRODUCED_INTERVAL;
55+
long now3 = now + chainBaseManager.getDynamicPropertiesStore().getProposalExpireTime();
5856
long round = (now3 - currentMaintenanceTime) / maintenanceTimeInterval;
5957
long expirationTime =
6058
currentMaintenanceTime + (round + 1) * maintenanceTimeInterval;

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import static org.tron.core.Constant.CREATE_ACCOUNT_TRANSACTION_MIN_BYTE_SIZE;
55
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
66
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
7-
import static org.tron.core.Constant.MAX_PROPOSAL_VOTING_WINDOW;
8-
import static org.tron.core.Constant.MIN_PROPOSAL_VOTING_WINDOW;
7+
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
8+
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
99
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;
1010

1111
import org.tron.common.utils.ForkController;
@@ -841,17 +841,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
841841
}
842842
break;
843843
}
844-
case PROPOSAL_VOTING_WINDOW: {
844+
case PROPOSAL_EXPIRE_TIME: {
845845
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
846846
throw new ContractValidateException(
847-
"Bad chain parameter id [PROPOSAL_VOTING_WINDOW]");
847+
"Bad chain parameter id [PROPOSAL_EXPIRE_TIME]");
848848
}
849-
if (value <= MIN_PROPOSAL_VOTING_WINDOW
850-
|| value > MAX_PROPOSAL_VOTING_WINDOW) {
849+
if (value <= MIN_PROPOSAL_EXPIRE_TIME
850+
|| value >= MAX_PROPOSAL_EXPIRE_TIME) {
851851
throw new ContractValidateException(
852-
"This value[PROPOSAL_VOTING_WINDOW] is only allowed to be greater than "
853-
+ MIN_PROPOSAL_VOTING_WINDOW + " and less than or equal to "
854-
+ MAX_PROPOSAL_VOTING_WINDOW + "!");
852+
"This value[PROPOSAL_EXPIRE_TIME] is only allowed to be greater than "
853+
+ MIN_PROPOSAL_EXPIRE_TIME + " and less than "
854+
+ MAX_PROPOSAL_EXPIRE_TIME + "!");
855855
}
856856
break;
857857
}
@@ -938,7 +938,7 @@ public enum ProposalType { // current value, value range
938938
ALLOW_STRICT_MATH(87), // 0, 1
939939
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
940940
ALLOW_TVM_BLOB(89), // 0, 1
941-
PROPOSAL_VOTING_WINDOW(92); // (0, 10512000]
941+
PROPOSAL_EXPIRE_TIME(92); // (0, 31536003000)
942942

943943
private long code;
944944

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.tron.core.store;
22

33
import static org.tron.common.math.Maths.max;
4+
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
5+
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
46
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
57
import static org.tron.core.config.Parameter.ChainConstant.DELEGATE_PERIOD;
68

@@ -231,7 +233,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
231233
private static final byte[] ALLOW_TVM_CANCUN = "ALLOW_TVM_CANCUN".getBytes();
232234

233235
private static final byte[] ALLOW_TVM_BLOB = "ALLOW_TVM_BLOB".getBytes();
234-
private static final byte[] PROPOSAL_VOTING_WINDOW = "PROPOSAL_VOTING_WINDOW".getBytes();
236+
private static final byte[] PROPOSAL_EXPIRE_TIME = "PROPOSAL_EXPIRE_TIME".getBytes();
235237

236238
@Autowired
237239
private DynamicPropertiesStore(@Value("properties") String dbName) {
@@ -2947,15 +2949,16 @@ public long getAllowTvmBlob() {
29472949
.orElse(CommonParameter.getInstance().getAllowTvmBlob());
29482950
}
29492951

2950-
public void saveProposalVotingWindow(long proposalVotingWindow) {
2951-
this.put(PROPOSAL_VOTING_WINDOW, new BytesCapsule(ByteArray.fromLong(proposalVotingWindow)));
2952+
public void saveProposalExpireTime(long proposalExpireTime) {
2953+
this.put(PROPOSAL_EXPIRE_TIME, new BytesCapsule(ByteArray.fromLong(proposalExpireTime)));
29522954
}
29532955

2954-
public long getProposalVotingWindow() {
2955-
return Optional.ofNullable(getUnchecked(PROPOSAL_VOTING_WINDOW))
2956+
public long getProposalExpireTime() {
2957+
return Optional.ofNullable(getUnchecked(PROPOSAL_EXPIRE_TIME))
29562958
.map(BytesCapsule::getData)
29572959
.map(ByteArray::toLong)
2958-
.orElse(CommonParameter.getInstance().getProposalVotingWindow());
2960+
.filter(time -> time > MIN_PROPOSAL_EXPIRE_TIME && time < MAX_PROPOSAL_EXPIRE_TIME)
2961+
.orElse(CommonParameter.getInstance().getProposalExpireTime());
29592962
}
29602963

29612964
private static class DynamicResourceProperties {

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,14 +724,6 @@ public class CommonParameter {
724724
@Setter
725725
public long allowTvmBlob;
726726

727-
/**
728-
* Committee parameter.
729-
* Indicate the number of blocks after which the proposal approval window will take effect.
730-
*/
731-
@Getter
732-
@Setter
733-
public long proposalVotingWindow;
734-
735727
private static double calcMaxTimeRatio() {
736728
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
737729
return 5.0;

common/src/main/java/org/tron/core/Constant.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ public class Constant {
3939
public static final long MAX_CONTRACT_RESULT_SIZE = 2L;
4040
public static final long PB_DEFAULT_ENERGY_LIMIT = 0L;
4141
public static final long CREATOR_DEFAULT_ENERGY_LIMIT = 1000 * 10_000L;
42-
public static final long MIN_PROPOSAL_VOTING_WINDOW = 0L; // Number of blocks to 0 day
43-
public static final long MAX_PROPOSAL_VOTING_WINDOW = 10512000L; // Number of blocks to 365 days
44-
/**
45-
* default number of blocks to 3 days
46-
*/
47-
public static final long DEFAULT_PROPOSAL_VOTING_WINDOW = 86400L;
42+
public static final long MIN_PROPOSAL_EXPIRE_TIME = 0L; // 0 ms
43+
public static final long MAX_PROPOSAL_EXPIRE_TIME = 31536003000L; // ms of 365 days + 3000 ms
44+
public static final long DEFAULT_PROPOSAL_EXPIRE_TIME = 259200000L; // ms of 3 days
4845

4946

5047
// Numbers
@@ -411,5 +408,5 @@ public class Constant {
411408
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";
412409

413410
public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
414-
public static final String COMMITTEE_PROPOSAL_VOTING_WINDOW = "committee.proposalVotingWindow";
411+
public static final String COMMITTEE_PROPOSAL_EXPIRE_TIME = "committee.proposalExpireTime";
415412
}

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,8 @@ public Protocol.ChainParameters getChainParameters() {
13881388
.build());
13891389

13901390
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
1391-
.setKey("getProposalVotingWindow")
1392-
.setValue(dbManager.getDynamicPropertiesStore().getProposalVotingWindow())
1391+
.setKey("getProposalExpireTime")
1392+
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
13931393
.build());
13941394

13951395
return builder.build();

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import static org.tron.common.math.Maths.max;
55
import static org.tron.common.math.Maths.min;
66
import static org.tron.core.Constant.ADD_PRE_FIX_BYTE_MAINNET;
7-
import static org.tron.core.Constant.DEFAULT_PROPOSAL_VOTING_WINDOW;
7+
import static org.tron.core.Constant.DEFAULT_PROPOSAL_EXPIRE_TIME;
88
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
99
import static org.tron.core.Constant.DYNAMIC_ENERGY_MAX_FACTOR_RANGE;
10+
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
11+
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
1012
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCE_TIMEOUT_PERCENT;
1113
import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM;
1214

@@ -248,7 +250,6 @@ public static void clearParam() {
248250
PARAMETER.consensusLogicOptimization = 0;
249251
PARAMETER.allowTvmCancun = 0;
250252
PARAMETER.allowTvmBlob = 0;
251-
PARAMETER.proposalVotingWindow = DEFAULT_PROPOSAL_VOTING_WINDOW;
252253
}
253254

254255
/**
@@ -817,9 +818,7 @@ public static void setParam(final Config config) {
817818
config.hasPath(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) ? config
818819
.getInt(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) : 21600000L;
819820

820-
PARAMETER.proposalExpireTime =
821-
config.hasPath(Constant.BLOCK_PROPOSAL_EXPIRE_TIME) ? config
822-
.getInt(Constant.BLOCK_PROPOSAL_EXPIRE_TIME) : 259200000L;
821+
PARAMETER.proposalExpireTime = getProposalExpirationTime(config);
823822

824823
PARAMETER.checkFrozenTime =
825824
config.hasPath(Constant.BLOCK_CHECK_FROZEN_TIME) ? config
@@ -1299,13 +1298,29 @@ public static void setParam(final Config config) {
12991298
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_BLOB) ? config
13001299
.getInt(Constant.COMMITTEE_ALLOW_TVM_BLOB) : 0;
13011300

1302-
PARAMETER.proposalVotingWindow =
1303-
config.hasPath(Constant.COMMITTEE_PROPOSAL_VOTING_WINDOW) ? config
1304-
.getInt(Constant.COMMITTEE_PROPOSAL_VOTING_WINDOW) : DEFAULT_PROPOSAL_VOTING_WINDOW;
1305-
13061301
logConfig();
13071302
}
13081303

1304+
private static long getProposalExpirationTime(final Config config) {
1305+
if (config.hasPath(Constant.COMMITTEE_PROPOSAL_EXPIRE_TIME)) {
1306+
throw new IllegalArgumentException("It is not allowed to configure "
1307+
+ "commit.proposalExpireTime in config.conf, please set the value in "
1308+
+ "block.proposalExpireTime.");
1309+
}
1310+
if (config.hasPath(Constant.BLOCK_PROPOSAL_EXPIRE_TIME)) {
1311+
long proposalExpireTime = config.getLong(Constant.BLOCK_PROPOSAL_EXPIRE_TIME);
1312+
if (proposalExpireTime <= MIN_PROPOSAL_EXPIRE_TIME
1313+
|| proposalExpireTime >= MAX_PROPOSAL_EXPIRE_TIME) {
1314+
throw new IllegalArgumentException("The value[block.proposalExpireTime] is only allowed to "
1315+
+ "be greater than " + MIN_PROPOSAL_EXPIRE_TIME + " and less than "
1316+
+ MAX_PROPOSAL_EXPIRE_TIME + "!");
1317+
}
1318+
return proposalExpireTime;
1319+
} else {
1320+
return DEFAULT_PROPOSAL_EXPIRE_TIME;
1321+
}
1322+
}
1323+
13091324
private static List<Witness> getWitnessesFromConfig(final com.typesafe.config.Config config) {
13101325
return config.getObjectList(Constant.GENESIS_BLOCK_WITNESSES).stream()
13111326
.map(Args::createWitness)

framework/src/main/java/org/tron/core/consensus/ProposalService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
384384
manager.getDynamicPropertiesStore().saveAllowTvmBlob(entry.getValue());
385385
break;
386386
}
387-
case PROPOSAL_VOTING_WINDOW: {
388-
manager.getDynamicPropertiesStore().saveProposalVotingWindow(entry.getValue());
387+
case PROPOSAL_EXPIRE_TIME: {
388+
manager.getDynamicPropertiesStore().saveProposalExpireTime(entry.getValue());
389389
break;
390390
}
391391
default:

framework/src/test/java/org/tron/common/ParameterTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,5 @@ public void testCommonParameter() {
316316
assertEquals(1, parameter.getAllowEnergyAdjustment());
317317
parameter.setMaxCreateAccountTxSize(1000);
318318
assertEquals(1000, parameter.getMaxCreateAccountTxSize());
319-
parameter.setProposalVotingWindow(86400L);
320-
assertEquals(86400L, parameter.getProposalVotingWindow());
321319
}
322320
}

framework/src/test/java/org/tron/core/services/ProposalServiceTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.tron.core.services;
22

3-
import static org.tron.core.Constant.MAX_PROPOSAL_VOTING_WINDOW;
3+
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
44
import static org.tron.core.utils.ProposalUtil.ProposalType.CONSENSUS_LOGIC_OPTIMIZATION;
55
import static org.tron.core.utils.ProposalUtil.ProposalType.ENERGY_FEE;
6-
import static org.tron.core.utils.ProposalUtil.ProposalType.PROPOSAL_VOTING_WINDOW;
6+
import static org.tron.core.utils.ProposalUtil.ProposalType.PROPOSAL_EXPIRE_TIME;
77
import static org.tron.core.utils.ProposalUtil.ProposalType.TRANSACTION_FEE;
88
import static org.tron.core.utils.ProposalUtil.ProposalType.WITNESS_127_PAY_PER_BLOCK;
99

@@ -135,20 +135,20 @@ public void testUpdateConsensusLogicOptimization() {
135135
}
136136

137137
@Test
138-
public void testProposalVotingWindow() {
139-
long defaultWindow = dbManager.getDynamicPropertiesStore().getProposalVotingWindow();
138+
public void testProposalExpireTime() {
139+
long defaultWindow = dbManager.getDynamicPropertiesStore().getProposalExpireTime();
140140
long proposalExpireTime = CommonParameter.getInstance().getProposalExpireTime();
141-
Assert.assertEquals(proposalExpireTime, defaultWindow * 3000);
141+
Assert.assertEquals(proposalExpireTime, defaultWindow);
142142

143-
Proposal proposal = Proposal.newBuilder().putParameters(PROPOSAL_VOTING_WINDOW.getCode(),
144-
MAX_PROPOSAL_VOTING_WINDOW).build();
143+
Proposal proposal = Proposal.newBuilder().putParameters(PROPOSAL_EXPIRE_TIME.getCode(),
144+
31536000000L).build();
145145
ProposalCapsule proposalCapsule = new ProposalCapsule(proposal);
146146
proposalCapsule.setExpirationTime(1627279200000L);
147147
boolean result = ProposalService.process(dbManager, proposalCapsule);
148148
Assert.assertTrue(result);
149149

150-
long window = dbManager.getDynamicPropertiesStore().getProposalVotingWindow();
151-
Assert.assertEquals(MAX_PROPOSAL_VOTING_WINDOW, window);
150+
long window = dbManager.getDynamicPropertiesStore().getProposalExpireTime();
151+
Assert.assertEquals(MAX_PROPOSAL_EXPIRE_TIME - 3000, window);
152152
}
153153

154154
}

0 commit comments

Comments
 (0)