|
| 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 | +} |
0 commit comments