Skip to content

Commit

Permalink
sync -- add handling for fatal error (ava-labs#1690)
Browse files Browse the repository at this point in the history
Co-authored-by: Darioush Jalali <[email protected]>
  • Loading branch information
Dan Laine and darioush authored Aug 9, 2023
1 parent 40a4c7f commit 285376a
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 115 deletions.
12 changes: 10 additions & 2 deletions x/sync/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ type ClientConfig struct {
}

func NewClient(config *ClientConfig) Client {
c := &client{
return &client{
networkClient: config.NetworkClient,
stateSyncNodes: config.StateSyncNodeIDs,
stateSyncMinVersion: config.StateSyncMinVersion,
log: config.Log,
metrics: config.Metrics,
}
return c
}

// GetChangeProof synchronously retrieves the change proof given by [req].
Expand Down Expand Up @@ -196,6 +195,8 @@ func (c *client) GetRangeProof(ctx context.Context, req *pb.SyncGetRangeProofReq
// [parseFn] parses the raw response.
// If the request is unsuccessful or the response can't be parsed,
// retries the request to a different peer until [ctx] expires.
// Returns [errAppRequestSendFailed] if we fail to send an AppRequest.
// This should be treated as a fatal error.
func getAndParse[T any](
ctx context.Context,
client *client,
Expand All @@ -215,6 +216,11 @@ func getAndParse[T any](
}
}

if errors.Is(err, errAppRequestSendFailed) {
// Failing to send an AppRequest is a fatal error.
return nil, err
}

client.log.Debug("request failed, retrying",
zap.Stringer("nodeID", nodeID),
zap.Int("attempt", attempt),
Expand Down Expand Up @@ -249,6 +255,8 @@ func getAndParse[T any](
// until the node receives a response, failure notification
// or [ctx] is canceled.
// Returns the peer's NodeID and response.
// Returns [errAppRequestSendFailed] if we failed to send an AppRequest.
// This should be treated as fatal.
// It's safe to call this method multiple times concurrently.
func (c *client) get(ctx context.Context, request []byte) (ids.NodeID, []byte, error) {
var (
Expand Down
Loading

0 comments on commit 285376a

Please sign in to comment.