Skip to content

Commit

Permalink
fix(rosetta): network status return the last committed block height
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Feb 17, 2023
1 parent ccd4625 commit 6a0c8cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions server/rosetta/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,17 @@ func (c converter) HashToTxType(hashBytes []byte) (txType TransactionType, realH
func (c converter) SyncStatus(status *tmcoretypes.ResultStatus) *rosettatypes.SyncStatus {
// determine sync status
stage := StatusPeerSynced
synced := true
if status.SyncInfo.CatchingUp {
stage = StatusPeerSyncing
synced = false
}

return &rosettatypes.SyncStatus{
CurrentIndex: &status.SyncInfo.LatestBlockHeight,
TargetIndex: nil, // sync info does not allow us to get target height
Stage: &stage,
Synced: &synced,
}
}

Expand Down
14 changes: 11 additions & 3 deletions server/rosetta/lib/internal/service/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,25 @@ func (on OnlineNetwork) NetworkOptions(_ context.Context, _ *types.NetworkReques
}

func (on OnlineNetwork) NetworkStatus(ctx context.Context, _ *types.NetworkRequest) (*types.NetworkStatusResponse, *types.Error) {
block, err := on.client.BlockByHeight(ctx, nil)
peers, err := on.client.Peers(ctx)
if err != nil {
return nil, errors.ToRosetta(err)
}

peers, err := on.client.Peers(ctx)
syncStatus, err := on.client.Status(ctx)
if err != nil {
return nil, errors.ToRosetta(err)
}

syncStatus, err := on.client.Status(ctx)
lastBlockHeight := *syncStatus.CurrentIndex
if *syncStatus.Synced {
lastBlockHeight, err = on.client.LastBlockHeight(ctx)
if err != nil {
return nil, errors.ToRosetta(err)
}
}

block, err := on.client.BlockByHeight(ctx, &lastBlockHeight)
if err != nil {
return nil, errors.ToRosetta(err)
}
Expand Down

0 comments on commit 6a0c8cb

Please sign in to comment.