insertChain injects a new blocks into the simulated chain.
(blocks types.Blocks)
| 116 | |
| 117 | // insertChain injects a new blocks into the simulated chain. |
| 118 | func (f *fetcherTester) insertChain(blocks types.Blocks) (int, error) { |
| 119 | f.lock.Lock() |
| 120 | defer f.lock.Unlock() |
| 121 | |
| 122 | for i, block := range blocks { |
| 123 | // Make sure the parent in known |
| 124 | if _, ok := f.blocks[block.ParentHash()]; !ok { |
| 125 | return i, errors.New("unknown parent") |
| 126 | } |
| 127 | // Discard any new blocks if the same height already exists |
| 128 | if block.NumberU64() <= f.blocks[f.hashes[len(f.hashes)-1]].NumberU64() { |
| 129 | return i, nil |
| 130 | } |
| 131 | // Otherwise build our current chain |
| 132 | f.hashes = append(f.hashes, block.Hash()) |
| 133 | f.blocks[block.Hash()] = block |
| 134 | } |
| 135 | return 0, nil |
| 136 | } |
| 137 | |
| 138 | // dropPeer is an emulator for the peer removal, simply accumulating the various |
| 139 | // peers dropped by the fetcher. |
no test coverage detected