File tree Expand file tree Collapse file tree
framework/src/main/java/org/tron/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,7 +193,8 @@ public class Manager {
193193 @ Getter
194194 @ Setter
195195 private boolean isSyncMode ;
196-
196+ @ Getter
197+ private Object forkLock = new Object ();
197198 // map<Long, IncrementalMerkleTree>
198199 @ Getter
199200 @ Setter
@@ -1269,8 +1270,9 @@ public void pushBlock(final BlockCapsule block)
12691270 chainBaseManager .getDynamicPropertiesStore ().getLatestBlockHeaderTimestamp (),
12701271 khaosDb .getHead (), khaosDb .getMiniStore ().size (),
12711272 khaosDb .getMiniUnlinkedStore ().size ());
1272-
1273- switchFork (newBlock );
1273+ synchronized (forkLock ) {
1274+ switchFork (newBlock );
1275+ }
12741276 logger .info (SAVE_BLOCK , newBlock );
12751277
12761278 logger .warn (
Original file line number Diff line number Diff line change @@ -349,4 +349,8 @@ public boolean allowPBFT() {
349349 return chainBaseManager .getDynamicPropertiesStore ().allowPBFT ();
350350 }
351351
352+ public Object getForkLock () {
353+ return dbManager .getForkLock ();
354+ }
355+
352356}
Original file line number Diff line number Diff line change 2323import org .tron .core .capsule .BlockCapsule .BlockId ;
2424import org .tron .core .config .Parameter .NetConstants ;
2525import org .tron .core .config .args .Args ;
26- import org .tron .core .exception .BadBlockException ;
2726import org .tron .core .exception .P2pException ;
2827import org .tron .core .exception .P2pException .TypeEnum ;
2928import org .tron .core .net .TronNetDelegate ;
@@ -114,7 +113,10 @@ public void syncNext(PeerConnection peer) {
114113 logger .warn ("Peer {} is in sync" , peer .getInetSocketAddress ());
115114 return ;
116115 }
117- LinkedList <BlockId > chainSummary = getBlockChainSummary (peer );
116+ LinkedList <BlockId > chainSummary ;
117+ synchronized (tronNetDelegate .getForkLock ()) {
118+ chainSummary = getBlockChainSummary (peer );
119+ }
118120 peer .setSyncChainRequested (new Pair <>(chainSummary , System .currentTimeMillis ()));
119121 peer .sendMessage (new SyncBlockChainMessage (chainSummary ));
120122 } catch (Exception e ) {
You can’t perform that action at this time.
0 commit comments