2020-02-18 21:10:54 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
2021-07-06 15:34:05 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/proto/interfaces"
|
2020-02-18 21:10:54 +00:00
|
|
|
)
|
|
|
|
|
2020-03-30 18:04:10 +00:00
|
|
|
// This saves a beacon block to the initial sync blocks cache.
|
2021-05-26 16:19:54 +00:00
|
|
|
func (s *Service) saveInitSyncBlock(r [32]byte, b interfaces.SignedBeaconBlock) {
|
2020-03-30 18:04:10 +00:00
|
|
|
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.
|
2021-05-26 16:19:54 +00:00
|
|
|
func (s *Service) getInitSyncBlock(r [32]byte) interfaces.SignedBeaconBlock {
|
2020-03-30 18:04:10 +00:00
|
|
|
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.
|
2021-05-26 16:19:54 +00:00
|
|
|
func (s *Service) getInitSyncBlocks() []interfaces.SignedBeaconBlock {
|
2020-03-30 18:04:10 +00:00
|
|
|
s.initSyncBlocksLock.RLock()
|
|
|
|
defer s.initSyncBlocksLock.RUnlock()
|
|
|
|
|
2021-05-26 16:19:54 +00:00
|
|
|
blks := make([]interfaces.SignedBeaconBlock, 0, len(s.initSyncBlocks))
|
2020-03-30 18:04:10 +00:00
|
|
|
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()
|
2021-05-26 16:19:54 +00:00
|
|
|
s.initSyncBlocks = make(map[[32]byte]interfaces.SignedBeaconBlock)
|
2020-03-30 18:04:10 +00:00
|
|
|
}
|