[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
safetyDepth *big.Int
watchNewBlocks bool
errorsCount int
}
// 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)
cancel()
if err != nil {
if c.NewError(err) {
return nil
}
return err
}
@ -720,11 +724,17 @@ func (c *controlCommand) Run(parent context.Context) error {
lastKnownEthBlocks, accountsWithoutHistory, err := c.db.GetLastKnownBlockByAddresses(c.accounts)
if err != nil {
log.Error("failed to load last head from database", "error", err)
if c.NewError(err) {
return nil
}
return err
}
fromMap, err := findFirstRanges(parent, accountsWithoutHistory, head.Number, c.client)
if err != nil {
if c.NewError(err) {
return nil
}
return err
}
@ -760,6 +770,9 @@ func (c *controlCommand) Run(parent context.Context) error {
err = cmnd.Command()(parent)
if err != nil {
if c.NewError(err) {
return nil
}
return err
}
@ -771,6 +784,9 @@ func (c *controlCommand) Run(parent context.Context) error {
}
_, err = c.LoadTransfers(parent, downloader, 40)
if err != nil {
if c.NewError(err) {
return nil
}
return err
}
@ -796,6 +812,9 @@ func (c *controlCommand) Run(parent context.Context) error {
head, err = c.client.HeaderByNumber(ctx, target)
cancel()
if err != nil {
if c.NewError(err) {
return nil
}
return err
}
@ -815,6 +834,9 @@ func (c *controlCommand) Run(parent context.Context) error {
err = cmd.Command()(parent)
if err != nil {
if c.NewError(err) {
return nil
}
log.Warn("error on running newBlocksTransfersCommand", "err", err)
return err
}
@ -830,6 +852,19 @@ func (c *controlCommand) Run(parent context.Context) error {
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 {
return FiniteCommand{
Interval: 5 * time.Second,

View File

@ -21,6 +21,8 @@ const (
EventFetchingRecentHistory EventType = "recent-history-fetching"
// EventRecentHistoryFetched emitted when fetching of lastest tx history is started
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.
@ -30,4 +32,5 @@ type Event struct {
Accounts []common.Address `json:"accounts"`
NewTransactionsPerAccount map[common.Address]int `json:"newTransactions"`
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,
safetyDepth: reorgSafetyDepth(r.chain),
watchNewBlocks: r.watchNewBlocks,
errorsCount: 0,
}
return ctl