Skip to content

Commit

Permalink
Support for older celestia data
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalex88 committed Feb 4, 2024
1 parent a04e15b commit 88989a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions frax-da/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ func (c DAClient) Read(ctx context.Context, id []byte) ([]byte, error) {
return body, nil
}

func (c DAClient) ReadCelestia(ctx context.Context, hexString string) ([]byte, error) {
fetchUrl := c.baseUrl.ResolveReference(&url.URL{Path: fmt.Sprintf("/v1/blobs/celestia-%s", hexString)})
request, err := http.NewRequestWithContext(ctx, "GET", fetchUrl.String(), nil)
if err != nil {
return nil, fmt.Errorf("unable to create request to fetch celestia data from DA: %w", err)
}
resp, err := c.httpClient.Do(request)

if err != nil {
return nil, fmt.Errorf("unable to fetch DA celestia data: %w", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("unable to fetch DA celestia data, got status code %d", resp.StatusCode)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unable to read DA celestia data fetch response: %w", err)
}

return body, nil
}

func (c DAClient) Write(ctx context.Context, data []byte) ([]byte, error) {
submitUrl := c.baseUrl.ResolveReference(&url.URL{Path: "/v1/blobs"})

Expand Down
3 changes: 3 additions & 0 deletions frax-da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ package fraxda

// DerivationVersionFraxDa is a byte prefix of frax DA based references
const DerivationVersionFraxDa = 0xfc

// DerivationVersionCelestia is used for retrocompatibility with the old testnet data
const DerivationVersionCelestia = 0xce
9 changes: 9 additions & 0 deletions op-node/rollup/derive/calldata_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ func DataFromEVMTransactions(dsCfg DataSourceConfig, batcherAddr common.Address,
return nil, NewResetError(fmt.Errorf("fraxda: failed to fetch data for id %s: %w", hex.EncodeToString(data), err))
}
out = append(out, data)
case fraxda.DerivationVersionCelestia:
log.Info("fraxda: requesting old celestia data", "id", hex.EncodeToString(data))
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
data, err := daClient.ReadCelestia(ctx, hex.EncodeToString(data[1:]))
cancel()
if err != nil {
return nil, NewResetError(fmt.Errorf("fraxda: failed to fetch celestia data for id %s: %w", hex.EncodeToString(data), err))
}
out = append(out, data)
default:
out = append(out, data)
log.Info("fraxda: using eth fallback")
Expand Down

0 comments on commit 88989a3

Please sign in to comment.