Skip to content
Draft
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 @@ -924,7 +924,6 @@ private long increase(long lastUsage, long usage, long lastTime, long now, long
}

if (lastTime != now) {
assert now > lastTime;
if (lastTime + windowSize > now) {
long delta = now - lastTime;
double decay = (windowSize - delta) / (double) windowSize;
Expand Down Expand Up @@ -973,8 +972,6 @@ public long calculateGlobalEnergyLimit(AccountCapsule accountCapsule) {
long totalEnergyLimit = getDynamicPropertiesStore().getTotalEnergyCurrentLimit();
long totalEnergyWeight = getDynamicPropertiesStore().getTotalEnergyWeight();

assert totalEnergyWeight > 0;

if (hardenResourceCalculation()) {
return BigInteger.valueOf(energyWeight)
.multiply(BigInteger.valueOf(totalEnergyLimit))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private static long convertVectorToLong(List<Boolean> v) throws ZksnarkException
}

public byte[] encode() throws ZksnarkException {
assert (authenticationPath.size() == index.size());
List<List<Byte>> pathByteList = Lists.newArrayList();
long indexLong; // 64
for (int i = 0; i < authenticationPath.size(); i++) {
Expand Down
3 changes: 0 additions & 3 deletions chainbase/src/main/java/org/tron/core/db/EnergyProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ public long calculateGlobalEnergyLimit(AccountCapsule accountCapsule) {
long totalEnergyWeight = dynamicPropertiesStore.getTotalEnergyWeight();
if (dynamicPropertiesStore.allowNewReward() && totalEnergyWeight <= 0) {
return 0;
} else {
assert totalEnergyWeight > 0;
}
if (hardenCalculation()) {
return calculateGlobalLimitV1(frozeBalance, totalEnergyLimit, totalEnergyWeight);
Expand Down Expand Up @@ -205,4 +203,3 @@ private long scaleByRate(long value, long numerator, long denominator) {
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ protected long increase(long lastUsage, long usage, long lastTime, long now, lon
}

if (lastTime != now) {
assert now > lastTime;
if (lastTime + windowSize > now) {
long delta = now - lastTime;
double decay = (windowSize - delta) / (double) windowSize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.tron.core.config.args;

import static org.tron.core.exception.TronError.ErrCode.PARAMETER_INIT;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigBeanFactory;
import com.typesafe.config.ConfigValue;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.tron.core.exception.TronError;

/**
* Committee (governance) configuration bean.
Expand Down Expand Up @@ -160,11 +163,11 @@ private void postProcess() {
// cross-field: allowOldRewardOpt requires at least one reward/vote flag
if (allowOldRewardOpt == 1 && allowNewRewardAlgorithm != 1
&& allowNewReward != 1 && allowTvmVote != 1) {
throw new IllegalArgumentException(
throw new TronError(
"At least one of the following proposals is required to be opened first: "
+ "committee.allowNewRewardAlgorithm = 1"
+ " or committee.allowNewReward = 1"
+ " or committee.allowTvmVote = 1.");
+ " or committee.allowTvmVote = 1.", PARAMETER_INIT);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.tron.core.config.args;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.junit.Test;
import org.tron.core.exception.TronError;

public class CommitteeConfigTest {

Expand Down Expand Up @@ -57,9 +59,16 @@ public void testDynamicEnergyThresholdClamped() {
.getDynamicEnergyThreshold());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testAllowOldRewardOptWithoutPrerequisites() {
CommitteeConfig.fromConfig(withRef("committee { allowOldRewardOpt = 1 }"));
TronError error = assertThrows(TronError.class,
() -> CommitteeConfig.fromConfig(withRef("committee { allowOldRewardOpt = 1 }")));

assertEquals(TronError.ErrCode.PARAMETER_INIT, error.getErrCode());
assertEquals("At least one of the following proposals is required to be opened first: "
+ "committee.allowNewRewardAlgorithm = 1"
+ " or committee.allowNewReward = 1"
+ " or committee.allowTvmVote = 1.", error.getMessage());
}

@Test
Expand Down
9 changes: 5 additions & 4 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,9 @@ private static void loadDnsPublishParameters(NodeConfig.DnsConfig dns,
String serverType = dns.getServerType();
if (StringUtils.isNotEmpty(serverType)) {
if (!"aws".equalsIgnoreCase(serverType) && !"aliyun".equalsIgnoreCase(serverType)) {
throw new IllegalArgumentException(
"Check node.dns.serverType, must be aws or aliyun");
throw new TronError(
"Check node.dns.serverType, must be aws or aliyun",
TronError.ErrCode.PARAMETER_INIT);
}
if ("aws".equalsIgnoreCase(serverType)) {
publishConfig.setDnsType(DnsType.AwsRoute53);
Expand Down Expand Up @@ -1088,7 +1089,8 @@ private static void loadDnsPublishParameters(NodeConfig.DnsConfig dns,
}

private static void logEmptyError(String arg) {
throw new IllegalArgumentException(String.format("Check %s, must not be null or empty", arg));
throw new TronError(String.format("Check %s, must not be null or empty", arg),
TronError.ErrCode.PARAMETER_INIT);
}

// createTriggerConfig removed — logic moved to applyEventConfig()
Expand Down Expand Up @@ -1315,4 +1317,3 @@ private static Map<String, String[]> getOptionGroup() {
return optionGroupMap;
}
}

58 changes: 58 additions & 0 deletions framework/src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,64 @@ public void testMaxMessageSizeNegativeValueRejected() {
}
}

@Test
public void testDnsPublishRejectsInvalidServerTypeWithParameterInitError() {
Config config = dnsPublishConfig(
"node.dns.serverType", "unsupported");

TronError error = Assert.assertThrows(TronError.class,
() -> Args.loadDnsPublishConfig(NodeConfig.fromConfig(config)));

Assert.assertEquals(TronError.ErrCode.PARAMETER_INIT, error.getErrCode());
Assert.assertEquals("Check node.dns.serverType, must be aws or aliyun",
error.getMessage());
}

@Test
public void testDnsPublishRejectsEmptyRequiredParameterWithParameterInitError() {
Config config = dnsPublishConfig("node.dns.dnsDomain", "");

TronError error = Assert.assertThrows(TronError.class,
() -> Args.loadDnsPublishConfig(NodeConfig.fromConfig(config)));

Assert.assertEquals(TronError.ErrCode.PARAMETER_INIT, error.getErrCode());
Assert.assertEquals("Check node.dns.dnsDomain, must not be null or empty",
error.getMessage());
}

@Test
public void testCommitteeConfigRejectsOldRewardOptimizationWithoutPrerequisite() {
Map<String, Object> configMap = new HashMap<>();
configMap.put("storage.db.directory", "database");
configMap.put("committee.allowOldRewardOpt", 1);
Config config = ConfigFactory.parseMap(configMap)
.withFallback(ConfigFactory.defaultReference());

try {
TronError error = Assert.assertThrows(TronError.class,
() -> Args.applyConfigParams(config));

Assert.assertEquals(TronError.ErrCode.PARAMETER_INIT, error.getErrCode());
} finally {
Args.clearParam();
}
}

private Config dnsPublishConfig(String key, String value) {
Map<String, Object> configMap = new HashMap<>();
configMap.put("node.dns.publish", true);
configMap.put("node.dns.dnsDomain", "nodes.example.org");
configMap.put("node.dns.dnsPrivate",
"1234567890123456789012345678901234567890123456789012345678901234");
configMap.put("node.dns.serverType", "aliyun");
configMap.put("node.dns.accessKeyId", "access-key-id");
configMap.put("node.dns.accessKeySecret", "access-key-secret");
configMap.put("node.dns.aliyunDnsEndpoint", "dns.aliyuncs.com");
configMap.put(key, value);
return ConfigFactory.parseMap(configMap)
.withFallback(ConfigFactory.defaultReference());
}

@Test
public void testRpcMaxMessageSizeExceedsIntMax() {
// HOCON's Config.getInt() throws when a numeric value exceeds int range.
Expand Down
Loading