Skip to content

Commit

Permalink
rawdb: add Consortium snapshot to inspect db's result (axieinfinity#407)
Browse files Browse the repository at this point in the history
This commit adds the key that Consortium snapshot uses to store the value into
key-value DB to database inspect command. This helps to get storage stats of
Consortium snapshot.
  • Loading branch information
minh-bq committed Apr 2, 2024
1 parent f04c893 commit 3af1e3e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion consensus/consortium/v1/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -65,7 +66,7 @@ func newSnapshot(config *params.ConsortiumConfig, sigcache *lru.ARCCache, number

// loadSnapshot loads an existing snapshot from the database.
func loadSnapshot(config *params.ConsortiumConfig, sigcache *lru.ARCCache, db ethdb.Database, hash common.Hash) (*Snapshot, error) {
blob, err := db.Get(append([]byte("consortium-"), hash[:]...))
blob, err := db.Get(append(rawdb.ConsortiumSnapshotPrefix, hash[:]...))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/consortium/v2/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
consortiumCommon "github.com/ethereum/go-ethereum/consensus/consortium/common"
v1 "github.com/ethereum/go-ethereum/consensus/consortium/v1"
"github.com/ethereum/go-ethereum/consensus/consortium/v2/finality"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
blsCommon "github.com/ethereum/go-ethereum/crypto/bls/common"
"github.com/ethereum/go-ethereum/ethdb"
Expand Down Expand Up @@ -111,7 +112,7 @@ func (s *Snapshot) store(db ethdb.Database) error {
if err != nil {
return err
}
return db.Put(append([]byte("consortium-"), s.Hash[:]...), blob)
return db.Put(append(rawdb.ConsortiumSnapshotPrefix, s.Hash[:]...), blob)
}

// copy creates a deep copy of the snapshot.
Expand Down
4 changes: 4 additions & 0 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
preimages stat
bloomBits stat
cliqueSnaps stat
consortiumSnaps stat

// Ancient store statistics
ancientHeadersSize common.StorageSize
Expand Down Expand Up @@ -466,6 +467,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
bloomBits.Add(size)
case bytes.HasPrefix(key, []byte("clique-")) && len(key) == 7+common.HashLength:
cliqueSnaps.Add(size)
case bytes.HasPrefix(key, ConsortiumSnapshotPrefix) && len(key) == len(ConsortiumSnapshotPrefix)+common.HashLength:
consortiumSnaps.Add(size)
case bytes.HasPrefix(key, []byte("cht-")) ||
bytes.HasPrefix(key, []byte("chtIndexV2-")) ||
bytes.HasPrefix(key, []byte("chtRootV2-")): // Canonical hash trie
Expand Down Expand Up @@ -528,6 +531,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
{"Key-Value store", "Account snapshot", accountSnaps.Size(), accountSnaps.Count()},
{"Key-Value store", "Storage snapshot", storageSnaps.Size(), storageSnaps.Count()},
{"Key-Value store", "Clique snapshots", cliqueSnaps.Size(), cliqueSnaps.Count()},
{"Key-Value store", "Consortium snapshots", consortiumSnaps.Size(), consortiumSnaps.Count()},
{"Key-Value store", "Singleton metadata", metadata.Size(), metadata.Count()},
{"Ancient store", "Headers", ancientHeadersSize.String(), ancients.String()},
{"Ancient store", "Bodies", ancientBodiesSize.String(), ancients.String()},
Expand Down
2 changes: 2 additions & 0 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var (
// lastFinalityVoteKey tracks the highest finality vote
highestFinalityVoteKey = []byte("HighestFinalityVote")

ConsortiumSnapshotPrefix = []byte("consortium-") // key = ConsortiumSnapshotPrefix + block hash

// Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes).
headerPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header
headerTDSuffix = []byte("t") // headerPrefix + num (uint64 big endian) + hash + headerTDSuffix -> td
Expand Down

0 comments on commit 3af1e3e

Please sign in to comment.