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.
This commit is contained in:
CalDescent 2021-03-12 19:48:49 +00:00
parent 7918622e2e
commit 847e81e95c
10 changed files with 34 additions and 14 deletions

View File

@ -176,19 +176,26 @@ public class Block {
* *
* @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() { public AccountLevelShareBin getShareBin(int blockHeight) {
if (this.isMinterFounder) if (this.isMinterFounder)
return null; return null;
final int accountLevel = this.mintingAccountData.getLevel(); final int accountLevel = this.mintingAccountData.getLevel();
if (accountLevel <= 0) 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) if (accountLevel > shareBinsByLevel.length)
return null; return null;
if (blockHeight < blockChain.getShareBinFixHeight())
// Off-by-one bug still in effect
return shareBinsByLevel[accountLevel]; 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) { 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. // 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); AccountLevelShareBin accountLevelShareBin = accountLevelShareBins.get(binIndex);
// Object reference compare is OK as all references are read-only from blockchain config. // 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 // No online accounts in this bin? Skip to next one
if (binnedAccounts.isEmpty()) if (binnedAccounts.isEmpty())

View File

@ -71,7 +71,8 @@ public class BlockChain {
public enum FeatureTrigger { public enum FeatureTrigger {
atFindNextTransactionFix, atFindNextTransactionFix,
newBlockSigHeight; newBlockSigHeight,
shareBinFix;
} }
/** Map of which blockchain features are enabled when (height/timestamp) */ /** 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(); 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 // More complex getters for aspects that change by height or timestamp
public long getRewardAtHeight(int ourHeight) { public long getRewardAtHeight(int ourHeight) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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