17
17
import org .apache .commons .lang3 .StringUtils ;
18
18
import org .tron .core .Wallet ;
19
19
import org .tron .core .capsule .BlockCapsule ;
20
- import org .tron .core .config .Parameter ;
21
20
import org .tron .core .config .Parameter .ForkBlockVersionConsts ;
22
21
import org .tron .core .db .Manager ;
23
22
24
23
@ Slf4j
25
24
@ NoArgsConstructor (access = AccessLevel .PRIVATE )
26
25
public class ForkController {
27
26
27
+ private static final byte VERSION_UPGRADE = (byte ) 1 ;
28
+ private static final byte HARD_FORK_EFFECTIVE = (byte ) 2 ;
28
29
private static final byte [] check ;
29
30
private static final byte [] check2 ;
30
31
static {
31
32
check = new byte [1024 ];
32
- Arrays .fill (check , ( byte ) 1 );
33
+ Arrays .fill (check , VERSION_UPGRADE );
33
34
check2 = new byte [1024 ];
34
- Arrays .fill (check2 , ( byte ) 2 );
35
+ Arrays .fill (check2 , HARD_FORK_EFFECTIVE );
35
36
}
36
37
37
38
@ Getter
@@ -45,7 +46,7 @@ public void init(Manager manager) {
45
46
}
46
47
47
48
public synchronized boolean pass (int version ) {
48
- if (!check (version )) {
49
+ if (!checkEnergy (version )) {
49
50
return false ;
50
51
}
51
52
@@ -67,7 +68,10 @@ public synchronized boolean pass(int version) {
67
68
return pass ;
68
69
}
69
70
70
- private boolean check (int version ) {
71
+ // when block.version = 5,
72
+ // it make block use new energy to handle transaction when block number >= 4727890L.
73
+ // version !=5, skip this.
74
+ private boolean checkEnergy (int version ) {
71
75
if (version != ForkBlockVersionConsts .ENERGY_LIMIT ) {
72
76
return true ;
73
77
}
@@ -120,7 +124,7 @@ public synchronized void update(BlockCapsule blockCapsule) {
120
124
stats = new byte [witnesses .size ()];
121
125
}
122
126
123
- stats [slot ] = ( byte ) 1 ;
127
+ stats [slot ] = VERSION_UPGRADE ;
124
128
manager .getDynamicPropertiesStore ().statsByVersion (version , stats );
125
129
logger .info (
126
130
"*******update hard fork:{}, witness size:{}, solt:{}, witness:{}, version:{}" ,
@@ -146,7 +150,7 @@ public synchronized void updateWhenMaintenance(BlockCapsule blockCapsule) {
146
150
}
147
151
148
152
if (check (stats )) {
149
- Arrays .fill (stats , ( byte ) 2 );
153
+ Arrays .fill (stats , HARD_FORK_EFFECTIVE );
150
154
manager .getDynamicPropertiesStore ().statsByVersion (version , stats );
151
155
logger .info ("*******hard fork is effective in the maintenance, version is {}" , version );
152
156
}
0 commit comments