Skip to content

Commit 8738da4

Browse files
committed
Merge remote-tracking branch 'upstream/release_v4.8.0' into feature/sensitive_information_optimization
2 parents c3686aa + 31016d3 commit 8738da4

File tree

75 files changed

+3989
-1379
lines changed

Some content is hidden

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

75 files changed

+3989
-1379
lines changed

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
794794
}
795795
break;
796796
}
797+
case CONSENSUS_LOGIC_OPTIMIZATION: {
798+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_8_0)) {
799+
throw new ContractValidateException(
800+
"Bad chain parameter id [CONSENSUS_LOGIC_OPTIMIZATION]");
801+
}
802+
if (dynamicPropertiesStore.getConsensusLogicOptimization() == 1) {
803+
throw new ContractValidateException(
804+
"[CONSENSUS_LOGIC_OPTIMIZATION] has been valid, no need to propose again");
805+
}
806+
if (value != 1) {
807+
throw new ContractValidateException(
808+
"This value[CONSENSUS_LOGIC_OPTIMIZATION] is only allowed to be 1");
809+
}
810+
break;
811+
}
797812
default:
798813
break;
799814
}
@@ -873,7 +888,8 @@ public enum ProposalType { // current value, value range
873888
ALLOW_OLD_REWARD_OPT(79), // 0, 1
874889
ALLOW_ENERGY_ADJUSTMENT(81), // 0, 1
875890
MAX_CREATE_ACCOUNT_TX_SIZE(82), // [500, 10000]
876-
ALLOW_STRICT_MATH(87); // 0, 1
891+
ALLOW_STRICT_MATH(87), // 0, 1
892+
CONSENSUS_LOGIC_OPTIMIZATION(88); // 0, 1
877893

878894
private long code;
879895

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ subprojects {
1111
targetCompatibility = JavaVersion.VERSION_1_8
1212

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

1518
buildscript {
1619
repositories {
@@ -52,7 +55,8 @@ subprojects {
5255
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
5356

5457
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
55-
testImplementation "org.mockito:mockito-core:2.13.0"
58+
testImplementation "org.mockito:mockito-core:4.11.0"
59+
testImplementation "org.mockito:mockito-inline:4.11.0"
5660
}
5761

5862
task sourcesJar(type: Jar, dependsOn: classes) {

chainbase/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ description = "chainbase – a decentralized database for blockchain."
22

33
// Dependency versions
44
// ---------------------------------------
5-
def jacocoVersion = "0.8.0"
65
def jansiVersion = "1.16"
76
// --------------------------------------
87

@@ -41,10 +40,6 @@ test {
4140
}
4241
}
4342

44-
jacoco {
45-
toolVersion = jacocoVersion // See http://www.eclemma.org/jacoco/.
46-
}
47-
4843
jacocoTestReport {
4944
reports {
5045
xml.enabled = true

chainbase/src/main/java/org/tron/core/service/MortgageService.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.tron.core.service;
22

3-
import com.google.protobuf.ByteString;
43
import java.math.BigInteger;
5-
import java.util.Comparator;
64
import java.util.List;
75
import java.util.stream.Collectors;
86
import lombok.Getter;
@@ -51,7 +49,8 @@ public void initStore(WitnessStore witnessStore, DelegationStore delegationStore
5149
}
5250

5351
public void payStandbyWitness() {
54-
List<WitnessCapsule> witnessStandbys = witnessStore.getWitnessStandby();
52+
List<WitnessCapsule> witnessStandbys = witnessStore.getWitnessStandby(
53+
dynamicPropertiesStore.allowWitnessSortOptimization());
5554
long voteSum = witnessStandbys.stream().mapToLong(WitnessCapsule::getVoteCount).sum();
5655
if (voteSum < 1) {
5756
return;
@@ -227,10 +226,6 @@ private long computeReward(long beginCycle, long endCycle, AccountCapsule accoun
227226
return reward;
228227
}
229228

230-
public WitnessCapsule getWitnessByAddress(ByteString address) {
231-
return witnessStore.get(address.toByteArray());
232-
}
233-
234229
public void adjustAllowance(byte[] address, long amount) {
235230
try {
236231
if (amount <= 0) {
@@ -259,11 +254,6 @@ public void adjustAllowance(AccountStore accountStore, byte[] accountAddress, lo
259254
accountStore.put(account.createDbKey(), account);
260255
}
261256

262-
private void sortWitness(List<ByteString> list) {
263-
list.sort(Comparator.comparingLong((ByteString b) -> getWitnessByAddress(b).getVoteCount())
264-
.reversed().thenComparing(Comparator.comparingInt(ByteString::hashCode).reversed()));
265-
}
266-
267257
private long getOldReward(long begin, long end, List<Pair<byte[], Long>> votes) {
268258
if (dynamicPropertiesStore.allowOldRewardOpt()) {
269259
return rewardViCalService.getNewRewardAlgorithmReward(begin, end, votes);

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
224224
private static final byte[] MAX_CREATE_ACCOUNT_TX_SIZE = "MAX_CREATE_ACCOUNT_TX_SIZE".getBytes();
225225
private static final byte[] ALLOW_STRICT_MATH = "ALLOW_STRICT_MATH".getBytes();
226226

227+
private static final byte[] CONSENSUS_LOGIC_OPTIMIZATION
228+
= "CONSENSUS_LOGIC_OPTIMIZATION".getBytes();
229+
227230
@Autowired
228231
private DynamicPropertiesStore(@Value("properties") String dbName) {
229232
super(dbName);
@@ -2891,6 +2894,26 @@ public boolean allowStrictMath() {
28912894
return getAllowStrictMath() == 1L;
28922895
}
28932896

2897+
public void saveConsensusLogicOptimization(long value) {
2898+
this.put(CONSENSUS_LOGIC_OPTIMIZATION,
2899+
new BytesCapsule(ByteArray.fromLong(value)));
2900+
}
2901+
2902+
public long getConsensusLogicOptimization() {
2903+
return Optional.ofNullable(getUnchecked(CONSENSUS_LOGIC_OPTIMIZATION))
2904+
.map(BytesCapsule::getData)
2905+
.map(ByteArray::toLong)
2906+
.orElse(CommonParameter.getInstance().getConsensusLogicOptimization());
2907+
}
2908+
2909+
public boolean allowConsensusLogicOptimization() {
2910+
return getConsensusLogicOptimization() == 1L;
2911+
}
2912+
2913+
public boolean allowWitnessSortOptimization() {
2914+
return this.allowConsensusLogicOptimization();
2915+
}
2916+
28942917
private static class DynamicResourceProperties {
28952918

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

chainbase/src/main/java/org/tron/core/store/WitnessStore.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tron.core.store;
22

33
import com.google.common.collect.Streams;
4+
import com.google.protobuf.ByteString;
45
import java.util.ArrayList;
56
import java.util.Comparator;
67
import java.util.List;
@@ -11,6 +12,7 @@
1112
import org.springframework.beans.factory.annotation.Autowired;
1213
import org.springframework.beans.factory.annotation.Value;
1314
import org.springframework.stereotype.Component;
15+
import org.tron.common.utils.ByteArray;
1416
import org.tron.core.capsule.WitnessCapsule;
1517
import org.tron.core.config.Parameter;
1618
import org.tron.core.db.TronStoreWithRevoking;
@@ -39,12 +41,10 @@ public WitnessCapsule get(byte[] key) {
3941
return ArrayUtils.isEmpty(value) ? null : new WitnessCapsule(value);
4042
}
4143

42-
public List<WitnessCapsule> getWitnessStandby() {
44+
public List<WitnessCapsule> getWitnessStandby(boolean isSortOpt) {
4345
List<WitnessCapsule> ret;
4446
List<WitnessCapsule> all = getAllWitnesses();
45-
all.sort(Comparator.comparingLong(WitnessCapsule::getVoteCount)
46-
.reversed().thenComparing(Comparator.comparingInt(
47-
(WitnessCapsule w) -> w.getAddress().hashCode()).reversed()));
47+
sortWitnesses(all, isSortOpt);
4848
if (all.size() > Parameter.ChainConstant.WITNESS_STANDBY_LENGTH) {
4949
ret = new ArrayList<>(all.subList(0, Parameter.ChainConstant.WITNESS_STANDBY_LENGTH));
5050
} else {
@@ -55,4 +55,18 @@ public List<WitnessCapsule> getWitnessStandby() {
5555
return ret;
5656
}
5757

58+
public void sortWitnesses(List<WitnessCapsule> witnesses, boolean isSortOpt) {
59+
witnesses.sort(Comparator.comparingLong(WitnessCapsule::getVoteCount).reversed()
60+
.thenComparing(isSortOpt
61+
? Comparator.comparing(WitnessCapsule::createReadableString).reversed()
62+
: Comparator.comparingInt((WitnessCapsule w) -> w.getAddress().hashCode()).reversed()));
63+
}
64+
65+
public void sortWitness(List<ByteString> list, boolean isSortOpt) {
66+
list.sort(Comparator.comparingLong((ByteString b) -> get(b.toByteArray()).getVoteCount())
67+
.reversed().thenComparing(isSortOpt
68+
? Comparator.comparing(
69+
(ByteString b) -> ByteArray.toHexString(b.toByteArray())).reversed()
70+
: Comparator.comparingInt(ByteString::hashCode).reversed()));
71+
}
5872
}

common/src/main/java/org/tron/common/parameter/CommonParameter.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,30 @@ public class CommonParameter {
456456
@Getter
457457
@Setter
458458
public String cryptoEngine = Constant.ECKey_ENGINE;
459+
460+
@Getter
461+
@Setter
462+
public boolean rpcEnable = true;
463+
464+
@Getter
465+
@Setter
466+
public boolean rpcSolidityEnable = true;
467+
468+
@Getter
469+
@Setter
470+
public boolean rpcPBFTEnable = true;
471+
459472
@Getter
460473
@Setter
461474
public boolean fullNodeHttpEnable = true;
462475
@Getter
463476
@Setter
464477
public boolean solidityNodeHttpEnable = true;
478+
479+
@Getter
480+
@Setter
481+
public boolean pBFTHttpEnable = true;
482+
465483
@Getter
466484
@Setter
467485
public boolean jsonRpcHttpFullNodeEnable = false;
@@ -681,6 +699,10 @@ public class CommonParameter {
681699
@Setter
682700
public long allowStrictMath;
683701

702+
@Getter
703+
@Setter
704+
public long consensusLogicOptimization;
705+
684706
private static double calcMaxTimeRatio() {
685707
//return max(2.0, min(5.0, 5 * 4.0 / max(Runtime.getRuntime().availableProcessors(), 1)));
686708
return 5.0;

common/src/main/java/org/tron/core/Constant.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,21 @@ public class Constant {
124124
public static final String NODE_DNS_AWS_REGION = "node.dns.awsRegion";
125125
public static final String NODE_DNS_AWS_HOST_ZONE_ID = "node.dns.awsHostZoneId";
126126

127+
// config for rpc
127128
public static final String NODE_RPC_PORT = "node.rpc.port";
128129
public static final String NODE_RPC_SOLIDITY_PORT = "node.rpc.solidityPort";
129130
public static final String NODE_RPC_PBFT_PORT = "node.rpc.PBFTPort";
131+
public static final String NODE_RPC_ENABLE = "node.rpc.enable";
132+
public static final String NODE_RPC_SOLIDITY_ENABLE = "node.rpc.solidityEnable";
133+
public static final String NODE_RPC_PBFT_ENABLE = "node.rpc.PBFTEnable";
134+
// config for http
130135
public static final String NODE_HTTP_FULLNODE_PORT = "node.http.fullNodePort";
131136
public static final String NODE_HTTP_SOLIDITY_PORT = "node.http.solidityPort";
132137
public static final String NODE_HTTP_FULLNODE_ENABLE = "node.http.fullNodeEnable";
133138
public static final String NODE_HTTP_SOLIDITY_ENABLE = "node.http.solidityEnable";
139+
public static final String NODE_HTTP_PBFT_ENABLE = "node.http.PBFTEnable";
134140
public static final String NODE_HTTP_PBFT_PORT = "node.http.PBFTPort";
135-
141+
// config for jsonrpc
136142
public static final String NODE_JSONRPC_HTTP_FULLNODE_ENABLE = "node.jsonrpc.httpFullNodeEnable";
137143
public static final String NODE_JSONRPC_HTTP_FULLNODE_PORT = "node.jsonrpc.httpFullNodePort";
138144
public static final String NODE_JSONRPC_HTTP_SOLIDITY_ENABLE = "node.jsonrpc.httpSolidityEnable";
@@ -387,4 +393,7 @@ public class Constant {
387393

388394
public static final String COMMITTEE_ALLOW_ENERGY_ADJUSTMENT = "committee.allowEnergyAdjustment";
389395
public static final String COMMITTEE_ALLOW_STRICT_MATH = "committee.allowStrictMath";
396+
397+
public static final String COMMITTEE_CONSENSUS_LOGIC_OPTIMIZATION
398+
= "committee.consensusLogicOptimization";
390399
}

common/src/main/java/org/tron/core/config/Parameter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public enum ForkBlockVersionEnum {
2525
VERSION_4_7_2(28, 1596780000000L, 80),
2626
VERSION_4_7_4(29, 1596780000000L, 80),
2727
VERSION_4_7_5(30, 1596780000000L, 80),
28-
VERSION_4_7_7(31, 1596780000000L, 80);
28+
VERSION_4_7_7(31, 1596780000000L, 80),
29+
VERSION_4_8_0(32, 1596780000000L, 80);
2930
// if add a version, modify BLOCK_VERSION simultaneously
3031

3132
@Getter
@@ -74,7 +75,7 @@ public class ChainConstant {
7475
public static final int SINGLE_REPEAT = 1;
7576
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
7677
public static final int MAX_FROZEN_NUMBER = 1;
77-
public static final int BLOCK_VERSION = 31;
78+
public static final int BLOCK_VERSION = 32;
7879
public static final long FROZEN_PERIOD = 86_400_000L;
7980
public static final long DELEGATE_PERIOD = 3 * 86_400_000L;
8081
public static final long TRX_PRECISION = 1000_000L;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.tron.core.exception;
2+
3+
import lombok.Getter;
4+
5+
/**
6+
* If a {@link TronError} is thrown, the service will trigger {@link System#exit(int)} by
7+
* {@link Thread#setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler)}.
8+
* NOTE: Do not attempt to catch {@link TronError}.
9+
*/
10+
@Getter
11+
public class TronError extends Error {
12+
13+
private final ErrCode errCode;
14+
15+
public TronError(String message, ErrCode exitCode) {
16+
super(message);
17+
this.errCode = exitCode;
18+
}
19+
20+
public TronError(String message, Throwable cause, ErrCode exitCode) {
21+
super(message, cause);
22+
this.errCode = exitCode;
23+
}
24+
25+
public TronError(Throwable cause, ErrCode exitCode) {
26+
super(cause);
27+
this.errCode = exitCode;
28+
}
29+
30+
@Getter
31+
public enum ErrCode {
32+
WITNESS_KEYSTORE_LOAD(-1),
33+
CHECKPOINT_VERSION(-1),
34+
LEVELDB_INIT(1),
35+
ROCKSDB_INIT(1),
36+
DB_FLUSH(1),
37+
REWARD_VI_CALCULATOR(1),
38+
KHAOS_DB_INIT(1),
39+
GENESIS_BLOCK_INIT(1),
40+
EVENT_SUBSCRIBE_ERROR(1),
41+
AUTO_STOP_PARAMS(1),
42+
API_SERVER_INIT(1),
43+
SOLID_NODE_INIT(0);
44+
45+
private final int code;
46+
47+
ErrCode(int code) {
48+
this.code = code;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return name() + "(" + code + ")";
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)