MCPcopy Create free account
hub / github.com/DNAProject/DNA / newBlockPool

Function newBlockPool

consensus/vbft/block_pool.go:80–105  ·  view source on GitHub ↗
(server *Server, historyLen uint32, store *ChainStore)

Source from the content-addressed store, hash-verified

78}
79
80func newBlockPool(server *Server, historyLen uint32, store *ChainStore) (*BlockPool, error) {
81 pool := &BlockPool{
82 server: server,
83 HistoryLen: historyLen,
84 chainStore: store,
85 candidateBlocks: make(map[uint32]*CandidateInfo),
86 }
87
88 var blkNum uint32
89 if store.GetChainedBlockNum() > historyLen {
90 blkNum = store.GetChainedBlockNum() - historyLen
91 }
92
93 // load history blocks from chainstore
94 for ; blkNum <= store.GetChainedBlockNum(); blkNum++ {
95 blk, err := store.getBlock(blkNum)
96 if err != nil {
97 return nil, fmt.Errorf("failed to load block %d: %s", blkNum, err)
98 }
99 pool.candidateBlocks[blkNum] = &CandidateInfo{
100 SealedBlock: blk,
101 }
102 }
103
104 return pool, nil
105}
106
107func (pool *BlockPool) clean() {
108 pool.lock.Lock()

Callers 2

initializeMethod · 0.85
buildTestBlockPoolFunction · 0.85

Calls 3

GetChainedBlockNumMethod · 0.80
ErrorfMethod · 0.80
getBlockMethod · 0.45

Tested by 1

buildTestBlockPoolFunction · 0.68