-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved transactions getting logic. #18
base: multiple-hd-accounts
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1616,7 +1616,7 @@ public boolean isConsistent() { | |
public void isConsistentOrThrow() throws IllegalStateException { | ||
lock.lock(); | ||
try { | ||
Set<Transaction> transactions = getTransactions(true); | ||
Collection<Transaction> transactions = this.transactions.values(); | ||
|
||
Set<Sha256Hash> hashes = new HashSet<Sha256Hash>(); | ||
for (Transaction tx : transactions) { | ||
|
@@ -1663,6 +1663,9 @@ boolean isTxConsistent(final Transaction tx, final boolean isSpent) { | |
log.error("isAvailableForSpending != spentBy"); | ||
return false; | ||
} | ||
if (!isActuallySpent) { | ||
return !isSpent; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, explain it to me.
ok, so far so good. I would prefer
which makes me even more confused about what is going on here. Something like
would be readable but what about the |
||
} else { | ||
if (o.getSpentBy() == null) { | ||
log.error("isAvailableForSpending != spentBy"); | ||
|
@@ -1909,7 +1912,7 @@ private Set<Transaction> findDoubleSpendsAgainst(Transaction tx, Map<Sha256Hash, | |
* Adds to txSet all the txns in txPool spending outputs of txns in txSet, | ||
* and all txns spending the outputs of those txns, recursively. | ||
*/ | ||
void addTransactionsDependingOn(Set<Transaction> txSet, Set<Transaction> txPool) { | ||
void addTransactionsDependingOn(Set<Transaction> txSet, Collection<Transaction> txPool) { | ||
Map<Sha256Hash, Transaction> txQueue = new LinkedHashMap<Sha256Hash, Transaction>(); | ||
for (Transaction tx : txSet) { | ||
txQueue.put(tx.getHash(), tx); | ||
|
@@ -2052,7 +2055,7 @@ private void receive(Transaction tx, StoredBlock block, BlockChain.NewBlockType | |
// change its confidence to PENDING (Unless they are also spending other txns IN_CONFLICT). | ||
// Consider dependency chains. | ||
Set<Transaction> currentTxDependencies = Sets.newHashSet(tx); | ||
addTransactionsDependingOn(currentTxDependencies, getTransactions(true)); | ||
addTransactionsDependingOn(currentTxDependencies, transactions.values()); | ||
currentTxDependencies.remove(tx); | ||
List<Transaction> currentTxDependenciesSorted = sortTxnsByDependency(currentTxDependencies); | ||
for (Transaction txDependency : currentTxDependenciesSorted) { | ||
|
@@ -2187,8 +2190,7 @@ public void notifyNewBestBlock(StoredBlock block) throws VerificationException { | |
setLastBlockSeenTimeSecs(block.getHeader().getTimeSeconds()); | ||
// Notify all the BUILDING transactions of the new block. | ||
// This is so that they can update their depth. | ||
Set<Transaction> transactions = getTransactions(true); | ||
for (Transaction tx : transactions) { | ||
for (Transaction tx : transactions.values()) { | ||
if (ignoreNextNewBlock.contains(tx.getHash())) { | ||
// tx was already processed in receive() due to it appearing in this block, so we don't want to | ||
// increment the tx confidence depth twice, it'd result in miscounting. | ||
|
@@ -2511,7 +2513,7 @@ public boolean maybeCommitTx(Transaction tx) throws VerificationException { | |
log.info("->pending (IN_CONFLICT): {}", tx.getHashAsString()); | ||
addWalletTransaction(Pool.PENDING, tx); | ||
doubleSpendPendingTxns.add(tx); | ||
addTransactionsDependingOn(doubleSpendPendingTxns, getTransactions(true)); | ||
addTransactionsDependingOn(doubleSpendPendingTxns, transactions.values()); | ||
for (Transaction doubleSpendTx : doubleSpendPendingTxns) { | ||
doubleSpendTx.getConfidence().setConfidenceType(ConfidenceType.IN_CONFLICT); | ||
confidenceChanged.put(doubleSpendTx, TransactionConfidence.Listener.ChangeReason.TYPE); | ||
|
@@ -2884,12 +2886,13 @@ public void run() { | |
public Set<Transaction> getTransactions(boolean includeDead) { | ||
lock.lock(); | ||
try { | ||
Set<Transaction> all = new HashSet<Transaction>(); | ||
if (includeDead) { | ||
return new HashSet<>(transactions.values()); | ||
} | ||
Set<Transaction> all = new HashSet<>(); | ||
all.addAll(unspent.values()); | ||
all.addAll(spent.values()); | ||
all.addAll(pending.values()); | ||
if (includeDead) | ||
all.addAll(dead.values()); | ||
return all; | ||
} finally { | ||
lock.unlock(); | ||
|
@@ -2991,7 +2994,7 @@ public List<Transaction> getRecentTransactions(int numTransactions, boolean incl | |
if (numTransactions > size || numTransactions == 0) { | ||
numTransactions = size; | ||
} | ||
ArrayList<Transaction> all = new ArrayList<Transaction>(getTransactions(includeDead)); | ||
ArrayList<Transaction> all = new ArrayList<Transaction>(transactions.values()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. includeDead is not always true. |
||
// Order by update time. | ||
Collections.sort(all, Transaction.SORT_TX_BY_UPDATE_TIME); | ||
if (numTransactions == all.size()) { | ||
|
@@ -4440,7 +4443,7 @@ public void reorganize(StoredBlock splitPoint, List<StoredBlock> oldBlocks, List | |
// Map block hash to transactions that appear in it. We ensure that the map values are sorted according | ||
// to their relative position within those blocks. | ||
ArrayListMultimap<Sha256Hash, TxOffsetPair> mapBlockTx = ArrayListMultimap.create(); | ||
for (Transaction tx : getTransactions(true)) { | ||
for (Transaction tx : transactions.values()) { | ||
Map<Sha256Hash, Integer> appearsIn = tx.getAppearsInHashes(); | ||
if (appearsIn == null) continue; // Pending. | ||
for (Map.Entry<Sha256Hash, Integer> block : appearsIn.entrySet()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is safe because we use the same lock as in getTransactions() and we don't change the transactions.
This is performant, as we don't need the
Set
property. Only iteration.