Only use fast sync on trimmed blocks, as others are too large.

This could probably be improved to make sure that all blocks in the next request are within the trimmed time range, but it's enough for now.
This commit is contained in:
CalDescent 2021-05-09 13:57:47 +01:00
parent 68544715bf
commit 428af3c0e8
2 changed files with 12 additions and 1 deletions

View File

@ -970,7 +970,8 @@ public class Synchronizer {
private SynchronizationResult applyNewBlocks(Repository repository, BlockData commonBlockData, int ourInitialHeight,
Peer peer, int peerHeight, List<BlockSummaryData> peerBlockSummaries) throws InterruptedException, DataException {
if (Settings.getInstance().isFastSyncEnabled() && peer.getPeersVersion() >= PEER_VERSION_160)
final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock();
if (Settings.getInstance().isFastSyncEnabled() && peer.getPeersVersion() >= PEER_VERSION_160 && ourLatestBlockData.isTrimmed())
// This peer supports syncing multiple blocks at once via GetBlocksMessage, and it is enabled in the settings
return this.applyNewBlocksUsingFastSync(repository, commonBlockData, ourInitialHeight, peer, peerHeight, peerBlockSummaries);
else

View File

@ -9,7 +9,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.qortal.block.BlockChain;
import org.qortal.settings.Settings;
import org.qortal.crypto.Crypto;
import org.qortal.utils.NTP;
// All properties to be converted to JSON via JAX-RS
@XmlAccessorType(XmlAccessType.FIELD)
@ -204,6 +207,13 @@ public class BlockData implements Serializable {
return this.onlineAccountsSignatures;
}
public boolean isTrimmed() {
long onlineAccountSignaturesTrimmedTimestamp = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMaxLifetime();
long currentTrimmableTimestamp = NTP.getTime() - Settings.getInstance().getAtStatesMaxLifetime();
long blockTimestamp = this.getTimestamp();
return blockTimestamp < onlineAccountSignaturesTrimmedTimestamp && blockTimestamp < currentTrimmableTimestamp;
}
// JAXB special
@XmlElement(name = "minterAddress")