Skip to content

Commit

Permalink
fix: adjust peer connected and disconnected events and log setting do…
Browse files Browse the repository at this point in the history
…wnloadPeer in AbstractQuorumState

Signed-off-by: HashEngineering <[email protected]>
  • Loading branch information
HashEngineering committed Mar 5, 2024
1 parent ac8f7f9 commit 4fb46e0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.bitcoinj.quorums.QuorumRotationInfo;
import org.bitcoinj.quorums.SigningManager;
import org.bitcoinj.quorums.SimplifiedQuorumList;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.utils.Threading;
import org.slf4j.Logger;
Expand Down Expand Up @@ -335,9 +334,9 @@ void requestNextMNListDiff() {
if (!shouldProcessMNListDiff())
return;

log.info("download peer = {}", downloadPeer);
log.info("download peer = {}, but obtaining backup from peerGroup downloadPeer", downloadPeer);
Peer downloadPeerBackup = downloadPeer == null ? context.peerGroup.getDownloadPeer() : downloadPeer;

log.info("backup download peer = {}", downloadPeerBackup);
lock.lock();
try {
if (waitingForMNListDiff)
Expand Down Expand Up @@ -421,7 +420,9 @@ void maybeGetMNListDiffFresh() {
return;

if (downloadPeer == null) {
log.info("using peerGroup downloadPeer in maybeGetMNListDiffFresh ");
downloadPeer = context.peerGroup.getDownloadPeer();
log.info("using peerGroup downloadPeer in maybeGetMNListDiffFresh {}", downloadPeer);
}

lock.lock();
Expand Down Expand Up @@ -584,22 +585,19 @@ public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
public final PeerConnectedEventListener peerConnectedEventListener = new PeerConnectedEventListener() {
@Override
public void onPeerConnected(Peer peer, int peerCount) {
lock.lock();
try {
if (downloadPeer == null)
downloadPeer = peer;
} finally {
lock.unlock();
}
downloadPeer = context.peerGroup.getDownloadPeer();
log.info("peer connected and setting download peer to {} with onPeerConnected", downloadPeer);
}
};

final PeerDisconnectedEventListener peerDisconnectedEventListener = new PeerDisconnectedEventListener() {
@Override
public void onPeerDisconnected(Peer peer, int peerCount) {
if (downloadPeer == peer) {
downloadPeer = null;
chooseRandomDownloadPeer();
downloadPeer = context.peerGroup.getDownloadPeer();
log.info("setting download peer to {} with onPeerDisconnected, previously was {}", downloadPeer, peer);
if (downloadPeer == null)
chooseRandomDownloadPeer();
}
if (peer.getAddress().equals(lastRequest.getPeerAddress()) && lastRequest.isFullfilled()) {
log.warn("Disconnecting from peer {} before processing mnlistdiff", peer.getAddress());
Expand Down Expand Up @@ -646,6 +644,7 @@ void chooseRandomDownloadPeer() {
List<Peer> peers = context.peerGroup.getConnectedPeers();
if (peers != null && !peers.isEmpty()) {
downloadPeer = peers.get(new Random().nextInt(peers.size()));
log.info("setting download peer with chooseRandomDownloadPeer: {}", downloadPeer);
}
}

Expand All @@ -655,6 +654,7 @@ public void onChainDownloadStarted(Peer peer, int blocksLeft) {
lock.lock();
try {
downloadPeer = peer;
log.info("setting download peer with onChainDownloadStarted {}", peer);
// perhaps this is not required with headers first sync
// does this need to be in the next listener?
if (stateManager.isLoadedFromFile())
Expand All @@ -671,6 +671,7 @@ public void onChainDownloadStarted(Peer peer, int blocksLeft) {
public void onHeadersDownloadStarted(Peer peer, int blocksLeft) {
lock.lock();
try {
log.info("setting download peer with onHeadersDownloadStarted: {}", peer);
downloadPeer = peer;
} finally {
lock.unlock();
Expand Down Expand Up @@ -835,7 +836,6 @@ Sha256Hash getHashModifier(LLMQParameters llmqParams, StoredBlock quorumBaseBloc
if (params.isV20Active(workBlock.getHeight())) {
// v20 is active: calculate modifier using the new way.
BLSSignature bestCLSignature = getCoinbaseChainlock(workBlock);
log.info("getHashModifier(..., {})\n work: {}\n sig: {}", quorumBaseBlock.getHeader().getHash(), workBlock.getHeader().getHash(), bestCLSignature);
if (bestCLSignature != null) {
// We have a non-null CL signature: calculate modifier using this CL signature

Expand Down

0 comments on commit 4fb46e0

Please sign in to comment.