|
8 | 8 |
|
9 | 9 | libshare "github.com/celestiaorg/go-square/v3/share" |
10 | 10 | "github.com/filecoin-project/go-jsonrpc" |
| 11 | + "github.com/rs/zerolog" |
11 | 12 | ) |
12 | 13 |
|
13 | 14 | // Client dials the celestia-node RPC "blob" and "header" namespaces. |
@@ -72,9 +73,15 @@ func NewClient(ctx context.Context, addr, token string, authHeaderName string) ( |
72 | 73 | // Automatically converts http:// to ws:// (and https:// to wss://). |
73 | 74 | // Supports channel-based subscriptions (e.g. Subscribe). |
74 | 75 | // Note: WebSocket connections are eager — they connect at creation time |
75 | | -// and will fail immediately if the server is unavailable. |
76 | | -func NewWSClient(ctx context.Context, addr, token string, authHeaderName string) (*Client, error) { |
77 | | - return NewClient(ctx, httpToWS(addr), token, authHeaderName) |
| 76 | +// if the initial WS dial fails, falls back to HTTP polling for the entire session. |
| 77 | +func NewWSClient(ctx context.Context, logger zerolog.Logger, addr, token string, authHeaderName string) (*Client, error) { |
| 78 | + client, err := NewClient(ctx, httpToWS(addr), token, authHeaderName) |
| 79 | + if err != nil { |
| 80 | + logger.Warn().Err(err).Msg("DA websocket connection failed, falling back to DA polling") |
| 81 | + return NewClient(ctx, addr, token, authHeaderName) |
| 82 | + } |
| 83 | + |
| 84 | + return client, nil |
78 | 85 | } |
79 | 86 |
|
80 | 87 | // BlobAPI mirrors celestia-node's blob module (nodebuilder/blob/blob.go). |
|
0 commit comments