From 52aef17fd32ae232f240ae003361fce2998835a5 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 25 Mar 2025 14:13:30 +0800 Subject: [PATCH] core/txpool, eth: polish --- core/txpool/blobpool/blobpool.go | 10 ++++++---- core/txpool/blobpool/lookup.go | 2 +- core/txpool/legacypool/legacypool.go | 5 ++--- core/txpool/subpool.go | 9 +++++---- eth/handler.go | 4 ++-- eth/protocols/eth/handler.go | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 853c40211f..0148e78b3e 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -89,7 +89,7 @@ type blobTxMeta struct { id uint64 // Storage ID in the pool's persistent store storageSize uint32 // Byte size in the pool's persistent store - size uint64 // RLP-encoded size of transaction + size uint64 // RLP-encoded size of transaction including the attached blob nonce uint64 // Needed to prioritize inclusion order within an account costCap *uint256.Int // Needed to validate cumulative balance sufficiency @@ -1238,14 +1238,16 @@ func (p *BlobPool) GetRLP(hash common.Hash) []byte { return p.getRLP(hash) } -// GetMetadata returns the transaction type and transaction size with the given -// hash. +// GetMetadata returns the transaction type and transaction size with the +// given transaction hash. +// +// The size refers the length of the 'rlp encoding' of a blob transaction +// including the attached blobs. func (p *BlobPool) GetMetadata(hash common.Hash) *txpool.TxMetadata { size, ok := p.lookup.sizeOfTx(hash) if !ok { return nil } - return &txpool.TxMetadata{ Type: types.BlobTxType, Size: size, diff --git a/core/txpool/blobpool/lookup.go b/core/txpool/blobpool/lookup.go index 60cac0011c..e3cfdea936 100644 --- a/core/txpool/blobpool/lookup.go +++ b/core/txpool/blobpool/lookup.go @@ -22,7 +22,7 @@ import ( type txMetadata struct { id uint64 // the billy id of transction - size uint64 // the RLP encoded size of transaction + size uint64 // the RLP encoded size of transaction (blobs are included) } // lookup maps blob versioned hashes to transaction hashes that include them, diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 3a6db98c04..9066f3e16b 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1035,14 +1035,13 @@ func (pool *LegacyPool) GetRLP(hash common.Hash) []byte { return encoded } -// GetMetadata returns the transaction type and transaction size with the given -// hash. +// GetMetadata returns the transaction type and transaction size with the +// given transaction hash. func (pool *LegacyPool) GetMetadata(hash common.Hash) *txpool.TxMetadata { tx := pool.all.Get(hash) if tx == nil { return nil } - return &txpool.TxMetadata{ Type: tx.Type(), Size: tx.Size(), diff --git a/core/txpool/subpool.go b/core/txpool/subpool.go index b37805f47a..f5cb852d8f 100644 --- a/core/txpool/subpool.go +++ b/core/txpool/subpool.go @@ -86,9 +86,10 @@ type PendingFilter struct { OnlyBlobTxs bool // Return only blob transactions (block blob-space filling) } +// TxMetadata denotes the metadata of a transaction. type TxMetadata struct { - Type uint8 - Size uint64 + Type uint8 // The type of the transaction + Size uint64 // The length of the 'rlp encoding' of a transaction } // SubPool represents a specialized transaction pool that lives on its own (e.g. @@ -132,8 +133,8 @@ type SubPool interface { // GetRLP returns a RLP-encoded transaction if it is contained in the pool. GetRLP(hash common.Hash) []byte - // GetMetadata returns the transaction type and transaction size with the given - // hash. + // GetMetadata returns the transaction type and transaction size with the + // given transaction hash. GetMetadata(hash common.Hash) *TxMetadata // GetBlobs returns a number of blobs are proofs for the given versioned hashes. diff --git a/eth/handler.go b/eth/handler.go index d205589aeb..b2ad6effdb 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -71,8 +71,8 @@ type txPool interface { // with given tx hash. GetRLP(hash common.Hash) []byte - // GetMetadata returns the transaction type and transaction size with the given - // hash. + // GetMetadata returns the transaction type and transaction size with the + // given transaction hash. GetMetadata(hash common.Hash) *txpool.TxMetadata // Add should add the given transactions to the pool. diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go index 00fd8d311d..f2a3cb0292 100644 --- a/eth/protocols/eth/handler.go +++ b/eth/protocols/eth/handler.go @@ -92,8 +92,8 @@ type TxPool interface { // the given hash. GetRLP(hash common.Hash) []byte - // GetMetadata returns the transaction type and transaction size with the given - // hash. + // GetMetadata returns the transaction type and transaction size with the + // given transaction hash. GetMetadata(hash common.Hash) *txpool.TxMetadata }