Skip to content

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

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

Merged
merged 3 commits into from
Mar 19, 2025

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.

fjl
fjl previously approved these changes Mar 18, 2025
@fjl fjl removed the status:triage label Mar 18, 2025
@rjl493456442 rjl493456442 added this to the 1.15.6 milestone Mar 19, 2025
@rjl493456442 rjl493456442 merged commit 930836e into ethereum:master Mar 19, 2025
5 of 6 checks passed
@minh-bq minh-bq deleted the get-pooled-tx branch March 19, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants