diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-09-21 20:36:29 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-10-19 15:03:09 +0800 |
commit | c33cc382b3561ca91871111933f81653bfd8532f (patch) | |
tree | 0749dd4e4ebd66efe1272ee984e4dda06b4462be /core/block_processor.go | |
parent | 92f9a3e5fa29e0f05c81b348b87cab4f7a94f0c8 (diff) | |
download | go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.tar go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.tar.gz go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.tar.bz2 go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.tar.lz go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.tar.xz go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.tar.zst go-tangerine-c33cc382b3561ca91871111933f81653bfd8532f.zip |
core: support inserting pure header chains
Diffstat (limited to 'core/block_processor.go')
-rw-r--r-- | core/block_processor.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index a07d79bcf..5dadd2a27 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -369,13 +369,26 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs vm.Logs, err error) return logs, nil } +// ValidateHeader verifies the validity of a header, relying on the database and +// POW behind the block processor. +func (sm *BlockProcessor) ValidateHeader(header *types.Header, checkPow, uncle bool) error { + // Short circuit if the header's already known or its parent missing + if sm.bc.HasHeader(header.Hash()) { + return nil + } + if parent := sm.bc.GetHeader(header.ParentHash); parent == nil { + return ParentError(header.ParentHash) + } else { + return ValidateHeader(sm.Pow, header, parent, checkPow, uncle) + } +} + // See YP section 4.3.4. "Block Header Validity" // Validates a header. Returns an error if the header is invalid. func ValidateHeader(pow pow.PoW, header *types.Header, parent *types.Header, checkPow, uncle bool) error { if big.NewInt(int64(len(header.Extra))).Cmp(params.MaximumExtraDataSize) == 1 { return fmt.Errorf("Header extra data too long (%d)", len(header.Extra)) } - if uncle { if header.Time.Cmp(common.MaxBig) == 1 { return BlockTSTooBigErr |