Bump additional expandedAccount level references held in memory.

This commit is contained in:
CalDescent 2022-12-22 14:18:39 +00:00
parent e40dc4af59
commit a75ed0e634

View File

@ -1522,6 +1522,9 @@ public class Block {
// Batch update in repository // Batch update in repository
repository.getAccountRepository().modifyMintedBlockCounts(allUniqueExpandedAccounts.stream().map(AccountData::getAddress).collect(Collectors.toList()), +1); repository.getAccountRepository().modifyMintedBlockCounts(allUniqueExpandedAccounts.stream().map(AccountData::getAddress).collect(Collectors.toList()), +1);
// Keep track of level bumps in case we need to apply to other entries
Map<String, Integer> bumpedAccounts = new HashMap<>();
// Local changes and also checks for level bump // Local changes and also checks for level bump
for (AccountData accountData : allUniqueExpandedAccounts) { for (AccountData accountData : allUniqueExpandedAccounts) {
// Adjust count locally (in Java) // Adjust count locally (in Java)
@ -1535,6 +1538,7 @@ public class Block {
if (newLevel > accountData.getLevel()) { if (newLevel > accountData.getLevel()) {
// Account has increased in level! // Account has increased in level!
accountData.setLevel(newLevel); accountData.setLevel(newLevel);
bumpedAccounts.put(accountData.getAddress(), newLevel);
repository.getAccountRepository().setLevel(accountData); repository.getAccountRepository().setLevel(accountData);
LOGGER.trace(() -> String.format("Block minter %s bumped to level %d", accountData.getAddress(), accountData.getLevel())); LOGGER.trace(() -> String.format("Block minter %s bumped to level %d", accountData.getAddress(), accountData.getLevel()));
} }
@ -1542,6 +1546,25 @@ public class Block {
break; break;
} }
} }
// Also bump other entries if need be
if (!bumpedAccounts.isEmpty()) {
for (ExpandedAccount expandedAccount : expandedAccounts) {
Integer newLevel = bumpedAccounts.get(expandedAccount.mintingAccountData.getAddress());
if (newLevel != null && expandedAccount.mintingAccountData.getLevel() != newLevel) {
expandedAccount.mintingAccountData.setLevel(newLevel);
LOGGER.trace("Also bumped {} to level {}", expandedAccount.mintingAccountData.getAddress(), newLevel);
}
if (!expandedAccount.isRecipientAlsoMinter) {
newLevel = bumpedAccounts.get(expandedAccount.recipientAccountData.getAddress());
if (newLevel != null && expandedAccount.recipientAccountData.getLevel() != newLevel) {
expandedAccount.recipientAccountData.setLevel(newLevel);
LOGGER.trace("Also bumped {} to level {}", expandedAccount.recipientAccountData.getAddress(), newLevel);
}
}
}
}
} }
protected void processBlockRewards() throws DataException { protected void processBlockRewards() throws DataException {