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
18 changes: 15 additions & 3 deletions chainbase/src/main/java/org/tron/core/db/TronDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,25 @@ public void reset() {
@Override
public void close() {
logger.info("******** Begin to close {}. ********", getName());
doClose();
logger.info("******** End to close {}. ********", getName());
}

/**
* Releases writeOptions and dbSource (best-effort, exceptions logged at WARN).
* Subclasses with extra resources should override {@link #close()} and call
* {@code doClose()} directly — not {@code super.close()} — to avoid duplicated logs.
*/
protected void doClose() {
try {
writeOptions.close();
} catch (Exception e) {
logger.warn("Failed to close writeOptions in {}.", getName(), e);
}
try {
dbSource.closeDB();
} catch (Exception e) {
logger.warn("Failed to close {}.", getName(), e);
} finally {
logger.info("******** End to close {}. ********", getName());
logger.warn("Failed to close dbSource in {}.", getName(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,16 @@ public void updateByBatch(Map<byte[], byte[]> rows) {
this.dbSource.updateByBatch(rows, writeOptions);
}

/**
* close the database.
*/
@Override
public void close() {
logger.debug("******** Begin to close {}. ********", getName());
try {
writeOptions.close();
dbSource.closeDB();
} catch (Exception e) {
logger.warn("Failed to close {}.", getName(), e);
} finally {
logger.debug("******** End to close {}. ********", getName());
logger.warn("Failed to close writeOptions in {}.", getName(), e);
}
doClose();
logger.debug("******** End to close {}. ********", getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public HttpRateLimiterItem(ConfigObject asset) {
strategy = asset.get("strategy").unwrapped().toString();
params = asset.get("paramString").unwrapped().toString();
}

public HttpRateLimiterItem(String component, String strategy, String params) {
this.component = component;
this.strategy = strategy;
this.params = params;
}
}


Expand All @@ -93,5 +99,11 @@ public RpcRateLimiterItem(ConfigObject asset) {
strategy = asset.get("strategy").unwrapped().toString();
params = asset.get("paramString").unwrapped().toString();
}

public RpcRateLimiterItem(String component, String strategy, String params) {
this.component = component;
this.strategy = strategy;
this.params = params;
}
}
}
3 changes: 2 additions & 1 deletion common/src/main/java/org/tron/core/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static com.typesafe.config.Config getByFileName(

private static void resolveConfigFile(String fileName, File confFile) {
if (confFile.exists()) {
config = ConfigFactory.parseFile(confFile);
config = ConfigFactory.parseFile(confFile)
.withFallback(ConfigFactory.defaultReference());
} else if (Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)
!= null) {
config = ConfigFactory.load(fileName);
Expand Down
55 changes: 55 additions & 0 deletions common/src/main/java/org/tron/core/config/args/BlockConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.tron.core.config.args;

import static org.tron.core.Constant.DEFAULT_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.Constant.MAX_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.Constant.MIN_PROPOSAL_EXPIRE_TIME;
import static org.tron.core.exception.TronError.ErrCode.PARAMETER_INIT;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigBeanFactory;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.tron.core.exception.TronError;

/**
* Block configuration bean. Field names match config.conf keys under the "block" section.
*/
@Slf4j
@Getter
@Setter
public class BlockConfig {

private boolean needSyncCheck = false;
private long maintenanceTimeInterval = 21600000L;
private long proposalExpireTime = DEFAULT_PROPOSAL_EXPIRE_TIME;
private int checkFrozenTime = 1;

// Defaults come from reference.conf (loaded globally via Configuration.java)

/**
* Create BlockConfig from the "block" section of the application config.
* Also checks that committee.proposalExpireTime is not used (must use block.proposalExpireTime).
*/
public static BlockConfig fromConfig(Config config) {
// Reject legacy committee.proposalExpireTime location
if (config.hasPath("committee.proposalExpireTime")) {
throw new TronError("It is not allowed to configure committee.proposalExpireTime in "
+ "config.conf, please set the value in block.proposalExpireTime.", PARAMETER_INIT);
}

Config blockSection = config.getConfig("block");
BlockConfig blockConfig = ConfigBeanFactory.create(blockSection, BlockConfig.class);
blockConfig.postProcess();
return blockConfig;
}

private void postProcess() {
if (proposalExpireTime <= MIN_PROPOSAL_EXPIRE_TIME
|| proposalExpireTime >= MAX_PROPOSAL_EXPIRE_TIME) {
throw new TronError("The value[block.proposalExpireTime] is only allowed to "
+ "be greater than " + MIN_PROPOSAL_EXPIRE_TIME + " and less than "
+ MAX_PROPOSAL_EXPIRE_TIME + "!", PARAMETER_INIT);
}
}
}
165 changes: 165 additions & 0 deletions common/src/main/java/org/tron/core/config/args/CommitteeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package org.tron.core.config.args;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigBeanFactory;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
* Committee (governance) configuration bean.
* Field names match config.conf keys under the "committee" section.
* All fields are governance proposal toggles, default 0 (disabled).
*/
@Slf4j
@Getter
@Setter
@SuppressWarnings("unused") // setters used by ConfigBeanFactory via reflection
public class CommitteeConfig {

private long allowCreationOfContracts = 0;
private long allowMultiSign = 0;
private long allowAdaptiveEnergy = 0;
private long allowDelegateResource = 0;
private long allowSameTokenName = 0;
private long allowTvmTransferTrc10 = 0;
private long allowTvmConstantinople = 0;
private long allowTvmSolidity059 = 0;
private long forbidTransferToContract = 0;
private long allowShieldedTRC20Transaction = 0;
private long allowMarketTransaction = 0;
private long allowTransactionFeePool = 0;
private long allowBlackHoleOptimization = 0;
private long allowNewResourceModel = 0;
private long allowTvmIstanbul = 0;
private long allowProtoFilterNum = 0;
private long allowAccountStateRoot = 0;
private long changedDelegation = 0;
// NON-STANDARD NAMING: "allowPBFT" and "pBFTExpireNum" in config.conf contain
// consecutive uppercase letters ("PBFT"), which violates JavaBean naming convention.
// ConfigBeanFactory derives config keys from setter names using JavaBean rules:
// setPBFTExpireNum -> property "PBFTExpireNum" (capital P, per JavaBean spec)
// but config.conf uses "pBFTExpireNum" (lowercase p) -> mismatch -> binding fails.
//
// These two fields are excluded from auto-binding and handled manually in fromConfig().
// TODO: Rename config keys to standard camelCase (allowPbft, pbftExpireNum) when
// PBFT feature is enabled and a breaking config change is acceptable.
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
private long allowPBFT = 0;
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
private long pBFTExpireNum = 20;

// Only getters are exposed. No public setters — ConfigBeanFactory scans public
// setters via reflection and would derive key "PBFTExpireNum" / "AllowPBFT"
// (JavaBean uppercase rule), which does not match config keys "pBFTExpireNum"
// / "allowPBFT" and would throw. Values are assigned to fields directly in
// fromConfig() below.
public long getAllowPBFT() { return allowPBFT; }
public long getPBFTExpireNum() { return pBFTExpireNum; }
private long allowTvmFreeze = 0;
private long allowTvmVote = 0;
private long allowTvmLondon = 0;
private long allowTvmCompatibleEvm = 0;
private long allowHigherLimitForMaxCpuTimeOfOneTx = 0;
private long allowNewRewardAlgorithm = 0;
private long allowOptimizedReturnValueOfChainId = 0;
private long allowTvmShangHai = 0;
private long allowOldRewardOpt = 0;
private long allowEnergyAdjustment = 0;
private long allowStrictMath = 0;
private long consensusLogicOptimization = 0;
private long allowTvmCancun = 0;
private long allowTvmBlob = 0;
private long allowTvmOsaka = 0;
private long unfreezeDelayDays = 0;
private long allowReceiptsMerkleRoot = 0;
private long allowAccountAssetOptimization = 0;
private long allowAssetOptimization = 0;
private long allowNewReward = 0;
private long memoFee = 0;
private long allowDelegateOptimization = 0;
private long allowDynamicEnergy = 0;
private long dynamicEnergyThreshold = 0;
private long dynamicEnergyIncreaseFactor = 0;
private long dynamicEnergyMaxFactor = 0;

// proposalExpireTime is NOT a committee field — it's in block.* and handled by BlockConfig

// Defaults come from reference.conf (loaded globally via Configuration.java)

/**
* Create CommitteeConfig from the "committee" section of the application config.
*
* Note: allowPBFT and pBFTExpireNum have non-standard JavaBean naming (consecutive
* uppercase letters) which causes ConfigBeanFactory key mismatch. These two fields
* are excluded from automatic binding and handled manually after.
*/
private static final String PBFT_EXPIRE_NUM_KEY = "pBFTExpireNum";
private static final String ALLOW_PBFT_KEY = "allowPBFT";

public static CommitteeConfig fromConfig(Config config) {
Config section = config.getConfig("committee");

CommitteeConfig cc = ConfigBeanFactory.create(section, CommitteeConfig.class);
// Ensure the manually-named fields get the right values from the original keys
cc.allowPBFT = section.hasPath(ALLOW_PBFT_KEY) ? section.getLong(ALLOW_PBFT_KEY) : 0;
cc.pBFTExpireNum = section.hasPath(PBFT_EXPIRE_NUM_KEY)
? section.getLong(PBFT_EXPIRE_NUM_KEY) : 20;

cc.postProcess();
return cc;
}

private void postProcess() {
// clamp unfreezeDelayDays to 0-365
if (unfreezeDelayDays < 0) {
unfreezeDelayDays = 0;
}
if (unfreezeDelayDays > 365) {
unfreezeDelayDays = 365;
}

// clamp allowDelegateOptimization to 0-1
if (allowDelegateOptimization < 0) { allowDelegateOptimization = 0; }
if (allowDelegateOptimization > 1) { allowDelegateOptimization = 1; }

// clamp allowDynamicEnergy to 0-1
if (allowDynamicEnergy < 0) { allowDynamicEnergy = 0; }
if (allowDynamicEnergy > 1) { allowDynamicEnergy = 1; }

// clamp dynamicEnergyThreshold to 0-100_000_000_000_000_000
if (dynamicEnergyThreshold < 0) { dynamicEnergyThreshold = 0; }
if (dynamicEnergyThreshold > 100_000_000_000_000_000L) {
dynamicEnergyThreshold = 100_000_000_000_000_000L;
}

// clamp dynamicEnergyIncreaseFactor to 0-10_000
if (dynamicEnergyIncreaseFactor < 0) { dynamicEnergyIncreaseFactor = 0; }
if (dynamicEnergyIncreaseFactor > 10_000L) { dynamicEnergyIncreaseFactor = 10_000L; }

// clamp dynamicEnergyMaxFactor to 0-100_000
if (dynamicEnergyMaxFactor < 0) { dynamicEnergyMaxFactor = 0; }
if (dynamicEnergyMaxFactor > 100_000L) { dynamicEnergyMaxFactor = 100_000L; }

// clamp allowNewReward to 0-1 (must run BEFORE the cross-field check below,
// which depends on allowNewReward != 1)
if (allowNewReward < 0) { allowNewReward = 0; }
if (allowNewReward > 1) { allowNewReward = 1; }

// clamp memoFee to 0-1_000_000_000
if (memoFee < 0) { memoFee = 0; }
if (memoFee > 1_000_000_000L) { memoFee = 1_000_000_000L; }

// cross-field: allowOldRewardOpt requires at least one reward/vote flag
if (allowOldRewardOpt == 1 && allowNewRewardAlgorithm != 1
&& allowNewReward != 1 && allowTvmVote != 1) {
throw new IllegalArgumentException(
"At least one of the following proposals is required to be opened first: "
+ "committee.allowNewRewardAlgorithm = 1"
+ " or committee.allowNewReward = 1"
+ " or committee.allowTvmVote = 1.");
}
}
}
Loading
Loading