Skip to content

Commit 365ae55

Browse files
committed
hard fork in mantenance
1 parent d736c3f commit 365ae55

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

src/main/java/org/tron/common/utils/ForkController.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
import org.tron.core.Wallet;
1919
import org.tron.core.capsule.BlockCapsule;
2020
import org.tron.core.config.Parameter.ForkBlockVersionConsts;
21+
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
2122
import org.tron.core.db.Manager;
2223

2324
@Slf4j
2425
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2526
public class ForkController {
2627

28+
private static final byte VERSION_DOWNGRADE = (byte) 0;
2729
private static final byte VERSION_UPGRADE = (byte) 1;
2830
private static final byte HARD_FORK_EFFECTIVE = (byte) 2;
2931
private static final byte[] check;
3032
private static final byte[] check2;
33+
3134
static {
3235
check = new byte[1024];
3336
Arrays.fill(check, VERSION_UPGRADE);
@@ -45,6 +48,10 @@ public void init(Manager manager) {
4548
passSet.clear();
4649
}
4750

51+
public boolean pass(ForkBlockVersionEnum forkBlockVersionEnum) {
52+
return pass(forkBlockVersionEnum.getValue());
53+
}
54+
4855
public synchronized boolean pass(int version) {
4956
if (!checkEnergy(version)) {
5057
return false;
@@ -102,6 +109,18 @@ private boolean check(byte[] check, byte[] stats) {
102109
return true;
103110
}
104111

112+
private void downgrade(int version, int slot) {
113+
for (ForkBlockVersionEnum versionEnum : ForkBlockVersionEnum.values()) {
114+
if (versionEnum.getValue() > version) {
115+
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(versionEnum.getValue());
116+
if (!check2(stats) && stats != null) {
117+
stats[slot] = VERSION_DOWNGRADE;
118+
manager.getDynamicPropertiesStore().statsByVersion(versionEnum.getValue(), stats);
119+
}
120+
}
121+
}
122+
}
123+
105124
public synchronized void update(BlockCapsule blockCapsule) {
106125
List<ByteString> witnesses = manager.getWitnessController().getActiveWitnesses();
107126
ByteString witness = blockCapsule.getWitnessAddress();
@@ -115,6 +134,8 @@ public synchronized void update(BlockCapsule blockCapsule) {
115134
return;
116135
}
117136

137+
downgrade(version, slot);
138+
118139
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(version);
119140
if (check(stats) || check2(stats)) {
120141
return;
@@ -138,9 +159,13 @@ public synchronized void update(BlockCapsule blockCapsule) {
138159
version);
139160
}
140161

162+
private void setSolidNumWithVersion5BeEffective() {
163+
164+
}
165+
141166
public synchronized void updateWhenMaintenance(BlockCapsule blockCapsule) {
142167
int version = blockCapsule.getInstance().getBlockHeader().getRawData().getVersion();
143-
if (version < ForkBlockVersionConsts.VERSION_3_2_2 || passSet.contains(version)) {
168+
if (version < ForkBlockVersionEnum.VERSION_3_2_2.getValue() || passSet.contains(version)) {
144169
return;
145170
}
146171

@@ -152,7 +177,10 @@ public synchronized void updateWhenMaintenance(BlockCapsule blockCapsule) {
152177
if (check(stats)) {
153178
Arrays.fill(stats, HARD_FORK_EFFECTIVE);
154179
manager.getDynamicPropertiesStore().statsByVersion(version, stats);
155-
logger.info("*******hard fork is effective in the maintenance, version is {}", version);
180+
logger.info(
181+
"*******hard fork is effective in the maintenance:{}, version:{}",
182+
ArrayUtils.toObject(stats),
183+
version);
156184
}
157185
}
158186

src/main/java/org/tron/core/actuator/ProposalCreateActuator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.tron.core.capsule.TransactionResultCapsule;
1717
import org.tron.core.config.Parameter.ChainParameters;
1818
import org.tron.core.config.Parameter.ForkBlockVersionConsts;
19+
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
1920
import org.tron.core.config.args.Args;
2021
import org.tron.core.db.Manager;
2122
import org.tron.core.exception.ContractExeException;
@@ -219,7 +220,7 @@ private void validateValue(Map.Entry<Long, Long> entry) throws ContractValidateE
219220
if (!dbManager.getForkController().pass(ForkBlockVersionConsts.ENERGY_LIMIT)) {
220221
throw new ContractValidateException("Bad chain parameter id");
221222
}
222-
if (dbManager.getForkController().pass(ForkBlockVersionConsts.VERSION_3_2_2)) {
223+
if (dbManager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_2_2)) {
223224
throw new ContractValidateException("Bad chain parameter id");
224225
}
225226
if (entry.getValue() < 0 || entry.getValue() > 100_000_000_000_000_000L) {
@@ -243,7 +244,7 @@ private void validateValue(Map.Entry<Long, Long> entry) throws ContractValidateE
243244
break;
244245
}
245246
case (19): {
246-
if (!dbManager.getForkController().pass(ForkBlockVersionConsts.VERSION_3_2_2)) {
247+
if (!dbManager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_2_2)) {
247248
throw new ContractValidateException("Bad chain parameter id");
248249
}
249250
if (entry.getValue() < 0 || entry.getValue() > 100_000_000_000_000_000L) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.tron.core.config;
22

3+
import lombok.Getter;
4+
35
public interface Parameter {
46

57
interface ChainConstant {
@@ -104,11 +106,22 @@ enum ChainParameters {
104106
// EXCHANGE_BALANCE_LIMIT,
105107
}
106108

109+
@Deprecated
107110
interface ForkBlockVersionConsts {
108111

109112
int START_NEW_TRANSACTION = 4;
110113
int ENERGY_LIMIT = 5;
111-
int VERSION_3_2_2 = 6;
114+
}
115+
116+
enum ForkBlockVersionEnum {
117+
VERSION_3_2_2(6);
118+
119+
@Getter
120+
int value;
121+
122+
ForkBlockVersionEnum(int value) {
123+
this.value = value;
124+
}
112125
}
113126

114127
}

0 commit comments

Comments
 (0)