Skip to content

Commit ebbad66

Browse files
committed
Merge upstream/release_v4.8.2 to pick up tronprotocol#6757 (--es fix) and tronprotocol#6761 (rate-limiter blocking mode)
2 parents 1384b91 + 5f7eeca commit ebbad66

448 files changed

Lines changed: 26014 additions & 3688 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr-build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ jobs:
5454
- name: Build
5555
run: ./gradlew clean build --no-daemon
5656

57+
- name: Toolkit jar smoke test
58+
run: |
59+
set -e
60+
JAR=plugins/build/libs/Toolkit.jar
61+
java -jar "$JAR" help
62+
java -jar "$JAR" db --help
63+
java -jar "$JAR" db archive -h
64+
java -jar "$JAR" keystore --help
65+
5766
build-ubuntu:
5867
name: Build ubuntu24 (JDK 17 / aarch64)
5968
if: ${{ github.event_name == 'pull_request' || inputs.job == 'all' || inputs.job == 'ubuntu' }}
@@ -84,6 +93,15 @@ jobs:
8493
- name: Build
8594
run: ./gradlew clean build --no-daemon
8695

96+
- name: Toolkit jar smoke test
97+
run: |
98+
set -e
99+
JAR=plugins/build/libs/Toolkit.jar
100+
java -jar "$JAR" help
101+
java -jar "$JAR" db --help
102+
java -jar "$JAR" db archive -h
103+
java -jar "$JAR" keystore --help
104+
87105
docker-build-rockylinux:
88106
name: Build rockylinux (JDK 8 / x86_64)
89107
if: ${{ github.event_name == 'pull_request' || inputs.job == 'all' || inputs.job == 'rockylinux' }}
@@ -127,6 +145,15 @@ jobs:
127145
- name: Build
128146
run: ./gradlew clean build --no-daemon
129147

148+
- name: Toolkit jar smoke test
149+
run: |
150+
set -e
151+
JAR=plugins/build/libs/Toolkit.jar
152+
java -jar "$JAR" help
153+
java -jar "$JAR" db --help
154+
java -jar "$JAR" db archive -h
155+
java -jar "$JAR" keystore --help
156+
130157
- name: Test with RocksDB engine
131158
run: ./gradlew :framework:testWithRocksDb --no-daemon
132159

@@ -172,6 +199,15 @@ jobs:
172199
- name: Build
173200
run: ./gradlew clean build --no-daemon --no-build-cache
174201

202+
- name: Toolkit jar smoke test
203+
run: |
204+
set -e
205+
JAR=plugins/build/libs/Toolkit.jar
206+
java -jar "$JAR" help
207+
java -jar "$JAR" db --help
208+
java -jar "$JAR" db archive -h
209+
java -jar "$JAR" keystore --help
210+
175211
- name: Test with RocksDB engine
176212
run: ./gradlew :framework:testWithRocksDb --no-daemon --no-build-cache
177213

