11package org .tron .common .overlay .server ;
22
3+ import com .google .protobuf .ByteString ;
34import java .net .InetAddress ;
45import java .net .InetSocketAddress ;
56import java .util .List ;
1314import org .tron .common .backup .BackupManager ;
1415import org .tron .common .backup .BackupManager .BackupStatusEnum ;
1516import org .tron .common .overlay .discover .node .Node ;
16- import org .tron .common .overlay .discover .node .NodeManager ;
1717import org .tron .core .config .args .Args ;
18- import org .tron .core .db .Manager ;
19- import org .tron .core .db .WitnessStore ;
18+ import org .tron .core .db .WitnessScheduleStore ;
2019import org .tron .core .services .WitnessService ;
2120import org .tron .protos .Protocol .ReasonCode ;
2221
@@ -27,12 +26,6 @@ public class FastForward {
2726 @ Autowired
2827 private ApplicationContext ctx ;
2928
30- private Manager manager ;
31-
32- private WitnessStore witnessStore ;
33-
34- private NodeManager nodeManager ;
35-
3629 private ChannelManager channelManager ;
3730
3831 private BackupManager backupManager ;
@@ -41,7 +34,8 @@ public class FastForward {
4134
4235 private Args args = Args .getInstance ();
4336 private List <Node > fastForwardNodes = args .getFastForwardNodes ();
44- private byte [] witnessAddress = args .getLocalWitnesses ().getWitnessAccountAddress ();
37+ private ByteString witnessAddress = ByteString
38+ .copyFrom (args .getLocalWitnesses ().getWitnessAccountAddress ());
4539 private int keySize = args .getLocalWitnesses ().getPrivateKeys ().size ();
4640
4741 public void init () {
@@ -53,21 +47,14 @@ public void init() {
5347 return ;
5448 }
5549
56- manager = ctx .getBean (Manager .class );
57- witnessStore = ctx .getBean (WitnessStore .class );
58- nodeManager = ctx .getBean (NodeManager .class );
5950 channelManager = ctx .getBean (ChannelManager .class );
6051 backupManager = ctx .getBean (BackupManager .class );
61-
62- if (args .getFastForwardNodes ().size () > 0 ) {
63- fastForwardNodes = args .getFastForwardNodes ();
64- }
52+ WitnessScheduleStore witnessScheduleStore = ctx .getBean (WitnessScheduleStore .class );
6553
6654 executorService .scheduleWithFixedDelay (() -> {
6755 try {
68- if (witnessStore .get (witnessAddress ) != null &&
69- backupManager .getStatus ().equals (BackupStatusEnum .MASTER ) &&
70- !WitnessService .isNeedSyncCheck ()) {
56+ if (witnessScheduleStore .getActiveWitnesses ().contains (witnessAddress ) &&
57+ backupManager .getStatus ().equals (BackupStatusEnum .MASTER )) {
7158 connect ();
7259 } else {
7360 disconnect ();
@@ -90,11 +77,10 @@ private void disconnect() {
9077 InetAddress address = new InetSocketAddress (node .getHost (), node .getPort ()).getAddress ();
9178 channelManager .getActiveNodes ().remove (address );
9279 channelManager .getActivePeers ().forEach (channel -> {
93- if (channel .getNode ().equals (node )) {
80+ if (channel .getInetAddress ().equals (address )) {
9481 channel .disconnect (ReasonCode .RESET );
9582 }
9683 });
9784 });
9885 }
99-
10086}
0 commit comments