Skip to content

Commit 005709e

Browse files
authored
Merge pull request #4769 from lxcmyf/release_4.6.0
fix(mechanism): fix deflation or expansion problems
2 parents e77b3d5 + 344d149 commit 005709e

9 files changed

Lines changed: 64 additions & 6 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
565565
throw new ContractValidateException(
566566
"Bad chain parameter id [ALLOW_NEW_REWARD_ALGO]");
567567
}
568-
if (dynamicPropertiesStore.useNewRewardAlgorithm()) {
568+
if (dynamicPropertiesStore.allowNewRewardEnable()) {
569569
throw new ContractValidateException(
570570
"New reward algorithm has been valid.");
571571
}

chainbase/src/main/java/org/tron/core/db/EnergyProcessor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ public long calculateGlobalEnergyLimit(AccountCapsule accountCapsule) {
133133
long energyWeight = frozeBalance / TRX_PRECISION;
134134
long totalEnergyLimit = dynamicPropertiesStore.getTotalEnergyCurrentLimit();
135135
long totalEnergyWeight = dynamicPropertiesStore.getTotalEnergyWeight();
136-
137-
assert totalEnergyWeight > 0;
138-
136+
if (dynamicPropertiesStore.allowNewRewardEnable() && totalEnergyWeight <= 0) {
137+
return 0;
138+
} else {
139+
assert totalEnergyWeight > 0;
140+
}
139141
return (long) (energyWeight * ((double) totalEnergyLimit / totalEnergyWeight));
140142
}
141143

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
187187
private static final byte[] ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX =
188188
"ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX".getBytes();
189189

190+
private static final byte[] ALLOW_NEW_REWARD = "ALLOW_NEW_REWARD".getBytes();
190191
private static final byte[] MEMO_FEE = "MEMO_FEE".getBytes();
191192
private static final byte[] MEMO_FEE_HISTORY = "MEMO_FEE_HISTORY".getBytes();
192193

@@ -861,6 +862,16 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
861862
}
862863
}
863864

