Skip to content

Commit 8320422

Browse files
committed
updates
1 parent 3ca5847 commit 8320422

File tree

4 files changed

+19
-66
lines changed

4 files changed

+19
-66
lines changed

pkg/da/app/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ func (c *Client) Retrieve(ctx context.Context, height uint64, namespace []byte)
166166
},
167167
}
168168
}
169+
if strings.Contains(err.Error(), "is not available, lowest height is") {
170+
c.logger.Debug().Uint64("height", height).Err(err).Msg("block is pruned or unavailable")
171+
return datypes.ResultRetrieve{
172+
BaseResult: datypes.BaseResult{
173+
Code: datypes.StatusNotFound,
174+
Message: datypes.ErrBlobNotFound.Error(),
175+
Height: height,
176+
Timestamp: time.Now(),
177+
},
178+
}
179+
}
169180
c.logger.Error().Err(err).Uint64("height", height).Msg("failed to get block")
170181
return datypes.ResultRetrieve{
171182
BaseResult: datypes.BaseResult{
@@ -375,6 +386,9 @@ type rpcError struct {
375386
}
376387

377388
func (e *rpcError) Error() string {
389+
if e.Data != "" {
390+
return fmt.Sprintf("RPC error %d: %s: %s", e.Code, e.Message, e.Data)
391+
}
378392
return fmt.Sprintf("RPC error %d: %s", e.Code, e.Message)
379393
}
380394

pkg/da/app/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestClient_Retrieve(t *testing.T) {
147147

148148
client := createTestClient(server.URL)
149149
result := client.Retrieve(ctx, 100, ns.Bytes())
150-
assert.Equal(t, datypes.StatusError, result.Code)
150+
assert.Equal(t, datypes.StatusNotFound, result.Code)
151151
})
152152

153153
t.Run("future height", func(t *testing.T) {
@@ -501,7 +501,7 @@ func TestRPCTypes(t *testing.T) {
501501
Message: "Invalid Request",
502502
Data: "extra data",
503503
}
504-
assert.Equal(t, "RPC error -32600: Invalid Request", err.Error())
504+
assert.Equal(t, "RPC error -32600: Invalid Request: extra data", err.Error())
505505
})
506506
}
507507

pkg/da/factory/factory.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"io"
1212
"net/http"
13-
"net/url"
1413
"strings"
1514
"time"
1615

@@ -62,6 +61,9 @@ type Config struct {
6261
// Note: celestia-app client does not support proof operations
6362
// (GetProofs/Validate). Use celestia-node client for full functionality.
6463
func NewClient(ctx context.Context, cfg Config) (datypes.BlobClient, error) {
64+
// Sanitize address to remove any surrounding quotes that might have been included from config
65+
cfg.Address = strings.Trim(strings.TrimSpace(cfg.Address), "\"'")
66+
6567
// Always use node client in aggregator mode
6668
if cfg.IsAggregator {
6769
cfg.Logger.Debug().
@@ -273,27 +275,3 @@ func IsNodeAddress(ctx context.Context, address string) bool {
273275
func IsAppAddress(ctx context.Context, address string) bool {
274276
return detectClientType(ctx, address) == ClientTypeApp
275277
}
276-
277-
// ValidateAddress checks if the address is valid and returns the detected client type.
278-
// It makes an HTTP request to detect the service type.
279-
func ValidateAddress(ctx context.Context, address string) (ClientType, error) {
280-
if strings.TrimSpace(address) == "" {
281-
return ClientTypeAuto, fmt.Errorf("DA address cannot be empty")
282-
}
283-
284-
// Try to parse as URL
285-
u, err := url.Parse(address)
286-
if err != nil {
287-
// Try with http:// prefix
288-
u, err = url.Parse("http://" + address)
289-
if err != nil {
290-
return ClientTypeAuto, fmt.Errorf("invalid DA address format: %w", err)
291-
}
292-
}
293-
294-
if u.Host == "" {
295-
return ClientTypeAuto, fmt.Errorf("DA address must include host")
296-
}
297-
298-
return detectClientType(ctx, address), nil
299-
}

pkg/da/factory/factory_test.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -196,45 +196,6 @@ func TestIsAppAddress(t *testing.T) {
196196
}
197197
}
198198

199-
func TestValidateAddress(t *testing.T) {
200-
ctx := context.Background()
201-
202-
tests := []struct {
203-
name string
204-
address string
205-
expectError bool
206-
expectType ClientType
207-
}{
208-
{
209-
name: "empty address",
210-
address: "",
211-
expectError: true,
212-
},
213-
{
214-
name: "whitespace address",
215-
address: " ",
216-
expectError: true,
217-
},
218-
{
219-
name: "address without host",
220-
address: "http://",
221-
expectError: true,
222-
},
223-
}
224-
225-
for _, tt := range tests {
226-
t.Run(tt.name, func(t *testing.T) {
227-
clientType, err := ValidateAddress(ctx, tt.address)
228-
if tt.expectError {
229-
require.Error(t, err)
230-
} else {
231-
require.NoError(t, err)
232-
assert.Equal(t, tt.expectType, clientType)
233-
}
234-
})
235-
}
236-
}
237-
238199
func TestNewClient_AggregatorMode(t *testing.T) {
239200
// In aggregator mode, should always use node client regardless of address
240201
cfg := Config{

0 commit comments

Comments
 (0)