Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public class Manager {
@Getter
@Setter
private boolean isSyncMode;

@Getter
private Object forkLock = new Object();
// map<Long, IncrementalMerkleTree>
@Getter
@Setter
Expand Down Expand Up @@ -1269,8 +1270,9 @@ public void pushBlock(final BlockCapsule block)
chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp(),
khaosDb.getHead(), khaosDb.getMiniStore().size(),
khaosDb.getMiniUnlinkedStore().size());

switchFork(newBlock);
synchronized (forkLock) {
switchFork(newBlock);
}
logger.info(SAVE_BLOCK, newBlock);

logger.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,8 @@ public boolean allowPBFT() {
return chainBaseManager.getDynamicPropertiesStore().allowPBFT();
}

public Object getForkLock() {
return dbManager.getForkLock();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.tron.core.capsule.BlockCapsule.BlockId;
import org.tron.core.config.Parameter.NetConstants;
import org.tron.core.config.args.Args;
import org.tron.core.exception.BadBlockException;
import org.tron.core.exception.P2pException;
import org.tron.core.exception.P2pException.TypeEnum;
import org.tron.core.net.TronNetDelegate;
Expand Down Expand Up @@ -114,7 +113,10 @@ public void syncNext(PeerConnection peer) {
logger.warn("Peer {} is in sync", peer.getInetSocketAddress());
return;
}
LinkedList<BlockId> chainSummary = getBlockChainSummary(peer);
LinkedList<BlockId> chainSummary;
synchronized (tronNetDelegate.getForkLock()) {
chainSummary = getBlockChainSummary(peer);
}
peer.setSyncChainRequested(new Pair<>(chainSummary, System.currentTimeMillis()));
peer.sendMessage(new SyncBlockChainMessage(chainSummary));
} catch (Exception e) {
Expand Down