Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: removed unneeded state-index query #650

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,11 @@ func (d *HubClient) PostBatch(batch *types.Batch, daClient da.Client, daResult *

// GetLatestBatch returns the latest batch from the Dymension Hub.
func (d *HubClient) GetLatestBatch(rollappID string) (*settlement.ResultRetrieveBatch, error) {
var latestStateInfoIndexResp *rollapptypes.QueryGetLatestStateIndexResponse

var stateInfoResp *rollapptypes.QueryGetStateInfoResponse
err := d.RunWithRetry(func() error {
var err error
latestStateInfoIndexResp, err = d.rollappQueryClient.LatestStateIndex(d.ctx,
&rollapptypes.QueryGetLatestStateIndexRequest{RollappId: d.config.RollappID})
stateInfoResp, err = d.rollappQueryClient.StateInfo(d.ctx,
&rollapptypes.QueryGetStateInfoRequest{RollappId: d.config.RollappID})

if status.Code(err) == codes.NotFound {
return retry.Unrecoverable(settlement.ErrBatchNotFound)
Expand All @@ -302,17 +301,12 @@ func (d *HubClient) GetLatestBatch(rollappID string) (*settlement.ResultRetrieve
if err != nil {
return nil, err
}

// not supposed to happen, but just in case
if latestStateInfoIndexResp == nil {
if stateInfoResp == nil {
return nil, settlement.ErrEmptyResponse
}

latestBatch, err := d.GetBatchAtIndex(rollappID, latestStateInfoIndexResp.StateIndex.Index)
if err != nil {
return nil, err
}
return latestBatch, nil
return d.convertStateInfoToResultRetrieveBatch(&stateInfoResp.StateInfo)
}

// GetBatchAtIndex returns the batch at the given index from the Dymension Hub.
Expand Down
5 changes: 1 addition & 4 deletions settlement/dymension/dymension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func TestPostBatch(t *testing.T) {
wg.Add(eventsCount)
// Reset the mock functions
testutil.UnsetMockFn(cosmosClientMock.On("BroadcastTx"))
testutil.UnsetMockFn(rollappQueryClientMock.On("LatestStateIndex"))
testutil.UnsetMockFn(rollappQueryClientMock.On("StateInfo"))
// Set the mock logic based on the test case
if !c.isBatchSubmitSuccess {
Expand All @@ -174,8 +173,6 @@ func TestPostBatch(t *testing.T) {
}
if c.shouldMockBatchIncluded {
if c.isBatchIncludedSuccess {
rollappQueryClientMock.On("LatestStateIndex", mock.Anything, mock.Anything).Return(
&rollapptypes.QueryGetLatestStateIndexResponse{StateIndex: rollapptypes.StateInfoIndex{Index: 1}}, nil)
daMetaData := &da.DASubmitMetaData{
Height: 1,
Client: da.Mock,
Expand All @@ -186,7 +183,7 @@ func TestPostBatch(t *testing.T) {
}},
nil)
} else {
rollappQueryClientMock.On("LatestStateIndex", mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error"))
rollappQueryClientMock.On("StateInfo", mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error"))
}
}
hubClient, err := newDymensionHubClient(settlement.Config{}, pubsubServer, log.TestingLogger(), options...)
Expand Down
Loading