prysm-pulse/beacon-chain/blockchain/chain_info.go

41 lines
1.1 KiB
Go
Raw Normal View History

Part 7 of update fork choice - chain info access (#3263) * Implemented new fork choice service and helpers * Added rest of the tests * Lint * Add back helpers test * Add benchmark tests * Add yaml driven framework tests * Reformatted to doc, helpers and metrics.go * include new getter for block * create block filters from indices * give every block index a unique bucket * construct block indices by bucket mmap * almost done save for the block filters * include block filters, need a few more small touches for fetching the proper indices by bucket * full functionality to filter by parent root * tests pass when using the same logic as attestations * todo * proper todo formatting * first minimum slot range filter * slot range filters pass * more filter criteria passing * tests passing * add todos * all block tests pass and work * rem fmt * range retrieval test * fixed test conditions * Implemented new receive block methods * Comments * Remove mark evil block * instantiate the other buckets * simplify bucket lookups * deprecate non map code * revamp to remove old index prefixes * create indices from data * create indices from data * fetch block roots by slot range * better abstractions * simpler abstractions * roots rename * comment * preston feedback * Fixed existing tests * allow blocks without parent root * Cleaned up a few things * Removed todo * Lint * Cleaned up a few things * A few functions don't need to be exported * Gaz * Fixed visibility * Review feedback * Review feedback part1 * Raul's feedback, refactored OnBlock and OnAttestation to its own file * Fixed grammar * Lint * Renamed to receive_block.go * Use time.Time * Preston's feedback, removed OnTick and Store.time * Dont have to cast it to kv * add block caching layer * runlock * lockinggg * Fixed * Avoid 2 fetches of the same data * latest votes map * Gaz * Test passes * Lint * Fixed db set up * Fixed all the tests * Gazelle * Added tests * Remove todo * remove kv * Last clean up * Last clean up Last clean up * Lint * Preston's feedback * Starting * Gazelle
2019-08-21 19:50:27 +00:00
package blockchain
import (
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
)
// ChainInfoRetriever defines a common interface for methods in blockchain service which
// directly retrieves chain head related data.
type ChainInfoRetriever interface {
FinalizedCheckpt() *ethpb.Checkpoint
HeadSlot() uint64
HeadRoot() []byte
CanonicalRoot(slot uint64) []byte
}
// FinalizedCheckpt returns the latest finalized checkpoint tracked in fork choice service.
func (c *ChainService) FinalizedCheckpt() *ethpb.Checkpoint {
return c.forkChoiceStore.FinalizedCheckpt()
}
// HeadSlot returns the slot of the head of the chain.
func (c *ChainService) HeadSlot() uint64 {
return c.headSlot
}
// HeadRoot returns the root of the head of the chain.
func (c *ChainService) HeadRoot() []byte {
c.canonicalRootsLock.RLock()
defer c.canonicalRootsLock.RUnlock()
return c.canonicalRoots[c.headSlot]
}
// CanonicalRoot returns the canonical root of a given slot.
func (c *ChainService) CanonicalRoot(slot uint64) []byte {
c.canonicalRootsLock.RLock()
defer c.canonicalRootsLock.RUnlock()
return c.canonicalRoots[slot]
}