Skip to content

Commit 8dfd30f

Browse files
authored
core/txpool/blobpool: add legacy sidecar conversion in reinject (#32688)
This adds the conversion for the legacy sidecar if these transactions are reorged out after the osaka.
1 parent 2b5718f commit 8dfd30f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,21 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
10301030
// TODO: seems like an easy optimization here would be getting the serialized tx
10311031
// from limbo instead of re-serializing it here.
10321032

1033+
// Converts reorged-out legacy blob transactions to the new format to prevent
1034+
// them from becoming stuck in the pool until eviction.
1035+
//
1036+
// Performance note: Conversion takes ~140ms (Mac M1 Pro). Since a maximum of
1037+
// 9 legacy blob transactions are allowed in a block pre-Osaka, an adversary
1038+
// could theoretically halt a Geth node for ~1.2s by reorging per block. However,
1039+
// this attack is financially inefficient to execute.
1040+
head := p.head.Load()
1041+
if p.chain.Config().IsOsaka(head.Number, head.Time) && tx.BlobTxSidecar().Version == types.BlobSidecarVersion0 {
1042+
if err := tx.BlobTxSidecar().ToV1(); err != nil {
1043+
log.Error("Failed to convert the legacy sidecar", "err", err)
1044+
return err
1045+
}
1046+
log.Info("Legacy blob transaction is reorged", "hash", tx.Hash())
1047+
}
10331048
// Serialize the transaction back into the primary datastore.
10341049
blob, err := rlp.EncodeToBytes(tx)
10351050
if err != nil {

crypto/kzg4844/kzg4844_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,31 @@ func testKZGCells(t *testing.T, ckzg bool) {
225225
t.Fatalf("failed to verify KZG proof at point: %v", err)
226226
}
227227
}
228+
229+
// goos: darwin
230+
// goarch: arm64
231+
// pkg: github.com/ethereum/go-ethereum/crypto/kzg4844
232+
// cpu: Apple M1 Pro
233+
// BenchmarkGOKZGComputeCellProofs
234+
// BenchmarkGOKZGComputeCellProofs-8 8 139012286 ns/op
235+
func BenchmarkGOKZGComputeCellProofs(b *testing.B) { benchmarkComputeCellProofs(b, false) }
236+
func BenchmarkCKZGComputeCellProofs(b *testing.B) { benchmarkComputeCellProofs(b, true) }
237+
238+
func benchmarkComputeCellProofs(b *testing.B, ckzg bool) {
239+
if ckzg && !ckzgAvailable {
240+
b.Skip("CKZG unavailable in this test build")
241+
}
242+
defer func(old bool) { useCKZG.Store(old) }(useCKZG.Load())
243+
useCKZG.Store(ckzg)
244+
245+
blob := randBlob()
246+
_, _ = ComputeCellProofs(blob) // for kzg initialization
247+
b.ResetTimer()
248+
249+
for b.Loop() {
250+
_, err := ComputeCellProofs(blob)
251+
if err != nil {
252+
b.Fatalf("failed to create KZG proof at point: %v", err)
253+
}
254+
}
255+
}

0 commit comments

Comments
 (0)