mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
caf9bdbc6f
* commit initial work * checkpoint current work * gaz * checkpoint * req/resp changes * initial-sync * finally works * fix error * fix bugs * fix issue * fix issues * fix refs * tests * more text fixes * more text fixes * more text fixes * fix tests * fix tests * tests * finally fix builds * finally * comments * fix fuzz * share common library * fix * fix * add in more defensive nil checks * add in more defensive nil checks * imports * Apply suggestions from code review Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Apply suggestions from code review Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Update shared/interfaces/block_interface.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Update shared/interfaces/block_wrapper.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Update shared/interfaces/block_interface.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * imports * fix bad changes * fix * terence's review * terence's review * fmt * Update beacon-chain/rpc/beacon/blocks.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * fix tests * fix * fix all tests Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"github.com/prysmaticlabs/prysm/shared/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)
|
|
}
|