Skip to content

Commit 000c17b

Browse files
fix: rosetta server boot and add burn event type to pass check:data (#10150) (#10165)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description closes: #10121 closes: #10088 rosetta server fails to run with genesis.json has initial_heights 2 or larger rosetta-cli check:data fails to parse EventTypeCoinBurn --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit 5a72b5e) Co-authored-by: Geoff Lee <[email protected]>
1 parent 6cfa58f commit 000c17b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

server/rosetta/client_online.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func NewClient(cfg *Config) (*Client, error) {
7676

7777
supportedOperations = append(
7878
supportedOperations,
79-
bank.EventTypeCoinSpent, bank.EventTypeCoinReceived,
79+
bank.EventTypeCoinSpent,
80+
bank.EventTypeCoinReceived,
81+
bank.EventTypeCoinBurn,
8082
)
8183

8284
return &Client{
@@ -185,6 +187,10 @@ func (c *Client) BlockByHash(ctx context.Context, hash string) (crgtypes.BlockRe
185187
}
186188

187189
func (c *Client) BlockByHeight(ctx context.Context, height *int64) (crgtypes.BlockResponse, error) {
190+
height, err := c.getHeight(ctx, height)
191+
if err != nil {
192+
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
193+
}
188194
block, err := c.tmRPC.Block(ctx, height)
189195
if err != nil {
190196
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
@@ -204,6 +210,10 @@ func (c *Client) BlockTransactionsByHash(ctx context.Context, hash string) (crgt
204210
}
205211

206212
func (c *Client) BlockTransactionsByHeight(ctx context.Context, height *int64) (crgtypes.BlockTransactionsResponse, error) {
213+
height, err := c.getHeight(ctx, height)
214+
if err != nil {
215+
return crgtypes.BlockTransactionsResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
216+
}
207217
blockTxResp, err := c.blockTxs(ctx, height)
208218
if err != nil {
209219
return crgtypes.BlockTransactionsResponse{}, err
@@ -468,3 +478,16 @@ func (c *Client) blockTxs(ctx context.Context, height *int64) (crgtypes.BlockTra
468478
Transactions: finalTxs,
469479
}, nil
470480
}
481+
482+
func (c *Client) getHeight(ctx context.Context, height *int64) (realHeight *int64, err error) {
483+
if height != nil && *height == -1 {
484+
genesis, err := c.tmRPC.Genesis(ctx)
485+
if err != nil {
486+
return nil, err
487+
}
488+
realHeight = &(genesis.Genesis.InitialHeight)
489+
} else {
490+
realHeight = height
491+
}
492+
return
493+
}

server/rosetta/lib/internal/service/offline.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NewOffline(network *types.NetworkIdentifier, client crgtypes.Client) (crgty
1717
OnlineNetwork{
1818
client: client,
1919
network: network,
20-
networkOptions: networkOptionsFromClient(client),
20+
networkOptions: networkOptionsFromClient(client, nil),
2121
},
2222
}, nil
2323
}

server/rosetta/lib/internal/service/online.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func NewOnlineNetwork(network *types.NetworkIdentifier, client crgtypes.Client)
1919
ctx, cancel := context.WithTimeout(context.Background(), genesisBlockFetchTimeout)
2020
defer cancel()
2121

22-
var genesisHeight int64 = 1
22+
var genesisHeight int64 = -1 // to use initial_height in genesis.json
2323
block, err := client.BlockByHeight(ctx, &genesisHeight)
2424
if err != nil {
2525
return OnlineNetwork{}, err
@@ -28,7 +28,7 @@ func NewOnlineNetwork(network *types.NetworkIdentifier, client crgtypes.Client)
2828
return OnlineNetwork{
2929
client: client,
3030
network: network,
31-
networkOptions: networkOptionsFromClient(client),
31+
networkOptions: networkOptionsFromClient(client, block.Block),
3232
genesisBlockIdentifier: block.Block,
3333
}, nil
3434
}
@@ -50,7 +50,11 @@ func (o OnlineNetwork) AccountCoins(_ context.Context, _ *types.AccountCoinsRequ
5050
}
5151

5252
// networkOptionsFromClient builds network options given the client
53-
func networkOptionsFromClient(client crgtypes.Client) *types.NetworkOptionsResponse {
53+
func networkOptionsFromClient(client crgtypes.Client, genesisBlock *types.BlockIdentifier) *types.NetworkOptionsResponse {
54+
var tsi *int64 = nil
55+
if genesisBlock != nil {
56+
tsi = &(genesisBlock.Index)
57+
}
5458
return &types.NetworkOptionsResponse{
5559
Version: &types.Version{
5660
RosettaVersion: crgtypes.SpecVersion,
@@ -61,6 +65,7 @@ func networkOptionsFromClient(client crgtypes.Client) *types.NetworkOptionsRespo
6165
OperationTypes: client.SupportedOperations(),
6266
Errors: crgerrs.SealAndListErrors(),
6367
HistoricalBalanceLookup: true,
68+
TimestampStartIndex: tsi,
6469
},
6570
}
6671
}

0 commit comments

Comments
 (0)