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 = (* SyncGetChangeProofHandler )(nil )
53
- _ p2p.Handler = (* SyncGetRangeProofHandler )(nil )
52
+ _ p2p.Handler = (* GetChangeProofHandler )(nil )
53
+ _ p2p.Handler = (* GetRangeProofHandler )(nil )
54
54
)
55
55
56
56
func maybeBytesToMaybe (mb * pb.MaybeBytes ) maybe.Maybe [[]byte ] {
@@ -60,21 +60,21 @@ func maybeBytesToMaybe(mb *pb.MaybeBytes) maybe.Maybe[[]byte] {
60
60
return maybe .Nothing [[]byte ]()
61
61
}
62
62
63
- func NewSyncGetChangeProofHandler (log logging.Logger , db DB ) * SyncGetChangeProofHandler {
64
- return & SyncGetChangeProofHandler {
63
+ func NewGetChangeProofHandler (log logging.Logger , db DB ) * GetChangeProofHandler {
64
+ return & GetChangeProofHandler {
65
65
log : log ,
66
66
db : db ,
67
67
}
68
68
}
69
69
70
- type SyncGetChangeProofHandler struct {
70
+ type GetChangeProofHandler struct {
71
71
log logging.Logger
72
72
db DB
73
73
}
74
74
75
- func (* SyncGetChangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
75
+ func (* GetChangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
76
76
77
- func (s * SyncGetChangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
77
+ func (g * GetChangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
78
78
req := & pb.SyncGetChangeProofRequest {}
79
79
if err := proto .Unmarshal (requestBytes , req ); err != nil {
80
80
return nil , & common.AppError {
@@ -115,11 +115,12 @@ func (s *SyncGetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID
115
115
}
116
116
117
117
for keyLimit > 0 {
118
- changeProof , err := s .db .GetChangeProof (ctx , startRoot , endRoot , start , end , int (keyLimit ))
118
+ changeProof , err := g .db .GetChangeProof (ctx , startRoot , endRoot , start , end , int (keyLimit ))
119
119
if err != nil {
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
123
124
return nil , & common.AppError {
124
125
Code : p2p .ErrUnexpected .Code ,
125
126
Message : fmt .Sprintf ("failed to get change proof: %s" , err ),
@@ -138,7 +139,7 @@ func (s *SyncGetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID
138
139
// Generate a range proof for the end root ID instead.
139
140
proofBytes , err := getRangeProof (
140
141
ctx ,
141
- s .db ,
142
+ g .db ,
142
143
& pb.SyncGetRangeProofRequest {
143
144
RootHash : req .EndRootHash ,
144
145
StartKey : req .StartKey ,
@@ -191,21 +192,21 @@ func (s *SyncGetChangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID
191
192
}
192
193
}
193
194
194
- func NewSyncGetRangeProofHandler (log logging.Logger , db DB ) * SyncGetRangeProofHandler {
195
- return & SyncGetRangeProofHandler {
195
+ func NewGetRangeProofHandler (log logging.Logger , db DB ) * GetRangeProofHandler {
196
+ return & GetRangeProofHandler {
196
197
log : log ,
197
198
db : db ,
198
199
}
199
200
}
200
201
201
- type SyncGetRangeProofHandler struct {
202
+ type GetRangeProofHandler struct {
202
203
log logging.Logger
203
204
db DB
204
205
}
205
206
206
- func (* SyncGetRangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
207
+ func (* GetRangeProofHandler ) AppGossip (context.Context , ids.NodeID , []byte ) {}
207
208
208
- func (s * SyncGetRangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
209
+ func (g * GetRangeProofHandler ) AppRequest (ctx context.Context , _ ids.NodeID , _ time.Time , requestBytes []byte ) ([]byte , * common.AppError ) {
209
210
req := & pb.SyncGetRangeProofRequest {}
210
211
if err := proto .Unmarshal (requestBytes , req ); err != nil {
211
212
return nil , & common.AppError {
@@ -227,7 +228,7 @@ func (s *SyncGetRangeProofHandler) AppRequest(ctx context.Context, _ ids.NodeID,
227
228
228
229
proofBytes , err := getRangeProof (
229
230
ctx ,
230
- s .db ,
231
+ g .db ,
231
232
req ,
232
233
func (rangeProof * merkledb.RangeProof ) ([]byte , error ) {
233
234
return proto .Marshal (rangeProof .ToProto ())
0 commit comments