Transaction Validation Optimization

Transaction Validation Optimization
2025-02-19  5:47 ` Eric Voskuil
  2025-02-19 18:20 ` Pieter Wuille
  
From: John @ 2025-02-18 15:22 UTC (permalink / raw)
  To: Bitcoin Development Mailing List


[-- Attachment #1.1: Type: text/plain, Size: 1483 bytes --]



Hi everyone,

While analyzing the codebase, I observed what seems to be duplicate 
validation steps for transactions that already exist in the mempool when 
they appear in new blocks. Specifically, I'm curious if the secondary 
validation performed during block acceptance could be safely optimized for 
SegWit-verified transactions using their wtxid hashes.（I'm still working on 
the source code, and I'm not sure if the source code was validated twice）

I'm particularly seeking clarification on two aspects: First, does the 
current implementation indeed perform full re-validation of mempool 
transactions during block processing? Second, if such optimization is 
theoretically possible, what subtle risks might emerge regarding 
transaction propagation timing or node synchronization that a newcomer like 
myself might overlook?

I'd be grateful for any insights about historical design decisions in this 
area, critical code sections I should study more deeply, or potential 
pitfalls in this line of thinking. 

Thanks in advance for sharing your expertise,
John

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/3c2b1e7a-ffcd-41da-a533-2d9224fc016fn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 3938 bytes --]

 permalink raw reply	[|nested]
2025-02-18 15:22 [bitcoindev] Transaction Validation Optimization John

  2025-02-19 18:20 ` Pieter Wuille
  
From: Eric Voskuil @ 2025-02-19  5:47 UTC (permalink / raw)
  To: John;  bitcoindev, bitcoindev

[-- Attachment #1: Type: text/html, Size: 6420 bytes --]

 permalink raw reply	[|nested]
2025-02-18 15:22 [bitcoindev] Transaction Validation Optimization John
  2025-02-19  5:47 ` Eric Voskuil

  
From: Pieter Wuille @ 2025-02-19 18:20 UTC ( / )
  To: John;  Bitcoin Development Mailing List

On Tuesday, February 18th, 2025 at 10:22 AM, John <csdarkcounter@gmail•com> wrote:

> Hi everyone,
> 
> While analyzing the codebase, I observed what seems to be duplicate validation steps for transactions that already exist in the mempool when they appear in new blocks. Specifically, I'm curious if the secondary validation performed during block acceptance could be safely optimized for SegWit-verified transactions using their wtxid hashes.（I'm still working on the source code, and I'm not sure if the source code was validated twice

Bitcoin Core maintains a signature validation cache and a script validation cache (see the ValidationCache class), which generally means that mempool transactions don't need to be (fully) validated again when seen in a block. The script validation cache includes the validation flags (including which consensus rules are active) too, so the cache will not function across softfork activations, for example.

-- 
Pieter

-- 
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups•com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/PwJsLY2Y0zpBfSnWT-O1iP-r6n7sipm-EFgK-LnnZqkPMoSUO6HJxigmt2J0CRTd8A6V4UVpA-JFCd6MaXZ0Up1bye5zVxXGdSrhIsyr38s%3D%40wuille.net.