MCPcopy Create free account
hub / github.com/CPChain/chain / processSection

Method processSection

core/chain_indexer.go:329–358  ·  view source on GitHub ↗

processSection processes an entire section by calling backend functions while ensuring the continuity of the passed headers. Since the chain mutex is not held while processing, the continuity can be broken by a long reorg, in which case the function returns with an error.

(section uint64, lastHead common.Hash)

Source from the content-addressed store, hash-verified

327// held while processing, the continuity can be broken by a long reorg, in which
328// case the function returns with an error.
329func (c *ChainIndexer) processSection(section uint64, lastHead common.Hash) (common.Hash, error) {
330 c.log.Debug("Processing new chain section", "section", section)
331
332 // Reset and partial processing
333
334 if err := c.backend.Reset(section, lastHead); err != nil {
335 c.setValidSections(0)
336 return common.Hash{}, err
337 }
338
339 for number := section * c.sectionSize; number < (section+1)*c.sectionSize; number++ {
340 hash := rawdb.ReadCanonicalHash(c.chainDb, number)
341 if hash == (common.Hash{}) {
342 return common.Hash{}, fmt.Errorf("canonical block #%d unknown", number)
343 }
344 header := rawdb.ReadHeader(c.chainDb, hash, number)
345 if header == nil {
346 return common.Hash{}, fmt.Errorf("block #%d [%x…] not found", number, hash[:4])
347 } else if header.ParentHash != lastHead {
348 return common.Hash{}, fmt.Errorf("chain reorged during section processing")
349 }
350 c.backend.Process(header)
351 lastHead = header.Hash()
352 }
353 if err := c.backend.Commit(); err != nil {
354 c.log.Error("Section commit failed", "error", err)
355 return common.Hash{}, err
356 }
357 return lastHead, nil
358}
359
360// Sections returns the number of processed sections maintained by the indexer
361// and also the information about the last header indexed for potential canonical

Callers 1

updateLoopMethod · 0.95

Calls 7

setValidSectionsMethod · 0.95
DebugMethod · 0.80
ResetMethod · 0.65
ProcessMethod · 0.65
HashMethod · 0.65
CommitMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected