forked from Qortal/qortal
Synchronize hasInvalidBlock predicate, as it wasn't thread safe
This commit is contained in:
parent
7e1ce38f0a
commit
a2e1efab90
@ -723,39 +723,41 @@ public class Controller extends Thread {
|
||||
};
|
||||
|
||||
public static final Predicate<Peer> hasInvalidBlock = peer -> {
|
||||
final PeerChainTipData peerChainTipData = peer.getChainTipData();
|
||||
Map<ByteArray, Long> invalidBlockSignatures = Synchronizer.getInstance().getInvalidBlockSignatures();
|
||||
List<byte[]> peerSignatures = new ArrayList<>();
|
||||
synchronized (peer.peerInfoLock) {
|
||||
final PeerChainTipData peerChainTipData = peer.getChainTipData();
|
||||
Map<ByteArray, Long> invalidBlockSignatures = Synchronizer.getInstance().getInvalidBlockSignatures();
|
||||
List<byte[]> peerSignatures = new ArrayList<>();
|
||||
|
||||
// Add peer's latest block signature
|
||||
if (peerChainTipData != null) {
|
||||
peerSignatures.add(peerChainTipData.getLastBlockSignature());
|
||||
}
|
||||
// Add peer's latest block signature
|
||||
if (peerChainTipData != null) {
|
||||
peerSignatures.add(peerChainTipData.getLastBlockSignature());
|
||||
}
|
||||
|
||||
// Add peer's blocks since common block
|
||||
if (peer.getCommonBlockData() != null) {
|
||||
List<BlockSummaryData> peerSummaries = peer.getCommonBlockData().getBlockSummariesAfterCommonBlock();
|
||||
if (peerSummaries != null) {
|
||||
for (BlockSummaryData blockSummaryData : peerSummaries) {
|
||||
peerSignatures.add(blockSummaryData.getSignature());
|
||||
// Add peer's blocks since common block
|
||||
if (peer.getCommonBlockData() != null) {
|
||||
List<BlockSummaryData> peerSummaries = peer.getCommonBlockData().getBlockSummariesAfterCommonBlock();
|
||||
if (peerSummaries != null) {
|
||||
for (BlockSummaryData blockSummaryData : peerSummaries) {
|
||||
peerSignatures.add(blockSummaryData.getSignature());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shortcut if no data
|
||||
if (peerSignatures.isEmpty() || invalidBlockSignatures == null || invalidBlockSignatures.isEmpty()) {
|
||||
// Shortcut if no data
|
||||
if (peerSignatures.isEmpty() || invalidBlockSignatures == null || invalidBlockSignatures.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loop through our known invalid blocks and check each one against supplied block summaries
|
||||
for (ByteArray invalidSignature : invalidBlockSignatures.keySet()) {
|
||||
for (byte[] peerSignature : peerSignatures) {
|
||||
if (Arrays.equals(peerSignature, invalidSignature.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loop through our known invalid blocks and check each one against supplied block summaries
|
||||
for (ByteArray invalidSignature : invalidBlockSignatures.keySet()) {
|
||||
for (byte[] peerSignature : peerSignatures) {
|
||||
if (Arrays.equals(peerSignature, invalidSignature.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
public static final Predicate<Peer> hasNoRecentBlock = peer -> {
|
||||
|
@ -121,7 +121,7 @@ public class Peer {
|
||||
|
||||
// Peer info
|
||||
|
||||
private final Object peerInfoLock = new Object();
|
||||
public final Object peerInfoLock = new Object();
|
||||
|
||||
private String peersNodeId;
|
||||
private byte[] peersPublicKey;
|
||||
|
Loading…
Reference in New Issue
Block a user