49
49
errInvalidBounds = errors .New ("start key is greater than end key" )
50
50
errInvalidRootHash = fmt .Errorf ("root hash must have length %d" , hashing .HashLen )
51
51
52
- _ p2p.Handler = (* GetChangeProofHandler )(nil )
53
- _ p2p.Handler = (* GetRangeProofHandler )(nil )
52
+ _ p2p.Handler = (* SyncGetChangeProofHandler )(nil )
53
+ _ p2p.Handler = (* SyncGetRangeProofHandler )(nil )
54
54
)
55
55
56
56
func maybeBytesToMaybe (mb * pb.MaybeBytes ) maybe.Maybe [[]byte ] {
@@ -60,30 +60,30 @@ func maybeBytesToMaybe(mb *pb.MaybeBytes) maybe.Maybe[[]byte] {
60
60
return maybe .Nothing [[]byte ]()
61
61
}
62
62
63
- func NewGetChangeProofHandler (log logging.Logger , db DB ) * GetChangeProofHandler {
64
- return & GetChangeProofHandler {
63
+ func NewSyncGetChangeProofHandler (log logging.Logger , db DB ) * SyncGetChangeProofHandler {
64
+ return & SyncGetChangeProofHandler {
65
65
log : log ,
66
66
db : db ,
67
67
}
68
68
}
69
69
70
- type GetChangeProofHandler struct {
70
+ type SyncGetChangeProofHandler struct {
71
71
log logging.Logger
72
72
db DB
73
73
}
74
74
75
- func (* GetChangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
75
+ func (* SyncGetChangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
76
76
77
- func (g * GetChangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
78
- req := & pb.SyncGetChangeProofRequest {}
79
- if err := proto .Unmarshal (requestBytes , req ); err != nil {
77
+ func (s * SyncGetChangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
78
+ request := & pb.SyncGetChangeProofRequest {}
79
+ if err := proto .Unmarshal (requestBytes , request ); err != nil {
80
80
return nil , & common.AppError {
81
81
Code : p2p .ErrUnexpected .Code ,
82
82
Message : fmt .Sprintf ("failed to unmarshal request: %s" , err ),
83
83
}
84
84
}
85
85
86
- if err := validateChangeProofRequest (req ); err != nil {
86
+ if err := validateChangeProofRequest (request ); err != nil {
87
87
return nil , & common.AppError {
88
88
Code : p2p .ErrUnexpected .Code ,
89
89
Message : fmt .Sprintf ("invalid request: %s" , err ),
@@ -92,21 +92,21 @@ func (g *GetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID, _
92
92
93
93
// override limits if they exceed caps
94
94
var (
95
- keyLimit = min (req .KeyLimit , maxKeyValuesLimit )
96
- bytesLimit = min (int (req .BytesLimit ), maxByteSizeLimit )
97
- start = maybeBytesToMaybe (req .StartKey )
98
- end = maybeBytesToMaybe (req .EndKey )
95
+ keyLimit = min (request .KeyLimit , maxKeyValuesLimit )
96
+ bytesLimit = min (int (request .BytesLimit ), maxByteSizeLimit )
97
+ start = maybeBytesToMaybe (request .StartKey )
98
+ end = maybeBytesToMaybe (request .EndKey )
99
99
)
100
100
101
- startRoot , err := ids .ToID (req .StartRootHash )
101
+ startRoot , err := ids .ToID (request .StartRootHash )
102
102
if err != nil {
103
103
return nil , & common.AppError {
104
104
Code : p2p .ErrUnexpected .Code ,
105
105
Message : fmt .Sprintf ("failed to parse start root hash: %s" , err ),
106
106
}
107
107
}
108
108
109
- endRoot , err := ids .ToID (req .EndRootHash )
109
+ endRoot , err := ids .ToID (request .EndRootHash )
110
110
if err != nil {
111
111
return nil , & common.AppError {
112
112
Code : p2p .ErrUnexpected .Code ,
@@ -120,7 +120,6 @@ func (g *GetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID, _
120
120
if ! errors .Is (err , merkledb .ErrInsufficientHistory ) {
121
121
// We should only fail to get a change proof if we have insufficient history.
122
122
// Other errors are unexpected.
123
- // TODO define custom errors
124
123
return nil , & common.AppError {
125
124
Code : p2p .ErrUnexpected .Code ,
126
125
Message : fmt .Sprintf ("failed to get change proof: %s" , err ),
@@ -141,11 +140,11 @@ func (g *GetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID, _
141
140
ctx ,
142
141
g .db ,
143
142
& pb.SyncGetRangeProofRequest {
144
- RootHash : req .EndRootHash ,
145
- StartKey : req .StartKey ,
146
- EndKey : req .EndKey ,
147
- KeyLimit : req .KeyLimit ,
148
- BytesLimit : req .BytesLimit ,
143
+ RootHash : request .EndRootHash ,
144
+ StartKey : request .StartKey ,
145
+ EndKey : request .EndKey ,
146
+ KeyLimit : request .KeyLimit ,
147
+ BytesLimit : request .BytesLimit ,
149
148
},
150
149
func (rangeProof * merkledb.RangeProof ) ([]byte , error ) {
151
150
return proto .Marshal (& pb.SyncGetChangeProofResponse {
@@ -192,44 +191,48 @@ func (g *GetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID, _
192
191
}
193
192
}
194
193
195
- func NewGetRangeProofHandler (log logging.Logger , db DB ) * GetRangeProofHandler {
196
- return & GetRangeProofHandler {
194
+ func (* SyncGetChangeProofHandler ) CrossChainAppRequest (context.Context , ids.ID , time.Time , []byte ) ([]byte , error ) {
195
+ return nil , nil
196
+ }
197
+
198
+ func NewSyncGetRangeProofHandler (log logging.Logger , db DB ) * SyncGetRangeProofHandler {
199
+ return & SyncGetRangeProofHandler {
197
200
log : log ,
198
201
db : db ,
199
202
}
200
203
}
201
204
202
- type GetRangeProofHandler struct {
205
+ type SyncGetRangeProofHandler struct {
203
206
log logging.Logger
204
207
db DB
205
208
}
206
209
207
- func (* GetRangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
210
+ func (* SyncGetRangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
208
211
209
- func (g * GetRangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
210
- req := & pb.SyncGetRangeProofRequest {}
211
- if err := proto .Unmarshal (requestBytes , req ); err != nil {
212
+ func (s * SyncGetRangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
213
+ request := & pb.SyncGetRangeProofRequest {}
214
+ if err := proto .Unmarshal (requestBytes , request ); err != nil {
212
215
return nil , & common.AppError {
213
216
Code : p2p .ErrUnexpected .Code ,
214
217
Message : fmt .Sprintf ("failed to unmarshal request: %s" , err ),
215
218
}
216
219
}
217
220
218
- if err := validateRangeProofRequest (req ); err != nil {
221
+ if err := validateRangeProofRequest (request ); err != nil {
219
222
return nil , & common.AppError {
220
223
Code : p2p .ErrUnexpected .Code ,
221
224
Message : fmt .Sprintf ("invalid range proof request: %s" , err ),
222
225
}
223
226
}
224
227
225
228
// override limits if they exceed caps
226
- req .KeyLimit = min (req .KeyLimit , maxKeyValuesLimit )
227
- req .BytesLimit = min (req .BytesLimit , maxByteSizeLimit )
229
+ request .KeyLimit = min (request .KeyLimit , maxKeyValuesLimit )
230
+ request .BytesLimit = min (request .BytesLimit , maxByteSizeLimit )
228
231
229
232
proofBytes , err := getRangeProof (
230
233
ctx ,
231
- g .db ,
232
- req ,
234
+ s .db ,
235
+ request ,
233
236
func (rangeProof * merkledb.RangeProof ) ([]byte , error ) {
234
237
return proto .Marshal (rangeProof .ToProto ())
235
238
},
@@ -244,6 +247,10 @@ func (g *GetRangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID, _ t
244
247
return proofBytes , nil
245
248
}
246
249
250
+ func (* SyncGetRangeProofHandler ) CrossChainAppRequest (context.Context , ids.ID , time.Time , []byte ) ([]byte , error ) {
251
+ return nil , nil
252
+ }
253
+
247
254
// Get the range proof specified by [req].
248
255
// If the generated proof is too large, the key limit is reduced
249
256
// and the proof is regenerated. This process is repeated until
0 commit comments