Skip to content

Commit

Permalink
Use Blob Submit in Celestia DA Implementation (cosmos#1141)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

Closes: cosmos#1107 

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [ ] Required CI checks are passing
- [ ] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords
  • Loading branch information
Manav-Aggarwal authored Aug 17, 2023
1 parent 91e1c64 commit e0cc388
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
20 changes: 3 additions & 17 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"strings"
"time"

"cosmossdk.io/math"
"github.com/gogo/protobuf/proto"
ds "github.com/ipfs/go-datastore"

Expand Down Expand Up @@ -99,7 +97,7 @@ func (c *DataAvailabilityLayerClient) SubmitBlocks(ctx context.Context, blocks [
blobs[blockIndex] = blockBlob
}

txResponse, err := c.rpc.State.SubmitPayForBlob(ctx, math.NewInt(c.config.Fee), c.config.GasLimit, blobs)
dataLayerHeight, err := c.rpc.Blob.Submit(ctx, blobs)
if err != nil {
return da.ResultSubmitBlocks{
BaseResult: da.BaseResult{
Expand All @@ -109,24 +107,12 @@ func (c *DataAvailabilityLayerClient) SubmitBlocks(ctx context.Context, blocks [
}
}

c.logger.Debug("successfully submitted PayForBlob transaction",
"fee", c.config.Fee, "gasLimit", c.config.GasLimit,
"daHeight", txResponse.Height, "daTxHash", txResponse.TxHash)

if txResponse.Code != 0 {
return da.ResultSubmitBlocks{
BaseResult: da.BaseResult{
Code: da.StatusError,
Message: fmt.Sprintf("Codespace: '%s', Code: %d, Message: %s", txResponse.Codespace, txResponse.Code, txResponse.RawLog),
},
}
}
c.logger.Debug("successfully submitted blobs", "daHeight", dataLayerHeight)

return da.ResultSubmitBlocks{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
Message: "tx hash: " + txResponse.TxHash,
DAHeight: uint64(txResponse.Height),
DAHeight: uint64(dataLayerHeight),
},
}
}
Expand Down
13 changes: 0 additions & 13 deletions da/celestia/mock/messages.go

This file was deleted.

19 changes: 8 additions & 11 deletions da/celestia/mock/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/rollkit/celestia-openrpc/types/blob"
"github.com/rollkit/celestia-openrpc/types/header"
"github.com/rollkit/celestia-openrpc/types/sdk"
mockda "github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/log"
"github.com/rollkit/rollkit/store"
Expand Down Expand Up @@ -197,20 +196,20 @@ func (s *Server) rpc(w http.ResponseWriter, r *http.Request) {
return
}
s.writeResponse(w, bytes)
case "state.SubmitPayForBlob":
case "blob.Submit":
var params []interface{}
err := json.Unmarshal(req.Params, &params)
if err != nil {
s.writeError(w, err)
return
}
if len(params) != 3 {
s.writeError(w, errors.New("expected 3 params: fee (uint64), gaslimit (uint64), data (base64 string)"))
if len(params) != 1 {
s.writeError(w, errors.New("expected 1 param: data (base64 string)"))
return
}

blocks := make([]*types.Block, len(params[2].([]interface{})))
for i, data := range params[2].([]interface{}) {
blocks := make([]*types.Block, len(params[0].([]interface{})))
for i, data := range params[0].([]interface{}) {
blockBase64 := data.(map[string]interface{})["data"].(string)
blockData, err := base64.StdEncoding.DecodeString(blockBase64)
if err != nil {
Expand All @@ -228,11 +227,9 @@ func (s *Server) rpc(w http.ResponseWriter, r *http.Request) {
res := s.mock.SubmitBlocks(r.Context(), blocks)
resp := &response{
Jsonrpc: "2.0",
Result: &sdk.TxResponse{
Height: int64(res.DAHeight),
},
ID: req.ID,
Error: nil,
Result: int64(res.DAHeight),
ID: req.ID,
Error: nil,
}
bytes, err := json.Marshal(resp)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/rollkit/rollkit
go 1.20

require (
cosmossdk.io/math v1.0.1
github.com/celestiaorg/go-header v0.2.13
github.com/celestiaorg/nmt v0.17.0
github.com/celestiaorg/rsmt2d v0.10.0
Expand Down Expand Up @@ -37,6 +36,7 @@ require (
)

require (
cosmossdk.io/math v1.0.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
Expand Down

0 comments on commit e0cc388

Please sign in to comment.