InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong. The verify parameter can be used to fine tune whether nonce verif
(chain []*types.Header, writeHeader WhCallback, start time.Time)
| 252 | // of the header retrieval mechanisms already need to verfy nonces, as well as |
| 253 | // because nonces can be verified sparsely, not needing to check each. |
| 254 | func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCallback, start time.Time) (int, error) { |
| 255 | // Collect some import statistics to report on |
| 256 | stats := struct{ processed, ignored int }{} |
| 257 | // All headers passed verification, import them into the database |
| 258 | for i, header := range chain { |
| 259 | // Short circuit insertion if shutting down |
| 260 | if hc.procInterrupt() { |
| 261 | log.Debug("Premature abort during headers import") |
| 262 | return i, errors.New("aborted") |
| 263 | } |
| 264 | // If the header's already known, skip it, otherwise store |
| 265 | if hc.HasHeader(header.Hash(), header.Number.Uint64()) { |
| 266 | stats.ignored++ |
| 267 | continue |
| 268 | } |
| 269 | if err := writeHeader(header); err != nil { |
| 270 | return i, err |
| 271 | } |
| 272 | stats.processed++ |
| 273 | } |
| 274 | // Report some public statistics so the user has a clue what's going on |
| 275 | last := chain[len(chain)-1] |
| 276 | log.Info("Imported new block headers", "count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)), |
| 277 | "number", last.Number, "hash", last.Hash(), "ignored", stats.ignored) |
| 278 | |
| 279 | return 0, nil |
| 280 | } |
| 281 | |
| 282 | // GetBlockHashesFromHash retrieves a number of block hashes starting at a given |
| 283 | // hash, fetching towards the genesis block. |