@@ -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 ();
0 commit comments