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, checkFreq int)
| 1824 | // of the header retrieval mechanisms already need to verify nonces, as well as |
| 1825 | // because nonces can be verified sparsely, not needing to check each. |
| 1826 | func (bc *BlockChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) { |
| 1827 | start := time.Now() |
| 1828 | if i, err := bc.hc.ValidateHeaderChain(chain, checkFreq); err != nil { |
| 1829 | return i, err |
| 1830 | } |
| 1831 | |
| 1832 | // Make sure only one thread manipulates the chain at once |
| 1833 | bc.chainmu.Lock() |
| 1834 | defer bc.chainmu.Unlock() |
| 1835 | |
| 1836 | bc.wg.Add(1) |
| 1837 | defer bc.wg.Done() |
| 1838 | |
| 1839 | whFunc := func(header *types.Header) error { |
| 1840 | bc.mu.Lock() |
| 1841 | defer bc.mu.Unlock() |
| 1842 | |
| 1843 | _, err := bc.hc.WriteHeader(header) |
| 1844 | return err |
| 1845 | } |
| 1846 | |
| 1847 | return bc.hc.InsertHeaderChain(chain, whFunc, start) |
| 1848 | } |
| 1849 | |
| 1850 | // writeHeader writes a header into the local chain, given that its parent is |
| 1851 | // already known. If the total difficulty of the newly inserted header becomes |
nothing calls this directly
no test coverage detected