2018-10-05 17:14:50 +00:00
|
|
|
package db
|
2018-09-02 16:44:03 +00:00
|
|
|
|
2019-03-03 17:31:29 +00:00
|
|
|
import (
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
|
|
)
|
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
|
|
|
|
//
|
2019-03-03 17:31:29 +00:00
|
|
|
// We store the state using the state lookup key, and
|
2018-09-02 16:44:03 +00:00
|
|
|
// 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 (
|
2019-01-30 19:48:50 +00:00
|
|
|
attestationBucket = []byte("attestation-bucket")
|
|
|
|
blockOperationsBucket = []byte("block-operations-bucket")
|
|
|
|
blockBucket = []byte("block-bucket")
|
|
|
|
mainChainBucket = []byte("main-chain-bucket")
|
2019-03-19 02:15:50 +00:00
|
|
|
histStateBucket = []byte("historical-state-bucket")
|
2019-01-30 19:48:50 +00:00
|
|
|
chainInfoBucket = []byte("chain-info")
|
2019-02-25 17:37:02 +00:00
|
|
|
validatorBucket = []byte("validator")
|
2018-10-17 06:11:24 +00:00
|
|
|
|
2019-03-07 03:02:47 +00:00
|
|
|
mainChainHeightKey = []byte("chain-height")
|
|
|
|
stateLookupKey = []byte("state")
|
|
|
|
finalizedStateLookupKey = []byte("finalized-state")
|
2019-03-13 15:12:42 +00:00
|
|
|
justifiedStateLookupKey = []byte("justified-state")
|
|
|
|
finalizedBlockLookupKey = []byte("finalized-block")
|
|
|
|
justifiedBlockLookupKey = []byte("justified-block")
|
2018-11-28 09:02:35 +00:00
|
|
|
|
|
|
|
// DB internal use
|
2019-03-27 14:24:34 +00:00
|
|
|
cleanupHistoryBucket = []byte("cleanup-history-bucket")
|
2018-09-02 16:44:03 +00:00
|
|
|
)
|
|
|
|
|
2019-02-12 03:57:00 +00:00
|
|
|
// encodeSlotNumber encodes a slot number as little-endian uint32.
|
2018-09-02 16:44:03 +00:00
|
|
|
func encodeSlotNumber(number uint64) []byte {
|
2019-01-31 02:53:58 +00:00
|
|
|
return bytesutil.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
|
2019-02-12 03:57:00 +00:00
|
|
|
// encoded as a little-endian uint32 in the byte array.
|
2018-11-21 18:00:36 +00:00
|
|
|
func decodeToSlotNumber(bytearray []byte) uint64 {
|
2019-01-31 02:53:58 +00:00
|
|
|
return bytesutil.FromBytes8(bytearray)
|
2018-11-21 18:00:36 +00:00
|
|
|
}
|