Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/txpool, eth: add GetRLP to transaction pool #31307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

minh-bq
Copy link
Contributor

@minh-bq minh-bq commented Mar 4, 2025

Currently, when answering GetPooledTransaction request, txpool.Get() is used. When the requested hash is blob transaction, blobpool.Get() is called. This function loads the RLP-encoded transaction from limbo then decodes and returns. Later, in answerGetPooledTransactions, we need to RLP encode again. This decode then encode is wasteful. This commit adds GetRLP to transaction pool interface so that answerGetPooledTransactions can use the RLP-encoded from limbo directly.

@rjl493456442 rjl493456442 self-assigned this Mar 4, 2025
Currently, when answering GetPooledTransaction request, txpool.Get() is used.
When the requested hash is blob transaction, blobpool.Get() is called. This
function loads the RLP-encoded transaction from limbo then decodes and returns.
Later, in answerGetPooledTransactions, we need to RLP encode again. This decode
then encode is wasteful. This commit adds GetRLP to transaction pool interface
so that answerGetPooledTransactions can use the RLP-encoded from limbo
directly.
@rjl493456442
Copy link
Member

func BenchmarkBlobTxEncodeDecode(b *testing.B) {
	key, _ := crypto.GenerateKey()
	tx := createEmptyBlobTx(key, true) // 1 blob
	b.ResetTimer()
	b.ReportAllocs()

	for i := 0; i < b.N; i++ {
		blob, _ := rlp.EncodeToBytes(tx)
		var dec Transaction
		rlp.DecodeBytes(blob, &dec)
	}
}
BenchmarkBlobTxEncodeDecode
BenchmarkBlobTxEncodeDecode-8   	   15196	     74555 ns/op	  680612 B/op	      30 allocs/op

The additional blobTx encode/decode is not trivial, I guess this optimization would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants