chore: update connected on global failure
This commit is contained in:
parent
0c8ce79941
commit
9c33049b4f
|
@ -124,13 +124,13 @@ func isVMError(err error) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientWithFallback) setIsConnected(value bool) {
|
func (c *ClientWithFallback) SetIsConnected(value bool) {
|
||||||
c.IsConnectedLock.Lock()
|
c.IsConnectedLock.Lock()
|
||||||
defer c.IsConnectedLock.Unlock()
|
defer c.IsConnectedLock.Unlock()
|
||||||
c.LastCheckedAt = time.Now().Unix()
|
c.LastCheckedAt = time.Now().Unix()
|
||||||
if !value {
|
if !value {
|
||||||
c.consecutiveFailureCount += 1
|
c.consecutiveFailureCount += 1
|
||||||
if c.consecutiveFailureCount > 1 && c.IsConnected {
|
if c.IsConnected {
|
||||||
if c.WalletNotifier != nil {
|
if c.WalletNotifier != nil {
|
||||||
c.WalletNotifier(c.ChainID, "down")
|
c.WalletNotifier(c.ChainID, "down")
|
||||||
}
|
}
|
||||||
|
@ -161,12 +161,12 @@ func (c *ClientWithFallback) makeCallNoReturn(main func() error, fallback func()
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setIsConnected(true)
|
c.SetIsConnected(true)
|
||||||
resultChan <- CommandResult{}
|
resultChan <- CommandResult{}
|
||||||
return nil
|
return nil
|
||||||
}, func(err error) error {
|
}, func(err error) error {
|
||||||
if c.fallback == nil {
|
if c.fallback == nil {
|
||||||
c.setIsConnected(false)
|
c.SetIsConnected(false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ func (c *ClientWithFallback) makeCallNoReturn(main func() error, fallback func()
|
||||||
resultChan <- CommandResult{vmError: err}
|
resultChan <- CommandResult{vmError: err}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.setIsConnected(false)
|
c.SetIsConnected(false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resultChan <- CommandResult{}
|
resultChan <- CommandResult{}
|
||||||
|
@ -205,15 +205,15 @@ func (c *ClientWithFallback) makeCallSingleReturn(main func() (any, error), fall
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if toggleIsConnected {
|
if true {
|
||||||
c.setIsConnected(true)
|
c.SetIsConnected(true)
|
||||||
}
|
}
|
||||||
resultChan <- CommandResult{res1: res}
|
resultChan <- CommandResult{res1: res}
|
||||||
return nil
|
return nil
|
||||||
}, func(err error) error {
|
}, func(err error) error {
|
||||||
if c.fallback == nil {
|
if c.fallback == nil {
|
||||||
if toggleIsConnected {
|
if true {
|
||||||
c.setIsConnected(false)
|
c.SetIsConnected(false)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -224,13 +224,13 @@ func (c *ClientWithFallback) makeCallSingleReturn(main func() (any, error), fall
|
||||||
resultChan <- CommandResult{vmError: err}
|
resultChan <- CommandResult{vmError: err}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if toggleIsConnected {
|
if true {
|
||||||
c.setIsConnected(false)
|
c.SetIsConnected(false)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if toggleIsConnected {
|
if true {
|
||||||
c.setIsConnected(true)
|
c.SetIsConnected(true)
|
||||||
}
|
}
|
||||||
resultChan <- CommandResult{res1: res}
|
resultChan <- CommandResult{res1: res}
|
||||||
return nil
|
return nil
|
||||||
|
@ -259,12 +259,12 @@ func (c *ClientWithFallback) makeCallDoubleReturn(main func() (any, any, error),
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setIsConnected(true)
|
c.SetIsConnected(true)
|
||||||
resultChan <- CommandResult{res1: a, res2: b}
|
resultChan <- CommandResult{res1: a, res2: b}
|
||||||
return nil
|
return nil
|
||||||
}, func(err error) error {
|
}, func(err error) error {
|
||||||
if c.fallback == nil {
|
if c.fallback == nil {
|
||||||
c.setIsConnected(false)
|
c.SetIsConnected(false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,10 +274,10 @@ func (c *ClientWithFallback) makeCallDoubleReturn(main func() (any, any, error),
|
||||||
resultChan <- CommandResult{vmError: err}
|
resultChan <- CommandResult{vmError: err}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.setIsConnected(false)
|
c.SetIsConnected(false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setIsConnected(true)
|
c.SetIsConnected(true)
|
||||||
resultChan <- CommandResult{res1: a, res2: b}
|
resultChan <- CommandResult{res1: a, res2: b}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -204,6 +204,9 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
|
||||||
group.Add(func(parent context.Context) error {
|
group.Add(func(parent context.Context) error {
|
||||||
balances, err = r.tokenManager.GetBalancesByChain(ctx, clients, addresses, tokenAddresses)
|
balances, err = r.tokenManager.GetBalancesByChain(ctx, clients, addresses, tokenAddresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
for _, client := range clients {
|
||||||
|
client.SetIsConnected(false)
|
||||||
|
}
|
||||||
log.Info("tokenManager.GetBalancesByChain err", err)
|
log.Info("tokenManager.GetBalancesByChain err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue