core/txpool, eth: polish

This commit is contained in:
Gary Rong 2025-03-19 09:05:47 +08:00
parent 4d0b8aa70c
commit a763bf1b8b
8 changed files with 25 additions and 25 deletions

View file

@ -1220,7 +1220,6 @@ func (p *BlobPool) Get(hash common.Hash) *types.Transaction {
if len(data) == 0 {
return nil
}
item := new(types.Transaction)
if err := rlp.DecodeBytes(data, item); err != nil {
id, _ := p.lookup.storeidOfTx(hash)
@ -1233,8 +1232,8 @@ func (p *BlobPool) Get(hash common.Hash) *types.Transaction {
}
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
func (p *BlobPool) GetRLP(hash common.Hash) ([]byte, error) {
return p.getRLP(hash), nil
func (p *BlobPool) GetRLP(hash common.Hash) []byte {
return p.getRLP(hash)
}
// GetBlobs returns a number of blobs are proofs for the given versioned hashes.

View file

@ -1012,17 +1012,17 @@ func (pool *LegacyPool) get(hash common.Hash) *types.Transaction {
}
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
func (pool *LegacyPool) GetRLP(hash common.Hash) ([]byte, error) {
func (pool *LegacyPool) GetRLP(hash common.Hash) []byte {
tx := pool.all.Get(hash)
if tx != nil {
if tx == nil {
return nil
}
encoded, err := rlp.EncodeToBytes(tx)
if err != nil {
log.Error("Failed to encoded transaction in legacy pool", "err", err)
return nil, err
log.Error("Failed to encoded transaction in legacy pool", "hash", hash, "err", err)
return nil
}
return encoded, nil
}
return nil, nil
return encoded
}
// GetBlobs is not supported by the legacy transaction pool, it is just here to

View file

@ -125,7 +125,7 @@ type SubPool interface {
Get(hash common.Hash) *types.Transaction
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
GetRLP(hash common.Hash) ([]byte, error)
GetRLP(hash common.Hash) []byte
// GetBlobs returns a number of blobs are proofs for the given versioned hashes.
// This is a utility method for the engine API, enabling consensus clients to

View file

@ -310,14 +310,14 @@ func (p *TxPool) Get(hash common.Hash) *types.Transaction {
}
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
func (p *TxPool) GetRLP(hash common.Hash) ([]byte, error) {
func (p *TxPool) GetRLP(hash common.Hash) []byte {
for _, subpool := range p.subpools {
encoded, err := subpool.GetRLP(hash)
if err != nil || len(encoded) != 0 {
return encoded, err
encoded := subpool.GetRLP(hash)
if len(encoded) != 0 {
return encoded
}
}
return nil, nil
return nil
}
// GetBlobs returns a number of blobs are proofs for the given versioned hashes.

View file

@ -69,7 +69,7 @@ type txPool interface {
// GetRLP retrieves the RLP-encoded transaction from local txpool
// with given tx hash.
GetRLP(hash common.Hash) ([]byte, error)
GetRLP(hash common.Hash) []byte
// Add should add the given transactions to the pool.
Add(txs []*types.Transaction, sync bool) []error

View file

@ -81,15 +81,16 @@ func (p *testTxPool) Get(hash common.Hash) *types.Transaction {
// Get retrieves the transaction from local txpool with given
// tx hash.
func (p *testTxPool) GetRLP(hash common.Hash) ([]byte, error) {
func (p *testTxPool) GetRLP(hash common.Hash) []byte {
p.lock.Lock()
defer p.lock.Unlock()
tx := p.pool[hash]
if tx != nil {
return rlp.EncodeToBytes(tx)
blob, _ := rlp.EncodeToBytes(tx)
return blob
}
return nil, nil
return nil
}
// Add appends a batch of transactions to the pool, and notifies any

View file

@ -89,7 +89,7 @@ type TxPool interface {
// GetRLP retrieves the RLP-encoded transaction from the local txpool with
// the given hash.
GetRLP(hash common.Hash) ([]byte, error)
GetRLP(hash common.Hash) []byte
}
// MakeProtocols constructs the P2P protocol definitions for `eth`.

View file

@ -397,8 +397,8 @@ func answerGetPooledTransactions(backend Backend, query GetPooledTransactionsReq
break
}
// Retrieve the requested transaction, skipping if unknown to us
encoded, err := backend.TxPool().GetRLP(hash)
if err != nil || len(encoded) == 0 {
encoded := backend.TxPool().GetRLP(hash)
if len(encoded) == 0 {
continue
}
hashes = append(hashes, hash)