METRICS_CHANGELOG.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Metrics Changelog
2+
=================
3+
4+
This file tracks Prometheus metric additions, changes, and removals in java-tron. For the full set of metrics emitted today, see the references at the bottom.
5+
6+
**4.8.2**
7+
8+
### New Metrics
9+
10+
#### Core
11+
12+
- `tron:block_transaction_count` (Histogram, label `miner`) — per-block transaction count, sampled at the entry of `Manager#pushBlock` before any early return so duplicate, stale, and fork-switched pushes are observed alongside applied blocks. Primary use cases: empty-block detection per super representative, and per-SR TPS / throughput percentile interpolation. Default buckets `[0, 20, 50, 80, 100, 120, 140, 160, 180, 200, 230, 260, 300, 500, 2000, 5000, 10000]` are densified around 0–300 for percentile interpolation in the typical TPS range; 5000 and 10000 are retained as safety-net buckets to preserve resolution for outlier events such as stress tests or repush storms. ([#6624](https://github.com/tronprotocol/java-tron/pull/6624))
13+
14+
> **Operational note:** The effective upper bound is 10000; blocks exceeding that land in `+Inf`. Monitor the overflow ratio — e.g. `(rate(tron_block_transaction_count_bucket{le="+Inf"}[5m]) - rate(tron_block_transaction_count_bucket{le="10000"}[5m])) / rate(tron_block_transaction_count_count[5m]) > 0.01` — as a signal to re-tune the upper bound.
15+
16+
#### Consensus
17+
18+
- `tron:sr_set_change` (Counter, labels `action`, `witness`) — incremented once per witness whenever the active SR set rotates at a maintenance boundary. `action` is one of `add` / `remove`. Cardinality grows with the number of distinct witnesses that have ever entered or left the active set, not with the active set size at any given moment. ([#6624](https://github.com/tronprotocol/java-tron/pull/6624))
19+
20+
**Pre-4.8.2 Baseline**
21+
22+
Snapshot of metrics emitted prior to this changelog. Per-version provenance is not tracked here; consult `git log` on [`common/src/main/java/org/tron/common/prometheus/`](common/src/main/java/org/tron/common/prometheus/) for exact origin of each metric.
23+
24+
### Existing Metrics
25+
26+
#### Core (block / transaction processing)
27+
28+
- `tron:header_height` (Gauge) — latest block height on this node.
29+
- `tron:header_time` (Gauge) — latest block timestamp on this node.
30+
- `tron:block_push_latency_seconds` (Histogram) — `Manager#pushBlock` latency.
31+
- `tron:block_process_latency_seconds` (Histogram, label `sync`) — `TronNetDelegate#processBlock` latency.
32+
- `tron:block_generate_latency_seconds` (Histogram, label `address`) — block generation latency per producer.
33+
- `tron:block_fetch_latency_seconds` (Histogram) — block fetch latency.
34+
- `tron:block_receive_delay_seconds` (Histogram) — `receiveTime - blockTime`.
35+
- `tron:block_fork` (Counter, label `type`) — fork events by type.
36+
- `tron:lock_acquire_latency_seconds` (Histogram, label `type`) — DB / chain lock acquisition latency.
37+
- `tron:miner` (Counter, labels `miner`, `type`) — blocks produced by an SR.
38+
- `tron:miner_latency_seconds` (Histogram, label `miner`) — block mining latency per producer.
39+
- `tron:miner_delay_seconds` (Histogram, label `miner`) — `actualTime - planTime` for block production.
40+
- `tron:txs` (Counter, labels `type`, `detail`) — transaction counts.
41+
- `tron:process_transaction_latency_seconds` (Histogram, labels `type`, `contract`) — transaction processing latency.
42+
- `tron:verify_sign_latency_seconds` (Histogram, label `type`) — signature verification latency for transactions and blocks.
43+
- `tron:tx_cache` (Gauge, label `type`) — transaction cache stats.
44+
- `tron:manager_queue_size` (Gauge, label `type`) — `Manager` queue sizes (pending / popped / queued / repush).
45+
46+
#### Net (P2P)
47+
48+
- `tron:peers` (Gauge, label `type`) — peer counts.
49+
- `tron:p2p_error` (Counter, label `type`) — P2P error events.
50+
- `tron:p2p_disconnect` (Counter, label `type`) — P2P disconnect events.
51+
- `tron:ping_pong_latency_seconds` (Histogram) — peer ping-pong RTT.
52+
- `tron:message_process_latency_seconds` (Histogram, label `type`) — peer message processing latency.
53+
- `tron:tcp_bytes` (Histogram, label `type`) — TCP traffic.
54+
- `tron:udp_bytes` (Histogram, label `type`) — UDP traffic.
55+
56+
#### API
57+
58+
- `tron:http_service_latency_seconds` (Histogram, label `url`) — HTTP endpoint latency.
59+
- `tron:http_bytes` (Histogram, labels `url`, `status`) — HTTP traffic.
60+
- `tron:grpc_service_latency_seconds` (Histogram, label `endpoint`) — gRPC endpoint latency.
61+
- `tron:jsonrpc_service_latency_seconds` (Histogram, label `method`) — JSON-RPC method latency.
62+
- `tron:internal_service_latency_seconds` (Histogram, labels `class`, `method`) — internal service-call latency.
63+
- `tron:internal_service_fail` (Counter, labels `class`, `method`) — internal service-call failure count.
64+
65+
#### DB
66+
67+
- `tron:db_size_bytes` (Gauge, labels `type`, `db`, `level`) — storage size in bytes per engine, database, and level; `type` is the storage engine (`LEVELDB` or `ROCKSDB`) depending on node configuration.
68+
- `tron:db_sst_level` (Gauge, labels `type`, `db`, `level`) — SST files per compaction level per engine and database; `type` is the storage engine (`LEVELDB` or `ROCKSDB`) depending on node configuration.
69+
- `tron:guava_cache_hit_rate` (Gauge, label `type`) — hit rate of a Guava cache; `type` is the cache name.
70+
- `tron:guava_cache_request` (Gauge, label `type`) — total request count of a Guava cache; `type` is the cache name.
71+
- `tron:guava_cache_eviction_count` (Gauge, label `type`) — eviction count of a Guava cache; `type` is the cache name.
72+
- (Registered via `GuavaCacheExports` for caches that opt in to `CacheManager`.)
73+
74+
#### Logging
75+
76+
- `tron:error_info` (Counter, labels `topic`, `type`) — incremented on every ERROR-level log line by `InstrumentedAppender`.
77+
78+
#### System
79+
80+
Emitted by `OperatingSystemExports` (no labels):
81+
82+
- `system_available_cpus`, `process_cpu_load`, `system_cpu_load`, `system_load_average`, `system_total_physical_memory_bytes`, `system_free_physical_memory_bytes`, `system_total_swap_spaces_bytes`, `system_free_swap_spaces_bytes`.
83+
84+
#### JVM / process
85+
86+
Auto-emitted by the Prometheus client library via `DefaultExports.initialize()` (`simpleclient_hotspot`). The full list is owned by the upstream library and not enumerated here; see the [client_java](https://github.com/prometheus/client_java) docs. Common ones: `jvm_memory_bytes_*`, `jvm_gc_collection_seconds_*`, `jvm_threads_*`, `process_cpu_seconds_total`, `process_open_fds`, `process_resident_memory_bytes`.
87+
88+
---
89+
90+
**References**
91+
92+
- [Official metrics documentation](https://tronprotocol.github.io/documentation-en/using_javatron/metrics/) — descriptions, configuration, and example queries.
93+
- [tron-docker `metric_monitor/README.md`](https://github.com/tronprotocol/tron-docker/blob/main/metric_monitor/README.md) — operator-oriented overview with deployment guidance.
94+
- [java-tron-server Grafana dashboard](https://github.com/tronprotocol/tron-docker/blob/main/metric_monitor/grafana_dashboard/java-tron-server.json) — maintained reference dashboard JSON.

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.protobuf.Any;
44
import com.google.protobuf.GeneratedMessageV3;
5+
import lombok.Getter;
56
import org.tron.common.math.Maths;
67
import org.tron.common.utils.Commons;
78
import org.tron.common.utils.ForkController;
@@ -16,48 +17,36 @@
1617

1718
public abstract class AbstractActuator implements Actuator {
1819

20+
@Getter
1921
protected Any any;
22+
@Getter
2023
protected ChainBaseManager chainBaseManager;
24+
@Getter
2125
protected Contract contract;
26+
@Getter
2227
protected TransactionCapsule tx;
2328
protected ForkController forkController;
2429

2530
public AbstractActuator(ContractType type, Class<? extends GeneratedMessageV3> clazz) {
2631
TransactionFactory.register(type, getClass(), clazz);
2732
}
2833

29-
public Any getAny() {
30-
return any;
31-
}
32-
3334
public AbstractActuator setAny(Any any) {
3435
this.any = any;
3536
return this;
3637
}
3738

38-
public ChainBaseManager getChainBaseManager() {
39-
return chainBaseManager;
40-
}
41-
4239
public AbstractActuator setChainBaseManager(ChainBaseManager chainBaseManager) {
4340
this.chainBaseManager = chainBaseManager;
4441
return this;
4542
}
4643

47-
public Contract getContract() {
48-
return contract;
49-
}
50-
5144
public AbstractActuator setContract(Contract contract) {
5245
this.contract = contract;
5346
this.any = contract.getParameter();
5447
return this;
5548
}
5649

57-
public TransactionCapsule getTx() {
58-
return tx;
59-
}
60-
6150
public AbstractActuator setTx(TransactionCapsule tx) {
6251
this.tx = tx;
6352
return this;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.tron.core.actuator;
2+
3+
import com.google.protobuf.GeneratedMessageV3;
4+
import org.tron.common.math.StrictMathWrapper;
5+
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
6+
7+
public abstract class AbstractExchangeActuator extends AbstractActuator {
8+
9+
public AbstractExchangeActuator(ContractType type, Class<? extends GeneratedMessageV3> clazz) {
10+
super(type, clazz);
11+
}
12+
13+
protected boolean allowHarden() {
14+
return chainBaseManager.getDynamicPropertiesStore().allowHardenExchangeCalculation();
15+
}
16+
17+
public long subtractExact(long x, long y) {
18+
return allowHarden() ? StrictMathWrapper.subtractExact(x, y) : x - y;
19+
}
20+
21+
public long addExact(long x, long y) {
22+
return allowHarden() ? StrictMathWrapper.addExact(x, y) : x + y;
23+
}
24+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.Iterator;
2424
import java.util.List;
25+
import java.util.Locale;
2526
import java.util.Objects;
2627
import lombok.extern.slf4j.Slf4j;
2728
import org.tron.common.math.StrictMathWrapper;
@@ -166,7 +167,7 @@ public boolean validate() throws ContractValidateException {
166167
}
167168

168169
if (dynamicStore.getAllowSameTokenName() != 0) {
169-
String name = assetIssueContract.getName().toStringUtf8().toLowerCase();
170+
String name = assetIssueContract.getName().toStringUtf8().toLowerCase(Locale.ROOT);
170171
if (("trx").equals(name)) {
171172
throw new ContractValidateException("assetName can't be trx");
172173
}

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.tron.protos.contract.ExchangeContract.ExchangeCreateContract;
2828

2929
@Slf4j(topic = "actuator")
30-
public class ExchangeCreateActuator extends AbstractActuator {
30+
public class ExchangeCreateActuator extends AbstractExchangeActuator {
3131

3232
public ExchangeCreateActuator() {
3333
super(ContractType.ExchangeCreateContract, ExchangeCreateContract.class);
@@ -57,25 +57,25 @@ public boolean execute(Object object) throws ContractExeException {
5757
long firstTokenBalance = exchangeCreateContract.getFirstTokenBalance();
5858
long secondTokenBalance = exchangeCreateContract.getSecondTokenBalance();
5959

60-
long newBalance = accountCapsule.getBalance() - fee;
60+
long newBalance = subtractExact(accountCapsule.getBalance(), fee);
6161

6262
accountCapsule.setBalance(newBalance);
6363

6464
if (Arrays.equals(firstTokenID, TRX_SYMBOL_BYTES)) {
65-
accountCapsule.setBalance(newBalance - firstTokenBalance);
65+
accountCapsule.setBalance(subtractExact(newBalance, firstTokenBalance));
6666
} else {
6767
accountCapsule
6868
.reduceAssetAmountV2(firstTokenID, firstTokenBalance, dynamicStore, assetIssueStore);
6969
}
7070

7171
if (Arrays.equals(secondTokenID, TRX_SYMBOL_BYTES)) {
72-
accountCapsule.setBalance(newBalance - secondTokenBalance);
72+
accountCapsule.setBalance(subtractExact(newBalance, secondTokenBalance));
7373
} else {
7474
accountCapsule
7575
.reduceAssetAmountV2(secondTokenID, secondTokenBalance, dynamicStore, assetIssueStore);
7676
}
7777

78-
long id = dynamicStore.getLatestExchangeNum() + 1;
78+
long id = addExact(dynamicStore.getLatestExchangeNum(), 1);
7979
long now = dynamicStore.getLatestBlockHeaderTimestamp();
8080
if (dynamicStore.getAllowSameTokenName() == 0) {
8181
//save to old asset store
@@ -124,7 +124,8 @@ public boolean execute(Object object) throws ContractExeException {
124124
}
125125
ret.setExchangeId(id);
126126
ret.setStatus(fee, code.SUCESS);
127-
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
127+
} catch (BalanceInsufficientException | InvalidProtocolBufferException
128+
| ArithmeticException e) {
128129
logger.debug(e.getMessage(), e);
129130
ret.setStatus(fee, code.FAILED);
130131
throw new ContractExeException(e.getMessage());
@@ -134,6 +135,14 @@ public boolean execute(Object object) throws ContractExeException {
134135

135136
@Override
136137
public boolean validate() throws ContractValidateException {
138+
try {
139+
return doValidate();
140+
} catch (ArithmeticException e) {
141+
throw new ContractValidateException(e.getMessage());
142+
}
143+
}
144+
145+
private boolean doValidate() throws ContractValidateException {
137146
if (this.any == null) {
138147
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
139148
}
@@ -199,7 +208,7 @@ public boolean validate() throws ContractValidateException {
199208
}
200209

201210
if (Arrays.equals(firstTokenID, TRX_SYMBOL_BYTES)) {
202-
if (accountCapsule.getBalance() < (firstTokenBalance + calcFee())) {
211+
if (accountCapsule.getBalance() < addExact(firstTokenBalance, calcFee())) {
203212
throw new ContractValidateException("balance is not enough");
204213
}
205214
} else {
@@ -209,7 +218,7 @@ public boolean validate() throws ContractValidateException {
209218
}
210219

211220
if (Arrays.equals(secondTokenID, TRX_SYMBOL_BYTES)) {
212-
if (accountCapsule.getBalance() < (secondTokenBalance + calcFee())) {
221+
if (accountCapsule.getBalance() < addExact(secondTokenBalance, calcFee())) {
213222
throw new ContractValidateException("balance is not enough");
214223
}
215224
} else {

0 commit comments

Comments
 (0)