prysm-pulse/beacon-chain/db/schema.go
Raul Jordan a4128f691b
Refactor DB Package to Enable Multiple Blocks/States at Slots (#2540)
* prefixed blocks blocked

* db refactor

* new historical state saving

* builds but tests fail

* more tests pass

* fix tests

* fix tests

* delete buf

* Update beacon-chain/db/block.go

Co-Authored-By: rauljordan <raul@prysmaticlabs.com>

* Update beacon-chain/db/block.go

Co-Authored-By: rauljordan <raul@prysmaticlabs.com>

* rem unused
2019-05-09 10:42:12 -05:00

53 lines
1.8 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")
attestationTargetBucket = []byte("attestation-target-bucket")
blockOperationsBucket = []byte("block-operations-bucket")
blockBucket = []byte("block-bucket")
mainChainBucket = []byte("main-chain-bucket")
histStateBucket = []byte("historical-state-bucket")
chainInfoBucket = []byte("chain-info")
validatorBucket = []byte("validator")
mainChainHeightKey = []byte("chain-height")
canonicalHeadKey = []byte("canonical-head")
stateLookupKey = []byte("state")
finalizedStateLookupKey = []byte("finalized-state")
justifiedStateLookupKey = []byte("justified-state")
finalizedBlockLookupKey = []byte("finalized-block")
justifiedBlockLookupKey = []byte("justified-block")
// DB internal use
cleanupHistoryBucket = []byte("cleanup-history-bucket")
)
func encodeSlotNumberRoot(number uint64, root [32]byte) []byte {
return append(bytesutil.Bytes8(number), root[:]...)
}
// 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)
}