Skip to content

Commit 8d68f9d

Browse files
authored
fix(pkg/da): fallback to polling when ws cannot connect (#3211)
* fix(pkg/da): fallback to polling when ws cannot connect * log err and fix typos * rewording
1 parent 5e3db23 commit 8d68f9d

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

apps/evm/cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var RunCmd = &cobra.Command{
5959
return err
6060
}
6161

62-
blobClient, err := blobrpc.NewWSClient(cmd.Context(), nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
62+
blobClient, err := blobrpc.NewWSClient(cmd.Context(), logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
6363
if err != nil {
6464
return fmt.Errorf("failed to create blob client: %w", err)
6565
}

apps/grpc/cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func createSequencer(
108108
genesis genesis.Genesis,
109109
executor execution.Executor,
110110
) (coresequencer.Sequencer, error) {
111-
blobClient, err := blobrpc.NewWSClient(ctx, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
111+
blobClient, err := blobrpc.NewWSClient(ctx, logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
112112
if err != nil {
113113
return nil, fmt.Errorf("failed to create blob client: %w", err)
114114
}

apps/testapp/cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func createSequencer(
111111
genesis genesis.Genesis,
112112
executor execution.Executor,
113113
) (coresequencer.Sequencer, error) {
114-
blobClient, err := blobrpc.NewWSClient(ctx, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
114+
blobClient, err := blobrpc.NewWSClient(ctx, logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
115115
if err != nil {
116116
return nil, fmt.Errorf("failed to create blob client: %w", err)
117117
}

pkg/cmd/run_node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func StartNode(
149149
}
150150
}
151151

152-
blobClient, err := blobrpc.NewWSClient(ctx, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
152+
blobClient, err := blobrpc.NewWSClient(ctx, logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, "")
153153
if err != nil {
154154
return fmt.Errorf("failed to create blob client: %w", err)
155155
}

pkg/da/jsonrpc/client.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
libshare "github.com/celestiaorg/go-square/v3/share"
1010
"github.com/filecoin-project/go-jsonrpc"
11+
"github.com/rs/zerolog"
1112
)
1213

1314
// Client dials the celestia-node RPC "blob" and "header" namespaces.
@@ -72,9 +73,15 @@ func NewClient(ctx context.Context, addr, token string, authHeaderName string) (
7273
// Automatically converts http:// to ws:// (and https:// to wss://).
7374
// Supports channel-based subscriptions (e.g. Subscribe).
7475
// 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
7885
}
7986

8087
// BlobAPI mirrors celestia-node's blob module (nodebuilder/blob/blob.go).

0 commit comments

Comments
 (0)