Skip to content

feat(proposal): prevent resubmission relating ALLOW_OLD_REWARD_OPT #5683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
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
4 changes: 4 additions & 0 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_OLD_REWARD_OPT]");
}
if (dynamicPropertiesStore.allowOldRewardOpt()) {
throw new ContractValidateException(
"[ALLOW_OLD_REWARD_OPT] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_OLD_REWARD_OPT] is only allowed to be 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -12,6 +13,7 @@
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.ForkController;
import org.tron.core.Constant;
import org.tron.core.capsule.BytesCapsule;
import org.tron.core.config.Parameter;
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
import org.tron.core.config.args.Args;
Expand All @@ -27,6 +29,11 @@ public class ProposalUtilTest extends BaseTest {
private static final String LONG_VALUE_ERROR =
"Bad chain parameter value, valid range is [0," + LONG_VALUE + "]";

@Resource
private DynamicPropertiesStore dynamicPropertiesStore;

ForkController forkUtils = ForkController.instance();

/**
* Init .
*/
Expand Down Expand Up @@ -60,8 +67,6 @@ public void validProposalTypeCheck() throws ContractValidateException {

@Test
public void validateCheck() {
DynamicPropertiesStore dynamicPropertiesStore = null;
ForkController forkUtils = ForkController.instance();
long invalidValue = -1;

try {
Expand Down Expand Up @@ -328,6 +333,66 @@ public void validateCheck() {
e.getMessage());
}

try {
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
ProposalType.ALLOW_OLD_REWARD_OPT.getCode(), 2);
Assert.fail();
} catch (ContractValidateException e) {
Assert.assertEquals(
"Bad chain parameter id [ALLOW_OLD_REWARD_OPT]",
e.getMessage());
}
hardForkTime =
((ForkBlockVersionEnum.VERSION_4_7_4.getHardForkTime() - 1) / maintenanceTimeInterval + 1)
* maintenanceTimeInterval;
forkUtils.getManager().getDynamicPropertiesStore()
.saveLatestBlockHeaderTimestamp(hardForkTime + 1);
forkUtils.getManager().getDynamicPropertiesStore()
.statsByVersion(ForkBlockVersionEnum.VERSION_4_7_4.getValue(), stats);
try {
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
ProposalType.ALLOW_OLD_REWARD_OPT.getCode(), 2);
Assert.fail();
} catch (ContractValidateException e) {
Assert.assertEquals(
"This value[ALLOW_OLD_REWARD_OPT] is only allowed to be 1",
e.getMessage());
}
try {
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
ProposalType.ALLOW_OLD_REWARD_OPT.getCode(), 1);
Assert.fail();
} catch (ContractValidateException e) {
Assert.assertEquals(
"[ALLOW_NEW_REWARD] proposal must be approved "
+ "before [ALLOW_OLD_REWARD_OPT] can be proposed",
e.getMessage());
}
dynamicPropertiesStore.saveCurrentCycleNumber(0);
dynamicPropertiesStore.saveNewRewardAlgorithmEffectiveCycle();
dynamicPropertiesStore.saveAllowNewReward(1);
try {
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
ProposalType.ALLOW_OLD_REWARD_OPT.getCode(), 1);
Assert.fail();
} catch (ContractValidateException e) {
Assert.assertEquals(
"no need old reward opt, ALLOW_NEW_REWARD from start cycle 1",
e.getMessage());
}
dynamicPropertiesStore.put("NEW_REWARD_ALGORITHM_EFFECTIVE_CYCLE".getBytes(),
new BytesCapsule(ByteArray.fromLong(4000)));
dynamicPropertiesStore.saveAllowOldRewardOpt(1);
try {
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
ProposalType.ALLOW_OLD_REWARD_OPT.getCode(), 1);
Assert.fail();
} catch (ContractValidateException e) {
Assert.assertEquals(
"[ALLOW_OLD_REWARD_OPT] has been valid, no need to propose again",
e.getMessage());
}

forkUtils.getManager().getDynamicPropertiesStore()
.statsByVersion(ForkBlockVersionEnum.ENERGY_LIMIT.getValue(), stats);
forkUtils.reset();
Expand Down