Skip to content

Commit

Permalink
Ignore chain indexer errors in CeloLatestSync mode (ethereum#97)
Browse files Browse the repository at this point in the history
Chain indexers assume a continuous chain of headers which we don't have
in CeloLatestSync mode. Therefore, ignore these noisy errors in the
CeloLatestSync mode.

This is how the errors currently look like

ERROR[11-14|20:00:48.193] Section processing failed                type=cht       error="canonical block ethereum#1 unknown"
ERROR[11-14|20:00:48.195] Section processing failed                type=bloombits error="canonical block ethereum#1 unknown"
  • Loading branch information
ashishb authored Nov 28, 2018
1 parent f7b9d1f commit 4ce492d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 26 deletions.
Binary file modified build/bin/geth.aar
Binary file not shown.
26 changes: 16 additions & 10 deletions core/chain_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,25 @@ type ChainIndexer struct {

log log.Logger
lock sync.RWMutex
// True in all sync modes except CeloLatestSync.
fullChainDownloaded bool
}

// NewChainIndexer creates a new chain indexer to do background processing on
// chain segments of a given size after certain number of confirmations passed.
// The throttling parameter might be used to prevent database thrashing.
func NewChainIndexer(chainDb, indexDb ethdb.Database, backend ChainIndexerBackend, section, confirm uint64, throttling time.Duration, kind string) *ChainIndexer {
func NewChainIndexer(chainDb, indexDb ethdb.Database, backend ChainIndexerBackend, section, confirm uint64, throttling time.Duration, kind string, fullChainDownloaded bool) *ChainIndexer {
c := &ChainIndexer{
chainDb: chainDb,
indexDb: indexDb,
backend: backend,
update: make(chan struct{}, 1),
quit: make(chan chan error),
sectionSize: section,
confirmsReq: confirm,
throttling: throttling,
log: log.New("type", kind),
chainDb: chainDb,
indexDb: indexDb,
backend: backend,
update: make(chan struct{}, 1),
quit: make(chan chan error),
sectionSize: section,
confirmsReq: confirm,
throttling: throttling,
log: log.New("type", kind),
fullChainDownloaded: fullChainDownloaded,
}
// Initialize database dependent fields and start the updater
c.loadValidSections()
Expand Down Expand Up @@ -392,6 +395,9 @@ func (c *ChainIndexer) processSection(section uint64, lastHead common.Hash) (com
for number := section * c.sectionSize; number < (section+1)*c.sectionSize; number++ {
hash := rawdb.ReadCanonicalHash(c.chainDb, number)
if hash == (common.Hash{}) {
if !c.fullChainDownloaded {
return lastHead, nil
}
return common.Hash{}, fmt.Errorf("canonical block #%d unknown", number)
}
header := rawdb.ReadHeader(c.chainDb, hash, number)
Expand Down
2 changes: 1 addition & 1 deletion core/chain_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func testChainIndexer(t *testing.T, count int) {
confirmsReq = uint64(rand.Intn(10))
)
backends[i] = &testChainIndexBackend{t: t, processCh: make(chan uint64)}
backends[i].indexer = NewChainIndexer(db, ethdb.NewTable(db, string([]byte{byte(i)})), backends[i], sectionSize, confirmsReq, 0, fmt.Sprintf("indexer-%d", i))
backends[i].indexer = NewChainIndexer(db, ethdb.NewTable(db, string([]byte{byte(i)})), backends[i], sectionSize, confirmsReq, 0, fmt.Sprintf("indexer-%d", i), true)

if sections, _, _ := backends[i].indexer.Sections(); sections != 0 {
t.Fatalf("Canonical section count mismatch: have %v, want %v", sections, 0)
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
gasPrice: config.MinerGasPrice,
etherbase: config.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms, config.SyncMode != downloader.CeloLatestSync),
}

log.Info("Initialising Ethereum protocol", "versions", ProtocolVersions, "network", config.NetworkId)
Expand Down
4 changes: 2 additions & 2 deletions eth/bloombits.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ type BloomIndexer struct {

// NewBloomIndexer returns a chain indexer that generates bloom bits data for the
// canonical chain for fast logs filtering.
func NewBloomIndexer(db ethdb.Database, size, confirms uint64) *core.ChainIndexer {
func NewBloomIndexer(db ethdb.Database, size, confirms uint64, fullChainAvailable bool) *core.ChainIndexer {
backend := &BloomIndexer{
db: db,
size: size,
}
table := ethdb.NewTable(db, string(rawdb.BloomBitsIndexPrefix))

return core.NewChainIndexer(db, table, backend, size, confirms, bloomThrottling, "bloombits")
return core.NewChainIndexer(db, table, backend, size, confirms, bloomThrottling, "bloombits", fullChainAvailable)
}

// Reset implements core.ChainIndexerBackend, starting a new bloombits index
Expand Down
9 changes: 6 additions & 3 deletions les/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ type LightEthereum struct {
func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
var chainName string
syncMode := config.SyncMode
var fullChainAvailable bool
if syncMode == downloader.LightSync {
chainName = "lightchaindata"
fullChainAvailable = true
} else if syncMode == downloader.CeloLatestSync {
chainName = "celolatestchaindata"
fullChainAvailable = false
} else {
panic("Unexpected sync mode: " + syncMode.String())
}
Expand Down Expand Up @@ -115,16 +118,16 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
shutdownChan: make(chan bool),
networkId: config.NetworkId,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: eth.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
bloomIndexer: eth.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations, fullChainAvailable),
}

leth.relay = NewLesTxRelay(peers, leth.reqDist)
leth.serverPool = newServerPool(chainDb, quitSync, &leth.wg)
leth.retriever = newRetrieveManager(peers, leth.reqDist, leth.serverPool)

leth.odr = NewLesOdr(chainDb, light.DefaultClientIndexerConfig, leth.retriever)
leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequencyClient, params.HelperTrieConfirmations)
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency)
leth.chtIndexer = light.NewChtIndexer(chainDb, leth.odr, params.CHTFrequencyClient, params.HelperTrieConfirmations, fullChainAvailable)
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency, fullChainAvailable)
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)

// Note: NewLightChain adds the trusted checkpoint so it needs an ODR with
Expand Down
6 changes: 3 additions & 3 deletions les/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func testChainGen(i int, block *core.BlockGen) {

// testIndexers creates a set of indexers with specified params for testing purpose.
func testIndexers(db ethdb.Database, odr light.OdrBackend, iConfig *light.IndexerConfig) (*core.ChainIndexer, *core.ChainIndexer, *core.ChainIndexer) {
chtIndexer := light.NewChtIndexer(db, odr, iConfig.ChtSize, iConfig.ChtConfirms)
bloomIndexer := eth.NewBloomIndexer(db, iConfig.BloomSize, iConfig.BloomConfirms)
bloomTrieIndexer := light.NewBloomTrieIndexer(db, odr, iConfig.BloomSize, iConfig.BloomTrieSize)
chtIndexer := light.NewChtIndexer(db, odr, iConfig.ChtSize, iConfig.ChtConfirms, true)
bloomIndexer := eth.NewBloomIndexer(db, iConfig.BloomSize, iConfig.BloomConfirms, true)
bloomTrieIndexer := light.NewBloomTrieIndexer(db, odr, iConfig.BloomSize, iConfig.BloomTrieSize, true)
bloomIndexer.AddChildIndexer(bloomTrieIndexer)
return chtIndexer, bloomIndexer, bloomTrieIndexer
}
Expand Down
4 changes: 2 additions & 2 deletions les/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
config: config,
chainDb: eth.ChainDb(),
iConfig: light.DefaultServerIndexerConfig,
chtIndexer: light.NewChtIndexer(eth.ChainDb(), nil, params.CHTFrequencyServer, params.HelperTrieProcessConfirmations),
bloomTrieIndexer: light.NewBloomTrieIndexer(eth.ChainDb(), nil, params.BloomBitsBlocks, params.BloomTrieFrequency),
chtIndexer: light.NewChtIndexer(eth.ChainDb(), nil, params.CHTFrequencyServer, params.HelperTrieProcessConfirmations, true),
bloomTrieIndexer: light.NewBloomTrieIndexer(eth.ChainDb(), nil, params.BloomBitsBlocks, params.BloomTrieFrequency, true),
protocolManager: pm,
},
quitSync: quitSync,
Expand Down
8 changes: 4 additions & 4 deletions light/postprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type ChtIndexerBackend struct {
}

// NewChtIndexer creates a Cht chain indexer
func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64) *core.ChainIndexer {
func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64, fullChainAvailable bool) *core.ChainIndexer {
trieTable := ethdb.NewTable(db, ChtTablePrefix)
backend := &ChtIndexerBackend{
diskdb: db,
Expand All @@ -162,7 +162,7 @@ func NewChtIndexer(db ethdb.Database, odr OdrBackend, size, confirms uint64) *co
triedb: trie.NewDatabase(trieTable),
sectionSize: size,
}
return core.NewChainIndexer(db, ethdb.NewTable(db, "chtIndex-"), backend, size, confirms, time.Millisecond*100, "cht")
return core.NewChainIndexer(db, ethdb.NewTable(db, "chtIndex-"), backend, size, confirms, time.Millisecond*100, "cht", fullChainAvailable)
}

