Speed up syncing blocks in the range of 1-12 hours ago by caching the valid online accounts.

This commit is contained in:
CalDescent 2022-10-28 16:02:25 +01:00
parent 510328db47
commit 30cd56165a
2 changed files with 8 additions and 4 deletions

View File

@ -1075,6 +1075,9 @@ public class Block {
if (!OnlineAccountsManager.getInstance().verifyMemoryPoW(onlineAccount)) if (!OnlineAccountsManager.getInstance().verifyMemoryPoW(onlineAccount))
return ValidationResult.ONLINE_ACCOUNT_NONCE_INCORRECT; 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. // Extract online accounts' timestamp signatures from block data. Only one signature if aggregated.
List<byte[]> onlineAccountsSignatures = BlockTransformer.decodeTimestampSignatures(encodedOnlineAccountSignatures); List<byte[]> onlineAccountsSignatures = BlockTransformer.decodeTimestampSignatures(encodedOnlineAccountSignatures);

View File

@ -737,11 +737,12 @@ public class OnlineAccountsManager {
* Typically called by {@link Block#areOnlineAccountsValid()} * Typically called by {@link Block#areOnlineAccountsValid()}
*/ */
public void addBlocksOnlineAccounts(Set<OnlineAccountData> blocksOnlineAccounts, Long timestamp) { public void addBlocksOnlineAccounts(Set<OnlineAccountData> blocksOnlineAccounts, Long timestamp) {
// We want to add to 'current' in preference if possible // If these are current accounts, then there is no need to cache them, and should instead rely
if (this.currentOnlineAccounts.containsKey(timestamp)) { // on the more complete entries we already have in self.currentOnlineAccounts.
addAccounts(blocksOnlineAccounts); // 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; return;
}
// Add to block cache instead // Add to block cache instead
this.latestBlocksOnlineAccounts.computeIfAbsent(timestamp, k -> ConcurrentHashMap.newKeySet()) this.latestBlocksOnlineAccounts.computeIfAbsent(timestamp, k -> ConcurrentHashMap.newKeySet())