3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-11 17:55:50 +00:00

Fix batch reward

This commit is contained in:
AlphaX-Qortal 2024-11-26 00:03:04 +01:00
parent d89f7ad41d
commit c010ab47db
3 changed files with 65 additions and 44 deletions

View File

@ -25,10 +25,7 @@ import org.qortal.data.block.BlockSummaryData;
import org.qortal.data.block.BlockTransactionData; import org.qortal.data.block.BlockTransactionData;
import org.qortal.data.network.OnlineAccountData; import org.qortal.data.network.OnlineAccountData;
import org.qortal.data.transaction.TransactionData; import org.qortal.data.transaction.TransactionData;
import org.qortal.repository.ATRepository; import org.qortal.repository.*;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.repository.TransactionRepository;
import org.qortal.settings.Settings; import org.qortal.settings.Settings;
import org.qortal.transaction.AtTransaction; import org.qortal.transaction.AtTransaction;
import org.qortal.transaction.Transaction; import org.qortal.transaction.Transaction;
@ -144,6 +141,7 @@ public class Block {
private final Account mintingAccount; private final Account mintingAccount;
private final AccountData mintingAccountData; private final AccountData mintingAccountData;
private final boolean isMinterFounder; private final boolean isMinterFounder;
private final boolean isMinterMember;
private final Account recipientAccount; private final Account recipientAccount;
private final AccountData recipientAccountData; private final AccountData recipientAccountData;
@ -157,6 +155,7 @@ public class Block {
this.isMinterFounder = Account.isFounder(mintingAccountData.getFlags()); this.isMinterFounder = Account.isFounder(mintingAccountData.getFlags());
this.isRecipientAlsoMinter = this.rewardShareData.getRecipient().equals(this.mintingAccount.getAddress()); this.isRecipientAlsoMinter = this.rewardShareData.getRecipient().equals(this.mintingAccount.getAddress());
this.isMinterMember = repository.getGroupRepository().memberExists(BlockChain.getInstance().getMintingGroupId(), this.mintingAccount.getAddress());
if (this.isRecipientAlsoMinter) { if (this.isRecipientAlsoMinter) {
// Self-share: minter is also recipient // Self-share: minter is also recipient
@ -181,7 +180,7 @@ public class Block {
* <p> * <p>
* This is a method, not a final variable, because account's level can change between construction and call, * This is a method, not a final variable, because account's level can change between construction and call,
* e.g. during Block.process() where account levels are bumped right before Block.distributeBlockReward(). * e.g. during Block.process() where account levels are bumped right before Block.distributeBlockReward().
* *
* @return account-level share "bin" from blockchain config, or null if founder / none found * @return account-level share "bin" from blockchain config, or null if founder / none found
*/ */
public AccountLevelShareBin getShareBin(int blockHeight) { public AccountLevelShareBin getShareBin(int blockHeight) {
@ -192,6 +191,11 @@ public class Block {
if (accountLevel <= 0) if (accountLevel <= 0)
return null; // level 0 isn't included in any share bins return null; // level 0 isn't included in any share bins
if (blockHeight >= BlockChain.getInstance().getFixBatchRewardHeight()) {
if (!this.isMinterMember)
return null; // not member of minter group isn't included in any share bins
}
// Select the correct set of share bins based on block height // Select the correct set of share bins based on block height
final BlockChain blockChain = BlockChain.getInstance(); final BlockChain blockChain = BlockChain.getInstance();
final AccountLevelShareBin[] shareBinsByLevel = (blockHeight >= blockChain.getSharesByLevelV2Height()) ? final AccountLevelShareBin[] shareBinsByLevel = (blockHeight >= blockChain.getSharesByLevelV2Height()) ?
@ -262,7 +266,7 @@ public class Block {
* Constructs new Block without loading transactions and AT states. * Constructs new Block without loading transactions and AT states.
* <p> * <p>
* Transactions and AT states are loaded on first call to getTransactions() or getATStates() respectively. * Transactions and AT states are loaded on first call to getTransactions() or getATStates() respectively.
* *
* @param repository * @param repository
* @param blockData * @param blockData
*/ */
@ -333,7 +337,7 @@ public class Block {
/** /**
* Constructs new Block with empty transaction list, using passed minter account. * Constructs new Block with empty transaction list, using passed minter account.
* *
* @param repository * @param repository
* @param blockData * @param blockData
* @param minter * @param minter
@ -351,7 +355,7 @@ public class Block {
* This constructor typically used when minting a new block. * This constructor typically used when minting a new block.
* <p> * <p>
* Note that CIYAM ATs will be executed and AT-Transactions prepended to this block, along with AT state data and fees. * Note that CIYAM ATs will be executed and AT-Transactions prepended to this block, along with AT state data and fees.
* *
* @param repository * @param repository
* @param parentBlockData * @param parentBlockData
* @param minter * @param minter
@ -377,7 +381,7 @@ public class Block {
byte[] encodedOnlineAccounts = new byte[0]; byte[] encodedOnlineAccounts = new byte[0];
int onlineAccountsCount = 0; int onlineAccountsCount = 0;
byte[] onlineAccountsSignatures = null; byte[] onlineAccountsSignatures = null;
if (isBatchRewardDistributionBlock(height)) { if (isBatchRewardDistributionBlock(height)) {
// Batch reward distribution block - copy online accounts from recent block with highest online accounts count // Batch reward distribution block - copy online accounts from recent block with highest online accounts count
@ -512,7 +516,7 @@ public class Block {
* Mints new block using this block as template, but with different minting account. * Mints new block using this block as template, but with different minting account.
* <p> * <p>
* NOTE: uses the same transactions list, AT states, etc. * NOTE: uses the same transactions list, AT states, etc.
* *
* @param minter * @param minter
* @return * @return
* @throws DataException * @throws DataException
@ -598,7 +602,7 @@ public class Block {
/** /**
* Return composite block signature (minterSignature + transactionsSignature). * Return composite block signature (minterSignature + transactionsSignature).
* *
* @return byte[], or null if either component signature is null. * @return byte[], or null if either component signature is null.
*/ */
public byte[] getSignature() { public byte[] getSignature() {
@ -613,7 +617,7 @@ public class Block {
* <p> * <p>
* We're starting with version 4 as a nod to being newer than successor Qora, * We're starting with version 4 as a nod to being newer than successor Qora,
* whose latest block version was 3. * whose latest block version was 3.
* *
* @return 1, 2, 3 or 4 * @return 1, 2, 3 or 4
*/ */
public int getNextBlockVersion() { public int getNextBlockVersion() {
@ -627,7 +631,7 @@ public class Block {
* Return block's transactions. * Return block's transactions.
* <p> * <p>
* If the block was loaded from repository then it's possible this method will call the repository to fetch the transactions if not done already. * If the block was loaded from repository then it's possible this method will call the repository to fetch the transactions if not done already.
* *
* @return * @return
* @throws DataException * @throws DataException
*/ */
@ -661,7 +665,7 @@ public class Block {
* If the block was loaded from repository then it's possible this method will call the repository to fetch the AT states if not done already. * If the block was loaded from repository then it's possible this method will call the repository to fetch the AT states if not done already.
* <p> * <p>
* <b>Note:</b> AT states fetched from repository only contain summary info, not actual data like serialized state data or AT creation timestamps! * <b>Note:</b> AT states fetched from repository only contain summary info, not actual data like serialized state data or AT creation timestamps!
* *
* @return * @return
* @throws DataException * @throws DataException
*/ */
@ -697,7 +701,7 @@ public class Block {
* <p> * <p>
* Typically called as part of Block.process() or Block.orphan() * Typically called as part of Block.process() or Block.orphan()
* so ideally after any calls to Block.isValid(). * so ideally after any calls to Block.isValid().
* *
* @throws DataException * @throws DataException
*/ */
public List<ExpandedAccount> getExpandedAccounts() throws DataException { public List<ExpandedAccount> getExpandedAccounts() throws DataException {
@ -715,8 +719,18 @@ public class Block {
List<ExpandedAccount> expandedAccounts = new ArrayList<>(); List<ExpandedAccount> expandedAccounts = new ArrayList<>();
for (RewardShareData rewardShare : this.cachedOnlineRewardShares) for (RewardShareData rewardShare : this.cachedOnlineRewardShares) {
expandedAccounts.add(new ExpandedAccount(repository, rewardShare)); if (this.getBlockData().getHeight() < BlockChain.getInstance().getFixBatchRewardHeight()) {
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));
}
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getFixBatchRewardHeight()) {
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(BlockChain.getInstance().getMintingGroupId(), rewardShare.getMinter());
if (isMinterGroupMember) {
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));
}
}
}
this.cachedExpandedAccounts = expandedAccounts; this.cachedExpandedAccounts = expandedAccounts;
@ -727,7 +741,7 @@ public class Block {
/** /**
* Load parent block's data from repository via this block's reference. * Load parent block's data from repository via this block's reference.
* *
* @return parent's BlockData, or null if no parent found * @return parent's BlockData, or null if no parent found
* @throws DataException * @throws DataException
*/ */
@ -741,7 +755,7 @@ public class Block {
/** /**
* Load child block's data from repository via this block's signature. * Load child block's data from repository via this block's signature.
* *
* @return child's BlockData, or null if no parent found * @return child's BlockData, or null if no parent found
* @throws DataException * @throws DataException
*/ */
@ -761,7 +775,7 @@ public class Block {
* Used when constructing a new block during minting. * Used when constructing a new block during minting.
* <p> * <p>
* Requires block's {@code minter} being a {@code PrivateKeyAccount} so block's transactions signature can be recalculated. * Requires block's {@code minter} being a {@code PrivateKeyAccount} so block's transactions signature can be recalculated.
* *
* @param transactionData * @param transactionData
* @return true if transaction successfully added to block, false otherwise * @return true if transaction successfully added to block, false otherwise
* @throws IllegalStateException * @throws IllegalStateException
@ -814,7 +828,7 @@ public class Block {
* Used when constructing a new block during minting. * Used when constructing a new block during minting.
* <p> * <p>
* Requires block's {@code minter} being a {@code PrivateKeyAccount} so block's transactions signature can be recalculated. * Requires block's {@code minter} being a {@code PrivateKeyAccount} so block's transactions signature can be recalculated.
* *
* @param transactionData * @param transactionData
* @throws IllegalStateException * @throws IllegalStateException
* if block's {@code minter} is not a {@code PrivateKeyAccount}. * if block's {@code minter} is not a {@code PrivateKeyAccount}.
@ -859,7 +873,7 @@ public class Block {
* previous block's minter signature + minter's public key + (encoded) online-accounts data * previous block's minter signature + minter's public key + (encoded) online-accounts data
* <p> * <p>
* (Previous block's minter signature is extracted from this block's reference). * (Previous block's minter signature is extracted from this block's reference).
* *
* @throws IllegalStateException * @throws IllegalStateException
* if block's {@code minter} is not a {@code PrivateKeyAccount}. * if block's {@code minter} is not a {@code PrivateKeyAccount}.
* @throws RuntimeException * @throws RuntimeException
@ -876,7 +890,7 @@ public class Block {
* Recalculate block's transactions signature. * Recalculate block's transactions signature.
* <p> * <p>
* Requires block's {@code minter} being a {@code PrivateKeyAccount}. * Requires block's {@code minter} being a {@code PrivateKeyAccount}.
* *
* @throws IllegalStateException * @throws IllegalStateException
* if block's {@code minter} is not a {@code PrivateKeyAccount}. * if block's {@code minter} is not a {@code PrivateKeyAccount}.
* @throws RuntimeException * @throws RuntimeException
@ -998,7 +1012,7 @@ public class Block {
* Recalculate block's minter and transactions signatures, thus giving block full signature. * Recalculate block's minter and transactions signatures, thus giving block full signature.
* <p> * <p>
* Note: Block instance must have been constructed with a <tt>PrivateKeyAccount</tt> minter or this call will throw an <tt>IllegalStateException</tt>. * Note: Block instance must have been constructed with a <tt>PrivateKeyAccount</tt> minter or this call will throw an <tt>IllegalStateException</tt>.
* *
* @throws IllegalStateException * @throws IllegalStateException
* if block's {@code minter} is not a {@code PrivateKeyAccount}. * if block's {@code minter} is not a {@code PrivateKeyAccount}.
*/ */
@ -1011,7 +1025,7 @@ public class Block {
/** /**
* Returns whether this block's signatures are valid. * Returns whether this block's signatures are valid.
* *
* @return true if both minter and transaction signatures are valid, false otherwise * @return true if both minter and transaction signatures are valid, false otherwise
*/ */
public boolean isSignatureValid() { public boolean isSignatureValid() {
@ -1035,7 +1049,7 @@ public class Block {
* <p> * <p>
* Used by BlockMinter to check whether it's time to mint a new block, * Used by BlockMinter to check whether it's time to mint a new block,
* and also used by Block.isValid for checks (if not a testchain). * and also used by Block.isValid for checks (if not a testchain).
* *
* @return ValidationResult.OK if timestamp valid, or some other ValidationResult otherwise. * @return ValidationResult.OK if timestamp valid, or some other ValidationResult otherwise.
* @throws DataException * @throws DataException
*/ */
@ -1215,7 +1229,7 @@ public class Block {
* <p> * <p>
* Checks block's transactions by testing their validity then processing them.<br> * Checks block's transactions by testing their validity then processing them.<br>
* Hence uses a repository savepoint during execution. * Hence uses a repository savepoint during execution.
* *
* @return ValidationResult.OK if block is valid, or some other ValidationResult otherwise. * @return ValidationResult.OK if block is valid, or some other ValidationResult otherwise.
* @throws DataException * @throws DataException
*/ */
@ -1386,7 +1400,7 @@ public class Block {
* <p> * <p>
* NOTE: will execute ATs locally if not already done.<br> * NOTE: will execute ATs locally if not already done.<br>
* This is so we have locally-generated AT states for comparison. * This is so we have locally-generated AT states for comparison.
* *
* @return OK, or some AT-related validation result * @return OK, or some AT-related validation result
* @throws DataException * @throws DataException
*/ */
@ -1462,11 +1476,11 @@ public class Block {
* Note: this method does not store new AT state data into repository - that is handled by <tt>process()</tt>. * Note: this method does not store new AT state data into repository - that is handled by <tt>process()</tt>.
* <p> * <p>
* This method is not needed if fetching an existing block from the repository as AT state data will be loaded from repository as well. * This method is not needed if fetching an existing block from the repository as AT state data will be loaded from repository as well.
* *
* @see #isValid() * @see #isValid()
* *
* @throws DataException * @throws DataException
* *
*/ */
private void executeATs() throws DataException { private void executeATs() throws DataException {
// We're expecting a lack of AT state data at this point. // We're expecting a lack of AT state data at this point.
@ -1538,7 +1552,7 @@ public class Block {
/** /**
* Process block, and its transactions, adding them to the blockchain. * Process block, and its transactions, adding them to the blockchain.
* *
* @throws DataException * @throws DataException
*/ */
public void process() throws DataException { public void process() throws DataException {
@ -1839,7 +1853,7 @@ public class Block {
/** /**
* Removes block from blockchain undoing transactions and adding them to unconfirmed pile. * Removes block from blockchain undoing transactions and adding them to unconfirmed pile.
* *
* @throws DataException * @throws DataException
*/ */
public void orphan() throws DataException { public void orphan() throws DataException {
@ -1879,7 +1893,7 @@ public class Block {
SelfSponsorshipAlgoV3Block.orphanAccountPenalties(this); SelfSponsorshipAlgoV3Block.orphanAccountPenalties(this);
} }
} }
// Account levels and block rewards are only processed/orphaned on block reward distribution blocks // Account levels and block rewards are only processed/orphaned on block reward distribution blocks
if (this.isRewardDistributionBlock()) { if (this.isRewardDistributionBlock()) {
// Block rewards, including transaction fees, removed after transactions undone // Block rewards, including transaction fees, removed after transactions undone
@ -2213,6 +2227,7 @@ public class Block {
List<AccountBalanceData> accountBalanceDeltas = balanceChanges.entrySet().stream() List<AccountBalanceData> accountBalanceDeltas = balanceChanges.entrySet().stream()
.map(entry -> new AccountBalanceData(entry.getKey(), Asset.QORT, entry.getValue())) .map(entry -> new AccountBalanceData(entry.getKey(), Asset.QORT, entry.getValue()))
.collect(Collectors.toList()); .collect(Collectors.toList());
LOGGER.trace("Account Balance Deltas: {}", accountBalanceDeltas);
this.repository.getAccountRepository().modifyAssetBalances(accountBalanceDeltas); this.repository.getAccountRepository().modifyAssetBalances(accountBalanceDeltas);
} }
@ -2225,30 +2240,30 @@ public class Block {
/* /*
* Distribution rules: * Distribution rules:
* *
* Distribution is based on the minting account of 'online' reward-shares. * Distribution is based on the minting account of 'online' reward-shares.
* *
* If ANY founders are online, then they receive the leftover non-distributed reward. * If ANY founders are online, then they receive the leftover non-distributed reward.
* If NO founders are online, then account-level-based rewards are scaled up so 100% of reward is allocated. * If NO founders are online, then account-level-based rewards are scaled up so 100% of reward is allocated.
* *
* If ANY non-maxxed legacy QORA holders exist then they are always allocated their fixed share (e.g. 20%). * If ANY non-maxxed legacy QORA holders exist then they are always allocated their fixed share (e.g. 20%).
* *
* There has to be either at least one 'online' account for blocks to be minted * There has to be either at least one 'online' account for blocks to be minted
* so there is always either one account-level-based or founder reward candidate. * so there is always either one account-level-based or founder reward candidate.
* *
* Examples: * Examples:
* *
* With at least one founder online: * With at least one founder online:
* Level 1/2 accounts: 5% * Level 1/2 accounts: 5%
* Legacy QORA holders: 20% * Legacy QORA holders: 20%
* Founders: ~75% * Founders: ~75%
* *
* No online founders: * No online founders:
* Level 1/2 accounts: 5% * Level 1/2 accounts: 5%
* Level 5/6 accounts: 15% * Level 5/6 accounts: 15%
* Legacy QORA holders: 20% * Legacy QORA holders: 20%
* Total: 40% * Total: 40%
* *
* After scaling account-level-based shares to fill 100%: * After scaling account-level-based shares to fill 100%:
* Level 1/2 accounts: 20% * Level 1/2 accounts: 20%
* Level 5/6 accounts: 60% * Level 5/6 accounts: 60%

View File

@ -87,7 +87,8 @@ public class BlockChain {
enableRewardshareHeight, enableRewardshareHeight,
onlyMintWithNameHeight, onlyMintWithNameHeight,
removeOnlyMintWithNameHeight, removeOnlyMintWithNameHeight,
groupMemberCheckHeight groupMemberCheckHeight,
fixBatchRewardHeight
} }
// Custom transaction fees // Custom transaction fees
@ -657,6 +658,10 @@ public class BlockChain {
return this.featureTriggers.get(FeatureTrigger.groupMemberCheckHeight.name()).intValue(); return this.featureTriggers.get(FeatureTrigger.groupMemberCheckHeight.name()).intValue();
} }
public int getFixBatchRewardHeight() {
return this.featureTriggers.get(FeatureTrigger.fixBatchRewardHeight.name()).intValue();
}
// More complex getters for aspects that change by height or timestamp // More complex getters for aspects that change by height or timestamp
public long getRewardAtHeight(int ourHeight) { public long getRewardAtHeight(int ourHeight) {

View File

@ -112,7 +112,8 @@
"enableRewardshareHeight": 1905100, "enableRewardshareHeight": 1905100,
"onlyMintWithNameHeight": 1900300, "onlyMintWithNameHeight": 1900300,
"removeOnlyMintWithNameHeight": 1935500, "removeOnlyMintWithNameHeight": 1935500,
"groupMemberCheckHeight": 1902700 "groupMemberCheckHeight": 1902700,
"fixBatchRewardHeight": 9999999
}, },
"checkpoints": [ "checkpoints": [
{ "height": 1136300, "signature": "3BbwawEF2uN8Ni5ofpJXkukoU8ctAPxYoFB7whq9pKfBnjfZcpfEJT4R95NvBDoTP8WDyWvsUvbfHbcr9qSZuYpSKZjUQTvdFf6eqznHGEwhZApWfvXu6zjGCxYCp65F4jsVYYJjkzbjmkCg5WAwN5voudngA23kMK6PpTNygapCzXt" } { "height": 1136300, "signature": "3BbwawEF2uN8Ni5ofpJXkukoU8ctAPxYoFB7whq9pKfBnjfZcpfEJT4R95NvBDoTP8WDyWvsUvbfHbcr9qSZuYpSKZjUQTvdFf6eqznHGEwhZApWfvXu6zjGCxYCp65F4jsVYYJjkzbjmkCg5WAwN5voudngA23kMK6PpTNygapCzXt" }