Skip to content

Commit c33cc38

Browse files
committed
core: support inserting pure header chains
1 parent 92f9a3e commit c33cc38

9 files changed

Lines changed: 651 additions & 346 deletions

File tree

‎core/block_processor.go‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,26 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs vm.Logs, err error)
369369
return logs, nil
370370
}
371371

372+
// ValidateHeader verifies the validity of a header, relying on the database and
373+
// POW behind the block processor.
374+
func (sm *BlockProcessor) ValidateHeader(header *types.Header, checkPow, uncle bool) error {
375+
// Short circuit if the header's already known or its parent missing
376+
if sm.bc.HasHeader(header.Hash()) {
377+
return nil
378+
}
379+
if parent := sm.bc.GetHeader(header.ParentHash); parent == nil {
380+
return ParentError(header.ParentHash)
381+
} else {
382+
return ValidateHeader(sm.Pow, header, parent, checkPow, uncle)
383+
}
384+
}
385+
372386
// See YP section 4.3.4. "Block Header Validity"
373387
// Validates a header. Returns an error if the header is invalid.
374388
func ValidateHeader(pow pow.PoW, header *types.Header, parent *types.Header, checkPow, uncle bool) error {
375389
if big.NewInt(int64(len(header.Extra))).Cmp(params.MaximumExtraDataSize) == 1 {
376390
return fmt.Errorf("Header extra data too long (%d)", len(header.Extra))
377391
}
378-
379392
if uncle {
380393
if header.Time.Cmp(common.MaxBig) == 1 {
381394
return BlockTSTooBigErr

0 commit comments

Comments
 (0)