Commit d7dfc942 authored by vicotor's avatar vicotor

fix bug for validator submit transfer

parent 0014e111
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"strings" "strings"
...@@ -33,6 +34,8 @@ type Dao struct { ...@@ -33,6 +34,8 @@ type Dao struct {
wg sync.WaitGroup wg sync.WaitGroup
handleMux sync.Mutex handleMux sync.Mutex
validatorPk *ecdsa.PrivateKey validatorPk *ecdsa.PrivateKey
failedEvent *lru.Cache[uint, bool]
} }
func New(_c *config.Config) (dao *Dao, err error) { func New(_c *config.Config) (dao *Dao, err error) {
...@@ -41,6 +44,7 @@ func New(_c *config.Config) (dao *Dao, err error) { ...@@ -41,6 +44,7 @@ func New(_c *config.Config) (dao *Dao, err error) {
chainGroup: make(map[int64]ChainInfo), chainGroup: make(map[int64]ChainInfo),
syncer: make(map[int64]ChainInterface), syncer: make(map[int64]ChainInterface),
quit: make(chan struct{}), quit: make(chan struct{}),
failedEvent: lru.NewCache[uint, bool](1000),
} }
if len(_c.OTPKeyPath) > 0 && len(_c.AesKeyPath) > 0 { if len(_c.OTPKeyPath) > 0 && len(_c.AesKeyPath) > 0 {
......
...@@ -258,16 +258,19 @@ func (d *Dao) HandleTasks() { ...@@ -258,16 +258,19 @@ func (d *Dao) HandleTasks() {
continue continue
} }
if failed, _ := d.failedEvent.Get(event.ID); failed {
if event.UpdatedAt.Compare(event.CreatedAt) > 0 && (int(time.Now().Sub(event.UpdatedAt).Seconds()) < d.c.TaskRetryInterval) { if event.UpdatedAt.Compare(event.CreatedAt) > 0 && (int(time.Now().Sub(event.UpdatedAt).Seconds()) < d.c.TaskRetryInterval) {
// skip recently failed tasks. // skip recently failed tasks.
continue continue
} }
}
if err := d.SubmitInTransfer(event); err != nil { if err := d.SubmitInTransfer(event); err != nil {
log.WithError(err).WithFields(log.Fields{ log.WithError(err).WithFields(log.Fields{
"fromChain": event.FromChain, "fromChain": event.FromChain,
"txhash": event.FromChainTxHash, "txhash": event.FromChainTxHash,
}).Error("failed to submit in transfer") }).Error("failed to submit in transfer")
d.failedEvent.Add(event.ID, true)
} else { } else {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"fromChain": event.FromChain, "fromChain": event.FromChain,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment