mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
light: nicer error handling
This commit is contained in:
parent
7a49759c3e
commit
5a37b923fa
1 changed files with 12 additions and 14 deletions
|
|
@ -156,25 +156,24 @@ func NewChtIndexer(db ethdb.Database, clientMode bool, odr OdrBackend) *core.Cha
|
||||||
func (c *ChtIndexerBackend) fetchMissingNodes(ctx context.Context, section uint64, root common.Hash) error {
|
func (c *ChtIndexerBackend) fetchMissingNodes(ctx context.Context, section uint64, root common.Hash) error {
|
||||||
batch := c.trieTable.NewBatch()
|
batch := c.trieTable.NewBatch()
|
||||||
r := &ChtRequest{ChtRoot: root, ChtNum: section - 1, BlockNum: section*c.sectionSize - 1}
|
r := &ChtRequest{ChtRoot: root, ChtNum: section - 1, BlockNum: section*c.sectionSize - 1}
|
||||||
var err error
|
|
||||||
for {
|
for {
|
||||||
err = c.odr.Retrieve(ctx, r)
|
err := c.odr.Retrieve(ctx, r)
|
||||||
if err == ErrNoPeers {
|
switch err {
|
||||||
|
case nil:
|
||||||
|
r.Proof.Store(batch)
|
||||||
|
return batch.Write()
|
||||||
|
case ErrNoPeers:
|
||||||
// if there are no peers to serve, retry later
|
// if there are no peers to serve, retry later
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
|
// stay in the loop and try again
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
r.Proof.Store(batch)
|
|
||||||
err = batch.Write()
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset implements core.ChainIndexerBackend
|
// Reset implements core.ChainIndexerBackend
|
||||||
|
|
@ -301,22 +300,21 @@ func (b *BloomTrieIndexerBackend) fetchMissingNodes(ctx context.Context, section
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r := &BloomRequest{BloomTrieRoot: root, BloomTrieNum: section - 1, BitIdx: bitIndex, SectionIdxList: []uint64{section - 1}}
|
r := &BloomRequest{BloomTrieRoot: root, BloomTrieNum: section - 1, BitIdx: bitIndex, SectionIdxList: []uint64{section - 1}}
|
||||||
var err error
|
|
||||||
for {
|
for {
|
||||||
err = b.odr.Retrieve(ctx, r)
|
if err := b.odr.Retrieve(ctx, r); err == ErrNoPeers {
|
||||||
if err == ErrNoPeers {
|
|
||||||
// if there are no peers to serve, retry later
|
// if there are no peers to serve, retry later
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
resCh <- res{nil, ctx.Err()}
|
resCh <- res{nil, ctx.Err()}
|
||||||
return
|
return
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
|
// stay in the loop and try again
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
resCh <- res{r.Proofs, err}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resCh <- res{r.Proofs, err}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue