Skip to content
Closed
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 @@ -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.

910 changes: 454 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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class FreezeTest {
+ "020019092919050505061017d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673fff"
+ "fffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600080606060405"
+ "1806020016101469061026e565b6020820181038252601f19601f82011660405250905083815160208301600"
+ "0f59150813b61017357600080fd5b8192505050919050565b60008060a060f81b30846040518060200161019"
+ "0f59150813b61017357600080fd5b8192505050919050565b600080604160f81b30846040518060200161019"
+ "79061026e565b6020820181038252601f19601f820116604052508051906020012060405160200180857efff"
+ "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167efffffffffffffffffffffff"
+ "fffffffffffffffffffffffffffffffffffffff191681526001018473fffffffffffffffffffffffffffffff"
Expand Down Expand Up @@ -114,11 +114,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
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ public class FreezeV2Test {

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
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void testIsContract()

// Trigger contract method: isTest(address)
String methodByAddr = "isTest(address)";
String nonexistentAccount = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc";
String nonexistentAccount = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi";
String hexInput = AbiUtil.parseMethod(methodByAddr, Arrays.asList(nonexistentAccount));
TVMTestResult result = TvmTestUtils
.triggerContractAndReturnTvmTestResult(Hex.decode(OWNER_ADDRESS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public void testIsSRCandidate()

// Trigger contract method: isSRCandidateTest(address)
String methodByAddr = "isSRCandidateTest(address)";
String nonexistentAccount = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc";
byte[] nonexistentAddr = Hex.decode("A0E6773BBF60F97D22AA3BF73D2FE235E816A1964F");
String nonexistentAccount = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi";
byte[] nonexistentAddr = Hex.decode("41E6773BBF60F97D22AA3BF73D2FE235E816A1964F");
String hexInput =
AbiUtil.parseMethod(methodByAddr, Collections.singletonList(nonexistentAccount));

Expand Down Expand Up @@ -209,8 +209,8 @@ public void testIsSRCandidate()
repository.commit();

// trigger deployed contract
String witnessAccount = "27Ssb1WE8FArwJVRRb8Dwy3ssVGuLY8L3S1";
byte[] witnessAddr = Hex.decode("a0299f3db80a24b20a254b89ce639d59132f157f13");
String witnessAccount = "TDmHUBuko2qhcKBCGGafu928hMRj1tX2RW";
byte[] witnessAddr = Hex.decode("41299f3db80a24b20a254b89ce639d59132f157f13");
hexInput = AbiUtil.parseMethod(methodByAddr, Collections.singletonList(witnessAccount));
trx =
TvmTestUtils.generateTriggerSmartContractAndGetTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void istanbulSelfBalanceChainIdTest()
0, fee, manager, null);
Assert.assertNull(result.getRuntime().getRuntimeError());
Assert.assertEquals(Hex.toHexString(result.getRuntime().getResult().getHReturn()),
"00000000000000007adbf8dc20423f587a5f3f8ea83e2877e2129c5128c12d1e");
"0000000000000000c56977ebd315874c5c3c0de6b05738117462db120d953577");
//genesis block hash

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,10 @@ public void resourceV2Test() {
Repository tempRepository = RepositoryImpl.createRoot(StoreFactory.getInstance());
resourceV2Pcc.setRepository(tempRepository);

String targetStr = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc";
String targetStr = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi";
byte[] targetAddr = Commons.decode58Check(targetStr);
byte[] target = new DataWord(targetAddr).getData();
String fromStr = "27jzp7nVEkH4Hf3H1PHPp4VDY7DxTy5eydL";
String fromStr = "TWtWaUAsJ933xs2n4RkXzaMoKJUrQmctBH";
byte[] fromAddr = Commons.decode58Check(fromStr);
byte[] from = new DataWord(fromAddr).getData();
byte[] type = ByteUtil.longTo32Bytes(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void testRewardBalance()

// Trigger contract method: rewardBalanceTest(address)
String methodByAddr = "rewardBalanceTest(address)";
String nonexistentAccount = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc";
String nonexistentAccount = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi";
String hexInput = AbiUtil.parseMethod(methodByAddr,
Collections.singletonList(nonexistentAccount));
BlockCapsule blockCap = new BlockCapsule(Protocol.Block.newBuilder().build());
Expand Down Expand Up @@ -195,7 +195,7 @@ public void testRewardBalance()
repository.commit();

// trigger deployed contract
String witnessAccount = "27Ssb1WE8FArwJVRRb8Dwy3ssVGuLY8L3S1";
String witnessAccount = "TDmHUBuko2qhcKBCGGafu928hMRj1tX2RW";
hexInput = AbiUtil.parseMethod(methodByAddr, Collections.singletonList(witnessAccount));
trx = TvmTestUtils.generateTriggerSmartContractAndGetTransaction(Hex.decode(OWNER_ADDRESS),
factoryAddress, Hex.decode(hexInput), 0, feeLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function test() payable public {}
}
*/

private static final String nonExistAddress = "27k66nycZATHzBasFT9782nTsYWqVtxdtAc"; // 21 char
private static final String nonExistAddress = "TWyoFfJBiKGkVQd28HTqxsc8kbMtQUmqgi"; // 21 char
TestCase[] testCasesAfterAllowTvmConstantinop = {
new TestCase("testTransferTrxSelf()", Collections.emptyList(), false,
contractResult.TRANSFER_FAILED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ public class VMContractTestBase {
MortgageService mortgageService;

static {
// 27Ssb1WE8FArwJVRRb8Dwy3ssVGuLY8L3S1 (test.config)
WITNESS_SR1_ADDRESS =
Constant.ADD_PRE_FIX_STRING_TESTNET + "299F3DB80A24B20A254B89CE639D59132F157F13";
// TDmHUBuko2qhcKBCGGafu928hMRj1tX2RW (test.config)
WITNESS_SR1_ADDRESS = "41" + "299F3DB80A24B20A254B89CE639D59132F157F13";
}

@Before
Expand Down
Loading
Loading