Skip to content

Commit

Permalink
fix: use non-overlapping DB prefix for L1 messages (#532)
Browse files Browse the repository at this point in the history
* fix: use non-overlapping db prefix for L1 messages

* bump version
  • Loading branch information
Thegaram authored Oct 4, 2023
1 parent fea7d94 commit 68697b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
}
}

// set db prefix for backward-compatibility
if cfg.NetworkId == 534351 {
log.Warn("Using legacy db prefix for L1 messages")
rawdb.SetL1MessageLegacyPrefix()
}
}

// SetDNSDiscoveryDefaults configures DNS discovery with the given URL if
Expand Down
4 changes: 4 additions & 0 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
bloomBits stat
cliqueSnaps stat
l1Messages stat
l1MessagesOld stat
lastL1Message stat

// Ancient store statistics
Expand Down Expand Up @@ -386,6 +387,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
cliqueSnaps.Add(size)
case bytes.HasPrefix(key, l1MessagePrefix) && len(key) == len(l1MessagePrefix)+8:
l1Messages.Add(size)
case bytes.HasPrefix(key, l1MessageLegacyPrefix) && len(key) == len(l1MessageLegacyPrefix)+8:
l1MessagesOld.Add(size)
case bytes.HasPrefix(key, firstQueueIndexNotInL2BlockPrefix) && len(key) == len(firstQueueIndexNotInL2BlockPrefix)+common.HashLength:
lastL1Message.Add(size)
case bytes.HasPrefix(key, []byte("cht-")) ||
Expand Down Expand Up @@ -451,6 +454,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
{"Key-Value store", "Clique snapshots", cliqueSnaps.Size(), cliqueSnaps.Count()},
{"Key-Value store", "Singleton metadata", metadata.Size(), metadata.Count()},
{"Key-Value store", "L1 messages", l1Messages.Size(), l1Messages.Count()},
{"Key-Value store", "L1 messages (legacy prefix)", l1MessagesOld.Size(), l1MessagesOld.Count()},
{"Key-Value store", "Last L1 message", lastL1Message.Size(), lastL1Message.Count()},
{"Ancient store", "Headers", ancientHeadersSize.String(), ancients.String()},
{"Ancient store", "Bodies", ancientBodiesSize.String(), ancients.String()},
Expand Down
10 changes: 9 additions & 1 deletion core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ var (

// Scroll L1 message store
syncedL1BlockNumberKey = []byte("LastSyncedL1BlockNumber")
l1MessagePrefix = []byte("l1") // l1MessagePrefix + queueIndex (uint64 big endian) -> L1MessageTx
l1MessageLegacyPrefix = []byte("l1")
l1MessagePrefix = []byte("L1") // l1MessagePrefix + queueIndex (uint64 big endian) -> L1MessageTx
firstQueueIndexNotInL2BlockPrefix = []byte("q") // firstQueueIndexNotInL2BlockPrefix + L2 block hash -> enqueue index
highestSyncedQueueIndexKey = []byte("HighestSyncedQueueIndex")

Expand All @@ -118,6 +119,13 @@ var (
skippedTransactionHashPrefix = []byte("sh") // skippedTransactionHashPrefix + index -> tx hash
)

// Use the updated "L1" prefix on all new networks
// to avoid overlap with txLookupPrefix.
// Use the legacy "l1" prefix on Scroll Sepolia.
func SetL1MessageLegacyPrefix() {
l1MessagePrefix = l1MessageLegacyPrefix
}

const (
// freezerHeaderTable indicates the name of the freezer header table.
freezerHeaderTable = "headers"
Expand Down
4 changes: 2 additions & 2 deletions params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

const (
VersionMajor = 4 // Major version component of the current release
VersionMinor = 4 // Minor version component of the current release
VersionPatch = 19 // Patch version component of the current release
VersionMinor = 5 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionMeta = "sepolia" // Version metadata to append to the version string
)

Expand Down

0 comments on commit 68697b0

Please sign in to comment.