Skip to content

Commit

Permalink
revert retries on hub client
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin committed Dec 25, 2023
1 parent d2b2cdf commit c534d1d
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,14 @@ 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
err := retry.Do(func() error {
var err error
latestStateInfoIndexResp, err = d.rollappQueryClient.LatestStateIndex(d.ctx,
&rollapptypes.QueryGetLatestStateIndexRequest{RollappId: d.config.RollappID})
return err
}, retry.Context(d.ctx), retry.LastErrorOnly(true),
retry.Delay(d.batchRetryDelay), retry.Attempts(d.batchRetryAttempts), retry.MaxDelay(batchRetryMaxDelay))

if err != nil {
return nil, err
}
latestStateInfoIndexResp, err := d.rollappQueryClient.LatestStateIndex(d.ctx,
&rollapptypes.QueryGetLatestStateIndexRequest{RollappId: d.config.RollappID})
if latestStateInfoIndexResp == nil {
return nil, settlement.ErrBatchNotFound
}

if err != nil {
return nil, err
}

Check warning on line 302 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L301-L302

Added lines #L301 - L302 were not covered by tests
latestBatch, err := d.GetBatchAtIndex(rollappID, latestStateInfoIndexResp.StateIndex.Index)
if err != nil {
return nil, err
Expand All @@ -317,41 +309,23 @@ func (d *HubClient) GetLatestBatch(rollappID string) (*settlement.ResultRetrieve

// GetBatchAtIndex returns the batch at the given index from the Dymension Hub.
func (d *HubClient) GetBatchAtIndex(rollappID string, index uint64) (*settlement.ResultRetrieveBatch, error) {
var stateInfoResp *rollapptypes.QueryGetStateInfoResponse
err := retry.Do(func() error {
var err error
stateInfoResp, err = d.rollappQueryClient.StateInfo(d.ctx,
&rollapptypes.QueryGetStateInfoRequest{RollappId: d.config.RollappID, Index: index})
return err
}, retry.Context(d.ctx), retry.LastErrorOnly(true),
retry.Delay(d.batchRetryDelay), retry.Attempts(d.batchRetryAttempts), retry.MaxDelay(batchRetryMaxDelay))

if err != nil {
return nil, err
}
stateInfoResp, err := d.rollappQueryClient.StateInfo(d.ctx,
&rollapptypes.QueryGetStateInfoRequest{RollappId: d.config.RollappID, Index: index})
if stateInfoResp == nil {
return nil, settlement.ErrBatchNotFound
}
if err != nil {
return nil, err
}

Check warning on line 319 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L318-L319

Added lines #L318 - L319 were not covered by tests
return d.convertStateInfoToResultRetrieveBatch(&stateInfoResp.StateInfo)
}

// GetSequencers returns the sequence of the given rollapp.
func (d *HubClient) GetSequencers(rollappID string) ([]*types.Sequencer, error) {
var sequencers *sequencertypes.QueryGetSequencersByRollappResponse
err := retry.Do(func() error {
var err error
sequencers, err = d.sequencerQueryClient.SequencersByRollapp(d.ctx, &sequencertypes.QueryGetSequencersByRollappRequest{RollappId: d.config.RollappID})
if err != nil {
return errors.Wrapf(settlement.ErrNoSequencerForRollapp, "rollappID: %s", rollappID)
}
return nil
}, retry.Context(d.ctx), retry.LastErrorOnly(true),
retry.Delay(d.batchRetryDelay), retry.Attempts(d.batchRetryAttempts), retry.MaxDelay(batchRetryMaxDelay))

sequencers, err := d.sequencerQueryClient.SequencersByRollapp(d.ctx, &sequencertypes.QueryGetSequencersByRollappRequest{RollappId: d.config.RollappID})
if err != nil {
return nil, err
return nil, errors.Wrapf(settlement.ErrNoSequencerForRollapp, "rollappID: %s", rollappID)

Check warning on line 327 in settlement/dymension/dymension.go

View check run for this annotation

Codecov / codecov/patch

settlement/dymension/dymension.go#L327

Added line #L327 was not covered by tests
}

sequencersList := []*types.Sequencer{}
for _, sequencer := range sequencers.SequencerInfoList {
var pubKey cryptotypes.PubKey
Expand Down

0 comments on commit c534d1d

Please sign in to comment.