change recursion in _processCatchupReplies to while
@@ -530,15 +530,15 @@ class LedgerManager(HasActionQueue):
# TODO: Inefficient, should check list in reverse and stop at first
# match since list is already sorted
numProcessed = sum(1 for s, _ in catchUpReplies if s <= ledger.size)
- if numProcessed:
- logger.info("{} found {} already processed transactions in the catchup replies".
- format(self, numProcessed))
+ num_replies = 0
# If `catchUpReplies` has any transaction that has not been applied
# to the ledger
catchUpReplies = catchUpReplies[numProcessed:]
- if catchUpReplies:
+ while catchUpReplies and catchUpReplies[0][0] - ledger.seqNo == 1:
seqNo = catchUpReplies[0][0]
- if seqNo - ledger.seqNo == 1:
+ if numProcessed:
+ logger.info("{} found {} already processed transactions in the catchup replies".
+ format(self, numProcessed))
result, nodeName, toBeProcessed = self.hasValidCatchupReplies(
ledgerId, ledger, seqNo, catchUpReplies)
if result:
@@ -547,9 +547,9 @@ class LedgerManager(HasActionQueue):
self._add_txn(ledgerId, ledger,
ledgerInfo, txn)
self._removePrcdCatchupReply(ledgerId, nodeName, seqNo)
- return numProcessed + toBeProcessed + \
- self._processCatchupReplies(ledgerId, ledger,
- catchUpReplies[toBeProcessed:])
+ num_replies += numProcessed + toBeProcessed
+ numProcessed = sum(1 for s, _ in catchUpReplies if s <= ledger.size)
+ catchUpReplies = catchUpReplies[numProcessed:]
else:
if self.ownedByNode:
self.owner.blacklistNode(nodeName,
@@ -561,7 +561,7 @@ class LedgerManager(HasActionQueue):
# Invalid transactions have to be discarded so letting
# the caller know how many txns have to removed from
# `self.receivedCatchUpReplies`
- return numProcessed + toBeProcessed
+ return numProcessed + toBeProcessed + num_replies
return numProcessed
def _add_txn(self, ledgerId, ledger: Ledger, ledgerInfo, txn):
