Skip to content

Commit

Permalink
feat(coordinator): clean up challenge (#946)
Browse files Browse the repository at this point in the history
Co-authored-by: georgehao <georgehao@users.noreply.github.com>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 17, 2023
1 parent 2a54c8a commit a79992e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/types/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions coordinator/internal/controller/cron/cleanup_challenge.go
Original file line number Diff line number Diff line change
@@ -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
}
}

}
2 changes: 2 additions & 0 deletions coordinator/internal/controller/cron/collect_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")

Expand Down
11 changes: 11 additions & 0 deletions coordinator/internal/orm/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a79992e

Please sign in to comment.