@@ -77,11 +77,12 @@ private boolean check(byte[] stats) {
77
77
78
78
private void downgrade (int version , int slot ) {
79
79
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 );
82
83
if (!check (stats ) && Objects .nonNull (stats )) {
83
84
stats [slot ] = VERSION_DOWNGRADE ;
84
- manager .getDynamicPropertiesStore ().statsByVersion (versionEnum . getValue () , stats );
85
+ manager .getDynamicPropertiesStore ().statsByVersion (versionValue , stats );
85
86
}
86
87
}
87
88
}
@@ -96,22 +97,23 @@ public synchronized void update(BlockCapsule blockCapsule) {
96
97
}
97
98
98
99
int version = blockCapsule .getInstance ().getBlockHeader ().getRawData ().getVersion ();
99
- if (version < ForkBlockVersionEnum . VERSION_3_2_2 . getValue () ) {
100
+ if (version < ForkBlockVersionConsts . ENERGY_LIMIT ) {
100
101
return ;
101
102
}
102
103
104
+ downgrade (version , slot );
105
+
103
106
byte [] stats = manager .getDynamicPropertiesStore ().statsByVersion (version );
104
107
if (check (stats )) {
105
108
return ;
106
109
}
107
110
108
- if (stats == null || stats .length != witnesses .size ()) {
111
+ if (Objects . isNull ( stats ) || stats .length != witnesses .size ()) {
109
112
stats = new byte [witnesses .size ()];
110
113
}
111
114
112
115
stats [slot ] = VERSION_UPGRADE ;
113
116
manager .getDynamicPropertiesStore ().statsByVersion (version , stats );
114
- downgrade (version , slot );
115
117
logger .info (
116
118
"*******update hard fork:{}, witness size:{}, solt:{}, witness:{}, version:{}" ,
117
119
Streams .zip (witnesses .stream (), Stream .of (ArrayUtils .toObject (stats )), Maps ::immutableEntry )
@@ -126,10 +128,11 @@ public synchronized void update(BlockCapsule blockCapsule) {
126
128
127
129
public synchronized void reset () {
128
130
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 );
130
133
if (!check (stats ) && Objects .nonNull (stats )) {
131
134
Arrays .fill (stats , VERSION_DOWNGRADE );
132
- manager .getDynamicPropertiesStore ().statsByVersion (versionEnum . getValue () , stats );
135
+ manager .getDynamicPropertiesStore ().statsByVersion (versionValue , stats );
133
136
}
134
137
}
135
138
}
0 commit comments