Skip to content
Merged
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
94 changes: 94 additions & 0 deletions METRICS_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Metrics Changelog
=================

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.

**4.8.2**

### New Metrics

#### Core

- `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))

> **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.

#### Consensus

- `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))

**Pre-4.8.2 Baseline**

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.

### Existing Metrics

#### Core (block / transaction processing)

- `tron:header_height` (Gauge) — latest block height on this node.
- `tron:header_time` (Gauge) — latest block timestamp on this node.
- `tron:block_push_latency_seconds` (Histogram) — `Manager#pushBlock` latency.
- `tron:block_process_latency_seconds` (Histogram, label `sync`) — `TronNetDelegate#processBlock` latency.
- `tron:block_generate_latency_seconds` (Histogram, label `address`) — block generation latency per producer.
- `tron:block_fetch_latency_seconds` (Histogram) — block fetch latency.
- `tron:block_receive_delay_seconds` (Histogram) — `receiveTime - blockTime`.
- `tron:block_fork` (Counter, label `type`) — fork events by type.
- `tron:lock_acquire_latency_seconds` (Histogram, label `type`) — DB / chain lock acquisition latency.
- `tron:miner` (Counter, labels `miner`, `type`) — blocks produced by an SR.
- `tron:miner_latency_seconds` (Histogram, label `miner`) — block mining latency per producer.
- `tron:miner_delay_seconds` (Histogram, label `miner`) — `actualTime - planTime` for block production.
- `tron:txs` (Counter, labels `type`, `detail`) — transaction counts.
- `tron:process_transaction_latency_seconds` (Histogram, labels `type`, `contract`) — transaction processing latency.
- `tron:verify_sign_latency_seconds` (Histogram, label `type`) — signature verification latency for transactions and blocks.
- `tron:tx_cache` (Gauge, label `type`) — transaction cache stats.
- `tron:manager_queue_size` (Gauge, label `type`) — `Manager` queue sizes (pending / popped / queued / repush).

#### Net (P2P)

- `tron:peers` (Gauge, label `type`) — peer counts.
- `tron:p2p_error` (Counter, label `type`) — P2P error events.
- `tron:p2p_disconnect` (Counter, label `type`) — P2P disconnect events.
- `tron:ping_pong_latency_seconds` (Histogram) — peer ping-pong RTT.
- `tron:message_process_latency_seconds` (Histogram, label `type`) — peer message processing latency.
- `tron:tcp_bytes` (Histogram, label `type`) — TCP traffic.
- `tron:udp_bytes` (Histogram, label `type`) — UDP traffic.

#### API

- `tron:http_service_latency_seconds` (Histogram, label `url`) — HTTP endpoint latency.
- `tron:http_bytes` (Histogram, labels `url`, `status`) — HTTP traffic.
- `tron:grpc_service_latency_seconds` (Histogram, label `endpoint`) — gRPC endpoint latency.
- `tron:jsonrpc_service_latency_seconds` (Histogram, label `method`) — JSON-RPC method latency.
- `tron:internal_service_latency_seconds` (Histogram, labels `class`, `method`) — internal service-call latency.
- `tron:internal_service_fail` (Counter, labels `class`, `method`) — internal service-call failure count.

#### DB

- `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.
- `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.
- `tron:guava_cache_hit_rate` (Gauge, label `type`) — hit rate of a Guava cache; `type` is the cache name.
- `tron:guava_cache_request` (Gauge, label `type`) — total request count of a Guava cache; `type` is the cache name.
- `tron:guava_cache_eviction_count` (Gauge, label `type`) — eviction count of a Guava cache; `type` is the cache name.
- (Registered via `GuavaCacheExports` for caches that opt in to `CacheManager`.)

#### Logging

- `tron:error_info` (Counter, labels `topic`, `type`) — incremented on every ERROR-level log line by `InstrumentedAppender`.

#### System

Emitted by `OperatingSystemExports` (no labels):

- `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`.

