Fix off-by-one error when reducing account level during block orphaning.

Added test to cover above.

Modified test-chain-v2.json so Dilbert starts with level 5, not 8,
to reduce number of blocks minted during tests.
This commit is contained in:
catbref
2020-01-21 13:34:46 +00:00
parent c3a6e0d9fd
commit 5cd35e07d0
5 changed files with 70 additions and 2 deletions

View File

@@ -192,6 +192,17 @@ public class Account {
// Minting blocks
/** Returns whether account can be considered a "minting account".
* <p>
* To be considered a "minting account", the account needs to pass at least one of these tests:<br>
* <ul>
* <li>account's level is at least <tt>minAccountLevelToMint</tt> from blockchain config</li>
* <li>account has 'founder' flag set</li>
* </ul>
*
* @return true if account can be considered "minting account"
* @throws DataException
*/
public boolean canMint() throws DataException {
Integer level = this.getLevel();
if (level != null && level >= BlockChain.getInstance().getMinAccountLevelToMint())
@@ -203,6 +214,17 @@ public class Account {
return false;
}
/** Returns whether account can build reward-shares.
* <p>
* To be able to create reward-shares, the account needs to pass at least one of these tests:<br>
* <ul>
* <li>account's level is at least <tt>minAccountLevelToRewardShare</tt> from blockchain config</li>
* <li>account has 'founder' flag set</li>
* </ul>
*
* @return true if account can be considered "minting account"
* @throws DataException
*/
public boolean canRewardShare() throws DataException {
Integer level = this.getLevel();
if (level != null && level >= BlockChain.getInstance().getMinAccountLevelToRewardShare())

View File

@@ -1584,7 +1584,7 @@ public class Block {
final int effectiveBlocksMinted = cumulativeBlocksByLevel.get(accountData.getInitialLevel()) + accountData.getBlocksMinted();
for (int newLevel = maximumLevel; newLevel > 0; --newLevel)
for (int newLevel = maximumLevel; newLevel >= 0; --newLevel)
if (effectiveBlocksMinted >= cumulativeBlocksByLevel.get(newLevel)) {
if (newLevel < accountData.getLevel()) {
// Account has decreased in level!