diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index d9b76dc674..59a5645040 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -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. diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index bae4e339aa..0a3903f058 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -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 { - encoded, err := rlp.EncodeToBytes(tx) - if err != nil { - log.Error("Failed to encoded transaction in legacy pool", "err", err) - return nil, err - } - return encoded, nil + if tx == nil { + return nil } - return nil, nil + encoded, err := rlp.EncodeToBytes(tx) + if err != nil { + log.Error("Failed to encoded transaction in legacy pool", "hash", hash, "err", err) + return nil + } + return encoded } // GetBlobs is not supported by the legacy transaction pool, it is just here to diff --git a/core/txpool/subpool.go b/core/txpool/subpool.go index a521baff86..1392cfb274 100644 --- a/core/txpool/subpool.go +++ b/core/txpool/subpool.go @@ -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 diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 3a38a455d1..042e3d36d9 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -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. diff --git a/eth/handler.go b/eth/handler.go index 9561c04159..4c83f5613c 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -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 diff --git a/eth/handler_test.go b/eth/handler_test.go index bb83c062f5..0c6b9854e6 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -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 diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go index 1679213c71..eca6777bd6 100644 --- a/eth/protocols/eth/handler.go +++ b/eth/protocols/eth/handler.go @@ -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`. diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index 97c660d415..ab56be7ffc 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -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)