Skip to content

Commit

Permalink
remove: CheckBlockAvailability function from DA (cosmos#1078)
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

Resolves cosmos#1040 

<!-- 
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
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords
  • Loading branch information
tzdybal authored Jul 17, 2023
1 parent 669f527 commit 9c9e4b0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 600 deletions.
47 changes: 0 additions & 47 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,53 +130,6 @@ func (c *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *ty
}
}

// CheckBlockAvailability queries DA layer to check data availability of block at given height.
func (c *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context, dataLayerHeight uint64) da.ResultCheckBlock {
header, err := c.rpc.Header.GetByHeight(ctx, dataLayerHeight)
if err != nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusError,
Message: err.Error(),
},
}
}
if header.DAH == nil {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
DAHeight: dataLayerHeight,
},
DataAvailable: false,
}
}
err = c.rpc.Share.SharesAvailable(ctx, header.DAH)
if err != nil {
if strings.Contains(err.Error(), share.ErrNotAvailable.Error()) {
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
DAHeight: dataLayerHeight,
},
DataAvailable: false,
}
}
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusError,
Message: err.Error(),
},
}
}
return da.ResultCheckBlock{
BaseResult: da.BaseResult{
Code: da.StatusSuccess,
DAHeight: dataLayerHeight,
},
DataAvailable: true,
}
}

// RetrieveBlocks gets a batch of blocks from DA layer.
func (c *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, dataLayerHeight uint64) da.ResultRetrieveBlocks {
c.logger.Debug("trying to retrieve blob using Blob.GetAll", "daHeight", dataLayerHeight, "namespace", hex.EncodeToString(c.namespace.Bytes()))
Expand Down
3 changes: 0 additions & 3 deletions da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ type DataAvailabilityLayerClient interface {
// This should create a transaction which (potentially)
// triggers a state transition in the DA layer.
SubmitBlock(ctx context.Context, block *types.Block) ResultSubmitBlock

// CheckBlockAvailability queries DA layer to check data availability of block corresponding at given height.
CheckBlockAvailability(ctx context.Context, dataLayerHeight uint64) ResultCheckBlock
}

// BlockRetriever is additional interface that can be implemented by Data Availability Layer Client that is able to retrieve
Expand Down
12 changes: 0 additions & 12 deletions da/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ func (d *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *ty
}
}

// CheckBlockAvailability proxies CheckBlockAvailability request to gRPC server.
func (d *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context, daHeight uint64) da.ResultCheckBlock {
resp, err := d.client.CheckBlockAvailability(ctx, &dalc.CheckBlockAvailabilityRequest{DAHeight: daHeight})
if err != nil {
return da.ResultCheckBlock{BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()}}
}
return da.ResultCheckBlock{
BaseResult: da.BaseResult{Code: da.StatusCode(resp.Result.Code), Message: resp.Result.Message},
DataAvailable: resp.DataAvailable,
}
}

// RetrieveBlocks proxies RetrieveBlocks request to gRPC server.
func (d *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, daHeight uint64) da.ResultRetrieveBlocks {
resp, err := d.client.RetrieveBlocks(ctx, &dalc.RetrieveBlocksRequest{DAHeight: daHeight})
Expand Down
11 changes: 0 additions & 11 deletions da/grpc/mockserv/mockserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ func (m *mockImpl) SubmitBlock(ctx context.Context, request *dalc.SubmitBlockReq
}, nil
}

func (m *mockImpl) CheckBlockAvailability(ctx context.Context, request *dalc.CheckBlockAvailabilityRequest) (*dalc.CheckBlockAvailabilityResponse, error) {
resp := m.mock.CheckBlockAvailability(ctx, request.DAHeight)
return &dalc.CheckBlockAvailabilityResponse{
Result: &dalc.DAResponse{
Code: dalc.StatusCode(resp.Code),
Message: resp.Message,
},
DataAvailable: resp.DataAvailable,
}, nil
}

func (m *mockImpl) RetrieveBlocks(ctx context.Context, request *dalc.RetrieveBlocksRequest) (*dalc.RetrieveBlocksResponse, error) {
resp := m.mock.RetrieveBlocks(ctx, request.DAHeight)
blocks := make([]*rollkit.Block, len(resp.Blocks))
Expand Down
6 changes: 0 additions & 6 deletions da/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ func (m *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *ty
}
}

