2018-10-05 17:14:50 +00:00
|
|
|
package db
|
2018-09-02 16:44:03 +00:00
|
|
|
|
|
|
|
import (
|
2018-11-08 16:52:51 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytes"
|
2018-09-02 16:44:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// The Schema will define how to store and retrieve data from the db.
|
|
|
|
// Currently we store blocks by prefixing `block` to their hash and
|
|
|
|
// using that as the key to store blocks.
|
|
|
|
// `block` + hash -> block
|
|
|
|
//
|
|
|
|
// We store the crystallized state using the crystallized state lookup key, and
|
|
|
|
// also the genesis block using the genesis lookup key.
|
|
|
|
// The canonical head is stored using the canonical head lookup key.
|
|
|
|
|
2018-09-14 05:07:30 +00:00
|
|
|
// The fields below define the suffix of keys in the db.
|
2018-09-02 16:44:03 +00:00
|
|
|
var (
|
2018-11-11 16:54:17 +00:00
|
|
|
attestationBucket = []byte("attestation-bucket")
|
|
|
|
blockBucket = []byte("block-bucket")
|
|
|
|
mainChainBucket = []byte("main-chain-bucket")
|
|
|
|
chainInfoBucket = []byte("chain-info")
|
|
|
|
blockVoteCacheBucket = []byte("block-vote-cache")
|
2018-10-17 06:11:24 +00:00
|
|
|
|
|
|
|
mainChainHeightKey = []byte("chain-height")
|
2018-12-01 22:09:12 +00:00
|
|
|
stateLookupKey = []byte("state")
|
2018-11-28 09:02:35 +00:00
|
|
|
|
|
|
|
// DB internal use
|
|
|
|
cleanupHistoryBucket = []byte("cleanup-history-bucket")
|
|
|
|
cleanedFinalizedSlotKey = []byte("cleaned-finalized-slot")
|
2018-09-02 16:44:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// encodeSlotNumber encodes a slot number as big endian uint64.
|
|
|
|
func encodeSlotNumber(number uint64) []byte {
|
2018-11-08 16:52:51 +00:00
|
|
|
return bytes.Bytes8(number)
|
2018-09-02 16:44:03 +00:00
|
|
|
}
|
2018-11-21 18:00:36 +00:00
|
|
|
|
|
|
|
// decodeSlotNumber returns a slot number which has been
|
|
|
|
// encoded as a big endian uint64 in the byte array.
|
|
|
|
func decodeToSlotNumber(bytearray []byte) uint64 {
|
|
|
|
return bytes.FromBytes8(bytearray)
|
|
|
|
}
|