Skip to content

Commit f9b5419

Browse files
committed
Merge branch 'develop' of https://github.com/tronprotocol/java-tron into hotfix/splitDBConfig
2 parents 7a3963e + fed8d25 commit f9b5419

File tree

16 files changed

+124
-76
lines changed

16 files changed

+124
-76
lines changed

actuator/src/main/java/org/tron/core/actuator/FreezeBalanceActuator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public boolean execute(Object result) throws ContractExeException {
9595
dynamicStore
9696
.addTotalEnergyWeight(frozenBalance / 1000_000L);
9797
break;
98+
default:
99+
logger.debug("Resource Code Error.");
98100
}
99101

100102
accountCapsule.setBalance(newBalance);

actuator/src/main/java/org/tron/core/vm/VM.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
public class VM {
3838

3939
public static final String ADDRESS_LOG = "address: ";
40+
private static final String DATA_LOG = "data: ";
41+
private static final String SIZE_LOG = "size: ";
42+
private static final String VALUE_LOG = " value: ";
4043
private static final BigInteger _32_ = BigInteger.valueOf(32);
4144
private static final String ENERGY_LOG_FORMATE = "{} Op:[{}] Energy:[{}] Deep:[{}] Hint:[{}]";
4245
// 3MB
@@ -817,7 +820,7 @@ public void step(Program program) {
817820
DataWord value = program.getDataValue(dataOffs);
818821

819822
if (logger.isDebugEnabled()) {
820-
hint = "data: " + value;
823+
hint = DATA_LOG + value;
821824
}
822825

823826
program.stackPush(value);
@@ -828,7 +831,7 @@ public void step(Program program) {
828831
DataWord dataSize = program.getDataSize();
829832

830833
if (logger.isDebugEnabled()) {
831-
hint = "size: " + dataSize.value();
834+
hint = SIZE_LOG + dataSize.value();
832835
}
833836

834837
program.stackPush(dataSize);
@@ -843,7 +846,7 @@ public void step(Program program) {
843846
byte[] msgData = program.getDataCopy(dataOffsetData, lengthData);
844847

845848
if (logger.isDebugEnabled()) {
846-
hint = "data: " + Hex.toHexString(msgData);
849+
hint = DATA_LOG + Hex.toHexString(msgData);
847850
}
848851

849852
program.memorySave(memOffsetData.intValueSafe(), msgData);
@@ -854,7 +857,7 @@ public void step(Program program) {
854857
DataWord dataSize = program.getReturnDataBufferSize();
855858

856859
if (logger.isDebugEnabled()) {
857-
hint = "size: " + dataSize.value();
860+
hint = SIZE_LOG + dataSize.value();
858861
}
859862

860863
program.stackPush(dataSize);
@@ -874,7 +877,7 @@ public void step(Program program) {
874877
}
875878

876879
if (logger.isDebugEnabled()) {
877-
hint = "data: " + Hex.toHexString(msgData);
880+
hint = DATA_LOG + Hex.toHexString(msgData);
878881
}
879882

880883
program.memorySave(memOffsetData.intValueSafe(), msgData);
@@ -894,7 +897,7 @@ public void step(Program program) {
894897
DataWord codeLength = new DataWord(length);
895898

896899
if (logger.isDebugEnabled()) {
897-
hint = "size: " + length;
900+
hint = SIZE_LOG + length;
898901
}
899902

900903
program.stackPush(codeLength);
@@ -1120,7 +1123,7 @@ public void step(Program program) {
11201123
DataWord data = program.memoryLoad(addr);
11211124

11221125
if (logger.isDebugEnabled()) {
1123-
hint = "data: " + data;
1126+
hint = DATA_LOG + data;
11241127
}
11251128

11261129
program.stackPush(data);
@@ -1132,7 +1135,7 @@ public void step(Program program) {
11321135
DataWord value = program.stackPop();
11331136

11341137
if (logger.isDebugEnabled()) {
1135-
hint = "addr: " + addr + " value: " + value;
1138+
hint = "addr: " + addr + VALUE_LOG + value;
11361139
}
11371140

11381141
program.memorySave(addr, value);
@@ -1152,7 +1155,7 @@ public void step(Program program) {
11521155
DataWord val = program.storageLoad(key);
11531156

11541157
if (logger.isDebugEnabled()) {
1155-
hint = "key: " + key + " value: " + val;
1158+
hint = "key: " + key + VALUE_LOG + val;
11561159
}
11571160

11581161
if (val == null) {
@@ -1173,7 +1176,7 @@ public void step(Program program) {
11731176

11741177
if (logger.isDebugEnabled()) {
11751178
hint =
1176-
"[" + program.getContractAddress().toPrefixString() + "] key: " + addr + " value: "
1179+
"[" + program.getContractAddress().toPrefixString() + "] key: " + addr + VALUE_LOG
11771180
+ value;
11781181
}
11791182

@@ -1407,7 +1410,7 @@ public void step(Program program) {
14071410
program.setHReturn(hReturn);
14081411

14091412
if (logger.isDebugEnabled()) {
1410-
hint = "data: " + Hex.toHexString(hReturn)
1413+
hint = DATA_LOG + Hex.toHexString(hReturn)
14111414
+ " offset: " + offset.value()
14121415
+ " size: " + size.value();
14131416
}

actuator/src/main/java/org/tron/core/vm/program/Program.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public class Program {
9292
private static final String VALIDATE_FOR_SMART_CONTRACT_FAILURE =
9393
"validateForSmartContract failure:%s";
9494
private static final String INVALID_TOKEN_ID_MSG = "not valid token id";
95+
private static final String REFUND_ENERGY_FROM_MESSAGE_CALL = "refund energy from message call";
96+
private static final String CALL_PRE_COMPILED = "call pre-compiled";
9597
private final VMConfig config;
9698
private long nonce;
9799
private byte[] rootTransactionId;
@@ -795,7 +797,7 @@ public void callToAddress(MessageCall msg) {
795797
long senderBalance = deposit.getBalance(senderAddress);
796798
if (senderBalance < endowment) {
797799
stackPushZero();
798-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
800+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
799801
return;
800802
}
801803
} else {
@@ -804,7 +806,7 @@ public void callToAddress(MessageCall msg) {
804806
long senderBalance = deposit.getTokenBalance(senderAddress, tokenId);
805807
if (senderBalance < endowment) {
806808
stackPushZero();
807-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
809+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
808810
return;
809811
}
810812
}
@@ -831,7 +833,7 @@ public void callToAddress(MessageCall msg) {
831833
.validateForSmartContract(deposit, senderAddress, contextAddress, endowment);
832834
} catch (ContractValidateException e) {
833835
if (VMConfig.allowTvmConstantinople()) {
834-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
836+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
835837
throw new TransferException("transfer trx failed: %s", e.getMessage());
836838
}
837839
throw new BytecodeExecutionException(VALIDATE_FOR_SMART_CONTRACT_FAILURE, e.getMessage());
@@ -844,7 +846,7 @@ public void callToAddress(MessageCall msg) {
844846
tokenId, endowment);
845847
} catch (ContractValidateException e) {
846848
if (VMConfig.allowTvmConstantinople()) {
847-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
849+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
848850
throw new TransferException("transfer trc10 failed: %s", e.getMessage());
849851
}
850852
throw new BytecodeExecutionException(VALIDATE_FOR_SMART_CONTRACT_FAILURE, e.getMessage());
@@ -938,7 +940,7 @@ this, new DataWord(contextAddress),
938940
}
939941
}
940942
} else {
941-
refundEnergy(msg.getEnergy().longValue(), "remaining esnergy from the internal call");
943+
refundEnergy(msg.getEnergy().longValue(), "remaining energy from the internal call");
942944
}
943945
}
944946

@@ -1358,7 +1360,7 @@ public void callToPrecompiledAddress(MessageCall msg,
13581360
}
13591361
if (senderBalance < endowment) {
13601362
stackPushZero();
1361-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
1363+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
13621364
return;
13631365
}
13641366
byte[] data = this.memoryChunk(msg.getInDataOffs().intValue(),
@@ -1390,7 +1392,7 @@ public void callToPrecompiledAddress(MessageCall msg,
13901392
if (requiredEnergy > msg.getEnergy().longValue()) {
13911393
// Not need to throw an exception, method caller needn't know that
13921394
// regard as consumed the energy
1393-
this.refundEnergy(0, "call pre-compiled"); //matches cpp logic
1395+
this.refundEnergy(0, CALL_PRE_COMPILED); //matches cpp logic
13941396
this.stackPushZero();
13951397
} else {
13961398
// Delegate or not. if is delegated, we will use msg sender, otherwise use contract address
@@ -1404,13 +1406,13 @@ public void callToPrecompiledAddress(MessageCall msg,
14041406
Pair<Boolean, byte[]> out = contract.execute(data);
14051407

14061408
if (out.getLeft()) { // success
1407-
this.refundEnergy(msg.getEnergy().longValue() - requiredEnergy, "call pre-compiled");
1409+
this.refundEnergy(msg.getEnergy().longValue() - requiredEnergy, CALL_PRE_COMPILED);
14081410
this.stackPushOne();
14091411
returnDataBuffer = out.getRight();
14101412
deposit.commit();
14111413
} else {
14121414
// spend all energy on failure, push zero and revert state changes
1413-
this.refundEnergy(0, "call pre-compiled");
1415+
this.refundEnergy(0, CALL_PRE_COMPILED);
14141416
this.stackPushZero();
14151417
if (Objects.nonNull(this.result.getException())) {
14161418
throw result.getException();
@@ -1449,7 +1451,7 @@ public void checkTokenId(MessageCall msg) {
14491451
tokenId = msg.getTokenId().sValue().longValueExact();
14501452
} catch (ArithmeticException e) {
14511453
if (VMConfig.allowTvmConstantinople()) {
1452-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
1454+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
14531455
throw new TransferException(VALIDATE_FOR_SMART_CONTRACT_FAILURE, INVALID_TOKEN_ID_MSG);
14541456
}
14551457
throw e;
@@ -1460,7 +1462,7 @@ public void checkTokenId(MessageCall msg) {
14601462
|| (tokenId == 0 && msg.isTokenTransferMsg())) {
14611463
// tokenId == 0 is a default value for token id DataWord.
14621464
if (VMConfig.allowTvmConstantinople()) {
1463-
refundEnergy(msg.getEnergy().longValue(), "refund energy from message call");
1465+
refundEnergy(msg.getEnergy().longValue(), REFUND_ENERGY_FROM_MESSAGE_CALL);
14641466
throw new TransferException(VALIDATE_FOR_SMART_CONTRACT_FAILURE, INVALID_TOKEN_ID_MSG);
14651467
}
14661468
throw new BytecodeExecutionException(

chainbase/src/main/java/org/tron/common/storage/rocksdb/RocksDbDataSourceImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class RocksDbDataSourceImpl implements DbSourceInter<byte[]>,
4141
Iterable<Map.Entry<byte[], byte[]>>, Instance<RocksDbDataSourceImpl> {
4242

4343
ReadOptions readOpts;
44+
private static final String FAIL_TO_INIT_DATABASE = "Failed to initialize database";
4445
private String dataBaseName;
4546
private RocksDB database;
4647
private boolean alive;
@@ -166,7 +167,7 @@ public boolean checkOrInitEngine() {
166167
public void initDB() {
167168
if (!checkOrInitEngine()) {
168169
logger.error("database engine do not match");
169-
throw new RuntimeException("Failed to initialize database");
170+
throw new RuntimeException(FAIL_TO_INIT_DATABASE);
170171
}
171172
initDB(RocksDbSettings.getSettings());
172173
}
@@ -230,14 +231,14 @@ public void initDB(RocksDbSettings settings) {
230231
database = RocksDB.open(options, dbPath.toString());
231232
} catch (RocksDBException e) {
232233
logger.error(e.getMessage(), e);
233-
throw new RuntimeException("Failed to initialize database", e);
234+
throw new RuntimeException(FAIL_TO_INIT_DATABASE, e);
234235
}
235236

236237
alive = true;
237238

238239
} catch (IOException ioe) {
239240
logger.error(ioe.getMessage(), ioe);
240-
throw new RuntimeException("Failed to initialize database", ioe);
241+
throw new RuntimeException(FAIL_TO_INIT_DATABASE, ioe);
241242
}
242243

243244
logger.debug("<~ RocksDbDataSource.initDB(): " + dataBaseName);

chainbase/src/main/java/org/tron/core/db/StorageMarket.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
public class StorageMarket {
1010

1111
private static final long MS_PER_YEAR = 365 * 24 * 3600 * 1000L;
12+
private static final String NEW_TOTAL_RESERVED = " newTotalReserved: ";
13+
private static final String NEW_STORAGE_LIMIT = " newStorageLimit: ";
14+
private static final String NEW_TOTAL_POOL = "newTotalPool: ";
1215
private AccountStore accountStore;
1316
private DynamicPropertiesStore dynamicPropertiesStore;
1417
private long supply = 1_000_000_000_000_000L;
@@ -111,7 +114,7 @@ public long tryPayTax(long duration, long limit) {
111114
== 128L * 1024 * 1024 * 1024;
112115
logger.info("reserved == 128GB: " + eq);
113116
logger.info("newTotalTax: " + newTotalTax + " newTotalPool: " + newTotalPool
114-
+ " newTotalReserved: " + newTotalReserved);
117+
+ NEW_TOTAL_RESERVED + newTotalReserved);
115118

116119
return storageTax;
117120
}
@@ -130,7 +133,7 @@ public long payTax(long duration, long limit) {
130133
== 128L * 1024 * 1024 * 1024;
131134
logger.info("reserved == 128GB: " + eq);
132135
logger.info("newTotalTax: " + newTotalTax + " newTotalPool: " + newTotalPool
133-
+ " newTotalReserved: " + newTotalReserved);
136+
+ NEW_TOTAL_RESERVED + newTotalReserved);
134137
dynamicPropertiesStore.saveTotalStorageTax(newTotalTax);
135138
dynamicPropertiesStore.saveTotalStoragePool(newTotalPool);
136139
dynamicPropertiesStore.saveTotalStorageReserved(newTotalReserved);
@@ -163,7 +166,7 @@ public AccountCapsule buyStorageBytes(AccountCapsule accountCapsule, long storag
163166

164167
long newStorageLimit = currentStorageLimit + storageBought;
165168
logger.info(
166-
"storageBought: " + storageBought + " newStorageLimit: "
169+
"storageBought: " + storageBought + NEW_STORAGE_LIMIT
167170
+ newStorageLimit);
168171

169172
accountCapsule.setLatestExchangeStorageTime(now);
@@ -174,7 +177,7 @@ public AccountCapsule buyStorageBytes(AccountCapsule accountCapsule, long storag
174177
long newTotalPool = dynamicPropertiesStore.getTotalStoragePool() + quant;
175178
long newTotalReserved = dynamicPropertiesStore.getTotalStorageReserved()
176179
- storageBought;
177-
logger.info("newTotalPool: " + newTotalPool + " newTotalReserved: " + newTotalReserved);
180+
logger.info(NEW_TOTAL_POOL + newTotalPool + NEW_TOTAL_RESERVED + newTotalReserved);
178181
dynamicPropertiesStore.saveTotalStoragePool(newTotalPool);
179182
dynamicPropertiesStore.saveTotalStorageReserved(newTotalReserved);
180183
return accountCapsule;
@@ -191,7 +194,7 @@ public void buyStorage(AccountCapsule accountCapsule, long quant) {
191194
long storageBought = exchange(quant, true);
192195
long newStorageLimit = currentStorageLimit + storageBought;
193196
logger.info(
194-
"storageBought: " + storageBought + " newStorageLimit: "
197+
"storageBought: " + storageBought + NEW_STORAGE_LIMIT
195198
+ newStorageLimit);
196199

197200
accountCapsule.setLatestExchangeStorageTime(now);
@@ -202,7 +205,7 @@ public void buyStorage(AccountCapsule accountCapsule, long quant) {
202205
long newTotalPool = dynamicPropertiesStore.getTotalStoragePool() + quant;
203206
long newTotalReserved = dynamicPropertiesStore.getTotalStorageReserved()
204207
- storageBought;
205-
logger.info("newTotalPool: " + newTotalPool + " newTotalReserved: " + newTotalReserved);
208+
logger.info(NEW_TOTAL_POOL + newTotalPool + NEW_TOTAL_RESERVED + newTotalReserved);
206209
dynamicPropertiesStore.saveTotalStoragePool(newTotalPool);
207210
dynamicPropertiesStore.saveTotalStorageReserved(newTotalReserved);
208211

@@ -216,7 +219,7 @@ public void sellStorage(AccountCapsule accountCapsule, long bytes) {
216219
long newBalance = accountCapsule.getBalance() + quant;
217220

218221
long newStorageLimit = currentStorageLimit - bytes;
219-
logger.info("quant: " + quant + " newStorageLimit: " + newStorageLimit);
222+
logger.info("quant: " + quant + NEW_STORAGE_LIMIT + newStorageLimit);
220223

221224
accountCapsule.setLatestExchangeStorageTime(now);
222225
accountCapsule.setStorageLimit(newStorageLimit);
@@ -226,7 +229,7 @@ public void sellStorage(AccountCapsule accountCapsule, long bytes) {
226229
long newTotalPool = dynamicPropertiesStore.getTotalStoragePool() - quant;
227230
long newTotalReserved = dynamicPropertiesStore.getTotalStorageReserved()
228231
+ bytes;
229-
logger.info("newTotalPool: " + newTotalPool + " newTotalReserved: " + newTotalReserved);
232+
logger.info(NEW_TOTAL_POOL + newTotalPool + NEW_TOTAL_RESERVED + newTotalReserved);
230233
dynamicPropertiesStore.saveTotalStoragePool(newTotalPool);
231234
dynamicPropertiesStore.saveTotalStorageReserved(newTotalReserved);
232235

common/src/main/java/org/tron/common/utils/Hash.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Hash {
3838
private static final Provider CRYPTO_PROVIDER;
3939
private static final String HASH_256_ALGORITHM_NAME;
4040
private static final String HASH_512_ALGORITHM_NAME;
41+
private static final String ALGORITHM_NOT_FOUND = "Can't find such algorithm";
4142
/**
4243
* [0x80] If a string is 0-55 bytes long, the RLP encoding consists of a single byte with value
4344
* 0x80 plus the length of the string followed by the string. The range of the first byte is thus
@@ -78,7 +79,7 @@ public static byte[] sha3(byte[] input) {
7879
digest.update(input);
7980
return digest.digest();
8081
} catch (NoSuchAlgorithmException e) {
81-
logger.error("Can't find such algorithm", e);
82+
logger.error(ALGORITHM_NOT_FOUND, e);
8283
throw new RuntimeException(e);
8384
}
8485

@@ -93,7 +94,7 @@ public static byte[] sha3(byte[] input1, byte[] input2) {
9394
digest.update(input2, 0, input2.length);
9495
return digest.digest();
9596
} catch (NoSuchAlgorithmException e) {
96-
logger.error("Can't find such algorithm", e);
97+
logger.error(ALGORITHM_NOT_FOUND, e);
9798
throw new RuntimeException(e);
9899
}
99100
}
@@ -114,7 +115,7 @@ public static byte[] sha3(byte[] input, int start, int length) {
114115
digest.update(input, start, length);
115116
return digest.digest();
116117
} catch (NoSuchAlgorithmException e) {
117-
logger.error("Can't find such algorithm", e);
118+
logger.error(ALGORITHM_NOT_FOUND, e);
118119
throw new RuntimeException(e);
119120
}
120121
}
@@ -127,7 +128,7 @@ public static byte[] sha512(byte[] input) {
127128
digest.update(input);
128129
return digest.digest();
129130
} catch (NoSuchAlgorithmException e) {
130-
logger.error("Can't find such algorithm", e);
131+
logger.error(ALGORITHM_NOT_FOUND, e);
131132
throw new RuntimeException(e);
132133
}
133134
}

framework/src/main/java/org/tron/common/net/udp/message/discover/DiscoverMessageInspector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
public class DiscoverMessageInspector {
1010

11-
public static final Pattern PATTERN_IP = Pattern.compile("\\d+\\.\\d+\\.\\d+\\.\\d+");
11+
public static final Pattern PATTERN_IP =
12+
Pattern.compile("^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\"
13+
+ ".(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\"
14+
+ ".(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\"
15+
+ ".(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$");
1216

1317
private static boolean isFound(String str, Pattern pattern) {
1418
if (str == null || pattern == null) {

0 commit comments

Comments
 (0)