From 30cd56165a69bbcbe75eb7c35eb33383cf3b653d Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 28 Oct 2022 16:02:25 +0100 Subject: [PATCH] Speed up syncing blocks in the range of 1-12 hours ago by caching the valid online accounts. --- src/main/java/org/qortal/block/Block.java | 3 +++ .../org/qortal/controller/OnlineAccountsManager.java | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/qortal/block/Block.java b/src/main/java/org/qortal/block/Block.java index c024308a..99a82808 100644 --- a/src/main/java/org/qortal/block/Block.java +++ b/src/main/java/org/qortal/block/Block.java @@ -1075,6 +1075,9 @@ public class Block { if (!OnlineAccountsManager.getInstance().verifyMemoryPoW(onlineAccount)) return ValidationResult.ONLINE_ACCOUNT_NONCE_INCORRECT; + // Cache the valid online accounts as they will likely be needed for the next block + OnlineAccountsManager.getInstance().addBlocksOnlineAccounts(onlineAccounts, onlineTimestamp); + // Extract online accounts' timestamp signatures from block data. Only one signature if aggregated. List onlineAccountsSignatures = BlockTransformer.decodeTimestampSignatures(encodedOnlineAccountSignatures); diff --git a/src/main/java/org/qortal/controller/OnlineAccountsManager.java b/src/main/java/org/qortal/controller/OnlineAccountsManager.java index aa35541d..53968cfd 100644 --- a/src/main/java/org/qortal/controller/OnlineAccountsManager.java +++ b/src/main/java/org/qortal/controller/OnlineAccountsManager.java @@ -737,11 +737,12 @@ public class OnlineAccountsManager { * Typically called by {@link Block#areOnlineAccountsValid()} */ public void addBlocksOnlineAccounts(Set blocksOnlineAccounts, Long timestamp) { - // We want to add to 'current' in preference if possible - if (this.currentOnlineAccounts.containsKey(timestamp)) { - addAccounts(blocksOnlineAccounts); + // If these are current accounts, then there is no need to cache them, and should instead rely + // on the more complete entries we already have in self.currentOnlineAccounts. + // Note: since sig-agg, we no longer have individual signatures included in blocks, so we + // mustn't add anything to currentOnlineAccounts from here. + if (this.currentOnlineAccounts.containsKey(timestamp)) return; - } // Add to block cache instead this.latestBlocksOnlineAccounts.computeIfAbsent(timestamp, k -> ConcurrentHashMap.newKeySet())