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

Create app #23

Merged
merged 29 commits into from
Aug 15, 2019
Merged

Create app #23

merged 29 commits into from
Aug 15, 2019

Conversation

orkunkl
Copy link
Contributor

@orkunkl orkunkl commented Jul 29, 2019

Closes #4
This is basically a copy-paste from the tutorial. If you think if there is an unnecessary chain decorator, let me know

@orkunkl orkunkl requested review from husio, alpe, ruseinov and ethanfrey July 29, 2019 10:40
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Nice start. Made some comments to clean up app.
Clearly docs need to exist to explain this. Thanks for figuring this out without proper docs.

app/app.go Outdated
// Router returns a default router
func Router(authFn x.Authenticator) *app.Router {
r := app.NewRouter()
// TODO implement orderbook router
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace this TODO with the multisig and cash router at least.

app/app.go Outdated
sigs.NewDecorator(),
multisig.NewDecorator(authFn),
utils.NewSavepoint().OnDeliver(),
msgfee.NewFeeDecorator(),
Copy link
Contributor

Choose a reason for hiding this comment

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

msgfee can probably be removed from base app.
And the cash.StaticFeeDecorator can be used above (this is the simplest case when the product fee doesn't depend on the output from the Handler)

// allowing access to "/auth", "/contracts" and "/"
func QueryRouter() weave.QueryRouter {
r := weave.NewQueryRouter()
r.RegisterAll(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add cash here, as this is basic to most apps.
And msgfee if you don't remove the decorator above.

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 thought we should keep weave-starter-kit simple as possible. So deleted msgfee

repeated bytes multisig = 4;
// msg is a sum type over all allowed messages on this chain.
oneof sum {
cash.SendMsg cash_send_msg = 51;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also add the create/update multisig msgs here

app/codec.proto Outdated
// space here to allow many more....

custom.CreateCustomStateIndexedMsg custom_create_state_indexed_msg = 100;
custom.CreateCustomStateMsg create_custom_state_msg = 101;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you add these, please update the Router and QueryHandler set in the app to include these

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 still need to implement handler and buckets. Lets keep this PR on until I finish and merge them

app/init.go Outdated
// DecorateApp adds initializers and Logger to an Application
func DecorateApp(application app.BaseApp, logger log.Logger) app.BaseApp {
application.WithInit(app.ChainInitializers(
&migration.Initializer{},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this to be in-line with the router/query/etc.

There are a few places that need to be kept in sync - good to add this to the docs.

When adding a package:

  • Stack if it has a Decorator
  • Router if it has a Handler
  • QueryRouter if it has any Buckets
  • DecorateApp/init if it has any Initializer.

Best to write down a list of all modules to use first, then make them all the same. As discussed above, I think the minimal set is:

  • cash
  • sigs
  • multisig
  • currency
  • migration (as a runtime dependency of above modules)

validators is a nice to have to run a PoA testnet and good to have as a demo.

--

msgfee is a bit more complex and requires more complex Fee handling. I would not use this for default app.

@@ -2,7 +2,7 @@ syntax = "proto3";

package custom;

import "github.com/iov-one/weave/codec.proto";
import "codec.proto";
Copy link
Contributor

Choose a reason for hiding this comment

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

This didn't work the other way?
I actually thought we wanted short paths for references in the same repo, and full for outside.

But if needed for protoc, then do it like this.

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 tried to make it work as it was but no chance 😞 The only thing worked is to make x/codec imports refer to weave codec without the prefix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, then we just document that. Maybe someone (maybe me?) has time to look into it. Otherwise we just explain how to work with this.

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 would appreciate it if somebody takes a look at it. I spent quite a time on the issue and this is the solution I come up with ¯_(ツ)_/¯

@ethanfrey
Copy link
Contributor

About protoc... these are key lines in prototool.yaml.

 includes:
    - .
    - /usr/include
    - spec
    - spec/github.com/iov-one/weave

. means that import "x/custom/codec.go" will work inside this app (recommended to avoid GOPATH issues)

spec means that we can import "github.com/iov-one/weave/coins/codec.proto" and it will use the protobuf file from our spec dir (which must be kept up to date with the weave repo).

spec/github.com/iov-one/weave is needed as if we import eg. github.com/iov-one/weave/x/cash/codec.proto, it imports coins/codec.proto using relative imports to it's project. When we then import this via spec, the relative import doesn't work without this second line.

That is - customapp imports modules from same repo with short path. customapp imports weave protobuf from spec with full path. weave protobuf inside spec imports other weave protobuf with short path.

Does this make sense? It was how I got it to work once (how it still does). But I really should have documented this better. Sorry.

@orkunkl
Copy link
Contributor Author

orkunkl commented Aug 6, 2019

Blocked by #31

Copy link

@husio husio left a comment

Choose a reason for hiding this comment

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

If you want to make this crips, please update the comments to follow https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences

app/app.go Outdated
)
}

/* custom app uses below weave modules apart from x/custom
Copy link

Choose a reason for hiding this comment

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

I am not sure why this comment is here. I think if at all, it should be part of general application documentation or package level comment. This place seems quite random for this listing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice advise 👍 I really enjoy writing go because only language itself covers and enforces structuring and documenting your code.

app/app.go Outdated
// Expand the path fully
path, err := filepath.Abs(dbPath)
if err != nil {
return nil, fmt.Errorf("Invalid Database Name: %s", path)
Copy link

Choose a reason for hiding this comment

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

Error string should not be capitalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings
Maybe it is worth using weave/errors package to produce a better error instance?

app/app.go Outdated
ctx := context.Background()
kv, err := CommitKVStore(dbPath)
if err != nil {
return app.BaseApp{}, err
Copy link

Choose a reason for hiding this comment

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

I think it is better to wrap error with additional information. Such context information is useful during debugging. For example:

return app.BaseApp{}, errors.Wrap(err, "cannot create database instance")

// Tx contains the message
message Tx {
// fee info, autogenerates GetFees()
cash.FeeInfo cash_fees = 1;
Copy link

Choose a reason for hiding this comment

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

Is the above comment true? This attribute will generate GetCashFees method. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/iov-one/weave/blob/master/x/cash/codec.pb.go#L220-L225 Auto-generation does not cover the concept though.

Copy link

Choose a reason for hiding this comment

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

It is not necessary to add comments for autogeneration. Just remove it to not create confusion with all the other fields where it is not added.

app/codec.proto Outdated
repeated sigs.StdSignature sigs_signatures = 2;
// ID of a multisig contract.
repeated bytes multisig = 4;
// msg is a sum type over all allowed messages on this chain.
Copy link

Choose a reason for hiding this comment

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

This attribute is called sum not msg 🚓

app/init.go Outdated
dict map[string]interface{}
array []interface{}
)
collectorAddr, err := hex.DecodeString("3b11c732b8fc1f09beb34031302fe2ab347c5c14")
Copy link

Choose a reason for hiding this comment

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

I think it is worth adding a comment what collector address is (to whom it belongs to?) and why it is hardcoded here.

Copy link
Contributor Author

@orkunkl orkunkl Aug 12, 2019

Choose a reason for hiding this comment

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

Nice point. I will take bnsd/init as an example because mycoind/initseems too much outdated

app/init.go Outdated
// You can give coins to this address and return the recovery
// phrase to the user to access them.
func GenerateCoinKey() (weave.Address, string, error) {
// TODO implement BIP39 recovery phrases
Copy link

Choose a reason for hiding this comment

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

I think a TODO does not belong in a good codebase. Either implement it or leave a good comment explaining why below functionality works in this certain way and what was the reason for choosing this implementation.

Leaving TODO like this will give an impression that the code is not finished and lacking, therefore cannot be trusted. No one will address this comment as well.

app/tx.go Outdated
// make sure tx fulfills all interfaces
var _ weave.Tx = (*Tx)(nil)

// GetMsg switches over all types defined in the protobuf file
Copy link

Choose a reason for hiding this comment

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

I think a much better comment explaining the functionality would be

GetMsg returns a single message instance that is represented by this transaction.

Copy link

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Only had a very brief look:

  • Please run go fmt $(go list ./... | grep -v "/vendor/")
  • make protoc fails on my box
<input>:1:1:Import "x/custom/codec.proto" was not found.
app/codec.proto:29:5:"custom.CreateTimedStateMsg" is not defined.
app/codec.proto:30:5:"custom.CreateStateMsg" is not defined.
  • make test fails on my box:
app/app.go:23:2: unknown import path "github.com/iov-one/weave-starter-kit/x/custom": import lookup disabled by -mod=readonly

// Tx contains the message
message Tx {
// fee info, autogenerates GetFees()
cash.FeeInfo cash_fees = 1;
Copy link

Choose a reason for hiding this comment

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

It is not necessary to add comments for autogeneration. Just remove it to not create confusion with all the other fields where it is not added.

@orkunkl
Copy link
Contributor Author

orkunkl commented Aug 12, 2019

@alpe really weird you are having errors on make protoc. I don't have any. Do you have any guess why you could be getting errors?

@orkunkl
Copy link
Contributor Author

orkunkl commented Aug 13, 2019

Waiting for response from gogo/protobuf#601

@orkunkl orkunkl mentioned this pull request Aug 14, 2019
@orkunkl
Copy link
Contributor Author

orkunkl commented Aug 15, 2019

I have fixed harmless protoc bug in iov-one/weave#953. Changes will be applied when upgraded to weave v0.21.0

@orkunkl orkunkl merged commit 482e603 into master Aug 15, 2019
@orkunkl orkunkl deleted the create-app branch August 15, 2019 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build sample app
4 participants