Extract mempool re-validation logic from CleanupWorker and test it - #2457
Open
Ergologica wants to merge 2 commits into
Open
Extract mempool re-validation logic from CleanupWorker and test it#2457Ergologica wants to merge 2 commits into
Ergologica wants to merge 2 commits into
Conversation
validatePool was a private method of the actor, closing over nodeSettings, the system clock and a hard-coded cost limit, so it could only be reached by starting an actor system. Move it to the companion object as a function of its arguments, with now and costLimit passed in, and return a named CleanupResult. The staleness filter is exposed separately as transactionsToValidate. The actor keeps its behaviour: same messages, same reply, same log line. Closes ergoplatform#1556
Covers the staleness filter and its boundary (exactly timeLimit old is not stale yet), still-valid transactions coming back with lastCost filled in, transactions spending non-existent inputs being reported as invalidated, a mixed pool splitting correctly, and the cost limit stopping the loop after exactly one transaction. No actor system involved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1556.
The change
CleanupWorker.validatePoolwas a private method of the actor, closing overnodeSettings, the system clock and a hard-coded cost limit, so the only way to reach it was to start an actor system and drive it throughMempoolAuditor.MempoolAuditorSpecdoes exactly that, and as a result covers the re-validation logic only indirectly and only in its happy path.The logic moves to
object CleanupWorkeras a function of its arguments:nowis passed in instead of callingSystem.currentTimeMillis(), so the staleness filter is testable without sleeping.costLimitis a parameter defaulting to the same hard-codedCostLimitas before, so the cut-off can be exercised with small numbers.CleanupResult(validated, invalidated)rather than a bare tuple.transactionsToValidate, since it is the part with an off-by-one worth pinning.The actor keeps its behaviour: it still runs the work in a
Future, still sendsRecheckedTransactions/EliminateTransactionsto the node view holder, still repliesCleanupDone, and still logs the same line at the same level. No behaviour change is intended anywhere.Tests
New
CleanupWorkerSpec, no actor system involved:timeLimitold is not stale yet,>and not>=;validatedwithlastCostfilled in, having beenNonebefore;invalidated;costLimit = 1exactly one transaction is processed, sincecostAccstarts at zero, and with no limit the whole pool is.I deliberately kept the diff to two files: #1560 grew to 25 files, which I suspect is part of why it stalled.
sbt "testOnly org.ergoplatform.local.*"— 9 tests, all green,MempoolAuditorSpecincluded.