forked from Qortal/qortal
Cache the online accounts validation result, to speed up block minting.
This commit is contained in:
parent
9574100a08
commit
d9147b3af3
@ -130,6 +130,9 @@ public class Block {
|
||||
/** Locally-generated AT fees */
|
||||
protected long ourAtFees; // Generated locally
|
||||
|
||||
/** Cached online accounts validation decision, to avoid revalidating when true */
|
||||
private boolean onlineAccountsAlreadyValid = false;
|
||||
|
||||
@FunctionalInterface
|
||||
private interface BlockRewardDistributor {
|
||||
long distribute(long amount, Map<String, Long> balanceChanges) throws DataException;
|
||||
@ -563,6 +566,13 @@ public class Block {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Force online accounts to be revalidated, e.g. at final stage of block minting.
|
||||
*/
|
||||
public void clearOnlineAccountsValidationCache() {
|
||||
this.onlineAccountsAlreadyValid = false;
|
||||
}
|
||||
|
||||
// More information
|
||||
|
||||
/**
|
||||
@ -1043,6 +1053,10 @@ public class Block {
|
||||
if (this.blockData.getHeight() != null && this.blockData.getHeight() == 1)
|
||||
return ValidationResult.OK;
|
||||
|
||||
// Don't bother revalidating if accounts have already been validated in this block
|
||||
if (this.onlineAccountsAlreadyValid)
|
||||
return ValidationResult.OK;
|
||||
|
||||
// Expand block's online accounts indexes into actual accounts
|
||||
ConciseSet accountIndexes = BlockTransformer.decodeOnlineAccounts(this.blockData.getEncodedOnlineAccounts());
|
||||
// We use count of online accounts to validate decoded account indexes
|
||||
@ -1130,6 +1144,9 @@ public class Block {
|
||||
// All online accounts valid, so save our list of online accounts for potential later use
|
||||
this.cachedOnlineRewardShares = onlineRewardShares;
|
||||
|
||||
// Remember that the accounts are valid, to speed up subsequent checks
|
||||
this.onlineAccountsAlreadyValid = true;
|
||||
|
||||
return ValidationResult.OK;
|
||||
}
|
||||
|
||||
|
@ -562,6 +562,9 @@ public class BlockMinter extends Thread {
|
||||
// Sign to create block's signature
|
||||
newBlock.sign();
|
||||
|
||||
// Ensure online accounts are fully re-validated in this final check
|
||||
newBlock.clearOnlineAccountsValidationCache();
|
||||
|
||||
// Is newBlock still valid?
|
||||
ValidationResult validationResult = newBlock.isValid();
|
||||
if (validationResult != ValidationResult.OK)
|
||||
|
Loading…
Reference in New Issue
Block a user