fix: fix tx size

This commit is contained in:
healthykim 2025-09-11 18:20:16 +09:00
parent 61c55eb1e5
commit 6cdba2145b

View file

@ -138,7 +138,7 @@ func newBlobTxMeta(id uint64, size uint64, storageSize uint32, tx *types.Transac
version: tx.BlobTxSidecar().Version, version: tx.BlobTxSidecar().Version,
id: id, id: id,
storageSize: storageSize, // size of tx including cells storageSize: storageSize, // size of tx including cells
size: size, // size of tx only size: size, // size of tx including blobs
nonce: tx.Nonce(), nonce: tx.Nonce(),
costCap: uint256.MustFromBig(tx.Cost()), costCap: uint256.MustFromBig(tx.Cost()),
execTipCap: uint256.MustFromBig(tx.GasTipCap()), execTipCap: uint256.MustFromBig(tx.GasTipCap()),
@ -156,12 +156,14 @@ func newBlobTxMeta(id uint64, size uint64, storageSize uint32, tx *types.Transac
type PooledBlobTx struct { type PooledBlobTx struct {
Transaction *types.Transaction Transaction *types.Transaction
Sidecar *types.BlobTxCellSidecar Sidecar *types.BlobTxCellSidecar
Size uint64 // original transaction size
} }
func NewPooledBlobTx(tx *types.Transaction, sidecar *types.BlobTxCellSidecar) *PooledBlobTx { func NewPooledBlobTx(tx *types.Transaction, sidecar *types.BlobTxCellSidecar, size uint64) *PooledBlobTx {
return &PooledBlobTx{ return &PooledBlobTx{
Transaction: tx, Transaction: tx,
Sidecar: sidecar, Sidecar: sidecar,
Size: size,
} }
} }
@ -1100,7 +1102,7 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
} }
// Update the indices and metrics // Update the indices and metrics
meta := newBlobTxMeta(id, tx.Transaction.Size(), p.store.Size(id), tx.Transaction) meta := newBlobTxMeta(id, tx.Size, p.store.Size(id), tx.Transaction)
if _, ok := p.index[addr]; !ok { if _, ok := p.index[addr]; !ok {
if err := p.reserver.Hold(addr); err != nil { if err := p.reserver.Hold(addr); err != nil {
log.Warn("Failed to reserve account for blob pool", "tx", tx.Transaction.Hash(), "from", addr, "err", err) log.Warn("Failed to reserve account for blob pool", "tx", tx.Transaction.Hash(), "from", addr, "err", err)
@ -1410,7 +1412,7 @@ func (p *BlobPool) GetRLP(hash common.Hash) []byte {
// given transaction hash. // given transaction hash.
// //
// The size refers the length of the 'rlp encoding' of a blob transaction // The size refers the length of the 'rlp encoding' of a blob transaction
// excluding the attached blobs. // including the attached blobs.
func (p *BlobPool) GetMetadata(hash common.Hash) *txpool.TxMetadata { func (p *BlobPool) GetMetadata(hash common.Hash) *txpool.TxMetadata {
p.lock.RLock() p.lock.RLock()
defer p.lock.RUnlock() defer p.lock.RUnlock()
@ -1564,7 +1566,7 @@ func (p *BlobPool) Add(txs []*types.Transaction, sync bool) []error {
errs[i] = err errs[i] = err
continue continue
} }
errs[i] = p.add(tx.WithoutBlobTxSidecar(), cellSidecar) errs[i] = p.add(tx.WithoutBlobTxSidecar(), cellSidecar, tx.Size())
if errs[i] == nil { if errs[i] == nil {
adds = append(adds, tx.WithoutBlobTxSidecar()) adds = append(adds, tx.WithoutBlobTxSidecar())
} }
@ -1578,7 +1580,7 @@ func (p *BlobPool) Add(txs []*types.Transaction, sync bool) []error {
// add inserts a new blob transaction into the pool if it passes validation (both // add inserts a new blob transaction into the pool if it passes validation (both
// consensus validity and pool restrictions). // consensus validity and pool restrictions).
func (p *BlobPool) add(tx *types.Transaction, cellSidecar *types.BlobTxCellSidecar) (err error) { func (p *BlobPool) add(tx *types.Transaction, cellSidecar *types.BlobTxCellSidecar, size uint64) (err error) {
// The blob pool blocks on adding a transaction. This is because blob txs are // The blob pool blocks on adding a transaction. This is because blob txs are
// only even pulled from the network, so this method will act as the overload // only even pulled from the network, so this method will act as the overload
// protection for fetches. // protection for fetches.
@ -1637,7 +1639,7 @@ func (p *BlobPool) add(tx *types.Transaction, cellSidecar *types.BlobTxCellSidec
// Transaction permitted into the pool from a nonce and cost perspective, // Transaction permitted into the pool from a nonce and cost perspective,
// insert it into the database and update the indices // insert it into the database and update the indices
pooledTx := NewPooledBlobTx(tx, cellSidecar) pooledTx := NewPooledBlobTx(tx, cellSidecar, size)
if pooledTx.RemoveParity() != nil { if pooledTx.RemoveParity() != nil {
return err return err
} }
@ -1651,7 +1653,7 @@ func (p *BlobPool) add(tx *types.Transaction, cellSidecar *types.BlobTxCellSidec
if err != nil { if err != nil {
return err return err
} }
meta := newBlobTxMeta(id, tx.Size(), p.store.Size(id), tx) meta := newBlobTxMeta(id, pooledTx.Size, p.store.Size(id), tx)
var ( var (
next = p.state.GetNonce(from) next = p.state.GetNonce(from)