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

[rosetta] implement balance tracking and redo tx construction #8729

Merged
merged 39 commits into from
Mar 11, 2021

Conversation

fdymylja
Copy link
Contributor

@fdymylja fdymylja commented Mar 1, 2021

Description

This PR fully implements balance tracking via data API using balance tracking events.

On top of that, now construction supports out of the box any message in any possible application that passes through the /tx endpoint without requiring any message extension.

closes: #8705


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Mar 5, 2021

Codecov Report

Merging #8729 (3e47bb4) into master (8f7cdaf) will decrease coverage by 0.28%.
The diff coverage is 32.70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8729      +/-   ##
==========================================
- Coverage   59.44%   59.15%   -0.29%     
==========================================
  Files         563      570       +7     
  Lines       31286    31764     +478     
==========================================
+ Hits        18598    18791     +193     
- Misses      10522    10774     +252     
- Partials     2166     2199      +33     
Impacted Files Coverage Δ
crypto/keyring/keyring.go 59.29% <0.00%> (-0.18%) ⬇️
server/rosetta/client_offline.go 0.00% <0.00%> (ø)
server/rosetta/client_online.go 0.00% <0.00%> (ø)
server/rosetta/types.go 0.00% <0.00%> (ø)
server/rosetta/util.go 0.00% <0.00%> (ø)
types/codec.go 50.00% <0.00%> (ø)
x/bank/types/msgs.go 96.87% <ø> (+42.96%) ⬆️
x/distribution/types/msg.go 47.54% <ø> (+15.67%) ⬆️
x/staking/types/msg.go 54.92% <ø> (+31.00%) ⬆️
server/rosetta/converter.go 54.44% <54.44%> (ø)
... and 8 more

@fdymylja fdymylja marked this pull request as ready for review March 5, 2021 10:27
@fdymylja
Copy link
Contributor Author

fdymylja commented Mar 5, 2021

I'd like to get this merged because it has got really big, and do immediately a follow up PR with extra tests.

@alessio
Copy link
Contributor

alessio commented Mar 5, 2021

Linter is failing

@alessio alessio requested a review from robert-zaremba March 5, 2021 12:35
Copy link
Contributor

@jgimeno jgimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent job!! We are very close!!

server/rosetta/types.go Outdated Show resolved Hide resolved
server/rosetta/types.go Outdated Show resolved Hide resolved
x/bank/types/msgs.go Show resolved Hide resolved
@alessio alessio requested a review from fedekunze March 9, 2021 18:05
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending changelog entry

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only reviewed part of it.

}

txBytes, err := TxConfig.TxEncoder()(txBldr.GetTx())
// now we need to parse the operations to cosmos sdk messages
tx, err := c.converter.ToSDK().UnsignedTx(req.Operations)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we can cache this operation (ToSDK) in the converter structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a lot of performance improvements that can be done (there's a double unmarshal on operations for example) but since I plan to do a follow up PR with extra tests immediately after this one is merged, I'd rather tackle the improvements in that, because this PR has got really big and its hard to review as it is. WDYT?

txConfig := authtx.NewTxConfig(cfg.Codec, authtx.DefaultSignModes)

var supportedOperations []string
for _, ii := range cfg.InterfaceRegistry.ListImplementations("cosmos.base.v1beta1.Msg") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't hardcode the message name. Instead:
let's create const in types/codec.go and export it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have any preference in the naming? I was thinking of having a name which contains the version of the interface such as: MsgV1Beta1InterfaceName, although it looks ugly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about MsgProtoName? This is what we would get from the following call:

proto.MessageName((*Msg)(nil))

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few more comments. For few general things:

  • godoc is missing for exported methods

@@ -104,7 +104,7 @@ Finally, a few more important parameterd:

```go
func NewBaseApp(
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
name string, logger log.Logger, db dbm.DB, txDecode sdk.TxDecoder, options ...func(*BaseApp),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original name is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i refactored something somewhere in the code and this got affected too! thanks for pointing it out!

}, nil
}

func (c *Client) accountInfo(ctx context.Context, addr string, height *int64) (auth.AccountI, error) {
// Bootstrap is gonna connect the client to the endpoints
func (c *Client) Bootstrap() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this method to Dial or Connect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is part of interface implementation

server/rosetta/client_online.go Outdated Show resolved Hide resolved
}

func (c *Client) Balances(ctx context.Context, addr string, height *int64) ([]*types.Amount, error) {
func (c *Client) Balances(ctx context.Context, addr string, height *int64) ([]*rosettatypes.Amount, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godoc is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godocs are missing because those methods are part of an interface implementation - which is in itself throughly documented - I will add the comments that those methods implement the said interface

server/rosetta/client_online.go Outdated Show resolved Hide resolved
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"

"github.com/coinbase/rosetta-sdk-go/types"
rosettatypes "github.com/coinbase/rosetta-sdk-go/types"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports are not ordered correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goimports does not give warnings, nor edit the files if I do run it against the rosetta dir.

do you use some other tooling?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, goimports is not able to reorder lines that are blank-separated. It's a known limitation. We can fix this in a separate PR


sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server/rosetta/converter_test.go Outdated Show resolved Hide resolved
s.Require().ErrorIs(err, crgerrs.ErrBadArgument)
})

s.Run("codec type but not sdk.Msg", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be converted to table tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fdymylja can you address this in your follow up PR, please?

server/rosetta/converter_test.go Outdated Show resolved Hide resolved
@alessio alessio added the A:automerge Automatically merge PR once all prerequisites pass. label Mar 11, 2021
@alessio alessio merged commit 288f8dd into master Mar 11, 2021
@alessio alessio deleted the frojdi/rosetta-balance-tracking branch March 11, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[rosetta]: support balance tracking via events
6 participants