// CheckBlockAvailability queries DA layer to check data availability of block corresponding to given header.
func (m *DataAvailabilityLayerClient) CheckBlockAvailability(ctx context.Context, daHeight uint64) da.ResultCheckBlock {
blocksRes := m.RetrieveBlocks(ctx, daHeight)
return da.ResultCheckBlock{BaseResult: da.BaseResult{Code: blocksRes.Code}, DataAvailable: len(blocksRes.Blocks) > 0}
}

// RetrieveBlocks returns block at given height from data availability layer.
func (m *DataAvailabilityLayerClient) RetrieveBlocks(ctx context.Context, daHeight uint64) da.ResultRetrieveBlocks {
if daHeight >= atomic.LoadUint64(&m.daHeight) {
Expand Down
64 changes: 0 additions & 64 deletions da/test/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,70 +79,6 @@ func doTestLifecycle(t *testing.T, dalc da.DataAvailabilityLayerClient) {
}()
}

func TestDALC(t *testing.T) {
for _, dalc := range registry.RegisteredClients() {
t.Run(dalc, func(t *testing.T) {
doTestDALC(t, registry.GetClient(dalc))
})
}
}

func doTestDALC(t *testing.T, dalc da.DataAvailabilityLayerClient) {
require := require.New(t)
assert := assert.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// mock DALC will advance block height every 100ms
conf := []byte{}
if _, ok := dalc.(*mock.DataAvailabilityLayerClient); ok {
conf = []byte(mockDaBlockTime.String())
}
if _, ok := dalc.(*celestia.DataAvailabilityLayerClient); ok {
conf, _ = json.Marshal(testConfig)
}
kvStore, _ := store.NewDefaultInMemoryKVStore()
err := dalc.Init(testNamespaceID, conf, kvStore, test.NewLogger(t))
require.NoError(err)

err = dalc.Start()
require.NoError(err)
defer func() {
require.NoError(dalc.Stop())
}()

// wait a bit more than mockDaBlockTime, so mock can "produce" some blocks
time.Sleep(mockDaBlockTime + 20*time.Millisecond)

// only blocks b1 and b2 will be submitted to DA
b1 := getRandomBlock(1, 10)
b2 := getRandomBlock(2, 10)

resp := dalc.SubmitBlock(ctx, b1)
h1 := resp.DAHeight
assert.Equal(da.StatusSuccess, resp.Code)

resp = dalc.SubmitBlock(ctx, b2)
h2 := resp.DAHeight
assert.Equal(da.StatusSuccess, resp.Code)

// wait a bit more than mockDaBlockTime, so Rollkit blocks can be "included" in mock block
time.Sleep(mockDaBlockTime + 20*time.Millisecond)

check := dalc.CheckBlockAvailability(ctx, h1)
assert.Equal(da.StatusSuccess, check.Code)
assert.True(check.DataAvailable)

check = dalc.CheckBlockAvailability(ctx, h2)
assert.Equal(da.StatusSuccess, check.Code)
assert.True(check.DataAvailable)

// this height should not be used by DALC
check = dalc.CheckBlockAvailability(ctx, h1-1)
assert.Equal(da.StatusSuccess, check.Code)
assert.False(check.DataAvailable)
}

func TestRetrieve(t *testing.T) {
for _, client := range registry.RegisteredClients() {
t.Run(client, func(t *testing.T) {
Expand Down
10 changes: 0 additions & 10 deletions proto/dalc/dalc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ message SubmitBlockResponse {
DAResponse result = 1;
}

message CheckBlockAvailabilityRequest {
uint64 da_height = 1 [(gogoproto.customname) = "DAHeight"];
}

message CheckBlockAvailabilityResponse {
DAResponse result = 1;
bool data_available = 2;
}

message RetrieveBlocksRequest {
uint64 da_height = 1 [(gogoproto.customname) = "DAHeight"];
}
Expand All @@ -46,6 +37,5 @@ message RetrieveBlocksResponse {

service DALCService {
rpc SubmitBlock(SubmitBlockRequest) returns (SubmitBlockResponse) {}
rpc CheckBlockAvailability(CheckBlockAvailabilityRequest) returns (CheckBlockAvailabilityResponse) {}
rpc RetrieveBlocks(RetrieveBlocksRequest) returns (RetrieveBlocksResponse) {}
}
Loading

0 comments on commit 9c9e4b0

Please sign in to comment.