Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge master into develop #5556

Merged
merged 48 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
91b6f33
test(net):add message handler test
jwrct Aug 31, 2023
04b1826
test(net):fix checkstyle issues
jwrct Aug 31, 2023
868faec
Revert "test(net):fix checkstyle issues"
jwrct Aug 31, 2023
6fdfd01
test(net):fix checkstyle issues
jwrct Aug 31, 2023
42635a8
Merge branch 'develop_upstream' into add_test
jwrct Aug 31, 2023
c175194
test(case): fix code style
Aug 28, 2023
6748bce
test(net):optimize test code
jwrct Sep 7, 2023
c0cd4e4
Merge branch 'develop_upstream' into add_test
jwrct Sep 7, 2023
1e500f0
feat(config): update jacoco config
Sep 7, 2023
17558c5
test(case): add WitnessScheduleStoreTest test case
Sep 7, 2023
660917a
Merge branch 'release_v4.7.3' into add_test
jwrct Sep 12, 2023
dc6f2d0
Merge branch 'develop' into feature/update_jacoco_config
Sep 12, 2023
2ce1fa7
Merge branch 'release_v4.7.3' into feature/update_jacoco_config
Sep 12, 2023
31e499d
Merge branch 'release_v4.7.3' into add_test
jwrct Sep 13, 2023
9d089e7
test(net):create folder with temporaryFolder
jwrct Sep 13, 2023
9750847
Merge pull request #5475 from forfreeday/feature/update_jacoco_config
forfreeday Sep 15, 2023
5e420e4
Merge pull request #5463 from forfreeday/feature/optimize_test_case
forfreeday Sep 18, 2023
47fe702
feat(db/checkPointV2Store): change log level from info to debug for c…
halibobo1205 Sep 18, 2023
c97617c
fix(test\db): fix wrong output path (#5501)
forfreeday Sep 19, 2023
6703d13
feat(api): add http/grpc interface rate limit
xxo1shine Sep 19, 2023
b4d1a6b
Merge branch 'release_v4.7.3' of github.com:tronprotocol/java-tron in…
xxo1shine Sep 19, 2023
290753a
fix(api): optimize API call compatibility
lxcmyf Sep 19, 2023
7ffd2fc
fix(event/mechanism): fix NPE in TransactionLogTriggerCapsule (#5500)
CarlChaoCarl Sep 19, 2023
0bacdaa
Merge remote-tracking branch 'upstream/release_v4.7.3' into release_v…
lxcmyf Sep 19, 2023
52283dc
Merge pull request #5502 from ss3344520/api
xxo1shine Sep 20, 2023
3e6eb02
Merge pull request #5504 from lxcmyf/release_v4.7.3
jwrct Sep 20, 2023
703a866
fix(db/trans-cache): avoid recovering a wrong cached data (#5505)
halibobo1205 Sep 20, 2023
9842b3f
fix(freezeV2): remove duplicate judgments (#5508)
lxcmyf Sep 21, 2023
6802f34
feat(test): add db test (#5461)
lurais Sep 22, 2023
c78c42e
test(db): add test case (#5503)
lurais Sep 22, 2023
9406d24
fix(api): add resource price query API for soliditynode (#5516)
lxcmyf Sep 25, 2023
962a3db
feat(net):update libp2p (#5517)
317787106 Sep 26, 2023
fe7715d
feat(LiteFullNodeTool): mark LiteFullNodeTool as deprecated (#5509)
forfreeday Oct 7, 2023
c623940
feat(db/trans-cache): verify cached files with crc32c (#5523)
halibobo1205 Oct 8, 2023
94e1a84
test(db): fix org.iq80.leveldb.DBException: Closed (#5528)
halibobo1205 Oct 11, 2023
419570c
Merge pull request #5459 from jwrct/add_test
jwrct Oct 11, 2023
283230a
test(api): add test cases of Wallet (#5442)
317787106 Oct 11, 2023
e987efb
feat(net): fix bug of getting head block concurrently (#5532)
317787106 Oct 12, 2023
2ab2677
fix(api):rollback due to insufficient compatibility (#5537)
lxcmyf Oct 16, 2023
1cb7f2c
feat(version): update version
Oct 16, 2023
46ea631
Merge pull request #5538 from forfreeday/feature/update_version
forfreeday Oct 16, 2023
87db52a
update libp2p version to release 2.1.0 (#5539)
317787106 Oct 16, 2023
d1f0ff3
add switch for transaction cache initialization optimization (#5543)
halibobo1205 Oct 17, 2023
5bafc0c
Add block height check when processing PBFT messages (#5548)
jwrct Oct 25, 2023
d18597f
Merge pull request #5554 from tronprotocol/release_v4.7.3.1
lvs007 Oct 25, 2023
9d13f9c
Merge pull request #5552 from tronprotocol/release_v4.7.3
lvs007 Oct 25, 2023
381c52c
update a new version. version name:GreatVoyage-v4.7.2-140-g9d13f9cb69…
Oct 25, 2023
440d062
Merge pull request #5555 from forfreeday/version/GreatVoyage-v4.7.2-1…
forfreeday Oct 25, 2023
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
2 changes: 1 addition & 1 deletion actuator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jacocoTestReport {
xml.enabled = true
html.enabled = true
}
executionData.from = '../framework/build/jacoco/jacocoTest.exec'
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
classDirectories.from = classDirectories.files.collect {
fileTree(dir: it,)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public boolean validate() throws ContractValidateException {

byte[] receiverAddress = delegateResourceContract.getReceiverAddress().toByteArray();

if (ArrayUtils.isEmpty(receiverAddress) || !DecodeUtil.addressValid(receiverAddress)) {
if (!DecodeUtil.addressValid(receiverAddress)) {
throw new ContractValidateException("Invalid receiverAddress");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void validate(DelegateResourceParam param, Repository repo) throws Contra

byte[] receiverAddress = param.getReceiverAddress();

if (ArrayUtils.isEmpty(receiverAddress) || !DecodeUtil.addressValid(receiverAddress)) {
if (!DecodeUtil.addressValid(receiverAddress)) {
throw new ContractValidateException("Invalid receiverAddress");
}
if (Arrays.equals(receiverAddress, ownerAddress)) {
Expand Down
2 changes: 1 addition & 1 deletion chainbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jacocoTestReport {
xml.enabled = true
html.enabled = true
}
executionData.from = '../framework/build/jacoco/jacocoTest.exec'
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
classDirectories.from = classDirectories.files.collect {
fileTree(dir: it,)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tron.core.capsule.BytesCapsule;
import org.tron.core.db2.common.TxCacheDB;
import org.tron.core.store.DynamicPropertiesStore;

@Slf4j
@Component
public class TransactionCache extends TronStoreWithRevoking<BytesCapsule> {

@Autowired
public TransactionCache(@Value("trans-cache") String dbName,
RecentTransactionStore recentTransactionStore) {
super(new TxCacheDB(dbName, recentTransactionStore));
@Autowired RecentTransactionStore recentTransactionStore,
@Autowired DynamicPropertiesStore dynamicPropertiesStore) {
super(new TxCacheDB(dbName, recentTransactionStore, dynamicPropertiesStore));
}

public void initCache() {
Expand Down
115 changes: 94 additions & 21 deletions chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource;
import com.google.common.primitives.Longs;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
Expand All @@ -18,6 +22,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -40,6 +45,7 @@
import org.tron.core.db.RecentTransactionItem;
import org.tron.core.db.RecentTransactionStore;
import org.tron.core.db.common.iterator.DBIterator;
import org.tron.core.store.DynamicPropertiesStore;

@Slf4j(topic = "DB")
public class TxCacheDB implements DB<byte[], byte[]>, Flusher {
Expand All @@ -59,7 +65,6 @@ public class TxCacheDB implements DB<byte[], byte[]>, Flusher {
private BloomFilter<byte[]>[] bloomFilters = new BloomFilter[2];
// filterStartBlock record the start block of the active filter
private volatile long filterStartBlock = INVALID_BLOCK;
private volatile long currentBlockNum = INVALID_BLOCK;
// currentFilterIndex records the index of the active filter
private volatile int currentFilterIndex = 0;

Expand All @@ -75,21 +80,28 @@ public class TxCacheDB implements DB<byte[], byte[]>, Flusher {
// replace persistentStore and optimizes startup performance
private RecentTransactionStore recentTransactionStore;

private DynamicPropertiesStore dynamicPropertiesStore;

private final Path cacheFile0;
private final Path cacheFile1;
private String crc32c0;
private String crc32c1;
private final Path cacheProperties;
private final Path cacheDir;
private AtomicBoolean isValid = new AtomicBoolean(false);
private boolean txCacheInitOptimization;

@Getter
@Setter
private volatile boolean alive;

public TxCacheDB(String name, RecentTransactionStore recentTransactionStore) {
public TxCacheDB(String name, RecentTransactionStore recentTransactionStore,
DynamicPropertiesStore dynamicPropertiesStore) {
this.name = name;
this.TRANSACTION_COUNT =
CommonParameter.getInstance().getStorage().getEstimatedBlockTransactions();
this.recentTransactionStore = recentTransactionStore;
this.dynamicPropertiesStore = dynamicPropertiesStore;
String dbEngine = CommonParameter.getInstance().getStorage().getDbEngine();
if ("LEVELDB".equals(dbEngine.toUpperCase())) {
this.persistentStore = new LevelDB(
Expand Down Expand Up @@ -117,6 +129,8 @@ public TxCacheDB(String name, RecentTransactionStore recentTransactionStore) {
this.cacheFile0 = Paths.get(cacheDir.toString(), "bloomFilters_0");
this.cacheFile1 = Paths.get(cacheDir.toString(), "bloomFilters_1");
this.cacheProperties = Paths.get(cacheDir.toString(), "txCache.properties");
this.txCacheInitOptimization = CommonParameter.getInstance()
.getStorage().isTxCacheInitOptimization();

}

Expand Down Expand Up @@ -211,7 +225,6 @@ public void put(byte[] key, byte[] value) {
MAX_BLOCK_SIZE * TRANSACTION_COUNT);
}
bloomFilters[currentFilterIndex].put(key);
currentBlockNum = blockNum;
if (lastMetricBlock != blockNum) {
lastMetricBlock = blockNum;
Metrics.gaugeSet(MetricKeys.Gauge.TX_CACHE,
Expand Down Expand Up @@ -270,6 +283,12 @@ public void reset() {
}

private boolean recovery() {
if (!txCacheInitOptimization) {
logger.info("txCache init optimization is disabled, skip fast recovery mode.");
logger.info("If you want fast recovery mode,"
+ " please set `storage.txCache.initOptimization = true` in config.conf.");
return false;
}
FileUtil.createDirIfNotExists(this.cacheDir.toString());
logger.info("recovery bloomFilters start.");
CompletableFuture<Boolean> loadProperties = CompletableFuture.supplyAsync(this::loadProperties);
Expand All @@ -278,13 +297,18 @@ private boolean recovery() {
CompletableFuture<Boolean> tk1 = loadProperties.thenApplyAsync(
v -> recovery(1, this.cacheFile1));

return CompletableFuture.allOf(tk0, tk1).thenApply(v -> {
logger.info("recovery bloomFilters success.");
return true;
}).exceptionally(this::handleException).join();
try {
return CompletableFuture.allOf(tk0, tk1).thenApply(v -> {
logger.info("recovery bloomFilters success.");
return true;
}).exceptionally(this::handleException).join();
} finally {
clearCrc32c();
}
}

private boolean recovery(int index, Path file) {
checkCrc32c(index, file);
try (InputStream in = new BufferedInputStream(Files.newInputStream(file,
StandardOpenOption.READ, StandardOpenOption.DELETE_ON_CLOSE))) {
logger.info("recovery bloomFilter[{}] from file.", index);
Expand Down Expand Up @@ -326,24 +350,38 @@ private void dump() {
() -> dump(0, this.cacheFile0));
CompletableFuture<Void> task1 = CompletableFuture.runAsync(
() -> dump(1, this.cacheFile1));
CompletableFuture.allOf(task0, task1).thenRun(() -> {
writeProperties();
logger.info("dump bloomFilters done.");

}).exceptionally(e -> {
logger.info("dump bloomFilters to file failed. {}", e.getMessage());
return null;
}).join();
try {
CompletableFuture.allOf(task0, task1).thenRun(() -> {
writeProperties();
logger.info("dump bloomFilters done.");
}).exceptionally(e -> {
logger.info("dump bloomFilters to file failed. {}", e.getMessage());
return null;
}).join();
} finally {
clearCrc32c();
}
}

private void dump(int index, Path file) {
logger.info("dump bloomFilters[{}] to file.", index);
long start = System.currentTimeMillis();
try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(file))) {
logger.info("dump bloomFilters[{}] to file.", index);
long start = System.currentTimeMillis();
bloomFilters[index].writeTo(out);
logger.info("dump bloomFilters[{}] to file done,filter: {}, filter-fpp: {}, cost {} ms.",
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
String crc32c = getCrc32c(file);
if (index == 0) {
this.crc32c0 = crc32c;
} else {
this.crc32c1 = crc32c;
}
logger.info("dump bloomFilters[{}] to file done,filter: {}, filter-fpp: {}, "
+ "crc32c: {}, cost {} ms.",
index, bloomFilters[index].approximateElementCount(), bloomFilters[index].expectedFpp(),
System.currentTimeMillis() - start);
crc32c, System.currentTimeMillis() - start);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -356,8 +394,16 @@ private boolean loadProperties() {
Properties properties = new Properties();
properties.load(r);
filterStartBlock = Long.parseLong(properties.getProperty("filterStartBlock"));
currentBlockNum = Long.parseLong(properties.getProperty("currentBlockNum"));
long currentBlockNum = Long.parseLong(properties.getProperty("currentBlockNum"));
long currentBlockNumFromDB = dynamicPropertiesStore.getLatestBlockHeaderNumberFromDB();
currentFilterIndex = Integer.parseInt(properties.getProperty("currentFilterIndex"));
if (currentBlockNum != currentBlockNumFromDB) {
throw new IllegalStateException(
String.format("currentBlockNum not match. filter: %d, db: %d",
currentBlockNum, currentBlockNumFromDB));
}
this.crc32c0 = properties.getProperty("crc32c0");
this.crc32c1 = properties.getProperty("crc32c1");
logger.info("filterStartBlock: {}, currentBlockNum: {}, currentFilterIndex: {}, load done.",
filterStartBlock, currentBlockNum, currentFilterIndex);
return true;
Expand All @@ -369,9 +415,12 @@ private boolean loadProperties() {
private void writeProperties() {
try (Writer w = Files.newBufferedWriter(this.cacheProperties, StandardCharsets.UTF_8)) {
Properties properties = new Properties();
long currentBlockNum = dynamicPropertiesStore.getLatestBlockHeaderNumberFromDB();
properties.setProperty("filterStartBlock", String.valueOf(filterStartBlock));
properties.setProperty("currentBlockNum", String.valueOf(currentBlockNum));
properties.setProperty("currentFilterIndex", String.valueOf(currentFilterIndex));
properties.setProperty("crc32c0", this.crc32c0);
properties.setProperty("crc32c1", this.crc32c1);
properties.store(w, "Generated by the application. PLEASE DO NOT EDIT! ");
logger.info("filterStartBlock: {}, currentBlockNum: {}, currentFilterIndex: {}, write done.",
filterStartBlock, currentBlockNum, currentFilterIndex);
Expand All @@ -380,9 +429,33 @@ private void writeProperties() {
}
}

private String getCrc32c(Path file) throws IOException {
ByteSource byteSource = com.google.common.io.Files.asByteSource(file.toFile());
HashCode hc = byteSource.hash(Hashing.crc32c());
return hc.toString();
}

private void checkCrc32c(int index, Path file) {
try {
String actual = getCrc32c(file);
String expect = index == 0 ? this.crc32c0 : this.crc32c1;
if (!Objects.equals(actual, expect)) {
throw new IllegalStateException("crc32c not match. index: " + index + ", expect: " + expect
+ ", actual: " + actual);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private void clearCrc32c() {
this.crc32c0 = null;
this.crc32c1 = null;
}

@Override
public TxCacheDB newInstance() {
return new TxCacheDB(name, recentTransactionStore);
return new TxCacheDB(name, recentTransactionStore, dynamicPropertiesStore);
}

@Override
Expand Down
17 changes: 17 additions & 0 deletions chainbase/src/main/java/org/tron/core/store/CheckPointV2Store.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.core.store;

import com.google.protobuf.InvalidProtocolBufferException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.tron.core.db.TronDatabase;
import org.tron.core.exception.BadItemException;
Expand All @@ -9,6 +10,7 @@
import java.util.Spliterator;
import java.util.function.Consumer;

@Slf4j(topic = "DB")
public class CheckPointV2Store extends TronDatabase<byte[]> {

@Autowired
Expand Down Expand Up @@ -50,4 +52,19 @@ public Spliterator spliterator() {
protected void init() {
}

/**
* close the database.
*/
@Override
public void close() {
logger.debug("******** Begin to close {}. ********", getName());
try {
dbSource.closeDB();
} catch (Exception e) {
logger.warn("Failed to close {}.", getName(), e);
} finally {
logger.debug("******** End to close {}. ********", getName());
}
}

}
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
compile 'org.aspectj:aspectjrt:1.8.13'
compile 'org.aspectj:aspectjweaver:1.8.13'
compile 'org.aspectj:aspectjtools:1.8.13'
compile group: 'com.github.tronprotocol', name: 'libp2p', version: 'test-v2.0.2',{
compile group: 'io.github.tronprotocol', name: 'libp2p', version: '2.1.0',{
exclude group: 'io.grpc', module: 'grpc-context'
exclude group: 'io.grpc', module: 'grpc-core'
exclude group: 'io.grpc', module: 'grpc-netty'
Expand All @@ -68,7 +68,7 @@ jacocoTestReport {
xml.enabled = true
html.enabled = true
}
executionData.from = '../framework/build/jacoco/jacocoTest.exec'
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
classDirectories.from = classDirectories.files.collect {
fileTree(dir: it,)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ public class CommonParameter {
@Setter
public int rateLimiterGlobalIpQps;
@Getter
public int rateLimiterGlobalApiQps;
@Getter
public DbBackupConfig dbBackupConfig;
@Getter
public RocksDbSettings rocksDBCustomSettings;
Expand Down Expand Up @@ -516,6 +518,9 @@ public class CommonParameter {
public int pBFTHttpPort;
@Getter
@Setter
public long pBFTExpireNum;
@Getter
@Setter
public long oldSolidityBlockNum = -1;

@Getter/**/
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public class Constant {

public static final String RATE_LIMITER_GLOBAL_IP_QPS = "rate.limiter.global.ip.qps";

public static final String RATE_LIMITER_GLOBAL_API_QPS = "rate.limiter.global.api.qps";

public static final String COMMITTEE_CHANGED_DELEGATION = "committee.changedDelegation";

public static final String CRYPTO_ENGINE = "crypto.engine";
Expand Down Expand Up @@ -301,6 +303,7 @@ public class Constant {
public static final String SEED_NODE_IP_LIST = "seed.node.ip.list";
public static final String NODE_METRICS_ENABLE = "node.metricsEnable";
public static final String COMMITTEE_ALLOW_PBFT = "committee.allowPBFT";
public static final String COMMITTEE_PBFT_EXPIRE_NUM = "committee.pBFTExpireNum";
public static final String NODE_AGREE_NODE_COUNT = "node.agreeNodeCount";

public static final String COMMITTEE_ALLOW_TRANSACTION_FEE_POOL = "committee.allowTransactionFeePool";
Expand Down
Loading
Loading