diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-12-13 22:14:33 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-12-13 22:19:45 +0800 |
commit | a59fcc33e66cf9021a5b3e30d480485ce88d7aae (patch) | |
tree | d15956ab108aebf46fe74a6409101abe8da70288 /core/headerchain.go | |
parent | f15828e901909ca348afe868defbb67095004f43 (diff) | |
download | dexon-a59fcc33e66cf9021a5b3e30d480485ce88d7aae.tar.gz dexon-a59fcc33e66cf9021a5b3e30d480485ce88d7aae.tar.zst dexon-a59fcc33e66cf9021a5b3e30d480485ce88d7aae.zip |
core: import future blocks one-by-one, enfore chain ancestry
Diffstat (limited to 'core/headerchain.go')
-rw-r--r-- | core/headerchain.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/headerchain.go b/core/headerchain.go index c53694571..ca630a4f7 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -224,6 +224,17 @@ type WhCallback func(*types.Header) error // of the header retrieval mechanisms already need to verfy nonces, as well as // because nonces can be verified sparsely, not needing to check each. func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, checkFreq int, writeHeader WhCallback) (int, error) { + // Do a sanity check that the provided chain is actually ordered and linked + for i := 1; i < len(chain); i++ { + if chain[i].Number.Uint64() != chain[i-1].Number.Uint64()+1 || chain[i].ParentHash != chain[i-1].Hash() { + // Chain broke ancestry, log a messge (programming error) and skip insertion + failure := fmt.Errorf("non contiguous insert: item %d is #%d [%x…], item %d is #%d [%x…] (parent [%x…])", + i-1, chain[i-1].Number.Uint64(), chain[i-1].Hash().Bytes()[:4], i, chain[i].Number.Uint64(), chain[i].Hash().Bytes()[:4], chain[i].ParentHash.Bytes()[:4]) + + glog.V(logger.Error).Info(failure.Error()) + return 0, failure + } + } // Collect some import statistics to report on stats := struct{ processed, ignored int }{} start := time.Now() |