865+
try {
866+
this.getAllowNewRewardEnable();
867+
} catch (IllegalArgumentException e) {
868+
this.saveAllowNewRewardEnable(CommonParameter.getInstance().getAllowNewRewardEnable());
869+
if (CommonParameter.getInstance().getAllowNewRewardEnable() == 1) {
870+
this.put(NEW_REWARD_ALGORITHM_EFFECTIVE_CYCLE,
871+
new BytesCapsule(ByteArray.fromLong(getCurrentCycleNumber())));
872+
}
873+
}
874+
864875
try {
865876
this.getMemoFee();
866877
} catch (IllegalArgumentException e) {
@@ -2145,20 +2156,29 @@ public void updateNextMaintenanceTime(long blockTime) {
21452156
public void addTotalNetWeight(long amount) {
21462157
long totalNetWeight = getTotalNetWeight();
21472158
totalNetWeight += amount;
2159+
if (allowNewRewardEnable()) {
2160+
totalNetWeight = Math.max(0, totalNetWeight);
2161+
}
21482162
saveTotalNetWeight(totalNetWeight);
21492163
}
21502164

21512165
//The unit is trx
21522166
public void addTotalEnergyWeight(long amount) {
21532167
long totalEnergyWeight = getTotalEnergyWeight();
21542168
totalEnergyWeight += amount;
2169+
if (allowNewRewardEnable()) {
2170+
totalEnergyWeight = Math.max(0, totalEnergyWeight);
2171+
}
21552172
saveTotalEnergyWeight(totalEnergyWeight);
21562173
}
21572174

21582175
//The unit is trx
21592176
public void addTotalTronPowerWeight(long amount) {
21602177
long totalWeight = getTotalTronPowerWeight();
21612178
totalWeight += amount;
2179+
if (allowNewRewardEnable()) {
2180+
totalWeight = Math.max(0, totalWeight);
2181+
}
21622182
saveTotalTronPowerWeight(totalWeight);
21632183
}
21642184

@@ -2561,6 +2581,21 @@ public void saveMemoFeeHistory(String value) {
25612581
this.put(MEMO_FEE_HISTORY, new BytesCapsule(ByteArray.fromString(value)));
25622582
}
25632583

2584+
public long getAllowNewRewardEnable() {
2585+
return Optional.ofNullable(getUnchecked(ALLOW_NEW_REWARD))
2586+
.map(BytesCapsule::getData)
2587+
.map(ByteArray::toLong)
2588+
.orElseThrow(() -> new IllegalArgumentException("not found AllowNewRewardEnable"));
2589+
}
2590+
2591+
public void saveAllowNewRewardEnable(long newReward) {
2592+
this.put(ALLOW_NEW_REWARD, new BytesCapsule(ByteArray.fromLong(newReward)));
2593+
}
2594+
2595+
public boolean allowNewRewardEnable() {
2596+
return getAllowNewRewardEnable() == 1;
2597+
}
2598+
25642599
private static class DynamicResourceProperties {
25652600

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,10 @@ public class CommonParameter {
561561
@Setter
562562
public long allowNewRewardAlgorithm;
563563

564+
@Getter
565+
@Setter
566+
public long allowNewRewardEnable = 0L;
567+
564568
@Getter
565569
@Setter
566570
public long memoFee = 0L;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ public class Constant {
307307

308308
public static final String ALLOW_ACCOUNT_ASSET_OPTIMIZATION = "committee.allowAccountAssetOptimization";
309309
public static final String ALLOW_ASSET_OPTIMIZATION = "committee.allowAssetOptimization";
310+
public static final String ALLOW_NEW_REWARD_ENABLE = "committee.allowNewRewardEnable";
310311
public static final String MEMO_FEE = "committee.memoFee";
311312

312313
public static final String LOCAL_HOST = "127.0.0.1";

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,8 @@ public Protocol.ChainParameters getChainParameters() {
10991099
.build());
11001100

11011101
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
1102-
.setKey("getNewRewardAlgorithm")
1103-
.setValue(dbManager.getDynamicPropertiesStore().useNewRewardAlgorithm() ? 1 : 0)
1102+
.setKey("getAllowNewRewardEnable")
1103+
.setValue(dbManager.getDynamicPropertiesStore().getAllowNewRewardEnable())
11041104
.build());
11051105

11061106
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ public static void clearParam() {
215215
PARAMETER.shutdownBlockCount = -1;
216216
PARAMETER.blockCacheTimeout = 60;
217217
PARAMETER.allowNewRewardAlgorithm = 0;
218+
PARAMETER.allowNewRewardEnable = 0;
219+
PARAMETER.memoFee = 0;
218220
}
219221

220222
/**
@@ -1034,6 +1036,16 @@ public static void setParam(final String[] args, final String confFileName) {
10341036
PARAMETER.blockCacheTimeout = config.getLong(Constant.BLOCK_CACHE_TIMEOUT);
10351037
}
10361038

1039+
if (config.hasPath(Constant.ALLOW_NEW_REWARD_ENABLE)) {
1040+
PARAMETER.allowNewRewardEnable = config.getLong(Constant.ALLOW_NEW_REWARD_ENABLE);
1041+
if (PARAMETER.allowNewRewardEnable > 1) {
1042+
PARAMETER.allowNewRewardEnable = 1;
1043+
}
1044+
if (PARAMETER.allowNewRewardEnable < 0) {
1045+
PARAMETER.allowNewRewardEnable = 0;
1046+
}
1047+
}
1048+
10371049
if (config.hasPath(Constant.MEMO_FEE)) {
10381050
PARAMETER.memoFee = config.getLong(Constant.MEMO_FEE);
10391051
if (PARAMETER.memoFee > 1_000_000_000) {

framework/src/main/java/org/tron/core/consensus/ProposalService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
286286
}
287287
case ALLOW_NEW_REWARD_ALGO: {
288288
manager.getDynamicPropertiesStore().saveNewRewardAlgorithmEffectiveCycle();
289+
manager.getDynamicPropertiesStore().saveAllowNewRewardEnable(entry.getValue());
289290
break;
290291
}
291292
case MEMO_FEE: {

framework/src/main/java/org/tron/core/db/BandwidthProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ public long calculateGlobalNetLimit(AccountCapsule accountCapsule) {
390390
long netWeight = frozeBalance / TRX_PRECISION;
391391
long totalNetLimit = chainBaseManager.getDynamicPropertiesStore().getTotalNetLimit();
392392
long totalNetWeight = chainBaseManager.getDynamicPropertiesStore().getTotalNetWeight();
393+
if (dynamicPropertiesStore.allowNewRewardEnable() && totalNetWeight <= 0) {
394+
return 0;
395+
}
393396
if (totalNetWeight == 0) {
394397
return 0;
395398
}

0 commit comments

Comments
 (0)