| 78 | } |
| 79 | |
| 80 | func 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 | |
| 107 | func (pool *BlockPool) clean() { |
| 108 | pool.lock.Lock() |