Skip to content

Commit f3fd9af

Browse files
committed
feat(approving): convert the approving window configuration to chain governance
1 parent 15e8c0e commit f3fd9af

11 files changed

Lines changed: 78 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
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;
67

78
import com.google.protobuf.ByteString;
89
import com.google.protobuf.InvalidProtocolBufferException;
910
import java.util.Map;
1011
import java.util.Objects;
1112
import lombok.extern.slf4j.Slf4j;
12-
import org.tron.common.parameter.CommonParameter;
1313
import org.tron.common.utils.DecodeUtil;
1414
import org.tron.common.utils.StringUtil;
1515
import org.tron.core.capsule.ProposalCapsule;
@@ -53,7 +53,8 @@ public boolean execute(Object result) throws ContractExeException {
5353

5454
long currentMaintenanceTime =
5555
chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
56-
long now3 = now + CommonParameter.getInstance().getProposalExpireTime();
56+
long now3 = now + chainBaseManager.getDynamicPropertiesStore().getProposalVotingWindow()
57+
* BLOCK_PRODUCED_INTERVAL;
5758
long round = (now3 - currentMaintenanceTime) / maintenanceTimeInterval;
5859
long expirationTime =
5960
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_VOTING_WINDOW;
8+
import static org.tron.core.Constant.MIN_PROPOSAL_VOTING_WINDOW;
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_VOTING_WINDOW: {
845+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
846+
throw new ContractValidateException(
847+
"Bad chain parameter id [PROPOSAL_VOTING_WINDOW]");
848+
}
849+
if (value < MIN_PROPOSAL_VOTING_WINDOW
850+
|| value > MAX_PROPOSAL_VOTING_WINDOW) {
851+
throw new ContractValidateException(
852+
"This value[PROPOSAL_VOTING_WINDOW] is only allowed to be greater than or equal "
853+
+ "to " + MIN_PROPOSAL_VOTING_WINDOW + " and less than or equal to "
854+
+ MAX_PROPOSAL_VOTING_WINDOW + "!");
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_VOTING_WINDOW(92); // (86400, 201600]
925942

926943
private long code;
927944

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
231231
private static final byte[] ALLOW_TVM_CANCUN = "ALLOW_TVM_CANCUN".getBytes();
232232

233233
private static final byte[] ALLOW_TVM_BLOB = "ALLOW_TVM_BLOB".getBytes();
234+
private static final byte[] PROPOSAL_VOTING_WINDOW = "PROPOSAL_VOTING_WINDOW".getBytes();
234235

235236
@Autowired
236237
private DynamicPropertiesStore(@Value("properties") String dbName) {
@@ -2946,6 +2947,17 @@ public long getAllowTvmBlob() {
29462947
.orElse(CommonParameter.getInstance().getAllowTvmBlob());
29472948
}
29482949

2950+
public void saveProposalVotingWindow(long proposalVotingWindow) {
2951+
this.put(PROPOSAL_VOTING_WINDOW, new BytesCapsule(ByteArray.fromLong(proposalVotingWindow)));
2952+
}
2953+
2954+
public long getProposalVotingWindow() {
2955+
return Optional.ofNullable(getUnchecked(PROPOSAL_VOTING_WINDOW))
2956+
.map(BytesCapsule::getData)
2957+
.map(ByteArray::toLong)
2958+
.orElse(CommonParameter.getInstance().getProposalVotingWindow());
2959+
}
2960+
29492961
private static class DynamicResourceProperties {
29502962

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

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

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

727+
@Getter
728+
@Setter
729+
public long proposalVotingWindow;
730+
727731
private static double calcMaxTimeRatio() {
728732
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
729733
return 5.0;

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

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

4345

4446
// Numbers
@@ -405,4 +407,5 @@ public class Constant {
405407
public static final String COMMITTEE_ALLOW_TVM_CANCUN = "committee.allowTvmCancun";
406408

407409
public static final String COMMITTEE_ALLOW_TVM_BLOB = "committee.allowTvmBlob";
410+
public static final String COMMITTEE_PROPOSAL_VOTING_WINDOW = "committee.proposalVotingWindow";
408411
}

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("getProposalVotingWindow")
1392+
.setValue(dbManager.getDynamicPropertiesStore().getProposalVotingWindow())
1393+
.build());
1394+
13901395
return builder.build();
13911396
}
13921397

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,10 @@ public static void setParam(final Config config) {
12971297
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_BLOB) ? config
12981298
.getInt(Constant.COMMITTEE_ALLOW_TVM_BLOB) : 0;
12991299

1300+
PARAMETER.proposalVotingWindow =
1301+
config.hasPath(Constant.COMMITTEE_PROPOSAL_VOTING_WINDOW) ? config
1302+
.getInt(Constant.COMMITTEE_PROPOSAL_VOTING_WINDOW) : 86400L;
1303+
13001304
logConfig();
13011305
}
13021306

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_VOTING_WINDOW: {
388+
manager.getDynamicPropertiesStore().saveProposalVotingWindow(entry.getValue());
389+
break;
390+
}
387391
default:
388392
find = false;
389393
break;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,7 @@ 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());
319321
}
320322
}

0 commit comments

Comments
 (0)