#### JVM / process

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`.

---

**References**

- [Official metrics documentation](https://tronprotocol.github.io/documentation-en/using_javatron/metrics/) — descriptions, configuration, and example queries.
- [tron-docker `metric_monitor/README.md`](https://github.com/tronprotocol/tron-docker/blob/main/metric_monitor/README.md) — operator-oriented overview with deployment guidance.
- [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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.tron.core.actuator;

import com.google.protobuf.GeneratedMessageV3;
import org.tron.common.math.StrictMathWrapper;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;

public abstract class AbstractExchangeActuator extends AbstractActuator {

public AbstractExchangeActuator(ContractType type, Class<? extends GeneratedMessageV3> clazz) {
super(type, clazz);
}

protected boolean allowHarden() {
return chainBaseManager.getDynamicPropertiesStore().allowHardenExchangeCalculation();
}

public long subtractExact(long x, long y) {
return allowHarden() ? StrictMathWrapper.subtractExact(x, y) : x - y;
}

public long addExact(long x, long y) {
return allowHarden() ? StrictMathWrapper.addExact(x, y) : x + y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.math.StrictMathWrapper;
Expand Down Expand Up @@ -166,7 +167,7 @@ public boolean validate() throws ContractValidateException {
}

if (dynamicStore.getAllowSameTokenName() != 0) {
String name = assetIssueContract.getName().toStringUtf8().toLowerCase();
String name = assetIssueContract.getName().toStringUtf8().toLowerCase(Locale.ROOT);
if (("trx").equals(name)) {
throw new ContractValidateException("assetName can't be trx");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.tron.protos.contract.ExchangeContract.ExchangeCreateContract;

@Slf4j(topic = "actuator")
public class ExchangeCreateActuator extends AbstractActuator {
public class ExchangeCreateActuator extends AbstractExchangeActuator {

public ExchangeCreateActuator() {
super(ContractType.ExchangeCreateContract, ExchangeCreateContract.class);
Expand Down Expand Up @@ -57,25 +57,25 @@ public boolean execute(Object object) throws ContractExeException {
long firstTokenBalance = exchangeCreateContract.getFirstTokenBalance();
long secondTokenBalance = exchangeCreateContract.getSecondTokenBalance();

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

accountCapsule.setBalance(newBalance);

if (Arrays.equals(firstTokenID, TRX_SYMBOL_BYTES)) {
accountCapsule.setBalance(newBalance - firstTokenBalance);
accountCapsule.setBalance(subtractExact(newBalance, firstTokenBalance));
} else {
accountCapsule
.reduceAssetAmountV2(firstTokenID, firstTokenBalance, dynamicStore, assetIssueStore);
}

if (Arrays.equals(secondTokenID, TRX_SYMBOL_BYTES)) {
accountCapsule.setBalance(newBalance - secondTokenBalance);
accountCapsule.setBalance(subtractExact(newBalance, secondTokenBalance));
} else {
accountCapsule
.reduceAssetAmountV2(secondTokenID, secondTokenBalance, dynamicStore, assetIssueStore);
}

long id = dynamicStore.getLatestExchangeNum() + 1;
long id = addExact(dynamicStore.getLatestExchangeNum(), 1);
long now = dynamicStore.getLatestBlockHeaderTimestamp();
if (dynamicStore.getAllowSameTokenName() == 0) {
//save to old asset store
Expand Down Expand Up @@ -124,7 +124,8 @@ public boolean execute(Object object) throws ContractExeException {
}
ret.setExchangeId(id);
ret.setStatus(fee, code.SUCESS);
} catch (BalanceInsufficientException | InvalidProtocolBufferException e) {
} catch (BalanceInsufficientException | InvalidProtocolBufferException
| ArithmeticException e) {
logger.debug(e.getMessage(), e);
ret.setStatus(fee, code.FAILED);
throw new ContractExeException(e.getMessage());
Expand All @@ -134,6 +135,14 @@ public boolean execute(Object object) throws ContractExeException {

@Override
public boolean validate() throws ContractValidateException {
try {
return doValidate();
} catch (ArithmeticException e) {
throw new ContractValidateException(e.getMessage());
}
}

private boolean doValidate() throws ContractValidateException {
if (this.any == null) {
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
}
Expand Down Expand Up @@ -199,7 +208,7 @@ public boolean validate() throws ContractValidateException {
}

if (Arrays.equals(firstTokenID, TRX_SYMBOL_BYTES)) {
if (accountCapsule.getBalance() < (firstTokenBalance + calcFee())) {
if (accountCapsule.getBalance() < addExact(firstTokenBalance, calcFee())) {
throw new ContractValidateException("balance is not enough");
}
} else {
Expand All @@ -209,7 +218,7 @@ public boolean validate() throws ContractValidateException {
}

if (Arrays.equals(secondTokenID, TRX_SYMBOL_BYTES)) {
if (accountCapsule.getBalance() < (secondTokenBalance + calcFee())) {
if (accountCapsule.getBalance() < addExact(secondTokenBalance, calcFee())) {
throw new ContractValidateException("balance is not enough");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
import org.tron.core.store.DynamicPropertiesStore;
import org.tron.core.store.ExchangeStore;
import org.tron.core.store.ExchangeV2Store;
import org.tron.core.utils.TransactionUtil;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.Transaction.Result.code;
import org.tron.protos.contract.ExchangeContract.ExchangeInjectContract;

@Slf4j(topic = "actuator")
public class ExchangeInjectActuator extends AbstractActuator {
public class ExchangeInjectActuator extends AbstractExchangeActuator {

public ExchangeInjectActuator() {
super(ContractType.ExchangeInjectContract, ExchangeInjectContract.class);
Expand All @@ -56,8 +55,8 @@ public boolean execute(Object object) throws ContractExeException {
.get(exchangeInjectContract.getOwnerAddress().toByteArray());

ExchangeCapsule exchangeCapsule;
exchangeCapsule = Commons.getExchangeStoreFinal(dynamicStore, exchangeStore, exchangeV2Store).
get(ByteArray.fromLong(exchangeInjectContract.getExchangeId()));
exchangeCapsule = Commons.getExchangeStoreFinal(dynamicStore, exchangeStore, exchangeV2Store)
.get(ByteArray.fromLong(exchangeInjectContract.getExchangeId()));
byte[] firstTokenID = exchangeCapsule.getFirstTokenId();
byte[] secondTokenID = exchangeCapsule.getSecondTokenId();
long firstTokenBalance = exchangeCapsule.getFirstTokenBalance();
Expand All @@ -73,27 +72,27 @@ public boolean execute(Object object) throws ContractExeException {
anotherTokenID = secondTokenID;
anotherTokenQuant = floorDiv(multiplyExact(
secondTokenBalance, tokenQuant), firstTokenBalance);
exchangeCapsule.setBalance(firstTokenBalance + tokenQuant,
secondTokenBalance + anotherTokenQuant);
exchangeCapsule.setBalance(addExact(firstTokenBalance, tokenQuant),
addExact(secondTokenBalance, anotherTokenQuant));
} else {
anotherTokenID = firstTokenID;
anotherTokenQuant = floorDiv(multiplyExact(
firstTokenBalance, tokenQuant), secondTokenBalance);
exchangeCapsule.setBalance(firstTokenBalance + anotherTokenQuant,
secondTokenBalance + tokenQuant);
exchangeCapsule.setBalance(addExact(firstTokenBalance, anotherTokenQuant),
addExact(secondTokenBalance, tokenQuant));
}

long newBalance = accountCapsule.getBalance() - calcFee();
long newBalance = subtractExact(accountCapsule.getBalance(), calcFee());
accountCapsule.setBalance(newBalance);

if (Arrays.equals(tokenID, TRX_SYMBOL_BYTES)) {
accountCapsule.setBalance(newBalance - tokenQuant);
accountCapsule.setBalance(subtractExact(newBalance, tokenQuant));
} else {
accountCapsule.reduceAssetAmountV2(tokenID, tokenQuant, dynamicStore, assetIssueStore);
}

if (Arrays.equals(anotherTokenID, TRX_SYMBOL_BYTES)) {
accountCapsule.setBalance(newBalance - anotherTokenQuant);
accountCapsule.setBalance(subtractExact(newBalance, anotherTokenQuant));
} else {
accountCapsule
.reduceAssetAmountV2(anotherTokenID, anotherTokenQuant, dynamicStore, assetIssueStore);
Expand All @@ -105,7 +104,8 @@ public boolean execute(Object object) throws ContractExeException {

ret.setExchangeInjectAnotherAmount(anotherTokenQuant);
ret.setStatus(fee, code.SUCESS);
} catch (ItemNotFoundException | InvalidProtocolBufferException e) {
} catch (ItemNotFoundException | InvalidProtocolBufferException
| ArithmeticException e) {
logger.debug(e.getMessage(), e);
ret.setStatus(fee, code.FAILED);
throw new ContractExeException(e.getMessage());
Expand All @@ -115,6 +115,14 @@ public boolean execute(Object object) throws ContractExeException {

@Override
public boolean validate() throws ContractValidateException {
try {
return doValidate();
} catch (ArithmeticException e) {
throw new ContractValidateException(e.getMessage());
}
}

private boolean doValidate() throws ContractValidateException {
if (this.any == null) {
throw new ContractValidateException(ActuatorConstant.CONTRACT_NOT_EXIST);
}
Expand Down Expand Up @@ -156,8 +164,8 @@ public boolean validate() throws ContractValidateException {

ExchangeCapsule exchangeCapsule;
try {
exchangeCapsule = Commons.getExchangeStoreFinal(dynamicStore, exchangeStore, exchangeV2Store).
get(ByteArray.fromLong(contract.getExchangeId()));
exchangeCapsule = Commons.getExchangeStoreFinal(dynamicStore, exchangeStore, exchangeV2Store)
.get(ByteArray.fromLong(contract.getExchangeId()));

} catch (ItemNotFoundException ex) {
throw new ContractValidateException("Exchange[" + contract.getExchangeId() + ActuatorConstant
Expand All @@ -179,9 +187,9 @@ public boolean validate() throws ContractValidateException {
byte[] anotherTokenID;
long anotherTokenQuant;

if (dynamicStore.getAllowSameTokenName() == 1 &&
!Arrays.equals(tokenID, TRX_SYMBOL_BYTES) &&
!isNumber(tokenID)) {
if (dynamicStore.getAllowSameTokenName() == 1
&& !Arrays.equals(tokenID, TRX_SYMBOL_BYTES)
&& !isNumber(tokenID)) {
throw new ContractValidateException("token id is not a valid number");
}

Expand All @@ -208,14 +216,14 @@ public boolean validate() throws ContractValidateException {
anotherTokenID = secondTokenID;
anotherTokenQuant = bigSecondTokenBalance.multiply(bigTokenQuant)
.divide(bigFirstTokenBalance).longValueExact();
newTokenBalance = firstTokenBalance + tokenQuant;
newAnotherTokenBalance = secondTokenBalance + anotherTokenQuant;
newTokenBalance = addExact(firstTokenBalance, tokenQuant);
newAnotherTokenBalance = addExact(secondTokenBalance, anotherTokenQuant);
} else {
anotherTokenID = firstTokenID;
anotherTokenQuant = bigFirstTokenBalance.multiply(bigTokenQuant)
.divide(bigSecondTokenBalance).longValueExact();
newTokenBalance = secondTokenBalance + tokenQuant;
newAnotherTokenBalance = firstTokenBalance + anotherTokenQuant;
newTokenBalance = addExact(secondTokenBalance, tokenQuant);
newAnotherTokenBalance = addExact(firstTokenBalance, anotherTokenQuant);
}

if (anotherTokenQuant <= 0) {
Expand All @@ -228,7 +236,7 @@ public boolean validate() throws ContractValidateException {
}

if (Arrays.equals(tokenID, TRX_SYMBOL_BYTES)) {
if (accountCapsule.getBalance() < (tokenQuant + calcFee())) {
if (accountCapsule.getBalance() < addExact(tokenQuant, calcFee())) {
throw new ContractValidateException("balance is not enough");
}
} else {
Expand All @@ -238,7 +246,7 @@ public boolean validate() throws ContractValidateException {
}

if (Arrays.equals(anotherTokenID, TRX_SYMBOL_BYTES)) {
if (accountCapsule.getBalance() < (anotherTokenQuant + calcFee())) {
if (accountCapsule.getBalance() < addExact(anotherTokenQuant, calcFee())) {
throw new ContractValidateException("balance is not enough");
}
} else {
Expand Down
Loading
Loading