Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fe065da
update jacoco version
chaosuper123321 Nov 14, 2024
4f143db
Merge branch 'develop' of https://github.com/CarlChaoCarl/java-tron i…
chaosuper123321 Nov 22, 2024
a365ee4
Merge branch 'develop' of https://github.com/CarlChaoCarl/java-tron i…
chaosuper123321 Dec 3, 2024
7047201
upgrade mockito and optimize tests coverage
chaosuper123321 Dec 9, 2024
e08511b
fix check style error
chaosuper123321 Dec 12, 2024
c36118f
fix(net): add check for the number of contracts in the transaction
jwrct Dec 24, 2024
42e79c2
jacoco.toolVersion optimize
chaosuper123321 Dec 26, 2024
021a5c1
feat(consensus): add consensus logic optimization proposal
zeusoo001 Jul 18, 2024
81a04e5
remove assertTrue(true)
chaosuper123321 Jan 10, 2025
92ae447
Merge pull request #6117 from CarlChaoCarl/feature/upgrade_mockito_an…
CodeNinjaEvan Jan 13, 2025
46826a7
feat(consensus): modify the review comments
zeusoo001 Jan 14, 2025
b4dea0d
Merge branch 'develop' of github.com:tronprotocol/java-tron into cons…
zeusoo001 Jan 15, 2025
1f0aa38
Merge pull request #6141 from zeusoo001/consensus_logic_opt
CodeNinjaEvan Jan 20, 2025
4e4881f
feat(witness): sort witness from address hashcode to address
halibobo1205 Jan 22, 2025
0642903
feat(exception): add TronError
halibobo1205 Jan 8, 2025
409c420
Merge pull request #6170 from halibobo1205/feat/add_tron_error
CodeNinjaEvan Feb 13, 2025
5619441
feat(api): optimize api service startup
halibobo1205 May 13, 2024
b1ac699
Merge pull request #6173 from halibobo1205/feat/sr_sort_opt
CodeNinjaEvan Feb 13, 2025
31016d3
Merge pull request #5857 from halibobo1205/feat/api_service_init_opt
CodeNinjaEvan Feb 13, 2025
1365aff
Merge remote-tracking branch 'upstream/release_v4.8.0' into fix_trans…
jwrct Feb 14, 2025
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
18 changes: 17 additions & 1 deletion actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case CONSENSUS_LOGIC_OPTIMIZATION: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_0)) {
throw new ContractValidateException(
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
}
if (dynamicPropertiesStore.getConsensusLogicOptimization() == 1) {
throw new ContractValidateException(
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again");
}
if (value != 1) {
throw new ContractValidateException(
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -873,7 +888,8 @@ public enum ProposalType { // current value, value range
ALLOW_OLD_REWARD_OPT(79), // 0, 1
ALLOW_ENERGY_ADJUSTMENT(81), // 0, 1
MAX_CREATE_ACCOUNT_TX_SIZE(82), // [500, 10000]
ALLOW_STRICT_MATH(87); // 0, 1
ALLOW_STRICT_MATH(87), // 0, 1
CONSENSUS_LOGIC_OPTIMIZATION(88); // 0, 1

private long code;

Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ subprojects {
targetCompatibility = JavaVersion.VERSION_1_8

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
jacoco {
toolVersion = "0.8.12" // see https://www.jacoco.org/jacoco/trunk/doc/changes.html
}

buildscript {
repositories {
Expand Down Expand Up @@ -52,7 +55,8 @@ subprojects {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'

testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation "org.mockito:mockito-core:2.13.0"
testImplementation "org.mockito:mockito-core:4.11.0"
testImplementation "org.mockito:mockito-inline:4.11.0"
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
5 changes: 0 additions & 5 deletions chainbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ description = "chainbase – a decentralized database for blockchain."

// Dependency versions
// ---------------------------------------
def jacocoVersion = "0.8.0"
def jansiVersion = "1.16"
// --------------------------------------

Expand Down Expand Up @@ -41,10 +40,6 @@ test {
}
}

jacoco {
toolVersion = jacocoVersion // See http://www.eclemma.org/jacoco/.
}

jacocoTestReport {
reports {
xml.enabled = true
Expand Down
14 changes: 2 additions & 12 deletions chainbase/src/main/java/org/tron/core/service/MortgageService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.tron.core.service;

import com.google.protobuf.ByteString;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Getter;
Expand Down Expand Up @@ -51,7 +49,8 @@ public void initStore(WitnessStore witnessStore, DelegationStore delegationStore
}

public void payStandbyWitness() {
List<WitnessCapsule> witnessStandbys = witnessStore.getWitnessStandby();
List<WitnessCapsule> witnessStandbys = witnessStore.getWitnessStandby(
dynamicPropertiesStore.allowWitnessSortOptimization());
long voteSum = witnessStandbys.stream().mapToLong(WitnessCapsule::getVoteCount).sum();
if (voteSum < 1) {
return;
Expand Down Expand Up @@ -227,10 +226,6 @@ private long computeReward(long beginCycle, long endCycle, AccountCapsule accoun
return reward;
}

public WitnessCapsule getWitnessByAddress(ByteString address) {
return witnessStore.get(address.toByteArray());
}

public void adjustAllowance(byte[] address, long amount) {
try {
if (amount <= 0) {
Expand Down Expand Up @@ -259,11 +254,6 @@ public void adjustAllowance(AccountStore accountStore, byte[] accountAddress, lo
accountStore.put(account.createDbKey(), account);
}

private void sortWitness(List<ByteString> list) {
list.sort(Comparator.comparingLong((ByteString b) -> getWitnessByAddress(b).getVoteCount())
.reversed().thenComparing(Comparator.comparingInt(ByteString::hashCode).reversed()));
}

private long getOldReward(long begin, long end, List<Pair<byte[], Long>> votes) {
if (dynamicPropertiesStore.allowOldRewardOpt()) {
return rewardViCalService.getNewRewardAlgorithmReward(begin, end, votes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] MAX_CREATE_ACCOUNT_TX_SIZE = "MAX_CREATE_ACCOUNT_TX_SIZE".getBytes();
private static final byte[] ALLOW_STRICT_MATH = "ALLOW_STRICT_MATH".getBytes();

private static final byte[] CONSENSUS_LOGIC_OPTIMIZATION
= "CONSENSUS_LOGIC_OPTIMIZATION".getBytes();

@Autowired
private DynamicPropertiesStore(@Value("properties") String dbName) {
super(dbName);
Expand Down Expand Up @@ -2891,6 +2894,26 @@ public boolean allowStrictMath() {
return getAllowStrictMath() == 1L;
}

public void saveConsensusLogicOptimization(long value) {
this.put(CONSENSUS_LOGIC_OPTIMIZATION,
new BytesCapsule(ByteArray.fromLong(value)));
}

public long getConsensusLogicOptimization() {
return Optional.ofNullable(getUnchecked(CONSENSUS_LOGIC_OPTIMIZATION))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElse(CommonParameter.getInstance().getConsensusLogicOptimization());
}

public boolean allowConsensusLogicOptimization() {
return getConsensusLogicOptimization() == 1L;
}

public boolean allowWitnessSortOptimization() {
return this.allowConsensusLogicOptimization();
}

private static class DynamicResourceProperties {

private static final byte[] ONE_DAY_NET_LIMIT = "ONE_DAY_NET_LIMIT".getBytes();
Expand Down
22 changes: 18 additions & 4 deletions chainbase/src/main/java/org/tron/core/store/WitnessStore.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.tron.core.store;

import com.google.common.collect.Streams;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
Expand All @@ -11,6 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tron.common.utils.ByteArray;
import org.tron.core.capsule.WitnessCapsule;
import org.tron.core.config.Parameter;
import org.tron.core.db.TronStoreWithRevoking;
Expand Down Expand Up @@ -39,12 +41,10 @@ public WitnessCapsule get(byte[] key) {
return ArrayUtils.isEmpty(value) ? null : new WitnessCapsule(value);
}

public List<WitnessCapsule> getWitnessStandby() {
public List<WitnessCapsule> getWitnessStandby(boolean isSortOpt) {
List<WitnessCapsule> ret;
List<WitnessCapsule> all = getAllWitnesses();
all.sort(Comparator.comparingLong(WitnessCapsule::getVoteCount)
.reversed().thenComparing(Comparator.comparingInt(
(WitnessCapsule w) -> w.getAddress().hashCode()).reversed()));
sortWitnesses(all, isSortOpt);
if (all.size() > Parameter.ChainConstant.WITNESS_STANDBY_LENGTH) {
ret = new ArrayList<>(all.subList(0, Parameter.ChainConstant.WITNESS_STANDBY_LENGTH));
} else {
Expand All @@ -55,4 +55,18 @@ public List<WitnessCapsule> getWitnessStandby() {
return ret;
}

public void sortWitnesses(List<WitnessCapsule> witnesses, boolean isSortOpt) {
witnesses.sort(Comparator.comparingLong(WitnessCapsule::getVoteCount).reversed()
.thenComparing(isSortOpt
? Comparator.comparing(WitnessCapsule::createReadableString).reversed()
: Comparator.comparingInt((WitnessCapsule w) -> w.getAddress().hashCode()).reversed()));
}

public void sortWitness(List<ByteString> list, boolean isSortOpt) {
list.sort(Comparator.comparingLong((ByteString b) -> get(b.toByteArray()).getVoteCount())
.reversed().thenComparing(isSortOpt
? Comparator.comparing(
(ByteString b) -> ByteArray.toHexString(b.toByteArray())).reversed()
: Comparator.comparingInt(ByteString::hashCode).reversed()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,30 @@ public class CommonParameter {
@Getter
@Setter
public String cryptoEngine = Constant.ECKey_ENGINE;

@Getter
@Setter
public boolean rpcEnable = true;

@Getter
@Setter
public boolean rpcSolidityEnable = true;

@Getter
@Setter
public boolean rpcPBFTEnable = true;

@Getter
@Setter
public boolean fullNodeHttpEnable = true;
@Getter
@Setter
public boolean solidityNodeHttpEnable = true;

@Getter
@Setter
public boolean pBFTHttpEnable = true;

@Getter
@Setter
public boolean jsonRpcHttpFullNodeEnable = false;
Expand Down Expand Up @@ -681,6 +699,10 @@ public class CommonParameter {
@Setter
public long allowStrictMath;

@Getter
@Setter
public long consensusLogicOptimization;

private static double calcMaxTimeRatio() {
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
return 5.0;
Expand Down
11 changes: 10 additions & 1 deletion common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,21 @@ public class Constant {
public static final String NODE_DNS_AWS_REGION = "node.dns.awsRegion";
public static final String NODE_DNS_AWS_HOST_ZONE_ID = "node.dns.awsHostZoneId";

// config for rpc
public static final String NODE_RPC_PORT = "node.rpc.port";
public static final String NODE_RPC_SOLIDITY_PORT = "node.rpc.solidityPort";
public static final String NODE_RPC_PBFT_PORT = "node.rpc.PBFTPort";
public static final String NODE_RPC_ENABLE = "node.rpc.enable";
public static final String NODE_RPC_SOLIDITY_ENABLE = "node.rpc.solidityEnable";
public static final String NODE_RPC_PBFT_ENABLE = "node.rpc.PBFTEnable";
// config for http
public static final String NODE_HTTP_FULLNODE_PORT = "node.http.fullNodePort";
public static final String NODE_HTTP_SOLIDITY_PORT = "node.http.solidityPort";
public static final String NODE_HTTP_FULLNODE_ENABLE = "node.http.fullNodeEnable";
public static final String NODE_HTTP_SOLIDITY_ENABLE = "node.http.solidityEnable";
public static final String NODE_HTTP_PBFT_ENABLE = "node.http.PBFTEnable";
public static final String NODE_HTTP_PBFT_PORT = "node.http.PBFTPort";

// config for jsonrpc
public static final String NODE_JSONRPC_HTTP_FULLNODE_ENABLE = "node.jsonrpc.httpFullNodeEnable";
public static final String NODE_JSONRPC_HTTP_FULLNODE_PORT = "node.jsonrpc.httpFullNodePort";
public static final String NODE_JSONRPC_HTTP_SOLIDITY_ENABLE = "node.jsonrpc.httpSolidityEnable";
Expand Down Expand Up @@ -387,4 +393,7 @@ public class Constant {

public static final String COMMITTEE_ALLOW_ENERGY_ADJUSTMENT = "committee.allowEnergyAdjustment";
public static final String COMMITTEE_ALLOW_STRICT_MATH = "committee.allowStrictMath";

public static final String COMMITTEE_CONSENSUS_LOGIC_OPTIMIZATION
= "committee.consensusLogicOptimization";
}
5 changes: 3 additions & 2 deletions common/src/main/java/org/tron/core/config/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum ForkBlockVersionEnum {
VERSION_4_7_2(28, 1596780000000L, 80),
VERSION_4_7_4(29, 1596780000000L, 80),
VERSION_4_7_5(30, 1596780000000L, 80),
VERSION_4_7_7(31, 1596780000000L, 80);
VERSION_4_7_7(31, 1596780000000L, 80),
VERSION_4_8_0(32, 1596780000000L, 80);
// if add a version, modify BLOCK_VERSION simultaneously

@Getter
Expand Down Expand Up @@ -74,7 +75,7 @@ public class ChainConstant {
public static final int SINGLE_REPEAT = 1;
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 31;
public static final int BLOCK_VERSION = 32;
public static final long FROZEN_PERIOD = 86_400_000L;
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
public static final long TRX_PRECISION = 1000_000L;
Expand Down
56 changes: 56 additions & 0 deletions common/src/main/java/org/tron/core/exception/TronError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.tron.core.exception;

import lombok.Getter;

/**
* If a {@link TronError} is thrown, the service will trigger {@link System#exit(int)} by
* {@link Thread#setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler)}.
* NOTE: Do not attempt to catch {@link TronError}.
*/
@Getter
public class TronError extends Error {

private final ErrCode errCode;

public TronError(String message, ErrCode exitCode) {
super(message);
this.errCode = exitCode;
}

public TronError(String message, Throwable cause, ErrCode exitCode) {
super(message, cause);
this.errCode = exitCode;
}

public TronError(Throwable cause, ErrCode exitCode) {
super(cause);
this.errCode = exitCode;
}

@Getter
public enum ErrCode {
WITNESS_KEYSTORE_LOAD(-1),
CHECKPOINT_VERSION(-1),
LEVELDB_INIT(1),
ROCKSDB_INIT(1),
DB_FLUSH(1),
REWARD_VI_CALCULATOR(1),
KHAOS_DB_INIT(1),
GENESIS_BLOCK_INIT(1),
EVENT_SUBSCRIBE_ERROR(1),
AUTO_STOP_PARAMS(1),
API_SERVER_INIT(1),
SOLID_NODE_INIT(0);

private final int code;

ErrCode(int code) {
this.code = code;
}

@Override
public String toString() {
return name() + "(" + code + ")";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ public void applyBlock(boolean flag) {
public boolean allowChangeDelegation() {
return dynamicPropertiesStore.allowChangeDelegation();
}

public void sortWitness(List<ByteString> list) {
witnessStore.sortWitness(list, dynamicPropertiesStore.allowWitnessSortOptimization());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ private void updateSolidBlock() {
}

public void updateWitness(List<ByteString> list) {
list.sort(Comparator.comparingLong((ByteString b) ->
consensusDelegate.getWitness(b.toByteArray()).getVoteCount())
.reversed()
.thenComparing(Comparator.comparingInt(ByteString::hashCode).reversed()));

consensusDelegate.sortWitness(list);
if (list.size() > MAX_ACTIVE_WITNESS_NUM) {
consensusDelegate
.saveActiveWitnesses(list.subList(0, MAX_ACTIVE_WITNESS_NUM));
Expand Down
3 changes: 0 additions & 3 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def versions = [
checkstyle: '8.7',
]

jacoco {
toolVersion = "0.8.1"
}


configurations {
Expand Down
Loading