Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSL-1054] refactor process-self-healing worker #741

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 represents the verification message
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"`
}

// Ticket represents the ticket details that require self-healing
type Ticket struct {
// 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"`
}

// 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
Loading