Browse Source

Disallow level 0 minters in blocks, and exclude them when minting a new block.

The validation is currently set to a feature trigger of height 0, although this will likely be set to a future block, in case there are any cases in the chain's history where this validation may fail (e.g. transfer privs?)
at-states-fix
CalDescent 2 years ago
parent
commit
68a0923582
  1. 22
      src/main/java/org/qortal/block/Block.java

22
src/main/java/org/qortal/block/Block.java

@ -370,12 +370,24 @@ public class Block {
return null; return null;
} }
int height = parentBlockData.getHeight() + 1;
long timestamp = calcTimestamp(parentBlockData, minter.getPublicKey(), minterLevel); long timestamp = calcTimestamp(parentBlockData, minter.getPublicKey(), minterLevel);
long onlineAccountsTimestamp = OnlineAccountsManager.getCurrentOnlineAccountTimestamp(); long onlineAccountsTimestamp = OnlineAccountsManager.getCurrentOnlineAccountTimestamp();
// Fetch our list of online accounts, removing any that are missing a nonce // Fetch our list of online accounts, removing any that are missing a nonce
List<OnlineAccountData> onlineAccounts = OnlineAccountsManager.getInstance().getOnlineAccounts(onlineAccountsTimestamp); List<OnlineAccountData> onlineAccounts = OnlineAccountsManager.getInstance().getOnlineAccounts(onlineAccountsTimestamp);
onlineAccounts.removeIf(a -> a.getNonce() == null || a.getNonce() < 0); onlineAccounts.removeIf(a -> a.getNonce() == null || a.getNonce() < 0);
// Remove any online accounts that are level 0
onlineAccounts.removeIf(a -> {
try {
return Account.getRewardShareEffectiveMintingLevel(repository, a.getPublicKey()) == 0;
} catch (DataException e) {
// Something went wrong, so remove the account
return true;
}
});
if (onlineAccounts.isEmpty()) { if (onlineAccounts.isEmpty()) {
LOGGER.debug("No online accounts - not even our own?"); LOGGER.debug("No online accounts - not even our own?");
return null; return null;
@ -442,7 +454,6 @@ public class Block {
int transactionCount = 0; int transactionCount = 0;
byte[] transactionsSignature = null; byte[] transactionsSignature = null;
int height = parentBlockData.getHeight() + 1;
int atCount = 0; int atCount = 0;
long atFees = 0; long atFees = 0;
@ -1036,6 +1047,15 @@ public class Block {
if (onlineRewardShares == null) if (onlineRewardShares == null)
return ValidationResult.ONLINE_ACCOUNT_UNKNOWN; return ValidationResult.ONLINE_ACCOUNT_UNKNOWN;
// After feature trigger, require all online account minters to be greater than level 0
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getOnlineAccountMinterLevelValidationHeight()) {
List<ExpandedAccount> expandedAccounts = this.getExpandedAccounts();
for (ExpandedAccount account : expandedAccounts) {
if (account.getMintingAccount().getEffectiveMintingLevel() == 0)
return ValidationResult.ONLINE_ACCOUNTS_INVALID;
}
}
// If block is past a certain age then we simply assume the signatures were correct // If block is past a certain age then we simply assume the signatures were correct
long signatureRequirementThreshold = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMinLifetime(); long signatureRequirementThreshold = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMinLifetime();
if (this.blockData.getTimestamp() < signatureRequirementThreshold) if (this.blockData.getTimestamp() < signatureRequirementThreshold)

Loading…
Cancel
Save