Skip to content

Commit ee83102

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into feat/opt-api
2 parents a1727f0 + 636667a commit ee83102

66 files changed

Lines changed: 9504 additions & 1960 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.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public HttpRateLimiterItem(ConfigObject asset) {
7474
strategy = asset.get("strategy").unwrapped().toString();
7575
params = asset.get("paramString").unwrapped().toString();
7676
}
77+
78+
public HttpRateLimiterItem(String component, String strategy, String params) {
79+
this.component = component;
80+
this.strategy = strategy;
81+
this.params = params;
82+
}
7783
}
7884

7985

@@ -93,5 +99,11 @@ public RpcRateLimiterItem(ConfigObject asset) {
9399
strategy = asset.get("strategy").unwrapped().toString();
94100
params = asset.get("paramString").unwrapped().toString();
95101
}
102+
103+
public RpcRateLimiterItem(String component, String strategy, String params) {
104+
this.component = component;
105+
this.strategy = strategy;
106+
this.params = params;
107+
}
96108
}
97109
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public static com.typesafe.config.Config getByFileName(
4848

4949
private static void resolveConfigFile(String fileName, File confFile) {
5050
if (confFile.exists()) {
51-
config = ConfigFactory.parseFile(confFile);
51+
config = ConfigFactory.parseFile(confFile)
52+
.withFallback(ConfigFactory.defaultReference());
5253
} else if (Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)
5354
!= null) {
5455
config = ConfigFactory.load(fileName);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.tron.core.config.args;
2+
3+
import static org.tron.core.Constant.DEFAULT_PROPOSAL_EXPIRE_TIME;
4+
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
5+
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
6+
import static org.tron.core.exception.TronError.ErrCode.PARAMETER_INIT;
7+
8+
import com.typesafe.config.Config;
9+
import com.typesafe.config.ConfigBeanFactory;
10+
import lombok.Getter;
11+
import lombok.Setter;
12+
import lombok.extern.slf4j.Slf4j;
13+
import org.tron.core.exception.TronError;
14+
15+
/**
16+
* Block configuration bean. Field names match config.conf keys under the "block" section.
17+
*/
18+
@Slf4j
19+
@Getter
20+
@Setter
21+
public class BlockConfig {
22+
23+
private boolean needSyncCheck = false;
24+
private long maintenanceTimeInterval = 21600000L;
25+
private long proposalExpireTime = DEFAULT_PROPOSAL_EXPIRE_TIME;
26+
private int checkFrozenTime = 1;
27+
28+
// Defaults come from reference.conf (loaded globally via Configuration.java)
29+
30+
/**
31+
* Create BlockConfig from the "block" section of the application config.
32+
* Also checks that committee.proposalExpireTime is not used (must use block.proposalExpireTime).
33+
*/
34+
public static BlockConfig fromConfig(Config config) {
35+
// Reject legacy committee.proposalExpireTime location
36+
if (config.hasPath("committee.proposalExpireTime")) {
37+
throw new TronError("It is not allowed to configure committee.proposalExpireTime in "
38+
+ "config.conf, please set the value in block.proposalExpireTime.", PARAMETER_INIT);
39+
}
40+
41+
Config blockSection = config.getConfig("block");
42+
BlockConfig blockConfig = ConfigBeanFactory.create(blockSection, BlockConfig.class);
43+
blockConfig.postProcess();
44+
return blockConfig;
45+
}
46+
47+
private void postProcess() {
48+
if (proposalExpireTime <= MIN_PROPOSAL_EXPIRE_TIME
49+
|| proposalExpireTime >= MAX_PROPOSAL_EXPIRE_TIME) {
50+
throw new TronError("The value[block.proposalExpireTime] is only allowed to "
51+
+ "be greater than " + MIN_PROPOSAL_EXPIRE_TIME + " and less than "
52+
+ MAX_PROPOSAL_EXPIRE_TIME + "!", PARAMETER_INIT);
53+
}
54+
}
55+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package org.tron.core.config.args;
2+
3+
import com.typesafe.config.Config;
4+
import com.typesafe.config.ConfigBeanFactory;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import lombok.extern.slf4j.Slf4j;
8+
9+
/**
10+
* Committee (governance) configuration bean.
11+
* Field names match config.conf keys under the "committee" section.
12+
* All fields are governance proposal toggles, default 0 (disabled).
13+
*/
14+
@Slf4j
15+
@Getter
16+
@Setter
17+
@SuppressWarnings("unused") // setters used by ConfigBeanFactory via reflection
18+
public class CommitteeConfig {
19+
20+
private long allowCreationOfContracts = 0;
21+
private long allowMultiSign = 0;
22+
private long allowAdaptiveEnergy = 0;
23+
private long allowDelegateResource = 0;
24+
private long allowSameTokenName = 0;
25+
private long allowTvmTransferTrc10 = 0;
26+
private long allowTvmConstantinople = 0;
27+
private long allowTvmSolidity059 = 0;
28+
private long forbidTransferToContract = 0;
29+
private long allowShieldedTRC20Transaction = 0;
30+
private long allowMarketTransaction = 0;
31+
private long allowTransactionFeePool = 0;
32+
private long allowBlackHoleOptimization = 0;
33+
private long allowNewResourceModel = 0;
34+
private long allowTvmIstanbul = 0;
35+
private long allowProtoFilterNum = 0;
36+
private long allowAccountStateRoot = 0;
37+
private long changedDelegation = 0;
38+
// NON-STANDARD NAMING: "allowPBFT" and "pBFTExpireNum" in config.conf contain
39+
// consecutive uppercase letters ("PBFT"), which violates JavaBean naming convention.
40+
// ConfigBeanFactory derives config keys from setter names using JavaBean rules:
41+
// setPBFTExpireNum -> property "PBFTExpireNum" (capital P, per JavaBean spec)
42+
// but config.conf uses "pBFTExpireNum" (lowercase p) -> mismatch -> binding fails.
43+
//
44+
// These two fields are excluded from auto-binding and handled manually in fromConfig().
45+
// TODO: Rename config keys to standard camelCase (allowPbft, pbftExpireNum) when
46+
// PBFT feature is enabled and a breaking config change is acceptable.
47+
@Getter(lombok.AccessLevel.NONE)
48+
@Setter(lombok.AccessLevel.NONE)
49+
private long allowPBFT = 0;
50+
@Getter(lombok.AccessLevel.NONE)
51+
@Setter(lombok.AccessLevel.NONE)
52+
private long pBFTExpireNum = 20;
53+
54+
// Only getters are exposed. No public setters — ConfigBeanFactory scans public
55+
// setters via reflection and would derive key "PBFTExpireNum" / "AllowPBFT"
56+
// (JavaBean uppercase rule), which does not match config keys "pBFTExpireNum"
57+
// / "allowPBFT" and would throw. Values are assigned to fields directly in
58+
// fromConfig() below.
59+
public long getAllowPBFT() { return allowPBFT; }
60+
public long getPBFTExpireNum() { return pBFTExpireNum; }
61+
private long allowTvmFreeze = 0;
62+
private long allowTvmVote = 0;
63+
private long allowTvmLondon = 0;
64+
private long allowTvmCompatibleEvm = 0;
65+
private long allowHigherLimitForMaxCpuTimeOfOneTx = 0;
66+
private long allowNewRewardAlgorithm = 0;
67+
private long allowOptimizedReturnValueOfChainId = 0;
68+
private long allowTvmShangHai = 0;
69+
private long allowOldRewardOpt = 0;
70+
private long allowEnergyAdjustment = 0;
71+
private long allowStrictMath = 0;
72+
private long consensusLogicOptimization = 0;
73+
private long allowTvmCancun = 0;
74+
private long allowTvmBlob = 0;
75+
private long allowTvmOsaka = 0;
76+
private long unfreezeDelayDays = 0;
77+
private long allowReceiptsMerkleRoot = 0;
78+
private long allowAccountAssetOptimization = 0;
79+
private long allowAssetOptimization = 0;
80+
private long allowNewReward = 0;
81+
private long memoFee = 0;
82+
private long allowDelegateOptimization = 0;
83+
private long allowDynamicEnergy = 0;
84+
private long dynamicEnergyThreshold = 0;
85+
private long dynamicEnergyIncreaseFactor = 0;
86+
private long dynamicEnergyMaxFactor = 0;
87+
88+
// proposalExpireTime is NOT a committee field — it's in block.* and handled by BlockConfig
89+
90+
// Defaults come from reference.conf (loaded globally via Configuration.java)
91+
92+
/**
93+
* Create CommitteeConfig from the "committee" section of the application config.
94+
*
95+
* Note: allowPBFT and pBFTExpireNum have non-standard JavaBean naming (consecutive
96+
* uppercase letters) which causes ConfigBeanFactory key mismatch. These two fields
97+
* are excluded from automatic binding and handled manually after.
98+
*/
99+
private static final String PBFT_EXPIRE_NUM_KEY = "pBFTExpireNum";
100+
private static final String ALLOW_PBFT_KEY = "allowPBFT";
101+
102+
public static CommitteeConfig fromConfig(Config config) {
103+
Config section = config.getConfig("committee");
104+
105+
CommitteeConfig cc = ConfigBeanFactory.create(section, CommitteeConfig.class);
106+
// Ensure the manually-named fields get the right values from the original keys
107+
cc.allowPBFT = section.hasPath(ALLOW_PBFT_KEY) ? section.getLong(ALLOW_PBFT_KEY) : 0;
108+
cc.pBFTExpireNum = section.hasPath(PBFT_EXPIRE_NUM_KEY)
109+
? section.getLong(PBFT_EXPIRE_NUM_KEY) : 20;
110+
111+
cc.postProcess();
112+
return cc;
113+
}
114+
115+
private void postProcess() {
116+
// clamp unfreezeDelayDays to 0-365
117+
if (unfreezeDelayDays < 0) {
118+
unfreezeDelayDays = 0;
119+
}
120+
if (unfreezeDelayDays > 365) {
121+
unfreezeDelayDays = 365;
122+
}
123+
124+
// clamp allowDelegateOptimization to 0-1
125+
if (allowDelegateOptimization < 0) { allowDelegateOptimization = 0; }
126+
if (allowDelegateOptimization > 1) { allowDelegateOptimization = 1; }
127+
128+
// clamp allowDynamicEnergy to 0-1
129+
if (allowDynamicEnergy < 0) { allowDynamicEnergy = 0; }
130+
if (allowDynamicEnergy > 1) { allowDynamicEnergy = 1; }
131+
132+
// clamp dynamicEnergyThreshold to 0-100_000_000_000_000_000
133+
if (dynamicEnergyThreshold < 0) { dynamicEnergyThreshold = 0; }
134+
if (dynamicEnergyThreshold > 100_000_000_000_000_000L) {
135+
dynamicEnergyThreshold = 100_000_000_000_000_000L;
136+
}
137+
138+
// clamp dynamicEnergyIncreaseFactor to 0-10_000
139+
if (dynamicEnergyIncreaseFactor < 0) { dynamicEnergyIncreaseFactor = 0; }
140+
if (dynamicEnergyIncreaseFactor > 10_000L) { dynamicEnergyIncreaseFactor = 10_000L; }
141+
142+
// clamp dynamicEnergyMaxFactor to 0-100_000
143+
if (dynamicEnergyMaxFactor < 0) { dynamicEnergyMaxFactor = 0; }
144+
if (dynamicEnergyMaxFactor > 100_000L) { dynamicEnergyMaxFactor = 100_000L; }
145+
146+
// clamp allowNewReward to 0-1 (must run BEFORE the cross-field check below,
147+
// which depends on allowNewReward != 1)
148+
if (allowNewReward < 0) { allowNewReward = 0; }
149+
if (allowNewReward > 1) { allowNewReward = 1; }
150+
151+
// clamp memoFee to 0-1_000_000_000
152+
if (memoFee < 0) { memoFee = 0; }
153+
if (memoFee > 1_000_000_000L) { memoFee = 1_000_000_000L; }
154+
155+
// cross-field: allowOldRewardOpt requires at least one reward/vote flag
156+
if (allowOldRewardOpt == 1 && allowNewRewardAlgorithm != 1
157+
&& allowNewReward != 1 && allowTvmVote != 1) {
158+
throw new IllegalArgumentException(
159+
"At least one of the following proposals is required to be opened first: "
160+
+ "committee.allowNewRewardAlgorithm = 1"
161+
+ " or committee.allowNewReward = 1"
162+
+ " or committee.allowTvmVote = 1.");
163+
}
164+
}
165+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package org.tron.core.config.args;
2+
3+
import com.typesafe.config.Config;
4+
import com.typesafe.config.ConfigBeanFactory;
5+
import com.typesafe.config.ConfigFactory;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import lombok.extern.slf4j.Slf4j;
11+
12+
/**
13+
* Event subscribe configuration bean.
14+
* Field names match config.conf keys under "event.subscribe".
15+
*/
16+
@Slf4j
17+
@Getter
18+
@Setter
19+
public class EventConfig {
20+
21+
private boolean enable = false;
22+
private int version = 0;
23+
private long startSyncBlockNum = 0;
24+
private String path = "";
25+
private String server = "";
26+
private String dbconfig = "";
27+
private boolean contractParse = true;
28+
@Getter(lombok.AccessLevel.NONE)
29+
@Setter(lombok.AccessLevel.NONE)
30+
private NativeConfig nativeQueue = new NativeConfig();
31+
32+
public NativeConfig getNativeQueue() { return nativeQueue; }
33+
// Topics list has optional fields (ethCompatible, redundancy, solidified) that
34+
// not all items have. ConfigBeanFactory requires all bean fields to exist in config.
35+
// Excluded from auto-binding, read manually in fromConfig().
36+
@Getter(lombok.AccessLevel.NONE)
37+
@Setter(lombok.AccessLevel.NONE)
38+
private List<TopicConfig> topics = new ArrayList<>();
39+
40+
public List<TopicConfig> getTopics() { return topics; }
41+
private FilterConfig filter = new FilterConfig();
42+
43+
@Getter
44+
@Setter
45+
public static class NativeConfig {
46+
private boolean useNativeQueue = true;
47+
private int bindport = 5555;
48+
private int sendqueuelength = 1000;
49+
}
50+
51+
@Getter
52+
@Setter
53+
public static class TopicConfig {
54+
private String triggerName = "";
55+
private boolean enable = false;
56+
private String topic = "";
57+
private boolean solidified = false;
58+
private boolean ethCompatible = false;
59+
private boolean redundancy = false;
60+
}
61+
62+
@Getter
63+
@Setter
64+
public static class FilterConfig {
65+
private String fromblock = "";
66+
private String toblock = "";
67+
private List<String> contractAddress = new ArrayList<>();
68+
private List<String> contractTopic = new ArrayList<>();
69+
}
70+
71+
// Defaults come from reference.conf (loaded globally via Configuration.java)
72+
73+
/**
74+
* Create EventConfig from the "event.subscribe" section of the application config.
75+
*
76+
* <p>Note: HOCON key "native" is a Java reserved word, so the bean field is named
77+
* "nativeQueue" but config key is "native". We handle this manually after binding.
78+
*/
79+
public static EventConfig fromConfig(Config config) {
80+
Config section = config.getConfig("event.subscribe");
81+
82+
// "native" is a Java reserved word, "topics" has optional fields per item —
83+
// strip both before binding, read manually
84+
String nativeKey = "native";
85+
String topicsKey = "topics";
86+
Config bindable = section.withoutPath(nativeKey).withoutPath(topicsKey)
87+
.withoutPath("topicDefaults");
88+
EventConfig ec = ConfigBeanFactory.create(bindable, EventConfig.class);
89+
90+
// manually bind "native" sub-section
91+
Config nativeSection = section.hasPath(nativeKey)
92+
? section.getConfig(nativeKey) : ConfigFactory.empty();
93+
ec.nativeQueue = new NativeConfig();
94+
if (nativeSection.hasPath("useNativeQueue")) {
95+
ec.nativeQueue.useNativeQueue = nativeSection.getBoolean("useNativeQueue");
96+
}
97+
if (nativeSection.hasPath("bindport")) {
98+
ec.nativeQueue.bindport = nativeSection.getInt("bindport");
99+
}
100+
if (nativeSection.hasPath("sendqueuelength")) {
101+
ec.nativeQueue.sendqueuelength = nativeSection.getInt("sendqueuelength");
102+
}
103+
104+
// manually bind topics — each item may have optional fields
105+
if (section.hasPath(topicsKey)) {
106+
ec.topics = new ArrayList<>();
107+
for (com.typesafe.config.ConfigObject obj : section.getObjectList(topicsKey)) {
108+
Config tc = obj.toConfig();
109+
TopicConfig topic = new TopicConfig();
110+
if (tc.hasPath("triggerName")) {
111+
topic.triggerName = tc.getString("triggerName");
112+
}
113+
if (tc.hasPath("enable")) {
114+
topic.enable = tc.getBoolean("enable");
115+
}
116+
if (tc.hasPath("topic")) {
117+
topic.topic = tc.getString("topic");
118+
}
119+
if (tc.hasPath("solidified")) {
120+
topic.solidified = tc.getBoolean("solidified");
121+
}
122+
if (tc.hasPath("ethCompatible")) {
123+
topic.ethCompatible = tc.getBoolean("ethCompatible");
124+
}
125+
if (tc.hasPath("redundancy")) {
126+
topic.redundancy = tc.getBoolean("redundancy");
127+
}
128+
ec.topics.add(topic);
129+
}
130+
}
131+
132+
return ec;
133+
}
134+
}

0 commit comments

Comments
 (0)