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 5a72b5e02b)

Co-authored-by: Geoff Lee <thirdchance@gmail.com>
This commit is contained in:
mergify[bot] 2021-09-16 13:19:53 +02:00 committed by GitHub
parent 6cfa58f1ce
commit 000c17b0c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions

View File

@ -76,7 +76,9 @@ func NewClient(cfg *Config) (*Client, error) {
supportedOperations = append(
supportedOperations,
bank.EventTypeCoinSpent, bank.EventTypeCoinReceived,
bank.EventTypeCoinSpent,
bank.EventTypeCoinReceived,
bank.EventTypeCoinBurn,
)
return &Client{
@ -185,6 +187,10 @@ func (c *Client) BlockByHash(ctx context.Context, hash string) (crgtypes.BlockRe
}
func (c *Client) BlockByHeight(ctx context.Context, height *int64) (crgtypes.BlockResponse, error) {
height, err := c.getHeight(ctx, height)
if err != nil {
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
}
block, err := c.tmRPC.Block(ctx, height)
if err != nil {
return crgtypes.BlockResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
@ -204,6 +210,10 @@ func (c *Client) BlockTransactionsByHash(ctx context.Context, hash string) (crgt
}
func (c *Client) BlockTransactionsByHeight(ctx context.Context, height *int64) (crgtypes.BlockTransactionsResponse, error) {
height, err := c.getHeight(ctx, height)
if err != nil {
return crgtypes.BlockTransactionsResponse{}, crgerrs.WrapError(crgerrs.ErrBadGateway, err.Error())
}
blockTxResp, err := c.blockTxs(ctx, height)
if err != nil {
return crgtypes.BlockTransactionsResponse{}, err
@ -468,3 +478,16 @@ func (c *Client) blockTxs(ctx context.Context, height *int64) (crgtypes.BlockTra
Transactions: finalTxs,
}, nil
}
func (c *Client) getHeight(ctx context.Context, height *int64) (realHeight *int64, err error) {
if height != nil && *height == -1 {
genesis, err := c.tmRPC.Genesis(ctx)
if err != nil {
return nil, err
}
realHeight = &(genesis.Genesis.InitialHeight)
} else {
realHeight = height
}
return
}

View File

@ -17,7 +17,7 @@ func NewOffline(network *types.NetworkIdentifier, client crgtypes.Client) (crgty
OnlineNetwork{
client: client,
network: network,
networkOptions: networkOptionsFromClient(client),
networkOptions: networkOptionsFromClient(client, nil),
},
}, nil
}

View File

@ -19,7 +19,7 @@ func NewOnlineNetwork(network *types.NetworkIdentifier, client crgtypes.Client)
ctx, cancel := context.WithTimeout(context.Background(), genesisBlockFetchTimeout)
defer cancel()
var genesisHeight int64 = 1
var genesisHeight int64 = -1 // to use initial_height in genesis.json
block, err := client.BlockByHeight(ctx, &genesisHeight)
if err != nil {
return OnlineNetwork{}, err
@ -28,7 +28,7 @@ func NewOnlineNetwork(network *types.NetworkIdentifier, client crgtypes.Client)
return OnlineNetwork{
client: client,
network: network,
networkOptions: networkOptionsFromClient(client),
networkOptions: networkOptionsFromClient(client, block.Block),
genesisBlockIdentifier: block.Block,
}, nil
}
@ -50,7 +50,11 @@ func (o OnlineNetwork) AccountCoins(_ context.Context, _ *types.AccountCoinsRequ
}
// networkOptionsFromClient builds network options given the client
func networkOptionsFromClient(client crgtypes.Client) *types.NetworkOptionsResponse {
func networkOptionsFromClient(client crgtypes.Client, genesisBlock *types.BlockIdentifier) *types.NetworkOptionsResponse {
var tsi *int64 = nil
if genesisBlock != nil {
tsi = &(genesisBlock.Index)
}
return &types.NetworkOptionsResponse{
Version: &types.Version{
RosettaVersion: crgtypes.SpecVersion,
@ -61,6 +65,7 @@ func networkOptionsFromClient(client crgtypes.Client) *types.NetworkOptionsRespo
OperationTypes: client.SupportedOperations(),
Errors: crgerrs.SealAndListErrors(),
HistoricalBalanceLookup: true,
TimestampStartIndex: tsi,
},
}
}