Browse Source

Fixed a mapping issue in Block->getShareBins(), to take effect at some future (undecided) height.

Post trigger, account levels will map correctly to share bins, subtracting 1 to account for the 0th element of the shareBinsByLevel array.
Pre-trigger, the legacy mapping will remain in effect.
block-reward-distribution-fix
CalDescent 4 years ago
parent
commit
847e81e95c
  1. 15
      src/main/java/org/qortal/block/Block.java
  2. 7
      src/main/java/org/qortal/block/BlockChain.java
  3. 3
      src/main/resources/blockchain.json
  4. 3
      src/test/resources/test-chain-v2-founder-rewards.json
  5. 3
      src/test/resources/test-chain-v2-leftover-reward.json
  6. 3
      src/test/resources/test-chain-v2-minting.json
  7. 3
      src/test/resources/test-chain-v2-qora-holder-extremes.json
  8. 3
      src/test/resources/test-chain-v2-qora-holder.json
  9. 3
      src/test/resources/test-chain-v2-reward-scaling.json
  10. 3
      src/test/resources/test-chain-v2.json

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

@ -176,19 +176,26 @@ public class Block {
*
* @return account-level share "bin" from blockchain config, or null if founder / none found
*/
public AccountLevelShareBin getShareBin() {
public AccountLevelShareBin getShareBin(int blockHeight) {
if (this.isMinterFounder)
return null;
final int accountLevel = this.mintingAccountData.getLevel();
if (accountLevel <= 0)
return null;
return null; // level 0 isn't included in any share bins
final AccountLevelShareBin[] shareBinsByLevel = BlockChain.getInstance().getShareBinsByAccountLevel();
final BlockChain blockChain = BlockChain.getInstance();
final AccountLevelShareBin[] shareBinsByLevel = blockChain.getShareBinsByAccountLevel();
if (accountLevel > shareBinsByLevel.length)
return null;
if (blockHeight < blockChain.getShareBinFixHeight())
// Off-by-one bug still in effect
return shareBinsByLevel[accountLevel];
// level 1 stored at index 0, level 2 stored at index 1, etc.
return shareBinsByLevel[accountLevel-1];
}
public long distribute(long accountAmount, Map<String, Long> balanceChanges) {
@ -1783,7 +1790,7 @@ public class Block {
// Find all accounts in share bin. getShareBin() returns null for minter accounts that are also founders, so they are effectively filtered out.
AccountLevelShareBin accountLevelShareBin = accountLevelShareBins.get(binIndex);
// Object reference compare is OK as all references are read-only from blockchain config.
List<ExpandedAccount> binnedAccounts = expandedAccounts.stream().filter(accountInfo -> accountInfo.getShareBin() == accountLevelShareBin).collect(Collectors.toList());
List<ExpandedAccount> binnedAccounts = expandedAccounts.stream().filter(accountInfo -> accountInfo.getShareBin(this.blockData.getHeight()) == accountLevelShareBin).collect(Collectors.toList());
// No online accounts in this bin? Skip to next one
if (binnedAccounts.isEmpty())

7
src/main/java/org/qortal/block/BlockChain.java

@ -71,7 +71,8 @@ public class BlockChain {
public enum FeatureTrigger {
atFindNextTransactionFix,
newBlockSigHeight;
newBlockSigHeight,
shareBinFix;
}
/** Map of which blockchain features are enabled when (height/timestamp) */
@ -381,6 +382,10 @@ public class BlockChain {
return this.featureTriggers.get(FeatureTrigger.newBlockSigHeight.name()).intValue();
}
public int getShareBinFixHeight() {
return this.featureTriggers.get(FeatureTrigger.shareBinFix.name()).intValue();
}
// More complex getters for aspects that change by height or timestamp
public long getRewardAtHeight(int ourHeight) {

3
src/main/resources/blockchain.json

@ -49,7 +49,8 @@
},
"featureTriggers": {
"atFindNextTransactionFix": 275000,
"newBlockSigHeight": 320000
"newBlockSigHeight": 320000,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2-founder-rewards.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2-leftover-reward.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2-minting.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2-qora-holder-extremes.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2-qora-holder.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2-reward-scaling.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

3
src/test/resources/test-chain-v2.json

@ -46,7 +46,8 @@
"newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
"newBlockSigHeight": 999999,
"shareBinFix": 999999
},
"genesisInfo": {
"version": 4,

Loading…
Cancel
Save