Skip to content

Commit

Permalink
feat(consensus): modify the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusoo001 committed Jan 14, 2025
1 parent 021a5c1 commit 46826a7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
14 changes: 9 additions & 5 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -782,26 +782,30 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
case ALLOW_STRICT_MATH: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_7_7)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_STRICT_MATH]");
"Bad chain parameter id [ALLOW_STRICT_MATH]");
}
if (dynamicPropertiesStore.allowStrictMath()) {
throw new ContractValidateException(
"[ALLOW_STRICT_MATH] has been valid, no need to propose again");
"[ALLOW_STRICT_MATH] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_STRICT_MATH] is only allowed to be 1");
"This value[ALLOW_STRICT_MATH] is only allowed to be 1");
}
break;
}
case CONSENSUS_LOGIC_OPTIMIZATION: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_0)) {
throw new ContractValidateException(
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
}
if (dynamicPropertiesStore.getConsensusLogicOptimization() == 1) {
throw new ContractValidateException(
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,10 @@ public long getConsensusLogicOptimization() {
.orElse(CommonParameter.getInstance().getConsensusLogicOptimization());
}

public boolean allowConsensusLogicOptimization() {
return getConsensusLogicOptimization() == 1L;
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.tron.consensus.dpos;

import static org.tron.core.config.Parameter.ChainConstant.MAX_ACTIVE_WITNESS_NUM;
import static org.tron.core.config.Parameter.ChainConstant.SOLIDIFIED_THRESHOLD;

import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.Comparator;
Expand All @@ -24,8 +27,6 @@
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.capsule.WitnessCapsule;

import static org.tron.core.config.Parameter.ChainConstant.*;

@Slf4j(topic = "consensus")
@Component
public class DposService implements ConsensusInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,18 @@ private void testConsensusLogicOptimizationProposal() {
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1",
e.getMessage());
}

dynamicPropertiesStore.saveConsensusLogicOptimization(1);
try {
ProposalUtil.validator(dynamicPropertiesStore, forkUtils,
ProposalType.CONSENSUS_LOGIC_OPTIMIZATION.getCode(), 1);
Assert.fail();
} catch (ContractValidateException e) {
Assert.assertEquals(
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again",
e.getMessage());
}

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void testUpdateTransactionFee() {
public void testUpdateConsensusLogicOptimization() {
long v = dbManager.getDynamicPropertiesStore().getConsensusLogicOptimization();
Assert.assertEquals(v, 0);
Assert.assertTrue(!dbManager.getDynamicPropertiesStore().allowConsensusLogicOptimization());

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

v = dbManager.getDynamicPropertiesStore().getConsensusLogicOptimization();
Assert.assertEquals(v, value);

Assert.assertTrue(dbManager.getDynamicPropertiesStore().allowConsensusLogicOptimization());
}

}

0 comments on commit 46826a7

Please sign in to comment.