Skip to content

Commit

Permalink
Use previously Unused bucket for Peers' storage (#1962)
Browse files Browse the repository at this point in the history
  • Loading branch information
IronGauntlets authored Jul 23, 2024
1 parent 06b2339 commit 0ea8fe1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 83 deletions.
3 changes: 1 addition & 2 deletions db/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Bucket byte
// man's bucket alternative.
const (
StateTrie Bucket = iota // state metadata (e.g., the state root)
Unused // Previously held contract storage roots and is now unused. May be reused in the future.
Peer // maps peer ID to peer multiaddresses
ContractClassHash // maps contract addresses and class hashes
ContractStorage // contract storages
Class // maps class hashes to classes
Expand All @@ -33,7 +33,6 @@ const (
BlockCommitments
Temporary // used temporarily for migrations
SchemaIntermediateState
Peer // maps peer ID to peer multiaddresses
)

// Key flattens a prefix and series of byte arrays into a single []byte.
Expand Down
152 changes: 74 additions & 78 deletions db/buckets_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ func relocateContractStorageRootKeys(txn db.Transaction, _ *utils.Network) error
// Iterate over all entries in the old bucket, copying each into memory.
// Even with millions of contracts, this shouldn't be too expensive.
oldEntries := make(map[string][]byte)
oldPrefix := db.Unused.Key()
// Previously ContractStorageRoot were stored in the Peer bucket.
oldPrefix := db.Peer.Key()
var value []byte
for it.Seek(oldPrefix); it.Valid(); it.Next() {
// Stop iterating once we're out of the old bucket.
Expand Down
4 changes: 2 additions & 2 deletions migration/migration_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestRelocateContractStorageRootKeys(t *testing.T) {
for i := 0; i < numberOfContracts; i++ {
exampleBytes := new(felt.Felt).SetUint64(uint64(i)).Bytes()
// Use exampleBytes for the key suffix (the contract address) and the value.
err := txn.Set(db.Unused.Key(exampleBytes[:]), exampleBytes[:])
err := txn.Set(db.Peer.Key(exampleBytes[:]), exampleBytes[:])
require.NoError(t, err)
}

Expand All @@ -72,7 +72,7 @@ func TestRelocateContractStorageRootKeys(t *testing.T) {
}))

// Old entry does not exist.
oldKey := db.Unused.Key(exampleBytes[:])
oldKey := db.Peer.Key(exampleBytes[:])
err := txn.Get(oldKey, func(val []byte) error { return nil })
require.ErrorIs(t, db.ErrKeyNotFound, err)
}
Expand Down

0 comments on commit 0ea8fe1

Please sign in to comment.