mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
42d93812ce
* Persist Dag * Add schema * Add new message * add mapping * Adding check to save block * Removing blocks mapping * Make changes to block processing * Change from mapping to a slice of hashes * Adding tests to core * adding more tests * Fixing service test * Add comments and fix bazel * fix lint * fix conflicts * addressing review comments * Removing references to active * fixing tests with active state * Protytype for #440: Persist blocks and latest state in DB * simplify code * removing block registry * fix test * adding block removal/iterator * Addressing review comments * Addressing comments * Adding block request * removing extra line * making vars private and adding canonical key * fix lint * splitting methods * adding more changes * lint * improving coverage * removing decodeslotnumber * Able to search for and send blocks * adding core tests * adding tests * adding documentation * addressing raul's comments * lint and gazelle * addressing yutaro's comments * improving coverage * improve coverage * improving coverage
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"encoding/binary"
|
|
)
|
|
|
|
// 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.
|
|
|
|
// The fields below define the prefixing of keys in the db.
|
|
var (
|
|
// CanonicalHeadLookupKey tracks the latest canonical head.
|
|
canonicalHeadLookupKey = []byte("latest-canonical-head")
|
|
|
|
// ActiveStateLookupKey tracks the current active state.
|
|
activeStateLookupKey = []byte("beacon-active-state")
|
|
|
|
// CrystallizedStateLookupKey tracks the current crystallized state.
|
|
crystallizedStateLookupKey = []byte("beacon-crystallized-state")
|
|
|
|
// GenesisLookupKey tracks the genesis block.
|
|
genesisLookupKey = []byte("genesis")
|
|
|
|
// Data item prefixes.
|
|
blockPrefix = []byte("block-") // blockPrefix + blockhash -> block
|
|
|
|
canonicalPrefix = []byte("canonical-") // canonicalPrefix + num(uint64 big endian) -> blockhash
|
|
)
|
|
|
|
// encodeSlotNumber encodes a slot number as big endian uint64.
|
|
func encodeSlotNumber(number uint64) []byte {
|
|
enc := make([]byte, 8)
|
|
binary.BigEndian.PutUint64(enc, number)
|
|
return enc
|
|
}
|
|
|
|
// blockKey = blockPrefix + hash.
|
|
func blockKey(hash [32]byte) []byte {
|
|
return append(blockPrefix, hash[:]...)
|
|
}
|
|
|
|
// canonicalBlockKey = canonicalPrefix + num(uint64 big endian)
|
|
func canonicalBlockKey(slotnumber uint64) []byte {
|
|
return append(canonicalPrefix, encodeSlotNumber(slotnumber)...)
|
|
}
|