Skip to content

Commit e561a53

Browse files
committed
core/txpool/blobpool: read slotter version from billy before doing migration
1 parent 3aebcb4 commit e561a53

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ const (
8888
// limboedTransactionStore is the subfolder containing the currently included
8989
// but not yet finalized transaction blobs.
9090
limboedTransactionStore = "limbo"
91+
92+
// storeVersion is the current slotter layout used for the billy.Database
93+
// store.
94+
storeVersion = 1
9195
)
9296

9397
// blobTxMeta is the minimal subset of types.BlobTx necessary to validate and
@@ -395,23 +399,48 @@ func (p *BlobPool) Init(gasTip uint64, head *types.Header, reserver txpool.Reser
395399
}
396400
p.head, p.state = head, state
397401

398-
// Check if we need to migrate the blob database to a new format
402+
// Create new slotter for pre-Osaka blob configuration.
399403
slotter := newSlotter(eip4844.LatestMaxBlobsPerBlock(p.chain.Config()))
404+
405+
// Check if we need to migrate our blob db to the new slotter.
400406
if p.chain.Config().IsOsaka(head.Number, head.Time) {
401-
// Check if we need to migrate our blob db to the new slotter
402-
oldSlotSize := 135168
403-
if _, err := os.Stat(filepath.Join(queuedir, fmt.Sprintf("bkt_%08d.bag", oldSlotSize))); err == nil {
407+
// Open the store using the version slotter to see if any version has been
408+
// written.
409+
var version int
410+
index := func(_ uint64, _ uint32, blob []byte) {
411+
version = max(version, parseSlotterVersion(blob))
412+
}
413+
store, err := billy.Open(billy.Options{Path: queuedir}, newVersionSlotter(), index)
414+
if err != nil {
415+
return err
416+
}
417+
store.Close()
418+
419+
// If the version found is less than the currently configured store version,
420+
// perform a migration then write the updated version of the store.
421+
if version < storeVersion {
404422
newSlotter := newSlotterEIP7594(eip4844.LatestMaxBlobsPerBlock(p.chain.Config()))
405423
if err := billy.Migrate(billy.Options{Path: queuedir, Repair: true}, slotter, newSlotter); err != nil {
406424
return err
407425
}
426+
store, err = billy.Open(billy.Options{Path: queuedir}, newVersionSlotter(), nil)
427+
if err != nil {
428+
return err
429+
}
430+
writeSlotterVersion(store, storeVersion)
431+
store.Close()
408432
}
433+
// Set the slotter to the format now that the Osaka is active.
409434
slotter = newSlotterEIP7594(eip4844.LatestMaxBlobsPerBlock(p.chain.Config()))
410435
}
411436

412437
// Index all transactions on disk and delete anything unprocessable
413438
var fails []uint64
414439
index := func(id uint64, size uint32, blob []byte) {
440+
if len(blob) == 1 {
441+
// Skip version blob if found.
442+
return
443+
}
415444
if p.parseTransaction(id, size, blob) != nil {
416445
fails = append(fails, id)
417446
}

core/txpool/blobpool/slotter.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package blobpool
1818

19+
import "github.com/holiman/billy"
20+
1921
// newSlotter creates a helper method for the Billy datastore that returns the
2022
// individual shelf sizes used to store transactions in.
2123
//
@@ -54,3 +56,24 @@ func newSlotterEIP7594(maxBlobsPerTransaction int) func() (uint32, bool) {
5456
return slotsize, finished
5557
}
5658
}
59+
60+
// newVersionSlotter creates a slotter with a single 8 byte shelf to store
61+
// version metadata in.
62+
func newVersionSlotter() func() (uint32, bool) {
63+
return func() (size uint32, done bool) {
64+
return 8, true
65+
}
66+
}
67+
68+
// parseSlotterVersion will parse the slotter's version from a given data blob.
69+
func parseSlotterVersion(blob []byte) int {
70+
if len(blob) > 0 {
71+
return int(blob[0])
72+
}
73+
return 0
74+
}
75+
76+
// writeSlotterVersion writes the current slotter version into the store.
77+
func writeSlotterVersion(store billy.Database, version int) {
78+
store.Put([]byte{byte(version)})
79+
}

0 commit comments

Comments
 (0)