[wallet] Dispatch event on tx history fetching failure

This commit is contained in:
Roman Volosovskyi 2020-12-02 11:48:18 +02:00
parent 149877a939
commit bf703254ba
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 40 additions and 1 deletions

View File

@ -1 +1 @@
0.66.0 0.66.1

View File

@ -451,6 +451,7 @@ type controlCommand struct {
feed *event.Feed feed *event.Feed
safetyDepth *big.Int safetyDepth *big.Int
watchNewBlocks bool watchNewBlocks bool
errorsCount int
} }
// run fast indexing for every accont up to canonical chain head minus safety depth. // run fast indexing for every accont up to canonical chain head minus safety depth.
@ -708,6 +709,9 @@ func (c *controlCommand) Run(parent context.Context) error {
head, err := c.client.HeaderByNumber(ctx, nil) head, err := c.client.HeaderByNumber(ctx, nil)
cancel() cancel()
if err != nil { if err != nil {
if c.NewError(err) {
return nil
}
return err return err
} }
@ -720,11 +724,17 @@ func (c *controlCommand) Run(parent context.Context) error {
lastKnownEthBlocks, accountsWithoutHistory, err := c.db.GetLastKnownBlockByAddresses(c.accounts) lastKnownEthBlocks, accountsWithoutHistory, err := c.db.GetLastKnownBlockByAddresses(c.accounts)
if err != nil { if err != nil {
log.Error("failed to load last head from database", "error", err) log.Error("failed to load last head from database", "error", err)
if c.NewError(err) {
return nil
}
return err return err
} }
fromMap, err := findFirstRanges(parent, accountsWithoutHistory, head.Number, c.client) fromMap, err := findFirstRanges(parent, accountsWithoutHistory, head.Number, c.client)
if err != nil { if err != nil {
if c.NewError(err) {
return nil
}
return err return err
} }
@ -760,6 +770,9 @@ func (c *controlCommand) Run(parent context.Context) error {
err = cmnd.Command()(parent) err = cmnd.Command()(parent)
if err != nil { if err != nil {
if c.NewError(err) {
return nil
}
return err return err
} }
@ -771,6 +784,9 @@ func (c *controlCommand) Run(parent context.Context) error {
} }
_, err = c.LoadTransfers(parent, downloader, 40) _, err = c.LoadTransfers(parent, downloader, 40)
if err != nil { if err != nil {
if c.NewError(err) {
return nil
}
return err return err
} }
@ -796,6 +812,9 @@ func (c *controlCommand) Run(parent context.Context) error {
head, err = c.client.HeaderByNumber(ctx, target) head, err = c.client.HeaderByNumber(ctx, target)
cancel() cancel()
if err != nil { if err != nil {
if c.NewError(err) {
return nil
}
return err return err
} }
@ -815,6 +834,9 @@ func (c *controlCommand) Run(parent context.Context) error {
err = cmd.Command()(parent) err = cmd.Command()(parent)
if err != nil { if err != nil {
if c.NewError(err) {
return nil
}
log.Warn("error on running newBlocksTransfersCommand", "err", err) log.Warn("error on running newBlocksTransfersCommand", "err", err)
return err return err
} }
@ -830,6 +852,19 @@ func (c *controlCommand) Run(parent context.Context) error {
return err return err
} }
func (c *controlCommand) NewError(err error) bool {
c.errorsCount++
log.Error("controlCommand error", "error", err, "counter", c.errorsCount)
if c.errorsCount >= 3 {
c.feed.Send(Event{
Type: EventFetchingHistoryError,
Message: err.Error(),
})
return true
}
return false
}
func (c *controlCommand) Command() Command { func (c *controlCommand) Command() Command {
return FiniteCommand{ return FiniteCommand{
Interval: 5 * time.Second, Interval: 5 * time.Second,

View File

@ -21,6 +21,8 @@ const (
EventFetchingRecentHistory EventType = "recent-history-fetching" EventFetchingRecentHistory EventType = "recent-history-fetching"
// EventRecentHistoryFetched emitted when fetching of lastest tx history is started // EventRecentHistoryFetched emitted when fetching of lastest tx history is started
EventRecentHistoryReady EventType = "recent-history-ready" EventRecentHistoryReady EventType = "recent-history-ready"
// EventRecentHistoryError emitted when fetching of tx history failed
EventFetchingHistoryError EventType = "fetching-history-error"
) )
// Event is a type for wallet events. // Event is a type for wallet events.
@ -30,4 +32,5 @@ type Event struct {
Accounts []common.Address `json:"accounts"` Accounts []common.Address `json:"accounts"`
NewTransactionsPerAccount map[common.Address]int `json:"newTransactions"` NewTransactionsPerAccount map[common.Address]int `json:"newTransactions"`
ERC20 bool `json:"erc20"` ERC20 bool `json:"erc20"`
Message string `json:"message"`
} }

View File

@ -102,6 +102,7 @@ func (r *Reactor) newControlCommand(accounts []common.Address) *controlCommand {
feed: r.feed, feed: r.feed,
safetyDepth: reorgSafetyDepth(r.chain), safetyDepth: reorgSafetyDepth(r.chain),
watchNewBlocks: r.watchNewBlocks, watchNewBlocks: r.watchNewBlocks,
errorsCount: 0,
} }
return ctl return ctl