When synchronizing, filter out peers that have a recent block with an invalid signer.

This avoids the wasted time and consensus confusion causes by syncing and then validation failing. This is significant after the algo has run, as many signers will become invalid.
This commit is contained in:
CalDescent 2022-11-26 11:52:27 +00:00
parent 68a0923582
commit 1c8a6ce204
2 changed files with 25 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import org.qortal.account.Account;
import org.qortal.api.ApiService;
import org.qortal.api.DomainMapService;
import org.qortal.api.GatewayService;
@ -756,6 +757,27 @@ public class Controller extends Thread {
return peer.isAtLeastVersion(minPeerVersion) == false;
};
public static final Predicate<Peer> hasInvalidSigner = peer -> {
final List<BlockSummaryData> peerChainTipSummaries = peer.getChainTipSummaries();
if (peerChainTipSummaries == null) {
return true;
}
try (Repository repository = RepositoryManager.getRepository()) {
for (BlockSummaryData blockSummaryData : peerChainTipSummaries) {
if (Account.getRewardShareEffectiveMintingLevel(repository, blockSummaryData.getMinterPublicKey()) == 0) {
return true;
}
}
} catch (DataException e) {
return true;
}
// We got this far without encountering invalid or missing summaries, nor was an exception thrown,
// so it is safe to assume that all of this peer's recent blocks had a valid signer.
return false;
};
private long getRandomRepositoryMaintenanceInterval() {
final long minInterval = Settings.getInstance().getRepositoryMaintenanceMinInterval();
final long maxInterval = Settings.getInstance().getRepositoryMaintenanceMaxInterval();

View File

@ -247,6 +247,9 @@ public class Synchronizer extends Thread {
// Disregard peers that are on the same block as last sync attempt and we didn't like their chain
peers.removeIf(Controller.hasInferiorChainTip);
// Disregard peers that have a block with an invalid signer
peers.removeIf(Controller.hasInvalidSigner);
final int peersBeforeComparison = peers.size();
// Request recent block summaries from the remaining peers, and locate our common block with each