fix compareTo bug with unconfirmed parents

This commit is contained in:
Craig Raw 2020-08-17 16:47:55 +02:00
parent 6a2af38b8a
commit f0aa949174

View file

@ -34,7 +34,7 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
@Override
public int compareTo(BlockTransaction blkTx) {
if(getHeight() != blkTx.getHeight()) {
return (getHeight() > 0 ? getHeight() : Integer.MAX_VALUE) - (blkTx.getHeight() > 0 ? blkTx.getHeight() : Integer.MAX_VALUE);
return getComparisonHeight() - blkTx.getComparisonHeight();
}
if(getReferencedOutpoints(this).removeAll(getOutputs(blkTx))) {
@ -48,6 +48,15 @@ public class BlockTransaction extends BlockTransactionHash implements Comparable
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) {
if(blockchainTransaction.getTransaction() == null) {
return Collections.emptyList();