prysm-pulse/beacon-chain/db/schema.go
Nishant Das 6d69ac1abd
Add State Generator (#1718)
* add finalized function

* add functions

* gazelle

* add separate package for import cycles

* main tests are passing

* add finalized state test

* add block test

* fix tests and gazelle

* lint

* build file

* remove package

* remove unecessary method

* visibility

* remove package

* comments

* final comments

* imports spacing

* goimports
2019-03-07 11:02:47 +08:00

44 lines
1.4 KiB
Go

package db
import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
// 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 state using the state lookup key, and
// also the genesis block using the genesis lookup key.
// The canonical head is stored using the canonical head lookup key.
// The fields below define the suffix of keys in the db.
var (
attestationBucket = []byte("attestation-bucket")
blockOperationsBucket = []byte("block-operations-bucket")
blockBucket = []byte("block-bucket")
mainChainBucket = []byte("main-chain-bucket")
chainInfoBucket = []byte("chain-info")
validatorBucket = []byte("validator")
mainChainHeightKey = []byte("chain-height")
stateLookupKey = []byte("state")
finalizedStateLookupKey = []byte("finalized-state")
// DB internal use
cleanupHistoryBucket = []byte("cleanup-history-bucket")
cleanedFinalizedSlotKey = []byte("cleaned-finalized-slot")
)
// encodeSlotNumber encodes a slot number as little-endian uint32.
func encodeSlotNumber(number uint64) []byte {
return bytesutil.Bytes8(number)
}
// decodeSlotNumber returns a slot number which has been
// encoded as a little-endian uint32 in the byte array.
func decodeToSlotNumber(bytearray []byte) uint64 {
return bytesutil.FromBytes8(bytearray)
}