Browse Source

Modified BlockMinter.higherWeightChainExists() so that it checks for invalid blocks before treating a chain as higher weight. Otherwise minting is slowed down when a higher weight but invalid chain exists on the network (e.g. after a hard fork).

reduce-reward-shares
CalDescent 2 years ago
parent
commit
a9b154b783
  1. 10
      src/main/java/org/qortal/controller/BlockMinter.java
  2. 2
      src/main/java/org/qortal/controller/Synchronizer.java

10
src/main/java/org/qortal/controller/BlockMinter.java

@ -571,25 +571,29 @@ public class BlockMinter extends Thread {
List<Peer> peers = Network.getInstance().getImmutableHandshakedPeers(); List<Peer> peers = Network.getInstance().getImmutableHandshakedPeers();
// Loop through handshaked peers and check for any new block candidates // Loop through handshaked peers and check for any new block candidates
// TODO: filter out peers with invalid blocks
for (Peer peer : peers) { for (Peer peer : peers) {
if (peer.getCommonBlockData() != null && peer.getCommonBlockData().getCommonBlockSummary() != null) { if (peer.getCommonBlockData() != null && peer.getCommonBlockData().getCommonBlockSummary() != null) {
// This peer has common block data // This peer has common block data
CommonBlockData commonBlockData = peer.getCommonBlockData(); CommonBlockData commonBlockData = peer.getCommonBlockData();
BlockSummaryData commonBlockSummaryData = commonBlockData.getCommonBlockSummary(); BlockSummaryData commonBlockSummaryData = commonBlockData.getCommonBlockSummary();
if (commonBlockData.getChainWeight() != null) { if (commonBlockData.getChainWeight() != null && peer.getCommonBlockData().getBlockSummariesAfterCommonBlock() != null) {
// The synchronizer has calculated this peer's chain weight // The synchronizer has calculated this peer's chain weight
if (!Synchronizer.getInstance().containsInvalidBlockSummary(peer.getCommonBlockData().getBlockSummariesAfterCommonBlock())) {
// .. and it doesn't hold any invalid blocks
BigInteger ourChainWeightSinceCommonBlock = this.getOurChainWeightSinceBlock(repository, commonBlockSummaryData, commonBlockData.getBlockSummariesAfterCommonBlock()); BigInteger ourChainWeightSinceCommonBlock = this.getOurChainWeightSinceBlock(repository, commonBlockSummaryData, commonBlockData.getBlockSummariesAfterCommonBlock());
BigInteger ourChainWeight = ourChainWeightSinceCommonBlock.add(blockCandidateWeight); BigInteger ourChainWeight = ourChainWeightSinceCommonBlock.add(blockCandidateWeight);
BigInteger peerChainWeight = commonBlockData.getChainWeight(); BigInteger peerChainWeight = commonBlockData.getChainWeight();
if (peerChainWeight.compareTo(ourChainWeight) >= 0) { if (peerChainWeight.compareTo(ourChainWeight) >= 0) {
// This peer has a higher weight chain than ours // This peer has a higher weight chain than ours
LOGGER.debug("Peer {} is on a higher weight chain ({}) than ours ({})", peer, formatter.format(peerChainWeight), formatter.format(ourChainWeight)); LOGGER.info("Peer {} is on a higher weight chain ({}) than ours ({})", peer, formatter.format(peerChainWeight), formatter.format(ourChainWeight));
return true; return true;
} else { } else {
LOGGER.debug("Peer {} is on a lower weight chain ({}) than ours ({})", peer, formatter.format(peerChainWeight), formatter.format(ourChainWeight)); LOGGER.debug("Peer {} is on a lower weight chain ({}) than ours ({})", peer, formatter.format(peerChainWeight), formatter.format(ourChainWeight));
} }
} else {
LOGGER.debug("Peer {} has an invalid block", peer);
}
} else { } else {
LOGGER.debug("Peer {} has no chain weight", peer); LOGGER.debug("Peer {} has no chain weight", peer);
} }

2
src/main/java/org/qortal/controller/Synchronizer.java

@ -874,7 +874,7 @@ public class Synchronizer extends Thread {
} }
} }
} }
private boolean containsInvalidBlockSummary(List<BlockSummaryData> blockSummaries) { public boolean containsInvalidBlockSummary(List<BlockSummaryData> blockSummaries) {
if (blockSummaries == null || invalidBlockSignatures == null) { if (blockSummaries == null || invalidBlockSignatures == null) {
return false; return false;
} }

Loading…
Cancel
Save