forked from Qortal/qortal
Avoid computing the proof of work for each online account more than once.
This commit is contained in:
parent
8cca6db316
commit
8879ec5bb4
@ -510,10 +510,26 @@ public class OnlineAccountsManager {
|
|||||||
byte[] timestampBytes = Longs.toByteArray(onlineAccountsTimestamp);
|
byte[] timestampBytes = Longs.toByteArray(onlineAccountsTimestamp);
|
||||||
List<OnlineAccountData> ourOnlineAccounts = new ArrayList<>();
|
List<OnlineAccountData> ourOnlineAccounts = new ArrayList<>();
|
||||||
|
|
||||||
|
int remaining = mintingAccounts.size();
|
||||||
for (MintingAccountData mintingAccountData : mintingAccounts) {
|
for (MintingAccountData mintingAccountData : mintingAccounts) {
|
||||||
|
remaining--;
|
||||||
byte[] privateKey = mintingAccountData.getPrivateKey();
|
byte[] privateKey = mintingAccountData.getPrivateKey();
|
||||||
byte[] publicKey = Crypto.toPublicKey(privateKey);
|
byte[] publicKey = Crypto.toPublicKey(privateKey);
|
||||||
|
|
||||||
|
// We don't want to compute the online account nonce and signature again if it already exists
|
||||||
|
Set<OnlineAccountData> onlineAccounts = this.currentOnlineAccounts.computeIfAbsent(onlineAccountsTimestamp, k -> ConcurrentHashMap.newKeySet());
|
||||||
|
boolean alreadyExists = onlineAccounts.stream().anyMatch(a -> Arrays.equals(a.getPublicKey(), publicKey));
|
||||||
|
if (alreadyExists) {
|
||||||
|
if (remaining > 0) {
|
||||||
|
// Move on to next account
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Everything exists, so return true
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Generate bytes for mempow
|
// Generate bytes for mempow
|
||||||
byte[] mempowBytes;
|
byte[] mempowBytes;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user