-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:add filter for dispute games, fix:sync process event error
- Loading branch information
Showing
8 changed files
with
101 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package handler | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/optimism-java/dispute-explorer/internal/schema" | ||
"github.com/optimism-java/dispute-explorer/internal/svc" | ||
"github.com/optimism-java/dispute-explorer/pkg/log" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// SyncClaimDataLen Compensation processing historical data | ||
func SyncClaimDataLen(ctx *svc.ServiceContext) { | ||
for { | ||
var disputeGames []schema.DisputeGame | ||
err := ctx.DB.Where("get_len_status = ? and status != ?", | ||
false, schema.DisputeGameStatusInProgress).Order("block_number").Limit(50).Find(&disputeGames).Error | ||
if err != nil { | ||
time.Sleep(3 * time.Second) | ||
continue | ||
} | ||
if len(disputeGames) == 0 { | ||
log.Infof("[Handler.SyncClaimDataLen] Pending games count is 0\n") | ||
time.Sleep(2 * time.Second) | ||
continue | ||
} | ||
|
||
for _, disputeGame := range disputeGames { | ||
var claimDataLen int64 | ||
ctx.DB.Model(schema.GameClaimData{}).Where("game_contract = ? and on_chain_status = ?", | ||
disputeGame.GameContract, schema.GameClaimDataOnChainStatusValid).Count(&claimDataLen) | ||
|
||
disputeGame.ClaimDataLen = claimDataLen | ||
disputeGame.GetLenStatus = true | ||
|
||
err := ctx.DB.Save(disputeGame).Error | ||
if err != nil { | ||
log.Errorf("[Handler.SyncClaimDataLen] update claim len err", errors.WithStack(err)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
migration/version/v7/add_claim_data_len_for_dispute_game.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package v7 | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
var AddClaimDataLenForDisputeGameTable = gormigrate.Migration{ | ||
ID: "v7", | ||
Migrate: func(tx *gorm.DB) error { | ||
type DisputeGame struct { | ||
ClaimDataLen int64 `json:"claim_data_len" gorm:"type:bigint;notnull;index:dispute_claim_data_len_index;default:1"` | ||
GetLenStatus bool `json:"get_len_status" gorm:"type:tinyint(1);notnull;default:0"` | ||
} | ||
return tx.Table("dispute_game").AutoMigrate(&DisputeGame{}) | ||
}, | ||
Rollback: func(db *gorm.DB) error { | ||
err := db.Migrator().DropColumn("dispute_game", "claim_data_len") | ||
if err != nil { | ||
return err | ||
} | ||
err = db.Migrator().DropColumn("dispute_game", "get_len_status") | ||
return err | ||
}, | ||
} |