Skip to content
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 @@ -9,7 +9,6 @@
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 +52,7 @@ public boolean execute(Object result) throws ContractExeException {

long currentMaintenanceTime =
chainBaseManager.getDynamicPropertiesStore().getNextMaintenanceTime();
long now3 = now + CommonParameter.getInstance().getProposalExpireTime();
Copy link
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().getProposalExpireTime();
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_EXPIRE_TIME;
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
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_EXPIRE_TIME: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_1)) {
throw new ContractValidateException(
"Bad chain parameter id [PROPOSAL_EXPIRE_TIME]");
}
if (value <= MIN_PROPOSAL_EXPIRE_TIME
|| value >= MAX_PROPOSAL_EXPIRE_TIME) {
throw new ContractValidateException(
"This value[PROPOSAL_EXPIRE_TIME] is only allowed to be greater than "
+ MIN_PROPOSAL_EXPIRE_TIME + " and less than "
+ MAX_PROPOSAL_EXPIRE_TIME + "!");
}
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_EXPIRE_TIME(92); // (0, 31536003000)

private long code;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.tron.core.store;

import static org.tron.common.math.Maths.max;
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
import static org.tron.core.config.Parameter.ChainConstant.DELEGATE_PERIOD;

Expand Down Expand Up @@ -231,6 +233,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_EXPIRE_TIME = "PROPOSAL_EXPIRE_TIME".getBytes();

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

public void saveProposalExpireTime(long proposalExpireTime) {
this.put(PROPOSAL_EXPIRE_TIME, new BytesCapsule(ByteArray.fromLong(proposalExpireTime)));
}

public long getProposalExpireTime() {
return Optional.ofNullable(getUnchecked(PROPOSAL_EXPIRE_TIME))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.filter(time -> time > MIN_PROPOSAL_EXPIRE_TIME && time < MAX_PROPOSAL_EXPIRE_TIME)
.orElse(CommonParameter.getInstance().getProposalExpireTime());
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
4 changes: 4 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,9 @@ 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_EXPIRE_TIME = 0L; // 0 ms
public static final long MAX_PROPOSAL_EXPIRE_TIME = 31536003000L; // ms of 365 days + 3000 ms
public static final long DEFAULT_PROPOSAL_EXPIRE_TIME = 259200000L; // ms of 3 days


// Numbers
Expand Down Expand Up @@ -405,4 +408,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_EXPIRE_TIME = "committee.proposalExpireTime";
}
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("getProposalExpireTime")
.setValue(dbManager.getDynamicPropertiesStore().getProposalExpireTime())
.build());

return builder.build();
}

Expand Down
27 changes: 24 additions & 3 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,8 +4,11 @@
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_EXPIRE_TIME;
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_EXPIRE_TIME;
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCE_TIMEOUT_PERCENT;
import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM;

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

PARAMETER.proposalExpireTime =
config.hasPath(Constant.BLOCK_PROPOSAL_EXPIRE_TIME) ? config
.getInt(Constant.BLOCK_PROPOSAL_EXPIRE_TIME) : 259200000L;
PARAMETER.proposalExpireTime = getProposalExpirationTime(config);

PARAMETER.checkFrozenTime =
config.hasPath(Constant.BLOCK_CHECK_FROZEN_TIME) ? config
Expand Down Expand Up @@ -1300,6 +1301,26 @@ public static void setParam(final Config config) {
logConfig();
}

private static long getProposalExpirationTime(final Config config) {
if (config.hasPath(Constant.COMMITTEE_PROPOSAL_EXPIRE_TIME)) {
throw new IllegalArgumentException("It is not allowed to configure "
+ "commit.proposalExpireTime in config.conf, please set the value in "
+ "block.proposalExpireTime.");
}
if (config.hasPath(Constant.BLOCK_PROPOSAL_EXPIRE_TIME)) {
long proposalExpireTime = config.getLong(Constant.BLOCK_PROPOSAL_EXPIRE_TIME);
if (proposalExpireTime <= MIN_PROPOSAL_EXPIRE_TIME
|| proposalExpireTime >= MAX_PROPOSAL_EXPIRE_TIME) {
throw new IllegalArgumentException("The value[block.proposalExpireTime] is only allowed to "
+ "be greater than " + MIN_PROPOSAL_EXPIRE_TIME + " and less than "
+ MAX_PROPOSAL_EXPIRE_TIME + "!");
}
return proposalExpireTime;
} else {
return DEFAULT_PROPOSAL_EXPIRE_TIME;
}
}

private static List<Witness> getWitnessesFromConfig(final com.typesafe.config.Config config) {
return config.getObjectList(Constant.GENESIS_BLOCK_WITNESSES).stream()
.map(Args::createWitness)
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_EXPIRE_TIME: {
manager.getDynamicPropertiesStore().saveProposalExpireTime(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
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_EXPIRE_TIME;
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_EXPIRE_TIME;
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 testProposalExpireTime() {
long defaultWindow = dbManager.getDynamicPropertiesStore().getProposalExpireTime();
long proposalExpireTime = CommonParameter.getInstance().getProposalExpireTime();
Assert.assertEquals(proposalExpireTime, defaultWindow);

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

long window = dbManager.getDynamicPropertiesStore().getProposalExpireTime();
Assert.assertEquals(MAX_PROPOSAL_EXPIRE_TIME - 3000, window);
}

}