Skip to content
Open
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 @@ -521,12 +521,7 @@ public class CommonParameter {
@Getter
@Setter
public int pBFTHttpPort;
@Getter
@Setter
public int maxNestingDepth = 100;
@Getter
@Setter
public int maxTokenCount = 100_000;

@Getter
@Setter
public long pBFTExpireNum; // clearParam: 20
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 @@ -63,4 +63,8 @@ public class Constant {
// Network
public static final String LOCAL_HOST = "127.0.0.1";

// JSON parsing (DoS protection)
public static final int MAX_NESTING_DEPTH = 100;
public static final int MAX_TOKEN_COUNT = 100_000;

}
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ public static class HttpConfig {
private boolean solidityEnable = true;
private int solidityPort = 8091;
private long maxMessageSize = 4194304;
private int maxNestingDepth = 100;
private int maxTokenCount = 100_000;
private boolean pBFTEnable = true;
private int pBFTPort = 8092;
}
Expand Down
11 changes: 0 additions & 11 deletions common/src/main/java/org/tron/core/config/args/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ public class Storage {
@Setter
private int maxFlushCount;

/**
* Index storage directory: /path/to/{indexDirectory}
*/
@Getter
@Setter
private String indexDirectory;

@Getter
@Setter
private String indexSwitch;

@Getter
@Setter
private boolean contractParseSwitch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
public class StorageConfig {

private DbConfig db = new DbConfig();
private IndexConfig index = new IndexConfig();
private TransHistoryConfig transHistory = new TransHistoryConfig();
private boolean needToUpdateAsset = true;
private DbSettingsConfig dbSettings = new DbSettingsConfig();
Expand Down Expand Up @@ -60,29 +59,10 @@ public static class DbConfig {
private String directory = "database";
}

@Getter
@Setter
public static class IndexConfig {
private String directory = "index";
// "switch" is a Java keyword, but HOCON key is "index.switch"
// ConfigBeanFactory would look for setSwitch which works fine in Java
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
private String switchValue = "on";

public String getSwitch() {
return switchValue;
}

public void setSwitch(String v) {
this.switchValue = v;
}
}

@Getter
@Setter
public static class TransHistoryConfig {
// "switch" is a Java keyword — same handling as IndexConfig
// "switch" is a reserved Java keyword; ConfigBeanFactory calls setSwitch() which works fine
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
private String switchValue = "on";
Expand Down
15 changes: 3 additions & 12 deletions common/src/main/java/org/tron/json/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.tron.common.parameter.CommonParameter;
import org.tron.core.Constant;

/**
* Drop-in replacement for {@code com.alibaba.fastjson.JSON}.
Expand All @@ -22,15 +22,6 @@
@Deprecated
public final class JSON {

// Initialization-order invariant: this class must NOT be loaded before
// Args.setParam() completes. The factory's StreamReadConstraints are a
// one-shot snapshot of CommonParameter at class-init time. If JSON is
// touched too early — e.g. a stray reference in startup code or in a static
// initializer that runs before Args — the snapshot captures CommonParameter's
// hardcoded defaults (100 / 100_000) and any user override of
// node.http.maxNestingDepth / maxTokenCount is silently ignored.
// Current production startup (FullNode.main) calls Args.setParam first and
// no path in that call chain references this class, so the invariant holds.
static final ObjectMapper MAPPER = JsonMapper.builder(buildFactory())
// Fastjson Feature.AllowUnQuotedFieldNames (default ON)
.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES)
Expand Down Expand Up @@ -67,9 +58,9 @@ public final class JSON {
.build();

private static JsonFactory buildFactory() {
CommonParameter p = CommonParameter.getInstance();
return JsonFactory.builder().streamReadConstraints(StreamReadConstraints.builder()
.maxNestingDepth(p.getMaxNestingDepth()).maxTokenCount(p.getMaxTokenCount())
.maxNestingDepth(Constant.MAX_NESTING_DEPTH)
.maxTokenCount(Constant.MAX_TOKEN_COUNT)
.build()).build();
}

Expand Down
6 changes: 0 additions & 6 deletions common/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ storage {
db.sync = false
db.directory = "database"

# Index directory (legacy, not consumed by any runtime code, kept for CLI/test compatibility)
index.directory = "index"
index.switch = "on"

# Whether to write transaction result in transactionRetStore
transHistory.switch = "on"

Expand Down Expand Up @@ -245,8 +241,6 @@ node {

# Maximum HTTP request body size, default 4MB. Independent from rpc.maxMessageSize.
maxMessageSize = 4M
maxNestingDepth = 100
maxTokenCount = 100000
}

rpc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public void testDefaults() {
assertEquals("LEVELDB", sc.getDb().getEngine());
assertFalse(sc.getDb().isSync());
assertEquals("database", sc.getDb().getDirectory());
assertEquals("index", sc.getIndex().getDirectory());
assertTrue(sc.isNeedToUpdateAsset());
assertEquals(7, sc.getDbSettings().getLevelNumber());
assertEquals(5000, sc.getDbSettings().getMaxOpenFiles());
Expand Down
14 changes: 0 additions & 14 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public class Args extends CommonParameter {
m.put("--storage-db-directory", "storage.db.directory");
m.put("--storage-db-engine", "storage.db.engine");
m.put("--storage-db-synchronous", "storage.db.sync");
m.put("--storage-index-directory", "storage.index.directory");
m.put("--storage-index-switch", "storage.index.switch");
m.put("--storage-transactionHistory-switch", "storage.transHistory.switch");
m.put("--contract-parse-enable", "event.subscribe.contractParse");
m.put("--support-constant", "vm.supportConstant");
Expand Down Expand Up @@ -215,10 +213,6 @@ private static void applyStorageConfig(StorageConfig sc) {
PARAMETER.storage.setDbEngine(sc.getDb().getEngine());
PARAMETER.storage.setDbSync(sc.getDb().isSync());
PARAMETER.storage.setDbDirectory(sc.getDb().getDirectory());
PARAMETER.storage.setIndexDirectory(sc.getIndex().getDirectory());
String indexSwitch = sc.getIndex().getSwitch();
PARAMETER.storage.setIndexSwitch(
org.apache.commons.lang3.StringUtils.isNotEmpty(indexSwitch) ? indexSwitch : "on");
PARAMETER.storage.setTransactionHistorySwitch(sc.getTransHistory().getSwitch());
// contractParse is set in applyConfigParams alongside event config, not here
PARAMETER.storage.setCheckpointVersion(sc.getCheckpoint().getVersion());
Expand Down Expand Up @@ -549,8 +543,6 @@ private static void applyNodeConfig(NodeConfig nc) {
PARAMETER.solidityHttpPort = http.getSolidityPort();
PARAMETER.pBFTHttpPort = http.getPBFTPort();
PARAMETER.httpMaxMessageSize = http.getMaxMessageSize();
PARAMETER.maxNestingDepth = http.getMaxNestingDepth();
PARAMETER.maxTokenCount = http.getMaxTokenCount();

// ---- JSON-RPC sub-bean ----
NodeConfig.JsonRpcConfig jsonrpc = nc.getJsonrpc();
Expand Down Expand Up @@ -865,12 +857,6 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
if (assigned.contains("--contract-parse-enable")) {
PARAMETER.storage.setContractParseSwitch(Boolean.valueOf(cmd.contractParseEnable));
}
if (assigned.contains("--storage-index-directory")) {
PARAMETER.storage.setIndexDirectory(cmd.storageIndexDirectory);
}
if (assigned.contains("--storage-index-switch")) {
PARAMETER.storage.setIndexSwitch(cmd.storageIndexSwitch);
}
if (assigned.contains("--storage-transactionHistory-switch")) {
PARAMETER.storage.setTransactionHistorySwitch(cmd.storageTransactionHistorySwitch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.tron.common.parameter.CommonParameter;
import org.tron.core.Constant;
import org.tron.core.services.filter.BufferedResponseWrapper;
import org.tron.core.services.filter.CachedBodyRequestWrapper;
import org.tron.core.services.http.RateLimiterServlet;
Expand All @@ -32,15 +33,13 @@
@Slf4j(topic = "API")
public class JsonRpcServlet extends RateLimiterServlet {

// Snapshot of node.http.maxNestingDepth / maxTokenCount at class-load time (after Args.setParam).
private static final ObjectMapper MAPPER = buildMapper();

private static ObjectMapper buildMapper() {
CommonParameter p = CommonParameter.getInstance();
JsonFactory factory = JsonFactory.builder()
.streamReadConstraints(StreamReadConstraints.builder()
.maxNestingDepth(p.getMaxNestingDepth())
.maxTokenCount(p.getMaxTokenCount())
.maxNestingDepth(Constant.MAX_NESTING_DEPTH)
.maxTokenCount(Constant.MAX_TOKEN_COUNT)
.build())
.build();
return new ObjectMapper(factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {

public static final long totalBalance = 1000_0000_000_000L;
private static final String dbDirectory = "db_BandWidthRuntimeOutOfTimeTest_test";
private static final String indexDirectory = "index_BandWidthRuntimeOutOfTimeTest_test";

private static final String OwnerAddress = "TCWHANtDDdkZCTo2T2peyEq3Eg9c2XB7ut";
private static final String TriggerOwnerAddress = "TCSgeWapPJhCqgWRxXCKb6jJ5AgNWSGjPA";
Expand All @@ -72,7 +71,6 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {

public static final long totalBalance = 1000_0000_000_000L;
private static final String dbDirectory = "db_BandWidthRuntimeOutOfTimeTest_test";
private static final String indexDirectory = "index_BandWidthRuntimeOutOfTimeTest_test";
private static final String OwnerAddress = "TCWHANtDDdkZCTo2T2peyEq3Eg9c2XB7ut";
private static final String TriggerOwnerAddress = "TCSgeWapPJhCqgWRxXCKb6jJ5AgNWSGjPA";
private static boolean init;
Expand All @@ -73,7 +72,6 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
"--debug"
},
"config-test-mainnet.conf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class BandWidthRuntimeTest extends BaseTest {

public static final long totalBalance = 1000_0000_000_000L;
private static final String dbDirectory = "db_BandWidthRuntimeTest_test";
private static final String indexDirectory = "index_BandWidthRuntimeTest_test";
private static final String OwnerAddress = "TCWHANtDDdkZCTo2T2peyEq3Eg9c2XB7ut";
private static final String TriggerOwnerAddress = "TCSgeWapPJhCqgWRxXCKb6jJ5AgNWSGjPA";
private static final String TriggerOwnerTwoAddress = "TPMBUANrTwwQAPwShn7ZZjTJz1f3F8jknj";
Expand All @@ -69,7 +68,6 @@ public static void init() {
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
},
"config-test-mainnet.conf"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class BandWidthRuntimeWithCheckTest extends BaseTest {

public static final long totalBalance = 1000_0000_000_000L;
private static final String dbDirectory = "db_BandWidthRuntimeWithCheckTest_test";
private static final String indexDirectory = "index_BandWidthRuntimeWithCheckTest_test";
private static final String OwnerAddress = "TCWHANtDDdkZCTo2T2peyEq3Eg9c2XB7ut";
private static final String TriggerOwnerAddress = "TCSgeWapPJhCqgWRxXCKb6jJ5AgNWSGjPA";
private static final String TriggerOwnerTwoAddress = "TPMBUANrTwwQAPwShn7ZZjTJz1f3F8jknj";
Expand All @@ -75,7 +74,6 @@ public class BandWidthRuntimeWithCheckTest extends BaseTest {
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory,
},
"config-test-mainnet.conf"
);
Expand Down
31 changes: 0 additions & 31 deletions framework/src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ public void testCliOverridesStorageConfig() {
"--storage-db-directory", "cli-db-dir",
"--storage-db-engine", "ROCKSDB",
"--storage-db-synchronous", "true",
"--storage-index-directory", "cli-index-dir",
"--storage-index-switch", "cli-index-switch",
"--storage-transactionHistory-switch", "off",
"--contract-parse-enable", "false"
}, TestConstants.TEST_CONF);
Expand All @@ -314,8 +312,6 @@ public void testCliOverridesStorageConfig() {
Assert.assertEquals("cli-db-dir", parameter.getStorage().getDbDirectory());
Assert.assertEquals("ROCKSDB", parameter.getStorage().getDbEngine());
Assert.assertTrue(parameter.getStorage().isDbSync());
Assert.assertEquals("cli-index-dir", parameter.getStorage().getIndexDirectory());
Assert.assertEquals("cli-index-switch", parameter.getStorage().getIndexSwitch());
Assert.assertEquals("off", parameter.getStorage().getTransactionHistorySwitch());
Assert.assertFalse(parameter.getStorage().isContractParseSwitch());

Expand Down Expand Up @@ -414,33 +410,6 @@ public void testFetchBlockTimeoutClampedAboveMax() {
}


@Test
public void testHttpJsonParseConstraints() {
Map<String, String> override = new HashMap<>();
override.put("storage.db.directory", "database");
Config config = ConfigFactory.parseMap(override)
.withFallback(ConfigFactory.defaultReference());
Args.applyConfigParams(config);

Assert.assertEquals(100, Args.getInstance().getMaxNestingDepth());
Assert.assertEquals(100_000, Args.getInstance().getMaxTokenCount());
Args.clearParam();
}

@Test
public void testHttpJsonParseConstraintsApplied() {
Map<String, String> override = new HashMap<>();
override.put("storage.db.directory", "database");
override.put("node.http.maxNestingDepth", "42");
override.put("node.http.maxTokenCount", "12345");
Config config = ConfigFactory.parseMap(override)
.withFallback(ConfigFactory.defaultReference());
Args.applyConfigParams(config);

Assert.assertEquals(42, Args.getInstance().getMaxNestingDepth());
Assert.assertEquals(12345, Args.getInstance().getMaxTokenCount());
Args.clearParam();
}

@Test
public void testFetchBlockTimeoutInRangeUnchanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public static void cleanup() {
@Test
public void getDirectory() {
Assert.assertEquals("database", storage.getDbDirectory());
Assert.assertEquals("index", storage.getIndexDirectory());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
public class AccountIndexStoreTest extends BaseTest {

private static String dbDirectory = "db_AccountIndexStore_test";
private static String indexDirectory = "index_AccountIndexStore_test";
@Resource
private AccountIndexStore accountIndexStore;
private static byte[] address = TransactionStoreTest.randomBytes(32);
Expand All @@ -26,8 +25,7 @@ public class AccountIndexStoreTest extends BaseTest {
Args.setParam(
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory
"--storage-db-directory", dbDirectory
},
TestConstants.TEST_CONF
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class AccountStoreTest extends BaseTest {

private static final byte[] data = TransactionStoreTest.randomBytes(32);
private static String dbDirectory = "db_AccountStore_test";
private static String indexDirectory = "index_AccountStore_test";
@Resource
private AccountStore accountStore;
@Resource
Expand All @@ -48,8 +47,7 @@ public class AccountStoreTest extends BaseTest {
Args.setParam(
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory
"--storage-db-directory", dbDirectory
},
TestConstants.TEST_CONF
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class TransactionHistoryTest extends BaseTest {

private static final byte[] transactionId = TransactionStoreTest.randomBytes(32);
private static String dbDirectory = "db_TransactionHistoryStore_test";
private static String indexDirectory = "index_TransactionHistoryStore_test";
@Resource
private TransactionHistoryStore transactionHistoryStore;

Expand All @@ -27,8 +26,7 @@ public class TransactionHistoryTest extends BaseTest {
Args.setParam(
new String[]{
"--output-directory", dbPath(),
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory
"--storage-db-directory", dbDirectory
},
TestConstants.TEST_CONF
);
Expand Down
Loading
Loading