Skip to content

Commit 46826a7

Browse files
committed
feat(consensus): modify the review comments
1 parent 021a5c1 commit 46826a7

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -782,26 +782,30 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
782782
case ALLOW_STRICT_MATH: {
783783
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_7)) {
784784
throw new ContractValidateException(
785-
"Bad chain parameter id [ALLOW_STRICT_MATH]");
785+
"Bad chain parameter id [ALLOW_STRICT_MATH]");
786786
}
787787
if (dynamicPropertiesStore.allowStrictMath()) {
788788
throw new ContractValidateException(
789-
"[ALLOW_STRICT_MATH] has been valid, no need to propose again");
789+
"[ALLOW_STRICT_MATH] has been valid, no need to propose again");
790790
}
791791
if (value != 1) {
792792
throw new ContractValidateException(
793-
"This value[ALLOW_STRICT_MATH] is only allowed to be 1");
793+
"This value[ALLOW_STRICT_MATH] is only allowed to be 1");
794794
}
795795
break;
796796
}
797797
case CONSENSUS_LOGIC_OPTIMIZATION: {
798798
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_0)) {
799799
throw new ContractValidateException(
800-
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
800+
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
801+
}
802+
if (dynamicPropertiesStore.getConsensusLogicOptimization() == 1) {
803+
throw new ContractValidateException(
804+
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again");
801805
}
802806
if (value != 1) {
803807
throw new ContractValidateException(
804-
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
808+
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
805809
}
806810
break;
807811
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,10 @@ public long getConsensusLogicOptimization() {
29062906
.orElse(CommonParameter.getInstance().getConsensusLogicOptimization());
29072907
}
29082908

2909+
public boolean allowConsensusLogicOptimization() {
2910+
return getConsensusLogicOptimization() == 1L;
2911+
}
2912+
29092913
private static class DynamicResourceProperties {
29102914

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

consensus/src/main/java/org/tron/consensus/dpos/DposService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.tron.consensus.dpos;
22

3+
import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM;
4+
import static org.tron.core.config.Parameter.ChainConstant.SOLIDIFIED_THRESHOLD;
5+
36
import com.google.protobuf.ByteString;
47
import java.util.ArrayList;
58
import java.util.Comparator;
@@ -24,8 +27,6 @@
2427
import org.tron.core.capsule.BlockCapsule;
2528
import org.tron.core.capsule.WitnessCapsule;
2629

27-
import static org.tron.core.config.Parameter.ChainConstant.*;
28-
2930
@Slf4j(topic = "consensus")
3031
@Component
3132
public class DposService implements ConsensusInterface {

framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,18 @@ private void testConsensusLogicOptimizationProposal() {
537537
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1",
538538
e.getMessage());
539539
}
540+
541+
dynamicPropertiesStore.saveConsensusLogicOptimization(1);
542+
try {
543+
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
544+
ProposalType.CONSENSUS_LOGIC_OPTIMIZATION.getCode(), 1);
545+
Assert.fail();
546+
} catch (ContractValidateException e) {
547+
Assert.assertEquals(
548+
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again",
549+
e.getMessage());
550+
}
551+
540552
}
541553

542554
@Test

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

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public void testUpdateTransactionFee() {
111111
public void testUpdateConsensusLogicOptimization() {
112112
long v = dbManager.getDynamicPropertiesStore().getConsensusLogicOptimization();
113113
Assert.assertEquals(v, 0);
114+
Assert.assertTrue(!dbManager.getDynamicPropertiesStore().allowConsensusLogicOptimization());
114115

115116
long value = 1;
116117
Proposal proposal =
@@ -122,6 +123,8 @@ public void testUpdateConsensusLogicOptimization() {
122123

123124
v = dbManager.getDynamicPropertiesStore().getConsensusLogicOptimization();
124125
Assert.assertEquals(v, value);
126+
127+
Assert.assertTrue(dbManager.getDynamicPropertiesStore().allowConsensusLogicOptimization());
125128
}
126129

127130
}

0 commit comments

Comments
 (0)