From d51b74a9020571fa11a6fa9592970860f9c958c2 Mon Sep 17 00:00:00 2001 From: anomit ghosh Date: Wed, 16 Aug 2023 18:56:46 +0530 Subject: [PATCH 1/2] feat: add relayer or tx submission update to epoch processing htable --- go/caching/redis.go | 36 ++++++++++++++++++++++++++++ go/goutils/datamodel/data_model.go | 14 +++++++++++ go/goutils/redisutils/redis_keys.go | 1 + go/payload-commit/service/service.go | 5 +++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/go/caching/redis.go b/go/caching/redis.go index 80785fb..7f14dd2 100644 --- a/go/caching/redis.go +++ b/go/caching/redis.go @@ -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 := "" diff --git a/go/goutils/datamodel/data_model.go b/go/goutils/datamodel/data_model.go index ff22bca..2eec8c9 100644 --- a/go/goutils/datamodel/data_model.go +++ b/go/goutils/datamodel/data_model.go @@ -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"` diff --git a/go/goutils/redisutils/redis_keys.go b/go/goutils/redisutils/redis_keys.go index f4cdab4..ea10ca4 100644 --- a/go/goutils/redisutils/redis_keys.go +++ b/go/goutils/redisutils/redis_keys.go @@ -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" ) diff --git a/go/payload-commit/service/service.go b/go/payload-commit/service/service.go index 06f7526..0e1465a 100644 --- a/go/payload-commit/service/service.go +++ b/go/payload-commit/service/service.go @@ -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, @@ -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) @@ -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, @@ -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 From 406fdbabb9d57ed17584e2fa512760748343890d Mon Sep 17 00:00:00 2001 From: anomit ghosh Date: Wed, 16 Aug 2023 21:22:02 +0530 Subject: [PATCH 2/2] fix: epoch processing status update data model in htable entry --- go/caching/redis.go | 8 +------- go/goutils/datamodel/data_model.go | 5 ----- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/go/caching/redis.go b/go/caching/redis.go index 7f14dd2..e71b005 100644 --- a/go/caching/redis.go +++ b/go/caching/redis.go @@ -44,13 +44,7 @@ func (r *RedisCache) UpdateEpochProcessingStatus(ctx context.Context, projectID 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) + 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") diff --git a/go/goutils/datamodel/data_model.go b/go/goutils/datamodel/data_model.go index 2eec8c9..999d790 100644 --- a/go/goutils/datamodel/data_model.go +++ b/go/goutils/datamodel/data_model.go @@ -18,11 +18,6 @@ type SnapshotterStateUpdate struct { 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"`