Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
}

// 2. Conventional format check
const conventionalRegex = /^(feat|fix|refactor|docs|style|test|chore|ci|perf|build|revert)(\([^)]+\))?:\s.+/;
const conventionalRegex = /^(feat|fix|refactor|docs|style|test|chore|ci|perf|build|revert)(\([^)]+\))?:\s\S.*/;
if (title && !conventionalRegex.test(title)) {
errors.push(
'PR title must follow conventional format: `type(scope): description`\n' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class CommonParameter {
@Parameter(names = {"-c", "--config"}, description = "Config file (default:config.conf)")
public String shellConfFileName = "";
@Getter
@Setter
public String configFilePath = "";
@Getter
@Parameter(names = {"-d", "--output-directory"},
description = "Data directory for the databases (default:output-directory)")
public String outputDirectory = "output-directory";
Expand Down
402 changes: 22 additions & 380 deletions common/src/main/java/org/tron/core/Constant.java

Large diffs are not rendered by default.

912 changes: 456 additions & 456 deletions framework/src/main/java/org/tron/core/config/args/Args.java

Large diffs are not rendered by default.

329 changes: 329 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/ConfigKey.java

Large diffs are not rendered by default.

45 changes: 12 additions & 33 deletions framework/src/main/java/org/tron/core/config/args/DynamicArgs.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.tron.core.config.args;

import static org.apache.commons.lang3.StringUtils.isNoneBlank;

import com.typesafe.config.Config;
import java.io.File;
import java.net.InetAddress;
Expand All @@ -15,7 +13,6 @@
import org.springframework.stereotype.Component;
import org.tron.common.es.ExecutorServiceManager;
import org.tron.common.parameter.CommonParameter;
import org.tron.core.Constant;
import org.tron.core.config.Configuration;
import org.tron.core.net.TronNetService;

Expand All @@ -25,6 +22,7 @@
public class DynamicArgs {
private final CommonParameter parameter = Args.getInstance();

private File configFile;
private long lastModified = 0;

private ScheduledExecutorService reloadExecutor;
Expand All @@ -36,11 +34,12 @@ public void init() {
reloadExecutor = ExecutorServiceManager.newSingleThreadScheduledExecutor(esName);
logger.info("Start the dynamic loading configuration service");
long checkInterval = parameter.getDynamicConfigCheckInterval();
File config = getConfigFile();
if (config == null) {
configFile = new File(parameter.getConfigFilePath());
if (!configFile.exists()) {
logger.warn("Configuration path is required! No such file {}", configFile);
return;
}
lastModified = config.lastModified();
lastModified = configFile.lastModified();
reloadExecutor.scheduleWithFixedDelay(() -> {
try {
run();
Expand All @@ -52,36 +51,16 @@ public void init() {
}

public void run() {
File config = getConfigFile();
if (config != null) {
long lastModifiedTime = config.lastModified();
if (lastModifiedTime > lastModified) {
reload();
lastModified = lastModifiedTime;
}
}
}

private File getConfigFile() {
String confFilePath;
if (isNoneBlank(parameter.getShellConfFileName())) {
confFilePath = parameter.getShellConfFileName();
} else {
confFilePath = Constant.NET_CONF;
}

File confFile = new File(confFilePath);
if (!confFile.exists()) {
logger.warn("Configuration path is required! No such file {}", confFile);
return null;
long lastModifiedTime = configFile.lastModified();
if (lastModifiedTime > lastModified) {
reload();
lastModified = lastModifiedTime;
}
return confFile;
}

public void reload() {
logger.debug("Reloading ... ");
Config config = Configuration.getByFileName(parameter.getShellConfFileName(),
Constant.NET_CONF);
Config config = Configuration.getByFileName(parameter.getConfigFilePath(), null);

updateActiveNodes(config);

Expand All @@ -90,7 +69,7 @@ public void reload() {

private void updateActiveNodes(Config config) {
List<InetSocketAddress> newActiveNodes =
Args.getInetSocketAddress(config, Constant.NODE_ACTIVE, true);
Args.getInetSocketAddress(config, ConfigKey.NODE_ACTIVE, true);
parameter.setActiveNodes(newActiveNodes);
List<InetSocketAddress> activeNodes = TronNetService.getP2pConfig().getActiveNodes();
activeNodes.clear();
Expand All @@ -100,7 +79,7 @@ private void updateActiveNodes(Config config) {
}

private void updateTrustNodes(Config config) {
List<InetAddress> newPassiveNodes = Args.getInetAddress(config, Constant.NODE_PASSIVE);
List<InetAddress> newPassiveNodes = Args.getInetAddress(config, ConfigKey.NODE_PASSIVE);
parameter.setPassiveNodes(newPassiveNodes);
List<InetAddress> trustNodes = TronNetService.getP2pConfig().getTrustNodes();
trustNodes.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.Commons;
import org.tron.common.utils.LocalWitnesses;
import org.tron.core.Constant;
import org.tron.core.exception.CipherException;
import org.tron.core.exception.TronError;
import org.tron.keystore.Credentials;
Expand Down Expand Up @@ -70,12 +69,12 @@ private boolean tryInitFromCommandLine() {
}

private boolean tryInitFromConfig() {
if (!config.hasPath(Constant.LOCAL_WITNESS) || config.getStringList(Constant.LOCAL_WITNESS)
if (!config.hasPath(ConfigKey.LOCAL_WITNESS) || config.getStringList(ConfigKey.LOCAL_WITNESS)
.isEmpty()) {
return false;
}

List<String> localWitness = config.getStringList(Constant.LOCAL_WITNESS);
List<String> localWitness = config.getStringList(ConfigKey.LOCAL_WITNESS);
this.localWitnesses.setPrivateKeys(localWitness);
logger.debug("Got privateKey from config.conf");
byte[] witnessAddress = getWitnessAddress();
Expand All @@ -85,12 +84,12 @@ private boolean tryInitFromConfig() {
}

private void tryInitFromKeystore() {
if (!config.hasPath(Constant.LOCAL_WITNESS_KEYSTORE)
|| config.getStringList(Constant.LOCAL_WITNESS_KEYSTORE).isEmpty()) {
if (!config.hasPath(ConfigKey.LOCAL_WITNESS_KEYSTORE)
|| config.getStringList(ConfigKey.LOCAL_WITNESS_KEYSTORE).isEmpty()) {
return;
}

List<String> localWitness = config.getStringList(Constant.LOCAL_WITNESS_KEYSTORE);
List<String> localWitness = config.getStringList(ConfigKey.LOCAL_WITNESS_KEYSTORE);
if (localWitness.size() > 1) {
logger.warn(
"Multiple keystores detected. Only the first keystore will be used as witness, all "
Expand Down Expand Up @@ -127,7 +126,7 @@ private void tryInitFromKeystore() {
}

private byte[] getWitnessAddress() {
if (!config.hasPath(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS)) {
if (!config.hasPath(ConfigKey.LOCAL_WITNESS_ACCOUNT_ADDRESS)) {
return null;
}

Expand All @@ -137,7 +136,7 @@ private byte[] getWitnessAddress() {
TronError.ErrCode.WITNESS_INIT);
}
byte[] witnessAddress = Commons
.decodeFromBase58Check(config.getString(Constant.LOCAL_WITNESS_ACCOUNT_ADDRESS));
.decodeFromBase58Check(config.getString(ConfigKey.LOCAL_WITNESS_ACCOUNT_ADDRESS));
if (witnessAddress != null) {
logger.debug("Got localWitnessAccountAddress from config.conf");
} else {
Expand Down
3 changes: 1 addition & 2 deletions framework/src/main/java/org/tron/program/FullNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.tron.common.log.LogService;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.prometheus.Metrics;
import org.tron.core.Constant;
import org.tron.core.config.DefaultConfig;
import org.tron.core.config.args.Args;

Expand All @@ -21,7 +20,7 @@ public class FullNode {
*/
public static void main(String[] args) {
ExitManager.initExceptionHandler();
Args.setParam(args, Constant.NET_CONF);
Args.setParam(args, "config.conf");
CommonParameter parameter = Args.getInstance();

LogService.load(parameter.getLogbackPath());
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/resources/config-backup.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
net {
type = mainnet
# type = testnet
# type is deprecated and has no effect.
# type = mainnet
}

storage {
Expand Down
2 changes: 1 addition & 1 deletion framework/src/main/resources/config-beta.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
net {
# type is deprecated and has no effect.
# type = mainnet
type = testnet
}

storage {
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/resources/config-localtest.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
net {
type = mainnet
# type = testnet
# type is deprecated and has no effect.
# type = mainnet
}

storage {
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/resources/config-test-net.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
net {
type = mainnet
# type = testnet
# type is deprecated and has no effect.
# type = mainnet
}

storage {
Expand Down
6 changes: 2 additions & 4 deletions framework/src/main/resources/config.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
net {
# Type can be 'mainnet' or 'testnet', refers to address type.
# Hex address of 'mainnet' begin with 0x41, and 'testnet' begin with 0xa0.
# Note: 'testnet' is not related to TRON network Nile, Shasta or private net
type = mainnet
# type is deprecated and has no effect.
# type = mainnet
}

storage {
Expand Down
1 change: 1 addition & 0 deletions framework/src/test/java/org/tron/common/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class TestConstants {

public static final String TEST_CONF = "config-test.conf";
public static final String NET_CONF = "config.conf";
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void testChainId() throws ContractExeException, ReceiptCheckErrException,
byte[] returnValue = result.getRuntime().getResult().getHReturn();
Assert.assertNull(result.getRuntime().getRuntimeError());
Assert.assertEquals(Hex.toHexString(returnValue),
"0000000000000000000000000000000000000000000000000000000028c12d1e");
"000000000000000000000000000000000000000000000000000000000d953577");

VMConfig.initAllowTvmCompatibleEvm(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testExtCodeHash()

// Trigger contract method: getCodeHashByAddr(address)
String methodByAddr = "getCodeHashByAddr(address)";
String nonexistentAccount = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc";
String nonexistentAccount = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi";
String hexInput = AbiUtil.parseMethod(methodByAddr, Arrays.asList(nonexistentAccount));
TVMTestResult result = TvmTestUtils
.triggerContractAndReturnTvmTestResult(Hex.decode(OWNER_ADDRESS),
Expand All @@ -68,7 +68,7 @@ public void testExtCodeHash()
"0000000000000000000000000000000000000000000000000000000000000000");

// trigger deployed contract
String existentAccount = "27WtBq2KoSy5v8VnVZBZHHJcDuWNiSgjbE3";
String existentAccount = "THmtHi1Rzq4gSKYGEKv1DPkV7au6xU1AUB";
hexInput = AbiUtil.parseMethod(methodByAddr, Arrays.asList(existentAccount));
result = TvmTestUtils
.triggerContractAndReturnTvmTestResult(Hex.decode(OWNER_ADDRESS),
Expand Down
21 changes: 17 additions & 4 deletions framework/src/test/java/org/tron/common/runtime/vm/FreezeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
@Slf4j
public class FreezeTest {

// Compiled from FreezeTest.sol (tron-solc ^0.5.16).
// FreezeContract — inner contract with TRON freeze/unfreeze opcodes:
// destroy(address) [0x00f55d9d] selfdestruct
// freeze(address,uint256,uint256) [0x30e1e4e5] opcode 0xd5 FREEZE
// unfreeze(address,uint256) [0x7b46b80b] opcode 0xd6 UNFREEZE
// getExpireTime(address,uint256) [0xe7aa4e0b] opcode 0xd7 FREEZEEXPIRETIME
private static final String CONTRACT_CODE = "608060405261037e806100136000396000f3fe6080604052"
+ "34801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600080fd5b506004361061"
+ "00655760003560e01c8062f55d9d1461006a57806330e1e4e5146100ae5780637b46b80b1461011a578063e7"
Expand All @@ -73,6 +79,13 @@ public class FreezeTest {
+ "506001905092915050565b60008273ffffffffffffffffffffffffffffffffffffffff1682d7905092915050"
+ "56fea26474726f6e58200fd975eab4a8c8afe73bf3841efe4da7832d5a0d09f07115bb695c7260ea64216473"
+ "6f6c63430005100031";
// Compiled from FreezeTest.sol (tron-solc ^0.5.16).
// Factory — deploys FreezeContract and predicts CREATE2 addresses:
// deployCreate2Contract(uint256) [0x41aa9014] CREATE deploy
// getCreate2Addr(uint256) [0xbb63e785] CREATE2 address prediction
// Note: getCreate2Addr uses bytes1(0x41) as the TRON mainnet prefix
// in keccak256(abi.encodePacked(0x41, address(this), salt, codeHash)).
// This value is hardcoded at compile time by tron-solc.
private static final String FACTORY_CODE = "6080604052610640806100136000396000f3fe60806040523"
+ "4801561001057600080fd5b50d3801561001d57600080fd5b50d2801561002a57600080fd5b5060043610610"
+ "0505760003560e01c806341aa901414610055578063bb63e785146100c3575b600080fd5b610081600480360"
Expand All @@ -82,7 +95,7 @@ public class FreezeTest {
+ "020019092919050505061017d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673fff"
+ "fffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600080606060405"
+ "1806020016101469061026e565b6020820181038252601f19601f82011660405250905083815160208301600"
+ "0f59150813b61017357600080fd5b8192505050919050565b60008060a060f81b30846040518060200161019"
+ "0f59150813b61017357600080fd5b8192505050919050565b600080604160f81b30846040518060200161019"
+ "79061026e565b6020820181038252601f19601f820116604052508051906020012060405160200180857efff"
+ "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167efffffffffffffffffffffff"
+ "fffffffffffffffffffffffffffffffffffffff191681526001018473fffffffffffffffffffffffffffffff"
Expand Down Expand Up @@ -114,11 +127,11 @@ public class FreezeTest {

private static final long value = 100_000_000_000_000_000L;
private static final long fee = 1_000_000_000;
private static final String userAStr = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc";
private static final String userAStr = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi";
private static final byte[] userA = Commons.decode58Check(userAStr);
private static final String userBStr = "27jzp7nVEkH4Hf3H1PHPp4VDY7DxTy5eydL";
private static final String userBStr = "TWtWaUAsJ933xs2n4RkXzaMoKJUrQmctBH";
private static final byte[] userB = Commons.decode58Check(userBStr);
private static final String userCStr = "27juXSbMvL6pb8VgmKRgW6ByCfw5RqZjUuo";
private static final String userCStr = "TWoDuH3YsxoMSKSXza3E2H7Tt1bpK5QZgm";
private static final byte[] userC = Commons.decode58Check(userCStr);

@Rule
Expand Down
Loading
Loading