From f63cc3c179c16254ca2a7cf74ae3aa6e26c8df1e Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 26 Feb 2024 15:22:01 +0800 Subject: [PATCH] core/txpool: get blob tx by storage id Signed-off-by: jsvisa --- core/txpool/blobpool/blobpool.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 276c2886e2..a150a61629 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1189,19 +1189,28 @@ func (p *BlobPool) Get(hash common.Hash) *types.Transaction { if !ok { return nil } - data, err := p.store.Get(id) + item, err := p.get(id) if err != nil { - log.Error("Tracked blob transaction missing from store", "hash", hash, "id", id, "err", err) - return nil - } - item := new(types.Transaction) - if err = rlp.DecodeBytes(data, item); err != nil { - log.Error("Blobs corrupted for traced transaction", "hash", hash, "id", id, "err", err) + log.Error("Failed to retrieve blob transaction", "hash", hash, "id", id, "err", err) return nil } return item } +// get retrieves a blob transaction from the pool's storage and assembles it into +// types.Transaction. +func (p *BlobPool) get(id uint64) (*types.Transaction, error) { + data, err := p.store.Get(id) + if err != nil { + return nil, fmt.Errorf("Tracked blob transaction missing from store: %w", err) + } + item := new(types.Transaction) + if err = rlp.DecodeBytes(data, item); err != nil { + return nil, fmt.Errorf("Blobs corrupted for traced transaction: %w", err) + } + return item, nil +} + // Add inserts a set of blob transactions into the pool if they pass validation (both // consensus validity and pool restrictions). func (p *BlobPool) Add(txs []*types.Transaction, local bool, sync bool) []error {