Skip to content

Commit 5df7511

Browse files
committed
hard fork in mantenance
1 parent 72255e9 commit 5df7511

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ private boolean check(byte[] stats) {
7777

7878
private void downgrade(int version, int slot) {
7979
for (ForkBlockVersionEnum versionEnum : ForkBlockVersionEnum.values()) {
80-
if (versionEnum.getValue() > version) {
81-
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(versionEnum.getValue());
80+
int versionValue = versionEnum.getValue();
81+
if (versionValue > version) {
82+
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(versionValue);
8283
if (!check(stats) && Objects.nonNull(stats)) {
8384
stats[slot] = VERSION_DOWNGRADE;
84-
manager.getDynamicPropertiesStore().statsByVersion(versionEnum.getValue(), stats);
85+
manager.getDynamicPropertiesStore().statsByVersion(versionValue, stats);
8586
}
8687
}
8788
}
@@ -96,22 +97,23 @@ public synchronized void update(BlockCapsule blockCapsule) {
9697
}
9798

9899
int version = blockCapsule.getInstance().getBlockHeader().getRawData().getVersion();
99-
if (version < ForkBlockVersionEnum.VERSION_3_2_2.getValue()) {
100+
if (version < ForkBlockVersionConsts.ENERGY_LIMIT) {
100101
return;
101102
}
102103

104+
downgrade(version, slot);
105+
103106
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(version);
104107
if (check(stats)) {
105108
return;
106109
}
107110

108-
if (stats == null || stats.length != witnesses.size()) {
111+
if (Objects.isNull(stats) || stats.length != witnesses.size()) {
109112
stats = new byte[witnesses.size()];
110113
}
111114

112115
stats[slot] = VERSION_UPGRADE;
113116
manager.getDynamicPropertiesStore().statsByVersion(version, stats);
114-
downgrade(version, slot);
115117
logger.info(
116118
"*******update hard fork:{}, witness size:{}, solt:{}, witness:{}, version:{}",
117119
Streams.zip(witnesses.stream(), Stream.of(ArrayUtils.toObject(stats)), Maps::immutableEntry)
@@ -126,10 +128,11 @@ public synchronized void update(BlockCapsule blockCapsule) {
126128

127129
public synchronized void reset() {
128130
for (ForkBlockVersionEnum versionEnum : ForkBlockVersionEnum.values()) {
129-
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(versionEnum.getValue());
131+
int versionValue = versionEnum.getValue();
132+
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(versionValue);
130133
if (!check(stats) && Objects.nonNull(stats)) {
131134
Arrays.fill(stats, VERSION_DOWNGRADE);
132-
manager.getDynamicPropertiesStore().statsByVersion(versionEnum.getValue(), stats);
135+
manager.getDynamicPropertiesStore().statsByVersion(versionValue, stats);
133136
}
134137
}
135138
}

0 commit comments

Comments
 (0)