Skip to content

Commit b59e694

Browse files
committed
feat(reward): add a proposal for new reward algorithm
1 parent f5d9e31 commit b59e694

5 files changed

Lines changed: 31 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,21 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
560560
}
561561
break;
562562
}
563+
case ALLOW_NEW_REWARD_ALGO: {
564+
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_6)) {
565+
throw new ContractValidateException(
566+
"Bad chain parameter id [ALLOW_NEW_REWARD_ALGO]");
567+
}
568+
if (dynamicPropertiesStore.useNewRewardAlgorithm()) {
569+
throw new ContractValidateException(
570+
"New reward algorithm has been valid.");
571+
}
572+
if (value != 1) {
573+
throw new ContractValidateException(
574+
"This value[ALLOW_NEW_REWARD_ALGO] is only allowed to be 1");
575+
}
576+
break;
577+
}
563578
default:
564579
break;
565580
}
@@ -623,7 +638,8 @@ public enum ProposalType { // current value, value range
623638
TOTAL_NET_LIMIT(62), // 43_200_000_000L, [0, 1000_000_000_000L]
624639
ALLOW_TVM_LONDON(63), // 0, 1
625640
ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX(65), // 0, 1
626-
ALLOW_ASSET_OPTIMIZATION(66); // 0, 1
641+
ALLOW_ASSET_OPTIMIZATION(66), // 0, 1
642+
ALLOW_NEW_REWARD_ALGO(67); // 0, 1
627643

628644
private long code;
629645

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ 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-
191190
@Autowired
192191
private DynamicPropertiesStore(@Value("properties") String dbName) {
193192
super(dbName);
@@ -2383,7 +2382,7 @@ public long getAllowTvmCompatibleEvm() {
23832382
}
23842383

23852384
public boolean useNewRewardAlgorithm() {
2386-
return getAllowTvmVote() == 1;
2385+
return getNewRewardAlgorithmEffectiveCycle() != Long.MAX_VALUE;
23872386
}
23882387

23892388
public void saveNewRewardAlgorithmEffectiveCycle() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum ForkBlockVersionEnum {
1818
VERSION_4_2(21, 1596780000000L, 80),
1919
VERSION_4_3(22, 1596780000000L, 80),
2020
VERSION_4_4(23, 1596780000000L, 80),
21-
VERSION_4_5(24, 1596780000000L, 80);
21+
VERSION_4_5(24, 1596780000000L, 80),
22+
VERSION_4_6(25, 1596780000000L, 80);
2223

2324
@Getter
2425
private int value;
@@ -66,7 +67,7 @@ public class ChainConstant {
6667
public static final int SINGLE_REPEAT = 1;
6768
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
6869
public static final int MAX_FROZEN_NUMBER = 1;
69-
public static final int BLOCK_VERSION = 24;
70+
public static final int BLOCK_VERSION = 25;
7071
public static final long FROZEN_PERIOD = 86_400_000L;
7172
public static final long TRX_PRECISION = 1000_000L;
7273
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,11 @@ public Protocol.ChainParameters getChainParameters() {
10981098
.setValue(dbManager.getDynamicPropertiesStore().getAllowAssetOptimization())
10991099
.build());
11001100

1101+
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
1102+
.setKey("getNewRewardAlgorithm")
1103+
.setValue(dbManager.getDynamicPropertiesStore().useNewRewardAlgorithm() ? 1 : 0)
1104+
.build());
1105+
11011106
return builder.build();
11021107
}
11031108

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
251251
break;
252252
}
253253
case ALLOW_TVM_VOTE: {
254-
manager.getDynamicPropertiesStore().saveAllowTvmVote(entry.getValue());
255254
manager.getDynamicPropertiesStore().saveNewRewardAlgorithmEffectiveCycle();
255+
manager.getDynamicPropertiesStore().saveAllowTvmVote(entry.getValue());
256256
break;
257257
}
258258
case ALLOW_TVM_LONDON: {
@@ -284,6 +284,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
284284
manager.getDynamicPropertiesStore().setAllowAssetOptimization(entry.getValue());
285285
break;
286286
}
287+
case ALLOW_NEW_REWARD_ALGO: {
288+
manager.getDynamicPropertiesStore().saveNewRewardAlgorithmEffectiveCycle();
289+
break;
290+
}
287291
default:
288292
find = false;
289293
break;

0 commit comments

Comments
 (0)