File tree Expand file tree Collapse file tree
src/main/java/org/tron/common/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .tron .common .utils ;
22
33import com .google .protobuf .ByteString ;
4+ import java .util .Arrays ;
45import java .util .List ;
56import lombok .Getter ;
67import org .springframework .stereotype .Component ;
@@ -17,13 +18,11 @@ public class ForkController {
1718
1819 @ Getter
1920 private Manager manager ;
20- private volatile int [] slots ;
21+ private volatile int [] slots = new int [ 0 ] ;
2122 private boolean fork = false ;
2223
2324 public void init (Manager manager ) {
2425 this .manager = manager ;
25- int size = manager .getWitnessController ().getActiveWitnesses ().size ();
26- slots = new int [size ];
2726 }
2827
2928 public synchronized boolean shouldBeForked () {
@@ -41,16 +40,20 @@ public synchronized boolean shouldBeForked() {
4140 return true ;
4241 }
4342
44- public boolean forkOrNot (TransactionCapsule capsule ) {
43+ public synchronized boolean forkOrNot (TransactionCapsule capsule ) {
4544 return shouldBeForked ()
4645 || capsule .getInstance ().getRawData ().getContractList ().get (0 ).getType ().getNumber ()
4746 <= DISCARD_SCOPE ;
4847 }
4948
5049 public synchronized void update (BlockCapsule blockCapsule ) {
50+ List <ByteString > witnesses = manager .getWitnessController ().getActiveWitnesses ();
51+ if (witnesses .size () > slots .length ) {
52+ slots = new int [witnesses .size ()];
53+ }
54+
5155 ByteString witness = blockCapsule .getWitnessAddress ();
5256 int slot = 0 ;
53- List <ByteString > witnesses = manager .getWitnessController ().getActiveWitnesses ();
5457 for (ByteString scheduledWitness : witnesses ) {
5558 if (!scheduledWitness .equals (witness )) {
5659 ++slot ;
You can’t perform that action at this time.
0 commit comments