Skip to content

Commit

Permalink
Merge pull request #41 from PowerLoom/feat/epoch-monitoring
Browse files Browse the repository at this point in the history
Record state transition: snapshot submission to relayer
  • Loading branch information
anomit authored Aug 21, 2023
2 parents 1d8b1ae + 406fdba commit 935fd4d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
30 changes: 30 additions & 0 deletions go/caching/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ 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_bytes, err2 := json.Marshal(transition_status_item)

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
9 changes: 9 additions & 0 deletions go/goutils/datamodel/data_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ 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 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 935fd4d

Please sign in to comment.