// fetchMissingNodes tries to retrieve the last entry of the latest trusted CHT from the
Expand Down Expand Up @@ -275,7 +275,7 @@ type BloomTrieIndexerBackend struct {
}

// NewBloomTrieIndexer creates a BloomTrie chain indexer
func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uint64) *core.ChainIndexer {
func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uint64, fullChainAvailable bool) *core.ChainIndexer {
trieTable := ethdb.NewTable(db, BloomTrieTablePrefix)
backend := &BloomTrieIndexerBackend{
diskdb: db,
Expand All @@ -287,7 +287,7 @@ func NewBloomTrieIndexer(db ethdb.Database, odr OdrBackend, parentSize, size uin
}
backend.bloomTrieRatio = size / parentSize
backend.sectionHeads = make([]common.Hash, backend.bloomTrieRatio)
return core.NewChainIndexer(db, ethdb.NewTable(db, "bltIndex-"), backend, size, 0, time.Millisecond*100, "bloomtrie")
return core.NewChainIndexer(db, ethdb.NewTable(db, "bltIndex-"), backend, size, 0, time.Millisecond*100, "bloomtrie", fullChainAvailable)
}

// fetchMissingNodes tries to retrieve the last entries of the latest trusted bloom trie from the
Expand Down

0 comments on commit 4ce492d

Please sign in to comment.