headerchain.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package core
  17. import (
  18. crand "crypto/rand"
  19. "errors"
  20. "fmt"
  21. "math"
  22. "math/big"
  23. mrand "math/rand"
  24. "sync/atomic"
  25. "time"
  26. "github.com/ethereum/go-ethereum/common"
  27. "github.com/ethereum/go-ethereum/consensus"
  28. "github.com/ethereum/go-ethereum/core/rawdb"
  29. "github.com/ethereum/go-ethereum/core/types"
  30. "github.com/ethereum/go-ethereum/ethdb"
  31. "github.com/ethereum/go-ethereum/log"
  32. "github.com/ethereum/go-ethereum/params"
  33. lru "github.com/hashicorp/golang-lru"
  34. )
  35. const (
  36. headerCacheLimit = 512
  37. tdCacheLimit = 1024
  38. numberCacheLimit = 2048
  39. )
  40. // HeaderChain implements the basic block header chain logic that is shared by
  41. // core.BlockChain and light.LightChain. It is not usable in itself, only as
  42. // a part of either structure.
  43. //
  44. // HeaderChain is responsible for maintaining the header chain including the
  45. // header query and updating.
  46. //
  47. // The components maintained by headerchain includes: (1) total difficult
  48. // (2) header (3) block hash -> number mapping (4) canonical number -> hash mapping
  49. // and (5) head header flag.
  50. //
  51. // It is not thread safe either, the encapsulating chain structures should do
  52. // the necessary mutex locking/unlocking.
  53. type HeaderChain struct {
  54. config *params.ChainConfig
  55. chainDb ethdb.Database
  56. genesisHeader *types.Header
  57. currentHeader atomic.Value // Current head of the header chain (may be above the block chain!)
  58. currentHeaderHash common.Hash // Hash of the current head of the header chain (prevent recomputing all the time)
  59. headerCache *lru.Cache // Cache for the most recent block headers
  60. tdCache *lru.Cache // Cache for the most recent block total difficulties
  61. numberCache *lru.Cache // Cache for the most recent block numbers
  62. procInterrupt func() bool
  63. rand *mrand.Rand
  64. engine consensus.Engine
  65. }
  66. // NewHeaderChain creates a new HeaderChain structure. ProcInterrupt points
  67. // to the parent's interrupt semaphore.
  68. func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
  69. headerCache, _ := lru.New(headerCacheLimit)
  70. tdCache, _ := lru.New(tdCacheLimit)
  71. numberCache, _ := lru.New(numberCacheLimit)
  72. // Seed a fast but crypto originating random generator
  73. seed, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
  74. if err != nil {
  75. return nil, err
  76. }
  77. hc := &HeaderChain{
  78. config: config,
  79. chainDb: chainDb,
  80. headerCache: headerCache,
  81. tdCache: tdCache,
  82. numberCache: numberCache,
  83. procInterrupt: procInterrupt,
  84. rand: mrand.New(mrand.NewSource(seed.Int64())),
  85. engine: engine,
  86. }
  87. hc.genesisHeader = hc.GetHeaderByNumber(0)
  88. if hc.genesisHeader == nil {
  89. return nil, ErrNoGenesis
  90. }
  91. hc.currentHeader.Store(hc.genesisHeader)
  92. if head := rawdb.ReadHeadBlockHash(chainDb); head != (common.Hash{}) {
  93. if chead := hc.GetHeaderByHash(head); chead != nil {
  94. hc.currentHeader.Store(chead)
  95. }
  96. }
  97. hc.currentHeaderHash = hc.CurrentHeader().Hash()
  98. headHeaderGauge.Update(hc.CurrentHeader().Number.Int64())
  99. return hc, nil
  100. }
  101. // GetBlockNumber retrieves the block number belonging to the given hash
  102. // from the cache or database
  103. func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64 {
  104. if cached, ok := hc.numberCache.Get(hash); ok {
  105. number := cached.(uint64)
  106. return &number
  107. }
  108. number := rawdb.ReadHeaderNumber(hc.chainDb, hash)
  109. if number != nil {
  110. hc.numberCache.Add(hash, *number)
  111. }
  112. return number
  113. }
  114. // WriteHeader writes a header into the local chain, given that its parent is
  115. // already known. If the total difficulty of the newly inserted header becomes
  116. // greater than the current known TD, the canonical chain is re-routed.
  117. //
  118. // Note: This method is not concurrent-safe with inserting blocks simultaneously
  119. // into the chain, as side effects caused by reorganisations cannot be emulated
  120. // without the real blocks. Hence, writing headers directly should only be done
  121. // in two scenarios: pure-header mode of operation (light clients), or properly
  122. // separated header/block phases (non-archive clients).
  123. func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, err error) {
  124. // Cache some values to prevent constant recalculation
  125. var (
  126. hash = header.Hash()
  127. number = header.Number.Uint64()
  128. )
  129. // Calculate the total difficulty of the header
  130. ptd := hc.GetTd(header.ParentHash, number-1)
  131. if ptd == nil {
  132. return NonStatTy, consensus.ErrUnknownAncestor
  133. }
  134. head := hc.CurrentHeader().Number.Uint64()
  135. localTd := hc.GetTd(hc.currentHeaderHash, head)
  136. externTd := new(big.Int).Add(header.Difficulty, ptd)
  137. // Irrelevant of the canonical status, write the td and header to the database
  138. //
  139. // Note all the components of header(td, hash->number index and header) should
  140. // be written atomically.
  141. headerBatch := hc.chainDb.NewBatch()
  142. rawdb.WriteTd(headerBatch, hash, number, externTd)
  143. rawdb.WriteHeader(headerBatch, header)
  144. if err := headerBatch.Write(); err != nil {
  145. log.Crit("Failed to write header into disk", "err", err)
  146. }
  147. // If the total difficulty is higher than our known, add it to the canonical chain
  148. // Second clause in the if statement reduces the vulnerability to selfish mining.
  149. // Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf
  150. reorg := externTd.Cmp(localTd) > 0
  151. if !reorg && externTd.Cmp(localTd) == 0 {
  152. if header.Number.Uint64() < head {
  153. reorg = true
  154. } else if header.Number.Uint64() == head {
  155. reorg = mrand.Float64() < 0.5
  156. }
  157. }
  158. if reorg {
  159. // If the header can be added into canonical chain, adjust the
  160. // header chain markers(canonical indexes and head header flag).
  161. //
  162. // Note all markers should be written atomically.
  163. // Delete any canonical number assignments above the new head
  164. markerBatch := hc.chainDb.NewBatch()
  165. for i := number + 1; ; i++ {
  166. hash := rawdb.ReadCanonicalHash(hc.chainDb, i)
  167. if hash == (common.Hash{}) {
  168. break
  169. }
  170. rawdb.DeleteCanonicalHash(markerBatch, i)
  171. }
  172. // Overwrite any stale canonical number assignments
  173. var (
  174. headHash = header.ParentHash
  175. headNumber = header.Number.Uint64() - 1
  176. headHeader = hc.GetHeader(headHash, headNumber)
  177. )
  178. for rawdb.ReadCanonicalHash(hc.chainDb, headNumber) != headHash {
  179. rawdb.WriteCanonicalHash(markerBatch, headHash, headNumber)
  180. headHash = headHeader.ParentHash
  181. headNumber = headHeader.Number.Uint64() - 1
  182. headHeader = hc.GetHeader(headHash, headNumber)
  183. }
  184. // Extend the canonical chain with the new header
  185. rawdb.WriteCanonicalHash(markerBatch, hash, number)
  186. rawdb.WriteHeadHeaderHash(markerBatch, hash)
  187. if err := markerBatch.Write(); err != nil {
  188. log.Crit("Failed to write header markers into disk", "err", err)
  189. }
  190. // Last step update all in-memory head header markers
  191. hc.currentHeaderHash = hash
  192. hc.currentHeader.Store(types.CopyHeader(header))
  193. headHeaderGauge.Update(header.Number.Int64())
  194. status = CanonStatTy
  195. } else {
  196. status = SideStatTy
  197. }
  198. hc.tdCache.Add(hash, externTd)
  199. hc.headerCache.Add(hash, header)
  200. hc.numberCache.Add(hash, number)
  201. return
  202. }
  203. // WhCallback is a callback function for inserting individual headers.
  204. // A callback is used for two reasons: first, in a LightChain, status should be
  205. // processed and light chain events sent, while in a BlockChain this is not
  206. // necessary since chain events are sent after inserting blocks. Second, the
  207. // header writes should be protected by the parent chain mutex individually.
  208. type WhCallback func(*types.Header) error
  209. func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
  210. // Do a sanity check that the provided chain is actually ordered and linked
  211. for i := 1; i < len(chain); i++ {
  212. if chain[i].Number.Uint64() != chain[i-1].Number.Uint64()+1 || chain[i].ParentHash != chain[i-1].Hash() {
  213. // Chain broke ancestry, log a message (programming error) and skip insertion
  214. log.Error("Non contiguous header insert", "number", chain[i].Number, "hash", chain[i].Hash(),
  215. "parent", chain[i].ParentHash, "prevnumber", chain[i-1].Number, "prevhash", chain[i-1].Hash())
  216. return 0, fmt.Errorf("non contiguous insert: item %d is #%d [%x…], item %d is #%d [%x…] (parent [%x…])", i-1, chain[i-1].Number,
  217. chain[i-1].Hash().Bytes()[:4], i, chain[i].Number, chain[i].Hash().Bytes()[:4], chain[i].ParentHash[:4])
  218. }
  219. }
  220. // Generate the list of seal verification requests, and start the parallel verifier
  221. seals := make([]bool, len(chain))
  222. if checkFreq != 0 {
  223. // In case of checkFreq == 0 all seals are left false.
  224. for i := 0; i < len(seals)/checkFreq; i++ {
  225. index := i*checkFreq + hc.rand.Intn(checkFreq)
  226. if index >= len(seals) {
  227. index = len(seals) - 1
  228. }
  229. seals[index] = true
  230. }
  231. // Last should always be verified to avoid junk.
  232. seals[len(seals)-1] = true
  233. }
  234. abort, results := hc.engine.VerifyHeaders(hc, chain, seals)
  235. defer close(abort)
  236. // Iterate over the headers and ensure they all check out
  237. for i, header := range chain {
  238. // If the chain is terminating, stop processing blocks
  239. if hc.procInterrupt() {
  240. log.Debug("Premature abort during headers verification")
  241. return 0, errors.New("aborted")
  242. }
  243. // If the header is a banned one, straight out abort
  244. if BadHashes[header.Hash()] {
  245. return i, ErrBlacklistedHash
  246. }
  247. // Otherwise wait for headers checks and ensure they pass
  248. if err := <-results; err != nil {
  249. return i, err
  250. }
  251. }
  252. return 0, nil
  253. }
  254. // InsertHeaderChain attempts to insert the given header chain in to the local
  255. // chain, possibly creating a reorg. If an error is returned, it will return the
  256. // index number of the failing header as well an error describing what went wrong.
  257. //
  258. // The verify parameter can be used to fine tune whether nonce verification
  259. // should be done or not. The reason behind the optional check is because some
  260. // of the header retrieval mechanisms already need to verfy nonces, as well as
  261. // because nonces can be verified sparsely, not needing to check each.
  262. func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCallback, start time.Time) (int, error) {
  263. // Collect some import statistics to report on
  264. stats := struct{ processed, ignored int }{}
  265. // All headers passed verification, import them into the database
  266. for i, header := range chain {
  267. // Short circuit insertion if shutting down
  268. if hc.procInterrupt() {
  269. log.Debug("Premature abort during headers import")
  270. return i, errors.New("aborted")
  271. }
  272. // If the header's already known, skip it, otherwise store
  273. hash := header.Hash()
  274. if hc.HasHeader(hash, header.Number.Uint64()) {
  275. externTd := hc.GetTd(hash, header.Number.Uint64())
  276. localTd := hc.GetTd(hc.currentHeaderHash, hc.CurrentHeader().Number.Uint64())
  277. if externTd == nil || externTd.Cmp(localTd) <= 0 {
  278. stats.ignored++
  279. continue
  280. }
  281. }
  282. if err := writeHeader(header); err != nil {
  283. return i, err
  284. }
  285. stats.processed++
  286. }
  287. // Report some public statistics so the user has a clue what's going on
  288. last := chain[len(chain)-1]
  289. context := []interface{}{
  290. "count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
  291. "number", last.Number, "hash", last.Hash(),
  292. }
  293. if timestamp := time.Unix(int64(last.Time), 0); time.Since(timestamp) > time.Minute {
  294. context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
  295. }
  296. if stats.ignored > 0 {
  297. context = append(context, []interface{}{"ignored", stats.ignored}...)
  298. }
  299. log.Info("Imported new block headers", context...)
  300. return 0, nil
  301. }
  302. // GetBlockHashesFromHash retrieves a number of block hashes starting at a given
  303. // hash, fetching towards the genesis block.
  304. func (hc *HeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash {
  305. // Get the origin header from which to fetch
  306. header := hc.GetHeaderByHash(hash)
  307. if header == nil {
  308. return nil
  309. }
  310. // Iterate the headers until enough is collected or the genesis reached
  311. chain := make([]common.Hash, 0, max)
  312. for i := uint64(0); i < max; i++ {
  313. next := header.ParentHash
  314. if header = hc.GetHeader(next, header.Number.Uint64()-1); header == nil {
  315. break
  316. }
  317. chain = append(chain, next)
  318. if header.Number.Sign() == 0 {
  319. break
  320. }
  321. }
  322. return chain
  323. }
  324. // GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or
  325. // a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the
  326. // number of blocks to be individually checked before we reach the canonical chain.
  327. //
  328. // Note: ancestor == 0 returns the same block, 1 returns its parent and so on.
  329. func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64) {
  330. if ancestor > number {
  331. return common.Hash{}, 0
  332. }
  333. if ancestor == 1 {
  334. // in this case it is cheaper to just read the header
  335. if header := hc.GetHeader(hash, number); header != nil {
  336. return header.ParentHash, number - 1
  337. } else {
  338. return common.Hash{}, 0
  339. }
  340. }
  341. for ancestor != 0 {
  342. if rawdb.ReadCanonicalHash(hc.chainDb, number) == hash {
  343. ancestorHash := rawdb.ReadCanonicalHash(hc.chainDb, number-ancestor)
  344. if rawdb.ReadCanonicalHash(hc.chainDb, number) == hash {
  345. number -= ancestor
  346. return ancestorHash, number
  347. }
  348. }
  349. if *maxNonCanonical == 0 {
  350. return common.Hash{}, 0
  351. }
  352. *maxNonCanonical--
  353. ancestor--
  354. header := hc.GetHeader(hash, number)
  355. if header == nil {
  356. return common.Hash{}, 0
  357. }
  358. hash = header.ParentHash
  359. number--
  360. }
  361. return hash, number
  362. }
  363. // GetTd retrieves a block's total difficulty in the canonical chain from the
  364. // database by hash and number, caching it if found.
  365. func (hc *HeaderChain) GetTd(hash common.Hash, number uint64) *big.Int {
  366. // Short circuit if the td's already in the cache, retrieve otherwise
  367. if cached, ok := hc.tdCache.Get(hash); ok {
  368. return cached.(*big.Int)
  369. }
  370. td := rawdb.ReadTd(hc.chainDb, hash, number)
  371. if td == nil {
  372. return nil
  373. }
  374. // Cache the found body for next time and return
  375. hc.tdCache.Add(hash, td)
  376. return td
  377. }
  378. // GetTdByHash retrieves a block's total difficulty in the canonical chain from the
  379. // database by hash, caching it if found.
  380. func (hc *HeaderChain) GetTdByHash(hash common.Hash) *big.Int {
  381. number := hc.GetBlockNumber(hash)
  382. if number == nil {
  383. return nil
  384. }
  385. return hc.GetTd(hash, *number)
  386. }
  387. // GetHeader retrieves a block header from the database by hash and number,
  388. // caching it if found.
  389. func (hc *HeaderChain) GetHeader(hash common.Hash, number uint64) *types.Header {
  390. // Short circuit if the header's already in the cache, retrieve otherwise
  391. if header, ok := hc.headerCache.Get(hash); ok {
  392. return header.(*types.Header)
  393. }
  394. header := rawdb.ReadHeader(hc.chainDb, hash, number)
  395. if header == nil {
  396. return nil
  397. }
  398. // Cache the found header for next time and return
  399. hc.headerCache.Add(hash, header)
  400. return header
  401. }
  402. // GetHeaderByHash retrieves a block header from the database by hash, caching it if
  403. // found.
  404. func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *types.Header {
  405. number := hc.GetBlockNumber(hash)
  406. if number == nil {
  407. return nil
  408. }
  409. return hc.GetHeader(hash, *number)
  410. }
  411. // HasHeader checks if a block header is present in the database or not.
  412. // In theory, if header is present in the database, all relative components
  413. // like td and hash->number should be present too.
  414. func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool {
  415. if hc.numberCache.Contains(hash) || hc.headerCache.Contains(hash) {
  416. return true
  417. }
  418. return rawdb.HasHeader(hc.chainDb, hash, number)
  419. }
  420. // GetHeaderByNumber retrieves a block header from the database by number,
  421. // caching it (associated with its hash) if found.
  422. func (hc *HeaderChain) GetHeaderByNumber(number uint64) *types.Header {
  423. hash := rawdb.ReadCanonicalHash(hc.chainDb, number)
  424. if hash == (common.Hash{}) {
  425. return nil
  426. }
  427. return hc.GetHeader(hash, number)
  428. }
  429. func (hc *HeaderChain) GetCanonicalHash(number uint64) common.Hash {
  430. return rawdb.ReadCanonicalHash(hc.chainDb, number)
  431. }
  432. // CurrentHeader retrieves the current head header of the canonical chain. The
  433. // header is retrieved from the HeaderChain's internal cache.
  434. func (hc *HeaderChain) CurrentHeader() *types.Header {
  435. return hc.currentHeader.Load().(*types.Header)
  436. }
  437. // SetCurrentHeader sets the in-memory head header marker of the canonical chan
  438. // as the given header.
  439. func (hc *HeaderChain) SetCurrentHeader(head *types.Header) {
  440. hc.currentHeader.Store(head)
  441. hc.currentHeaderHash = head.Hash()
  442. headHeaderGauge.Update(head.Number.Int64())
  443. }
  444. type (
  445. // UpdateHeadBlocksCallback is a callback function that is called by SetHead
  446. // before head header is updated.
  447. UpdateHeadBlocksCallback func(ethdb.KeyValueWriter, *types.Header)
  448. // DeleteBlockContentCallback is a callback function that is called by SetHead
  449. // before each header is deleted.
  450. DeleteBlockContentCallback func(ethdb.KeyValueWriter, common.Hash, uint64)
  451. )
  452. // SetHead rewinds the local chain to a new head. Everything above the new head
  453. // will be deleted and the new one set.
  454. func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, delFn DeleteBlockContentCallback) {
  455. var (
  456. parentHash common.Hash
  457. batch = hc.chainDb.NewBatch()
  458. )
  459. for hdr := hc.CurrentHeader(); hdr != nil && hdr.Number.Uint64() > head; hdr = hc.CurrentHeader() {
  460. hash, num := hdr.Hash(), hdr.Number.Uint64()
  461. // Rewind block chain to new head.
  462. parent := hc.GetHeader(hdr.ParentHash, num-1)
  463. if parent == nil {
  464. parent = hc.genesisHeader
  465. }
  466. parentHash = hdr.ParentHash
  467. // Notably, since geth has the possibility for setting the head to a low
  468. // height which is even lower than ancient head.
  469. // In order to ensure that the head is always no higher than the data in
  470. // the database(ancient store or active store), we need to update head
  471. // first then remove the relative data from the database.
  472. //
  473. // Update head first(head fast block, head full block) before deleting the data.
  474. markerBatch := hc.chainDb.NewBatch()
  475. if updateFn != nil {
  476. updateFn(markerBatch, parent)
  477. }
  478. // Update head header then.
  479. rawdb.WriteHeadHeaderHash(markerBatch, parentHash)
  480. if err := markerBatch.Write(); err != nil {
  481. log.Crit("Failed to update chain markers", "error", err)
  482. }
  483. hc.currentHeader.Store(parent)
  484. hc.currentHeaderHash = parentHash
  485. headHeaderGauge.Update(parent.Number.Int64())
  486. // Remove the relative data from the database.
  487. if delFn != nil {
  488. delFn(batch, hash, num)
  489. }
  490. // Rewind header chain to new head.
  491. rawdb.DeleteHeader(batch, hash, num)
  492. rawdb.DeleteTd(batch, hash, num)
  493. rawdb.DeleteCanonicalHash(batch, num)
  494. }
  495. // Flush all accumulated deletions.
  496. if err := batch.Write(); err != nil {
  497. log.Crit("Failed to rewind block", "error", err)
  498. }
  499. // Clear out any stale content from the caches
  500. hc.headerCache.Purge()
  501. hc.tdCache.Purge()
  502. hc.numberCache.Purge()
  503. }
  504. // SetGenesis sets a new genesis block header for the chain
  505. func (hc *HeaderChain) SetGenesis(head *types.Header) {
  506. hc.genesisHeader = head
  507. }
  508. // Config retrieves the header chain's chain configuration.
  509. func (hc *HeaderChain) Config() *params.ChainConfig { return hc.config }
  510. // Engine retrieves the header chain's consensus engine.
  511. func (hc *HeaderChain) Engine() consensus.Engine { return hc.engine }
  512. // GetBlock implements consensus.ChainReader, and returns nil for every input as
  513. // a header chain does not have blocks available for retrieval.
  514. func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.Block {
  515. return nil
  516. }