Skip to content

Commit

Permalink
feat: add relayer or tx submission update to epoch processing htable
Browse files Browse the repository at this point in the history
  • Loading branch information
anomit committed Aug 16, 2023
1 parent 1d8b1ae commit d51b74a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
36 changes: 36 additions & 0 deletions go/caching/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,42 @@ func NewRedisCache(readClient, writeClient *redis.Client) *RedisCache {
return cache
}

func (r *RedisCache) UpdateEpochProcessingStatus(ctx context.Context, projectID string, epochId int, status string, err string) error {
htable := fmt.Sprintf(redisutils.REDIS_KEY_EPOCH_STATE_ID, strconv.Itoa(epochId), datamodel.RELAYER_SEND_STATE_ID)

l := log.WithField("hash table", htable).
WithField("projectID", projectID).WithField("epochId", epochId).WithField("status", status)

transition_status_item := datamodel.SnapshotterStateUpdate{
Status: status,
Error: err,
Timestamp: time.Now().Unix(),
}
state_update := datamodel.SnapshotterEpochProcessingReportItem{
EpochID: epochId,
TransitionStatus: map[string]interface{}{
projectID: transition_status_item,
},
}
state_update_bytes, err2 := json.Marshal(state_update)

if err2 != nil {
log.WithError(err2).Error("failed to marshal state update message on relayer submission")
return err2
}
err_ := r.writeClient.HSet(
ctx,
htable,
projectID,
string(state_update_bytes),
).Err()
if err_ != nil {
l.WithError(err_).Error("failed to update epoch processing status in redis")
return err_
}
return nil
}

func (r *RedisCache) GetUnfinalizedSnapshotAtEpochID(ctx context.Context, projectID string, epochId int) (*datamodel.UnfinalizedSnapshot, error) {
key := fmt.Sprintf(redisutils.REDIS_KEY_PROJECT_UNFINALIZED_SNAPSHOT_CIDS, projectID)
snapshotCid := ""
Expand Down
14 changes: 14 additions & 0 deletions go/goutils/datamodel/data_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ const (
IncorrectSnapshotSubmission SnapshotSubmissionState = "SUBMITTED_INCORRECT_SNAPSHOT"
)

type SnapshotterStateUpdate struct {
Status string `json:"status"`
Error string `json:"error"`
Extra map[string]interface{} `json:"extra"`
Timestamp int64 `json:"timestamp"`
}

const RELAYER_SEND_STATE_ID string = "RELAYER_SEND"

type SnapshotterEpochProcessingReportItem struct {
EpochID int `json:"epochId"`
TransitionStatus map[string]interface{} `json:"transitionStatus"`
}

type SummaryProjectVerificationStatus struct {
ProjectId string `json:"projectId"`
ProjectHeight string `json:"chainHeight"`
Expand Down
1 change: 1 addition & 0 deletions go/goutils/redisutils/redis_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ const (
REDIS_KEY_TOTAL_INCORRECT_SNAPSHOT_COUNT string = "projectID:%s:totalIncorrectSnapshotCount"
REDIS_KEY_LAST_FINALIZED_EPOCH string = "projectID:%s:lastFinalizedEpoch"
REDIS_KEY_FINALIZED_SNAPSHOTS string = "projectID:%s:finalizedSnapshots"
REDIS_KEY_EPOCH_STATE_ID string = "epochID:%s:stateID:%s:processingStatus"
)
5 changes: 4 additions & 1 deletion go/payload-commit/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func (s *PayloadCommitService) HandlePayloadCommitTask(msg *datamodel.PayloadCom
"issueDetails": "Error: " + err.Error(),
"msg": "failed to submit snapshot to contract",
})
go s.redisCache.UpdateEpochProcessingStatus(context.Background(), msg.ProjectID, msg.EpochID, "failed", err.Error())

go s.redisCache.AddSnapshotterStatusReport(context.Background(), msg.EpochID, msg.ProjectID, &datamodel.SnapshotterStatusReport{
SubmittedSnapshotCid: msg.SnapshotCID,
Expand All @@ -261,6 +262,7 @@ func (s *PayloadCommitService) HandlePayloadCommitTask(msg *datamodel.PayloadCom

return err
}
go s.redisCache.UpdateEpochProcessingStatus(context.Background(), msg.ProjectID, msg.EpochID, "success", "")
} else {
// send payload commit message with signature to relayer
err = s.sendSignatureToRelayer(txPayload)
Expand All @@ -275,7 +277,7 @@ func (s *PayloadCommitService) HandlePayloadCommitTask(msg *datamodel.PayloadCom
"issueDetails": "Error: " + err.Error(),
"msg": "failed to submit snapshot to relayer",
})

go s.redisCache.UpdateEpochProcessingStatus(context.Background(), msg.ProjectID, msg.EpochID, "failed", err.Error())
go s.redisCache.AddSnapshotterStatusReport(context.Background(), msg.EpochID, msg.ProjectID, &datamodel.SnapshotterStatusReport{
SubmittedSnapshotCid: msg.SnapshotCID,
State: datamodel.MissedSnapshotSubmission,
Expand All @@ -284,6 +286,7 @@ func (s *PayloadCommitService) HandlePayloadCommitTask(msg *datamodel.PayloadCom

return err
}
go s.redisCache.UpdateEpochProcessingStatus(context.Background(), msg.ProjectID, msg.EpochID, "success", "")
}

// store unfinalized payload cid in redis
Expand Down

0 comments on commit d51b74a

Please sign in to comment.