improve blocktx ordering behaviour

This commit is contained in:
Craig Raw 2020-08-19 08:39:33 +02:00
parent 0639f408db
commit b9ef670e61
2 changed files with 10 additions and 10 deletions

View file

@ -48,15 +48,6 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
return super.compareTo(blkTx); return super.compareTo(blkTx);
} }
/**
* Calculates a special height value that places txes with unconfirmed parents first, then normal unconfirmed txes, then confirmed txes
*
* @return the modified height value
*/
private int getComparisonHeight() {
return (getHeight() > 0 ? getHeight() : (getHeight() == -1 ? Integer.MAX_VALUE : Integer.MAX_VALUE - getHeight() - 1));
}
private static List<HashIndex> getReferencedOutpoints(BlockTransaction blockchainTransaction) { private static List<HashIndex> getReferencedOutpoints(BlockTransaction blockchainTransaction) {
if(blockchainTransaction.getTransaction() == null) { if(blockchainTransaction.getTransaction() == null) {
return Collections.emptyList(); return Collections.emptyList();

View file

@ -35,6 +35,15 @@ public abstract class BlockTransactionHash {
return height; return height;
} }
/**
* Calculates a special height value that places txes with unconfirmed parents first, then normal unconfirmed txes, then confirmed txes
*
* @return the modified height value
*/
public int getComparisonHeight() {
return (getHeight() > 0 ? getHeight() : (getHeight() == -1 ? Integer.MAX_VALUE : Integer.MAX_VALUE - getHeight() - 1));
}
public int getConfirmations(int currentBlockHeight) { public int getConfirmations(int currentBlockHeight) {
if(height <= 0) { if(height <= 0) {
return 0; return 0;
@ -79,7 +88,7 @@ public abstract class BlockTransactionHash {
public int compareTo(BlockTransactionHash reference) { public int compareTo(BlockTransactionHash reference) {
if(height != reference.height) { if(height != reference.height) {
return (height > 0 ? height : Integer.MAX_VALUE) - (reference.height > 0 ? reference.height : Integer.MAX_VALUE); return getComparisonHeight() - reference.getComparisonHeight();
} }
return hash.compareTo(reference.hash); return hash.compareTo(reference.hash);