Skip to content

Commit 8e5cfca

Browse files
committed
self-healing: finalize verify->commit flow and hash assertions
1 parent a45870f commit 8e5cfca

11 files changed

Lines changed: 1127 additions & 145 deletions

File tree

gen/supernode/self_healing.pb.go

Lines changed: 331 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/supernode/self_healing.swagger.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@
4545
}
4646
}
4747
},
48+
"supernodeCommitSelfHealingResponse": {
49+
"type": "object",
50+
"properties": {
51+
"challengeId": {
52+
"type": "string"
53+
},
54+
"epochId": {
55+
"type": "string",
56+
"format": "uint64"
57+
},
58+
"recipientId": {
59+
"type": "string"
60+
},
61+
"stored": {
62+
"type": "boolean"
63+
},
64+
"error": {
65+
"type": "string"
66+
}
67+
}
68+
},
4869
"supernodeRequestSelfHealingResponse": {
4970
"type": "object",
5071
"properties": {

gen/supernode/self_healing_grpc.pb.go

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/supernode/self_healing.proto

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ option go_package = "github.com/LumeraProtocol/supernode/v2/gen/supernode";
77
service SelfHealingService {
88
rpc RequestSelfHealing(RequestSelfHealingRequest) returns (RequestSelfHealingResponse) {}
99
rpc VerifySelfHealing(VerifySelfHealingRequest) returns (VerifySelfHealingResponse) {}
10+
rpc CommitSelfHealing(CommitSelfHealingRequest) returns (CommitSelfHealingResponse) {}
1011
}
1112

1213
message RequestSelfHealingRequest {
@@ -17,6 +18,7 @@ message RequestSelfHealingRequest {
1718
string challenger_id = 4;
1819
string recipient_id = 5;
1920
repeated string observer_ids = 6;
21+
string action_id = 7;
2022
}
2123

2224
message RequestSelfHealingResponse {
@@ -38,6 +40,7 @@ message VerifySelfHealingRequest {
3840
string recipient_id = 4;
3941
string reconstructed_hash_hex = 5;
4042
string observer_id = 6;
43+
string action_id = 7;
4144
}
4245

4346
message VerifySelfHealingResponse {
@@ -47,3 +50,21 @@ message VerifySelfHealingResponse {
4750
bool ok = 4;
4851
string error = 5;
4952
}
53+
54+
message CommitSelfHealingRequest {
55+
string challenge_id = 1;
56+
uint64 epoch_id = 2;
57+
58+
string file_key = 3;
59+
string action_id = 4;
60+
string challenger_id = 5;
61+
string recipient_id = 6;
62+
}
63+
64+
message CommitSelfHealingResponse {
65+
string challenge_id = 1;
66+
uint64 epoch_id = 2;
67+
string recipient_id = 3;
68+
bool stored = 4;
69+
string error = 5;
70+
}

supernode/cascade/reseed.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cascade
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"sort"
78
"strings"
@@ -13,14 +14,16 @@ import (
1314
)
1415

1516
type RecoveryReseedRequest struct {
16-
ActionID string
17+
ActionID string
18+
PersistArtifacts *bool
1719
}
1820

1921
type RecoveryReseedResult struct {
2022
ActionID string
2123
DownloadEvents int
2224
DownloadLastEvent string
2325
DecodeCleanupError string
26+
ReconstructedHashHex string
2427
RQIC uint64
2528
RQMax uint64
2629
DataHashVerified bool
@@ -114,8 +117,13 @@ func (task *CascadeRegistrationTask) RecoveryReseed(ctx context.Context, req *Re
114117
if err := cascadekit.VerifyB64DataHash(fileHash, meta.DataHash); err != nil {
115118
return result, task.wrapErr(ctx, "decoded file hash does not match action metadata", err, fields)
116119
}
120+
result.ReconstructedHashHex = hex.EncodeToString(fileHash)
117121
result.DataHashVerified = true
118122

123+
if !shouldPersistArtifacts(req) {
124+
return result, nil
125+
}
126+
119127
encodeResult, err := task.encodeInput(ctx, actionID, decodeFilePath, fields)
120128
if err != nil {
121129
return result, err
@@ -143,6 +151,13 @@ func (task *CascadeRegistrationTask) RecoveryReseed(ctx context.Context, req *Re
143151
return result, nil
144152
}
145153

154+
func shouldPersistArtifacts(req *RecoveryReseedRequest) bool {
155+
if req == nil || req.PersistArtifacts == nil {
156+
return true
157+
}
158+
return *req.PersistArtifacts
159+
}
160+
146161
func symbolIDsFromLayout(layout codec.Layout) []string {
147162
seen := make(map[string]struct{}, 1024)
148163
for _, block := range layout.Blocks {

0 commit comments

Comments
 (0)