From 69fe54b2e50e406b2525857350e3de4761d9384e Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 8 Jul 2025 14:04:25 +0200 Subject: [PATCH] core/types: maintain tx size cache in WithoutBlobTxSidecar --- core/types/transaction.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 934feb7353..733b6510f1 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -449,14 +449,18 @@ func (tx *Transaction) BlobGasFeeCapIntCmp(other *big.Int) int { // WithoutBlobTxSidecar returns a copy of tx with the blob sidecar removed. func (tx *Transaction) WithoutBlobTxSidecar() *Transaction { blobtx, ok := tx.inner.(*BlobTx) - if !ok { + if !ok || blobtx.Sidecar == nil { return tx } cpy := &Transaction{ inner: blobtx.withoutSidecar(), time: tx.time, } - // Note: tx.size cache not carried over because the sidecar is included in size! + if size := tx.size.Load(); size != 0 { + // The tx had a sidecar before, so we need to subtract it from the size. + scSize := rlp.ListSize(blobtx.Sidecar.encodedSize()) + cpy.size.Store(size - scSize) + } if h := tx.hash.Load(); h != nil { cpy.hash.Store(h) }