mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
1d3a9983cc
* Move block interface next to pb * Update fuzz build bazel * Move interface to /proto/interface and wrapper next to generated pb * Fix fuzz build bazel * Add //proto/eth/v1alpha1/wrapper Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"github.com/prysmaticlabs/prysm/proto/interfaces"
|
|
)
|
|
|
|
// This saves a beacon block to the initial sync blocks cache.
|
|
func (s *Service) saveInitSyncBlock(r [32]byte, b interfaces.SignedBeaconBlock) {
|
|
s.initSyncBlocksLock.Lock()
|
|
defer s.initSyncBlocksLock.Unlock()
|
|
s.initSyncBlocks[r] = b
|
|
}
|
|
|
|
// This checks if a beacon block exists in the initial sync blocks cache using the root
|
|
// of the block.
|
|
func (s *Service) hasInitSyncBlock(r [32]byte) bool {
|
|
s.initSyncBlocksLock.RLock()
|
|
defer s.initSyncBlocksLock.RUnlock()
|
|
_, ok := s.initSyncBlocks[r]
|
|
return ok
|
|
}
|
|
|
|
// This retrieves a beacon block from the initial sync blocks cache using the root of
|
|
// the block.
|
|
func (s *Service) getInitSyncBlock(r [32]byte) interfaces.SignedBeaconBlock {
|
|
s.initSyncBlocksLock.RLock()
|
|
defer s.initSyncBlocksLock.RUnlock()
|
|
b := s.initSyncBlocks[r]
|
|
return b
|
|
}
|
|
|
|
// This retrieves all the beacon blocks from the initial sync blocks cache, the returned
|
|
// blocks are unordered.
|
|
func (s *Service) getInitSyncBlocks() []interfaces.SignedBeaconBlock {
|
|
s.initSyncBlocksLock.RLock()
|
|
defer s.initSyncBlocksLock.RUnlock()
|
|
|
|
blks := make([]interfaces.SignedBeaconBlock, 0, len(s.initSyncBlocks))
|
|
for _, b := range s.initSyncBlocks {
|
|
blks = append(blks, b)
|
|
}
|
|
return blks
|
|
}
|
|
|
|
// This clears out the initial sync blocks cache.
|
|
func (s *Service) clearInitSyncBlocks() {
|
|
s.initSyncBlocksLock.Lock()
|
|
defer s.initSyncBlocksLock.Unlock()
|
|
s.initSyncBlocks = make(map[[32]byte]interfaces.SignedBeaconBlock)
|
|
}
|