Skip to content

Commit

Permalink
[PSL-1054] refactor process-self-healing worker
Browse files Browse the repository at this point in the history
  • Loading branch information
j-rafique committed Dec 8, 2023
1 parent a7d4ffd commit dced978
Show file tree
Hide file tree
Showing 11 changed files with 718 additions and 633 deletions.
62 changes: 46 additions & 16 deletions common/types/self_healing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
SelfHealingChallengeMessage SelfHealingMessageType = iota + 1
//SelfHealingResponseMessage represents the response message
SelfHealingResponseMessage

SelfHealingVerificationMessage
)

// TicketType represents the type of ticket; nft, cascade, sense
Expand Down Expand Up @@ -58,33 +60,61 @@ type SelfHealingMessage struct {

// SelfHealingMessageData represents the self-healing message data
type SelfHealingMessageData struct {
ChallengerID string `json:"challenger_id"`
RecipientID string `json:"recipient_id"`
Challenge SelfHealingChallengeData `json:"challenge"`
Response SelfHealingResponseData `json:"response"`
ChallengerID string `json:"challenger_id"`
RecipientID string `json:"recipient_id"`
Challenge SelfHealingChallengeData `json:"challenge"`
Response SelfHealingResponseData `json:"response"`
Verification SelfHealingVerificationData `json:"verification"`
}

// SelfHealingChallengeData represents the challenge data for self-healing sent by the challenger
type SelfHealingChallengeData struct {
Block int32 `json:"block"`
Merkelroot string `json:"merkelroot"`
Timestamp time.Time `json:"timestamp"`
Tickets []Ticket `json:"tickets"`
Block int32 `json:"block"`
Merkelroot string `json:"merkelroot"`
Timestamp time.Time `json:"timestamp"`
ChallengeTickets []ChallengeTicket `json:"challenge_tickets"`
}

// ChallengeTicket represents the ticket details for self-healing challenge
type ChallengeTicket struct {
TxID string `json:"tx_id"`
TicketType TicketType `json:"ticket_type"`
MissingKeys []string `json:"missing_keys"`
DataHash string `json:"data_hash"`
}

// Ticket represents the ticket details that require self-healing
type Ticket struct {
// RespondedTicket represents the details of ticket responded in a self-healing challenge
type RespondedTicket struct {
TxID string `json:"tx_id"`
TicketType TicketType `json:"ticket_type"`
MissingKeys []string `json:"missing_keys"`
DataHash string `json:"data_hash"`
ReconstructedFileHash string `json:"reconstructed_file_hash"`
ReconstructedFileHash []byte `json:"reconstructed_file_hash"`
FileIDs []string `json:"sense_file_ids"`
}

// SelfHealingResponseData represents the response data for self-healing sent by the recipient
type SelfHealingResponseData struct {
Block int32 `json:"block"`
Merkelroot string `json:"merkelroot"`
Timestamp time.Time `json:"timestamp"`
Tickets []Ticket `json:"tickets"`
Block int32 `json:"block"`
Merkelroot string `json:"merkelroot"`
Timestamp time.Time `json:"timestamp"`
RespondedTickets []RespondedTicket `json:"responded_tickets"`
}

// VerifiedTicket represents the details of ticket verified in self-healing challenge
type VerifiedTicket struct {
TxID string `json:"tx_id"`
TicketType TicketType `json:"ticket_type"`
MissingKeys []string `json:"missing_keys"`
DataHash string `json:"data_hash"`
ReconstructedFileHash []byte `json:"reconstructed_file_hash"`
FileIDs []string `json:"sense_file_ids"`
IsVerified bool `json:"is_verified"`
}

// SelfHealingVerificationData represents the verification data for self-healing challenge
type SelfHealingVerificationData struct {
Block int32 `json:"block"`
Merkelroot string `json:"merkelroot"`
Timestamp time.Time `json:"timestamp"`
VerifiedTickets []VerifiedTicket `json:"verified_tickets"`
}
4 changes: 2 additions & 2 deletions proto/supernode/protobuf/self_healing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ message ProcessSelfHealingChallengeReply {
}

message VerifySelfHealingChallengeRequest {
SelfHealingData data = 1;
SelfHealingMessage data = 1;
}

message VerifySelfHealingChallengeReply {
SelfHealingData data = 1;
SelfHealingMessage data = 1;
}

message SelfHealingMessage {
Expand Down
145 changes: 72 additions & 73 deletions proto/supernode/self_healing.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions supernode/node/grpc/client/self_healing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package client

import (
"context"
json "github.com/json-iterator/go"
"github.com/pastelnetwork/gonode/common/types"
"io"

"github.com/pastelnetwork/gonode/common/errors"
Expand Down Expand Up @@ -93,14 +95,30 @@ func (service *selfHealingGRPCClient) ProcessSelfHealingChallenge(ctx context.Co

return nil
}
func (service *selfHealingGRPCClient) VerifySelfHealingChallenge(ctx context.Context, challengeMessage *pb.SelfHealingData) (*pb.SelfHealingData, error) {
func (service *selfHealingGRPCClient) VerifySelfHealingChallenge(ctx context.Context, challengeMessage *pb.SelfHealingMessage) (types.SelfHealingMessage, error) {
ctx = contextWithLogPrefix(ctx, service.conn.id)
ctx = contextWithMDSessID(ctx, service.sessID)

res, err := service.client.VerifySelfHealingChallenge(ctx, &pb.VerifySelfHealingChallengeRequest{
Data: challengeMessage,
})
if err != nil {
return types.SelfHealingMessage{}, err
}

msg := types.SelfHealingMessage{
ChallengeID: res.Data.ChallengeId,
MessageType: types.SelfHealingMessageType(res.Data.MessageType),
SenderID: res.Data.SenderId,
SenderSignature: res.Data.SenderSignature,
}

if err := json.Unmarshal(res.Data.Data, &msg.SelfHealingMessageData); err != nil {
log.WithContext(ctx).WithError(err).Error("Error un-marshaling received challenge message")
return msg, errors.Errorf("error un-marshaling the received challenge message")
}

return res.Data, err
return msg, nil
}

func newSelfHealingGRPCClient(conn *clientConn) node.SelfHealingChallengeInterface {
Expand Down
Loading

0 comments on commit dced978

Please sign in to comment.