Exclude reward share transactions from the online accounts blocks

This commit is contained in:
AlphaX-Projects
2024-01-14 18:40:40 +01:00
parent 83e324c4ad
commit 41645ac7b4
20 changed files with 187 additions and 17 deletions

View File

@@ -1309,6 +1309,9 @@ public class Block {
if (!transaction.isConfirmable()) {
return ValidationResult.TRANSACTION_NOT_CONFIRMABLE;
}
if (!transaction.isConfirmableAtHeight(this.blockData.getHeight())) {
return ValidationResult.TRANSACTION_NOT_CONFIRMABLE;
}
}
// Check transaction isn't already included in a block
@@ -2088,7 +2091,7 @@ public class Block {
return Block.isOnlineAccountsBlock(this.getBlockData().getHeight());
}
private static boolean isOnlineAccountsBlock(int height) {
public static boolean isOnlineAccountsBlock(int height) {
// After feature trigger, only certain blocks contain online accounts
if (height >= BlockChain.getInstance().getBlockRewardBatchStartHeight()) {
final int leadingBlockCount = BlockChain.getInstance().getBlockRewardBatchAccountsBlockCount();

View File

@@ -75,7 +75,8 @@ public class BlockChain {
selfSponsorshipAlgoV1Height,
feeValidationFixTimestamp,
chatReferenceTimestamp,
arbitraryOptionalFeeTimestamp;
arbitraryOptionalFeeTimestamp,
unconfirmableRewardSharesHeight;
}
// Custom transaction fees
@@ -556,6 +557,10 @@ public class BlockChain {
return this.featureTriggers.get(FeatureTrigger.arbitraryOptionalFeeTimestamp.name()).longValue();
}
public int getUnconfirmableRewardSharesHeight() {
return this.featureTriggers.get(FeatureTrigger.unconfirmableRewardSharesHeight.name()).intValue();
}
// More complex getters for aspects that change by height or timestamp

View File

@@ -474,6 +474,7 @@ public class BlockMinter extends Thread {
Iterator<TransactionData> unconfirmedTransactionsIterator = unconfirmedTransactions.iterator();
final long newBlockTimestamp = newBlock.getBlockData().getTimestamp();
final int newBlockHeight = newBlock.getBlockData().getHeight();
while (unconfirmedTransactionsIterator.hasNext()) {
TransactionData transactionData = unconfirmedTransactionsIterator.next();
@@ -481,6 +482,12 @@ public class BlockMinter extends Thread {
// Ignore transactions that have expired before this block - they will be cleaned up later
if (transactionData.getTimestamp() > newBlockTimestamp || Transaction.getDeadline(transactionData) <= newBlockTimestamp)
unconfirmedTransactionsIterator.remove();
// Ignore transactions that are unconfirmable at this block height
Transaction transaction = Transaction.fromData(repository, transactionData);
if (!transaction.isConfirmableAtHeight(newBlockHeight)) {
unconfirmedTransactionsIterator.remove();
}
}
// Sign to create block's signature, needed by Block.isValid()

View File

@@ -3,6 +3,7 @@ package org.qortal.transaction;
import org.qortal.account.Account;
import org.qortal.account.PublicKeyAccount;
import org.qortal.asset.Asset;
import org.qortal.block.Block;
import org.qortal.block.BlockChain;
import org.qortal.crypto.Crypto;
import org.qortal.data.account.RewardShareData;
@@ -180,6 +181,17 @@ public class RewardShareTransaction extends Transaction {
// Nothing to do
}
@Override
public boolean isConfirmableAtHeight(int height) {
if (height >= BlockChain.getInstance().getUnconfirmableRewardSharesHeight()) {
// Not confirmable in online accounts or distribution blocks
if (Block.isOnlineAccountsBlock(height) || Block.isBatchRewardDistributionBlock(height)) {
return false;
}
}
return true;
}
@Override
public void process() throws DataException {
PublicKeyAccount mintingAccount = getMintingAccount();

View File

@@ -904,6 +904,15 @@ public abstract class Transaction {
return true;
}
/**
* Returns whether transaction is confirmable in a block at a given height.
* @return
*/
public boolean isConfirmableAtHeight(int height) {
/* To be optionally overridden */
return true;
}
/**
* Returns whether transaction can be added to the blockchain.
* <p>

View File

@@ -95,7 +95,8 @@
"selfSponsorshipAlgoV1Height": 1092400,
"feeValidationFixTimestamp": 1671918000000,
"chatReferenceTimestamp": 1674316800000,
"arbitraryOptionalFeeTimestamp": 1680278400000
"arbitraryOptionalFeeTimestamp": 1680278400000,
"unconfirmableRewardSharesHeight": 99999500
},
"checkpoints": [
{ "height": 1136300, "signature": "3BbwawEF2uN8Ni5ofpJXkukoU8ctAPxYoFB7whq9pKfBnjfZcpfEJT4R95NvBDoTP8WDyWvsUvbfHbcr9qSZuYpSKZjUQTvdFf6eqznHGEwhZApWfvXu6zjGCxYCp65F4jsVYYJjkzbjmkCg5WAwN5voudngA23kMK6PpTNygapCzXt" }