Skip to content

Commit a763bf1

Browse files
committed
core/txpool, eth: polish
1 parent 4d0b8aa commit a763bf1

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,6 @@ func (p *BlobPool) Get(hash common.Hash) *types.Transaction {
12201220
if len(data) == 0 {
12211221
return nil
12221222
}
1223-
12241223
item := new(types.Transaction)
12251224
if err := rlp.DecodeBytes(data, item); err != nil {
12261225
id, _ := p.lookup.storeidOfTx(hash)
@@ -1233,8 +1232,8 @@ func (p *BlobPool) Get(hash common.Hash) *types.Transaction {
12331232
}
12341233

12351234
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
1236-
func (p *BlobPool) GetRLP(hash common.Hash) ([]byte, error) {
1237-
return p.getRLP(hash), nil
1235+
func (p *BlobPool) GetRLP(hash common.Hash) []byte {
1236+
return p.getRLP(hash)
12381237
}
12391238

12401239
// GetBlobs returns a number of blobs are proofs for the given versioned hashes.

core/txpool/legacypool/legacypool.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,17 +1012,17 @@ func (pool *LegacyPool) get(hash common.Hash) *types.Transaction {
10121012
}
10131013

10141014
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
1015-
func (pool *LegacyPool) GetRLP(hash common.Hash) ([]byte, error) {
1015+
func (pool *LegacyPool) GetRLP(hash common.Hash) []byte {
10161016
tx := pool.all.Get(hash)
1017-
if tx != nil {
1018-
encoded, err := rlp.EncodeToBytes(tx)
1019-
if err != nil {
1020-
log.Error("Failed to encoded transaction in legacy pool", "err", err)
1021-
return nil, err
1022-
}
1023-
return encoded, nil
1017+
if tx == nil {
1018+
return nil
10241019
}
1025-
return nil, nil
1020+
encoded, err := rlp.EncodeToBytes(tx)
1021+
if err != nil {
1022+
log.Error("Failed to encoded transaction in legacy pool", "hash", hash, "err", err)
1023+
return nil
1024+
}
1025+
return encoded
10261026
}
10271027

10281028
// GetBlobs is not supported by the legacy transaction pool, it is just here to

core/txpool/subpool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ type SubPool interface {
125125
Get(hash common.Hash) *types.Transaction
126126

127127
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
128-
GetRLP(hash common.Hash) ([]byte, error)
128+
GetRLP(hash common.Hash) []byte
129129

130130
// GetBlobs returns a number of blobs are proofs for the given versioned hashes.
131131
// This is a utility method for the engine API, enabling consensus clients to

core/txpool/txpool.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ func (p *TxPool) Get(hash common.Hash) *types.Transaction {
310310
}
311311

312312
// GetRLP returns a RLP-encoded transaction if it is contained in the pool.
313-
func (p *TxPool) GetRLP(hash common.Hash) ([]byte, error) {
313+
func (p *TxPool) GetRLP(hash common.Hash) []byte {
314314
for _, subpool := range p.subpools {
315-
encoded, err := subpool.GetRLP(hash)
316-
if err != nil || len(encoded) != 0 {
317-
return encoded, err
315+
encoded := subpool.GetRLP(hash)
316+
if len(encoded) != 0 {
317+
return encoded
318318
}
319319
}
320-
return nil, nil
320+
return nil
321321
}
322322

323323
// GetBlobs returns a number of blobs are proofs for the given versioned hashes.

eth/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type txPool interface {
6969

7070
// GetRLP retrieves the RLP-encoded transaction from local txpool
7171
// with given tx hash.
72-
GetRLP(hash common.Hash) ([]byte, error)
72+
GetRLP(hash common.Hash) []byte
7373

7474
// Add should add the given transactions to the pool.
7575
Add(txs []*types.Transaction, sync bool) []error

eth/handler_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,16 @@ func (p *testTxPool) Get(hash common.Hash) *types.Transaction {
8181

8282
// Get retrieves the transaction from local txpool with given
8383
// tx hash.
84-
func (p *testTxPool) GetRLP(hash common.Hash) ([]byte, error) {
84+
func (p *testTxPool) GetRLP(hash common.Hash) []byte {
8585
p.lock.Lock()
8686
defer p.lock.Unlock()
8787

8888
tx := p.pool[hash]
8989
if tx != nil {
90-
return rlp.EncodeToBytes(tx)
90+
blob, _ := rlp.EncodeToBytes(tx)
91+
return blob
9192
}
92-
return nil, nil
93+
return nil
9394
}
9495

9596
// Add appends a batch of transactions to the pool, and notifies any

eth/protocols/eth/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type TxPool interface {
8989

9090
// GetRLP retrieves the RLP-encoded transaction from the local txpool with
9191
// the given hash.
92-
GetRLP(hash common.Hash) ([]byte, error)
92+
GetRLP(hash common.Hash) []byte
9393
}
9494

9595
// MakeProtocols constructs the P2P protocol definitions for `eth`.

eth/protocols/eth/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ func answerGetPooledTransactions(backend Backend, query GetPooledTransactionsReq
397397
break
398398
}
399399
// Retrieve the requested transaction, skipping if unknown to us
400-
encoded, err := backend.TxPool().GetRLP(hash)
401-
if err != nil || len(encoded) == 0 {
400+
encoded := backend.TxPool().GetRLP(hash)
401+
if len(encoded) == 0 {
402402
continue
403403
}
404404
hashes = append(hashes, hash)

0 commit comments

Comments
 (0)