diff --git a/common/types/db.go b/common/types/db.go index fe17df0f52..5a24856fb2 100644 --- a/common/types/db.go +++ b/common/types/db.go @@ -103,7 +103,7 @@ const ( ProverTaskFailureTypeUndefined ProverTaskFailureType = iota // ProverTaskFailureTypeTimeout prover task failure of timeout ProverTaskFailureTypeTimeout - // ProverTaskFailureTypeSubmitStatusNotOk prover task failure of validated failed by coordinator + // ProverTaskFailureTypeSubmitStatusNotOk prover task failure of submit status not ok ProverTaskFailureTypeSubmitStatusNotOk // ProverTaskFailureTypeVerifiedFailed prover task failure of verified failed by coordinator ProverTaskFailureTypeVerifiedFailed diff --git a/common/version/version.go b/common/version/version.go index 1e8ac9e94b..ba1cf69c4a 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.3.7" +var tag = "v4.3.8" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/coordinator/internal/controller/cron/cleanup_challenge.go b/coordinator/internal/controller/cron/cleanup_challenge.go new file mode 100644 index 0000000000..081d19d03f --- /dev/null +++ b/coordinator/internal/controller/cron/cleanup_challenge.go @@ -0,0 +1,39 @@ +package cron + +import ( + "fmt" + "time" + + "github.com/scroll-tech/go-ethereum/log" + + "scroll-tech/common/utils" +) + +func (c *Collector) cleanupChallenge() { + defer func() { + if err := recover(); err != nil { + nerr := fmt.Errorf("clean challenge panic error:%v", err) + log.Warn(nerr.Error()) + } + }() + + ticker := time.NewTicker(time.Minute * 10) + for { + select { + case <-ticker.C: + expiredTime := utils.NowUTC().Add(time.Hour) + if err := c.challenge.DeleteExpireChallenge(c.ctx, expiredTime); err != nil { + log.Error("delete expired challenge failure", "error", err) + } + case <-c.ctx.Done(): + if c.ctx.Err() != nil { + log.Error("manager context canceled with error", "error", c.ctx.Err()) + } + return + case <-c.stopTimeoutChan: + log.Info("the coordinator run loop exit") + return + } + } + +} diff --git a/coordinator/internal/controller/cron/collect_proof.go b/coordinator/internal/controller/cron/collect_proof.go index 7bc580d6a7..7b52b61410 100644 --- a/coordinator/internal/controller/cron/collect_proof.go +++ b/coordinator/internal/controller/cron/collect_proof.go @@ -28,6 +28,7 @@ type Collector struct { proverTaskOrm *orm.ProverTask chunkOrm *orm.Chunk batchOrm *orm.Batch + challenge *orm.Challenge timeoutBatchCheckerRunTotal prometheus.Counter batchProverTaskTimeoutTotal prometheus.Counter @@ -72,6 +73,7 @@ func NewCollector(ctx context.Context, db *gorm.DB, cfg *config.Config, reg prom go c.timeoutBatchProofTask() go c.timeoutChunkProofTask() go c.checkBatchAllChunkReady() + go c.cleanupChallenge() log.Info("Start coordinator successfully.") diff --git a/coordinator/internal/orm/challenge.go b/coordinator/internal/orm/challenge.go index faf1b6b604..17d051d257 100644 --- a/coordinator/internal/orm/challenge.go +++ b/coordinator/internal/orm/challenge.go @@ -55,3 +55,14 @@ func (r *Challenge) InsertChallenge(ctx context.Context, challengeString string) return fmt.Errorf("insert challenge string affected rows more than 1") } + +// DeleteExpireChallenge delete the expire challenge +func (r *Challenge) DeleteExpireChallenge(ctx context.Context, expiredTime time.Time) error { + db := r.db.WithContext(ctx) + db = db.Model(&Challenge{}) + db = db.Where("created_at < ?", expiredTime) + if err := db.Unscoped().Delete(&Challenge{}).Error; err != nil { + return fmt.Errorf("Challenge.DeleteExpireChallenge err: %w", err) + } + return nil +}