From 7216e44477a00a84710259a70f779ae50f6eb01a Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Wed, 11 Oct 2017 14:43:58 +0200 Subject: [PATCH] core, light, eth: handle errors in ChainIndexerBackend.Reset --- core/chain_indexer.go | 8 ++++++-- core/chain_indexer_test.go | 3 ++- eth/bloombits.go | 6 ++---- light/postprocess.go | 12 ++++-------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/chain_indexer.go b/core/chain_indexer.go index 278f76ef4d..a27caeed5e 100644 --- a/core/chain_indexer.go +++ b/core/chain_indexer.go @@ -36,7 +36,7 @@ import ( type ChainIndexerBackend interface { // Reset initiates the processing of a new chain segment, potentially terminating // any partially completed operations (in case of a reorg). - Reset(section uint64, lastSectionHead common.Hash) + Reset(section uint64, lastSectionHead common.Hash) error // Process crunches through the next header in the chain segment. The caller // will ensure a sequential order of headers. @@ -340,7 +340,11 @@ func (c *ChainIndexer) processSection(section uint64, lastHead common.Hash) (com c.log.Trace("Processing new chain section", "section", section) // Reset and partial processing - c.backend.Reset(section, lastHead) + + if err := c.backend.Reset(section, lastHead); err != nil { + c.setValidSections(0) + return common.Hash{}, err + } for number := section * c.sectionSize; number < (section+1)*c.sectionSize; number++ { hash := GetCanonicalHash(c.chainDb, number) diff --git a/core/chain_indexer_test.go b/core/chain_indexer_test.go index 247f52cf9e..d685d3f8da 100644 --- a/core/chain_indexer_test.go +++ b/core/chain_indexer_test.go @@ -209,9 +209,10 @@ func (b *testChainIndexBackend) reorg(headNum uint64) uint64 { return b.stored * b.indexer.sectionSize } -func (b *testChainIndexBackend) Reset(section uint64, lastSectionHead common.Hash) { +func (b *testChainIndexBackend) Reset(section uint64, lastSectionHead common.Hash) error { b.section = section b.headerCnt = 0 + return nil } func (b *testChainIndexBackend) Process(header *types.Header) { diff --git a/eth/bloombits.go b/eth/bloombits.go index cecbb761a2..c5597391c5 100644 --- a/eth/bloombits.go +++ b/eth/bloombits.go @@ -114,12 +114,10 @@ func NewBloomIndexer(db ethdb.Database, size uint64) *core.ChainIndexer { // Reset implements core.ChainIndexerBackend, starting a new bloombits index // section. -func (b *BloomIndexer) Reset(section uint64, lastSectionHead common.Hash) { +func (b *BloomIndexer) Reset(section uint64, lastSectionHead common.Hash) error { gen, err := bloombits.NewGenerator(uint(b.size)) - if err != nil { - panic(err) - } b.gen, b.section, b.head = gen, section, common.Hash{} + return err } // Process implements core.ChainIndexerBackend, adding a new header's bloom into diff --git a/light/postprocess.go b/light/postprocess.go index c9a5d27c5c..2e54b1d79f 100644 --- a/light/postprocess.go +++ b/light/postprocess.go @@ -135,17 +135,15 @@ func NewChtIndexer(db ethdb.Database, clientMode bool) *core.ChainIndexer { } // Reset implements core.ChainIndexerBackend -func (c *ChtIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) { +func (c *ChtIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) error { var root common.Hash if section > 0 { root = GetChtRoot(c.db, section-1, lastSectionHead) } var err error c.trie, err = trie.New(root, c.cdb) - if err != nil { - panic(err) - } c.section = section + return err } // Process implements core.ChainIndexerBackend @@ -232,17 +230,15 @@ func NewBloomTrieIndexer(db ethdb.Database, clientMode bool) *core.ChainIndexer } // Reset implements core.ChainIndexerBackend -func (b *BloomTrieIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) { +func (b *BloomTrieIndexerBackend) Reset(section uint64, lastSectionHead common.Hash) error { var root common.Hash if section > 0 { root = GetBloomTrieRoot(b.db, section-1, lastSectionHead) } var err error b.trie, err = trie.New(root, b.cdb) - if err != nil { - panic(err) - } b.section = section + return err } // Process implements core.ChainIndexerBackend