Skip to content

Conversation

@dimension-drifter
Copy link

Problem

Currently, all mempool transactions are fully revalidated on each cleanup cycle, which is computationally expensive. Many transactions don't use blockchain context (like HEIGHT, CONTEXT.headers, etc.) in their spending conditions, so their validity doesn't change with new blocks - only their inputs' existence matters.

Solution

This PR implements optimization for mempool transaction revalidation by:

  1. Extended UnconfirmedTransaction class with new fields:

    • isUsingBlockchainContext: Option[Boolean] - flag indicating if any input's ErgoTree uses blockchain context
    • validationResult: Option[Boolean] - cached validation result for transactions using blockchain context
  2. Updated validation in ErgoMemPool (process method):

    • During initial validation, checks if any input's ErgoTree has the isUsingBlockchainContext flag set
    • Stores this information along with validation result in UnconfirmedTransaction
  3. Optimized CleanupWorker.validatePool:

    • For transactions NOT using blockchain context with successful previous validation:
      • Only checks that inputs still exist in UTXO set
      • Skips expensive script execution
    • For transactions using blockchain context:
      • Performs full validation as before

Benefits

  • Performance: Significantly reduced mempool cleanup cost for common transactions (simple P2PK payments, basic token transfers)
  • Scalability: Better mempool handling during high transaction volume
  • Backward compatible: Gracefully handles transactions created before this change

Dependencies

@dimension-drifter dimension-drifter changed the title Fix Issue (#1722): Label transactions with inputs not using blockchain context, simplify their revalidation in mempool Fix Issue: Label transactions with inputs not using blockchain context, simplify their revalidation in mempool Dec 14, 2025
@dimension-drifter dimension-drifter changed the title Fix Issue: Label transactions with inputs not using blockchain context, simplify their revalidation in mempool Fix Issue (#2092): Label transactions with inputs not using blockchain context, simplify their revalidation in mempool Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant