github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/blockchain/init_sync_process_block.go (about)

     1  package blockchain
     2  
     3  import (
     4  	"github.com/prysmaticlabs/prysm/proto/interfaces"
     5  )
     6  
     7  // This saves a beacon block to the initial sync blocks cache.
     8  func (s *Service) saveInitSyncBlock(r [32]byte, b interfaces.SignedBeaconBlock) {
     9  	s.initSyncBlocksLock.Lock()
    10  	defer s.initSyncBlocksLock.Unlock()
    11  	s.initSyncBlocks[r] = b
    12  }
    13  
    14  // This checks if a beacon block exists in the initial sync blocks cache using the root
    15  // of the block.
    16  func (s *Service) hasInitSyncBlock(r [32]byte) bool {
    17  	s.initSyncBlocksLock.RLock()
    18  	defer s.initSyncBlocksLock.RUnlock()
    19  	_, ok := s.initSyncBlocks[r]
    20  	return ok
    21  }
    22  
    23  // This retrieves a beacon block from the initial sync blocks cache using the root of
    24  // the block.
    25  func (s *Service) getInitSyncBlock(r [32]byte) interfaces.SignedBeaconBlock {
    26  	s.initSyncBlocksLock.RLock()
    27  	defer s.initSyncBlocksLock.RUnlock()
    28  	b := s.initSyncBlocks[r]
    29  	return b
    30  }
    31  
    32  // This retrieves all the beacon blocks from the initial sync blocks cache, the returned
    33  // blocks are unordered.
    34  func (s *Service) getInitSyncBlocks() []interfaces.SignedBeaconBlock {
    35  	s.initSyncBlocksLock.RLock()
    36  	defer s.initSyncBlocksLock.RUnlock()
    37  
    38  	blks := make([]interfaces.SignedBeaconBlock, 0, len(s.initSyncBlocks))
    39  	for _, b := range s.initSyncBlocks {
    40  		blks = append(blks, b)
    41  	}
    42  	return blks
    43  }
    44  
    45  // This clears out the initial sync blocks cache.
    46  func (s *Service) clearInitSyncBlocks() {
    47  	s.initSyncBlocksLock.Lock()
    48  	defer s.initSyncBlocksLock.Unlock()
    49  	s.initSyncBlocks = make(map[[32]byte]interfaces.SignedBeaconBlock)
    50  }