Skip to content

Commit ae6222c

Browse files
authored
Merge pull request #6399 from lxcmyf/feature/voting_window_period
feat(consensus): convert the local proposal expire time configuration to a chain parameter
2 parents 2c06f4f + ff2a507 commit ae6222c

File tree

9 files changed

+94
-8
lines changed

9 files changed

+94
-8
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Map;
1010
import java.util.Objects;
1111
import lombok.extern.slf4j.Slf4j;
12-
import org.tron.common.parameter.CommonParameter;
1312
import org.tron.common.utils.DecodeUtil;
1413
import org.tron.common.utils.StringUtil;
1514
import org.tron.core.capsule.ProposalCapsule;
@@ -53,7 +52,7 @@ public boolean execute(Object result) throws ContractExeException {
5352

5453
long currentMaintenanceTime =
5554
chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
56-
long now3 = now + CommonParameter.getInstance().getProposalExpireTime();
55+
long now3 = now + chainBaseManager.getDynamicPropertiesStore().getProposalExpireTime();
5756
long round = (now3 - currentMaintenanceTime) / maintenanceTimeInterval;
5857
long expirationTime =
5958
currentMaintenanceTime + (round + 1) * maintenanceTimeInterval;

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +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_EXPIRE_TIME;
8+
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
79
import static org.tron.core.config.Parameter.ChainConstant.ONE_YEAR_BLOCK_NUMBERS;
810

911
import org.tron.common.utils.ForkController;
@@ -839,6 +841,20 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
839841
}
840842
break;
841843
}
844+
case PROPOSAL_EXPIRE_TIME: {
845+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
846+
throw new ContractValidateException(
847+
"Bad chain parameter id [PROPOSAL_EXPIRE_TIME]");
848+
}
849+
if (value <= MIN_PROPOSAL_EXPIRE_TIME
850+
|| value >= MAX_PROPOSAL_EXPIRE_TIME) {
851+
throw new ContractValidateException(
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 + "!");
855+
}
856+
break;
857+
}
842858
default:
843859
break;
844860
}
@@ -921,7 +937,8 @@ public enum ProposalType { // current value, value range
921937
ALLOW_TVM_CANCUN(83), // 0, 1
922938
ALLOW_STRICT_MATH(87), // 0, 1
923939
CONSENSUS_LOGIC_OPTIMIZATION(88), // 0, 1
924-
ALLOW_TVM_BLOB(89); // 0, 1
940+
ALLOW_TVM_BLOB(89), // 0, 1
941+
PROPOSAL_EXPIRE_TIME(92); // (0, 31536003000)
925942

926943
private long code;
927944

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

Lines changed: 15 additions & 0 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,6 +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();
236+
private static final byte[] PROPOSAL_EXPIRE_TIME = "PROPOSAL_EXPIRE_TIME".getBytes();
234237

235238
@Autowired
236239
private DynamicPropertiesStore(@Value("properties") String dbName) {
@@ -2946,6 +2949,18 @@ public long getAllowTvmBlob() {
29462949
.orElse(CommonParameter.getInstance().getAllowTvmBlob());
29472950
}
29482951

2952+
public void saveProposalExpireTime(long proposalExpireTime) {
2953+
this.put(PROPOSAL_EXPIRE_TIME, new BytesCapsule(ByteArray.fromLong(proposalExpireTime)));
2954+
}
2955+
2956+
public long getProposalExpireTime() {
2957+
return Optional.ofNullable(getUnchecked(PROPOSAL_EXPIRE_TIME))
2958+
.map(BytesCapsule::getData)
2959+
.map(ByteArray::toLong)
2960+
.filter(time -> time > MIN_PROPOSAL_EXPIRE_TIME && time < MAX_PROPOSAL_EXPIRE_TIME)
2961+
.orElse(CommonParameter.getInstance().getProposalExpireTime());
2962+
}
2963+
29492964
private static class DynamicResourceProperties {
29502965

29512966
private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +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_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
4245

4346

4447
// Numbers
@@ -405,4 +408,5 @@ public class Constant {
405408
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";
406409

407410
public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
411+
public static final String COMMITTEE_PROPOSAL_EXPIRE_TIME = "committee.proposalExpireTime";
408412
}

common/src/main/java/org/tron/core/config/Parameter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public enum ForkBlockVersionEnum {
2626
VERSION_4_7_4(29, 1596780000000L, 80),
2727
VERSION_4_7_5(30, 1596780000000L, 80),
2828
VERSION_4_7_7(31, 1596780000000L, 80),
29-
VERSION_4_8_0(32, 1596780000000L, 80);
29+
VERSION_4_8_0(32, 1596780000000L, 80),
30+
VERSION_4_8_1(33, 1596780000000L, 80);
3031
// if add a version, modify BLOCK_VERSION simultaneously
3132

3233
@Getter
@@ -75,7 +76,7 @@ public class ChainConstant {
7576
public static final int SINGLE_REPEAT = 1;
7677
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
7778
public static final int MAX_FROZEN_NUMBER = 1;
78-
public static final int BLOCK_VERSION = 32;
79+
public static final int BLOCK_VERSION = 33;
7980
public static final long FROZEN_PERIOD = 86_400_000L;
8081
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
8182
public static final long TRX_PRECISION = 1000_000L;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,11 @@ public Protocol.ChainParameters getChainParameters() {
13871387
.setValue(dbManager.getDynamicPropertiesStore().getAllowTvmBlob())
13881388
.build());
13891389

1390+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
1391+
.setKey("getProposalExpireTime")
1392+
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
1393+
.build());
1394+
13901395
return builder.build();
13911396
}
13921397

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +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_EXPIRE_TIME;
78
import static org.tron.core.Constant.DYNAMIC_ENERGY_INCREASE_FACTOR_RANGE;
89
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;
912
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCE_TIMEOUT_PERCENT;
1013
import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM;
1114

@@ -815,9 +818,7 @@ public static void setParam(final Config config) {
815818
config.hasPath(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) ? config
816819
.getInt(Constant.BLOCK_MAINTENANCE_TIME_INTERVAL) : 21600000L;
817820

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

822823
PARAMETER.checkFrozenTime =
823824
config.hasPath(Constant.BLOCK_CHECK_FROZEN_TIME) ? config
@@ -1300,6 +1301,26 @@ public static void setParam(final Config config) {
13001301
logConfig();
13011302
}
13021303

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+
13031324
private static List<Witness> getWitnessesFromConfig(final com.typesafe.config.Config config) {
13041325
return config.getObjectList(Constant.GENESIS_BLOCK_WITNESSES).stream()
13051326
.map(Args::createWitness)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
384384
manager.getDynamicPropertiesStore().saveAllowTvmBlob(entry.getValue());
385385
break;
386386
}
387+
case PROPOSAL_EXPIRE_TIME: {
388+
manager.getDynamicPropertiesStore().saveProposalExpireTime(entry.getValue());
389+
break;
390+
}
387391
default:
388392
find = false;
389393
break;

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

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

3+
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
34
import static org.tron.core.utils.ProposalUtil.ProposalType.CONSENSUS_LOGIC_OPTIMIZATION;
45
import static org.tron.core.utils.ProposalUtil.ProposalType.ENERGY_FEE;
6+
import static org.tron.core.utils.ProposalUtil.ProposalType.PROPOSAL_EXPIRE_TIME;
57
import static org.tron.core.utils.ProposalUtil.ProposalType.TRANSACTION_FEE;
68
import static org.tron.core.utils.ProposalUtil.ProposalType.WITNESS_127_PAY_PER_BLOCK;
79

@@ -13,6 +15,7 @@
1315
import org.junit.BeforeClass;
1416
import org.junit.Test;
1517
import org.tron.common.BaseTest;
18+
import org.tron.common.parameter.CommonParameter;
1619
import org.tron.core.Constant;
1720
import org.tron.core.capsule.ProposalCapsule;
1821
import org.tron.core.config.args.Args;
@@ -131,4 +134,21 @@ public void testUpdateConsensusLogicOptimization() {
131134
Assert.assertTrue(dbManager.getDynamicPropertiesStore().disableJavaLangMath());
132135
}
133136

137+
@Test
138+
public void testProposalExpireTime() {
139+
long defaultWindow = dbManager.getDynamicPropertiesStore().getProposalExpireTime();
140+
long proposalExpireTime = CommonParameter.getInstance().getProposalExpireTime();
141+
Assert.assertEquals(proposalExpireTime, defaultWindow);
142+
143+
Proposal proposal = Proposal.newBuilder().putParameters(PROPOSAL_EXPIRE_TIME.getCode(),
144+
31536000000L).build();
145+
ProposalCapsule proposalCapsule = new ProposalCapsule(proposal);
146+
proposalCapsule.setExpirationTime(1627279200000L);
147+
boolean result = ProposalService.process(dbManager, proposalCapsule);
148+
Assert.assertTrue(result);
149+
150+
long window = dbManager.getDynamicPropertiesStore().getProposalExpireTime();
151+
Assert.assertEquals(MAX_PROPOSAL_EXPIRE_TIME - 3000, window);
152+
}
153+
134154
}

0 commit comments

Comments
 (0)