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

Bianjie/lcd implementation #2118

Closed

Conversation

abelliumnt
Copy link

@abelliumnt abelliumnt commented Aug 22, 2018

Lcd spec location: https://github.com/cosmos/cosmos-sdk/tree/adrian/lcd_spec_final/docs/light
Main new feature:

  • Add query store proof verification
  • Add swagger-ui
  • Lcd can connect to multiply full nodes and will do load balancing
  • Support modular APIs. Currently we only support key management, token query, token send, stake query, node version query.

Test report:
https://github.com/HaoyangLiu/cosmos-sdk/blob/haoyang/lcd-test/docs/light/Cosmos-LCD-Test-Report.md


Closes #525

@abelliumnt
Copy link
Author

@jaekwon @jackzampolin
This is bianjie lcd implementation which has brought in proof verification and swagger-ui. Please help take a look at this pull request. Thanks

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.

Hi @HaoyangLiu, thanks so much for the work here. Could you change every reference of LCD to Gaia-lite ?

@@ -113,3 +116,15 @@ func (ctx CLIContext) WithUseLedger(useLedger bool) CLIContext {
ctx.UseLedger = useLedger
return ctx
}

// WithCert - return a copy of the context with an updated Cert
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use Tendermint Lint to avoid verbose comments. You won't need to add the function name at the beginning of the comment with it

@@ -288,6 +288,23 @@ func (rs *rootMultiStore) Query(req abci.RequestQuery) abci.ResponseQuery {
// trim the path and make the query
req.Path = subpath
res := queryable.Query(req)

// WARNING This should be consistent with query method in iavlstore.go
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you open a separate issue for this warning ?

// RegisterSwaggerRoutes - Central function to define routes that get registered by the main application
func RegisterSwaggerRoutes(routerGroup *gin.RouterGroup, ctx context.CLIContext, cdc *wire.Codec, kb keys.Keybase) {
routerGroup.POST("/accounts/:address/send", sendRequestFn(cdc, ctx, kb))
routerGroup.POST("/create_transfer", createTransferTxForSignFn(cdc, ctx))
Copy link
Collaborator

@fedekunze fedekunze Aug 22, 2018

Choose a reason for hiding this comment

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

was changed to transfers. See #1979

func RegisterSwaggerRoutes(routerGroup *gin.RouterGroup, ctx context.CLIContext, cdc *wire.Codec, kb keys.Keybase) {
routerGroup.POST("/accounts/:address/send", sendRequestFn(cdc, ctx, kb))
routerGroup.POST("/create_transfer", createTransferTxForSignFn(cdc, ctx))
routerGroup.POST("/signed_transfer", composeAndBroadcastSignedTransferTxFn(cdc, ctx))
Copy link
Collaborator

@fedekunze fedekunze Aug 22, 2018

Choose a reason for hiding this comment

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

I would also suggest to change it to transfers and add a boolean parameter called signed in POST body. cc: @jackzampolin

Copy link
Author

Choose a reason for hiding this comment

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

add a boolean parameter called signed in POST body

Could you clarify this? Do you mean merge /create_transfer and /signed_transfer into one rest api, such as /bank/transfers? I think this sound weird. How do you think about this? @jackzampolin

Copy link
Member

Choose a reason for hiding this comment

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

Here we are adding to the transfers resource so the restful route here would be POST /bank/transfers. It sounds like this route has two different behaviors:

  • Create a transaction formatted for signing
  • Create a transaction, sign and send this transaction.

I think the dominant behavior here would be to send a transaction and the transaction generation is more secondary. In the CLI we plan to handle this workflow (generate, sign,send) by adding a --generate-only flag to commands that normally do all 3.

The analogue here would be to add a query param (maybe ?generate=true) that enables the generation behavior. What do you think @fedekunze @HaoyangLiu

Copy link
Author

Choose a reason for hiding this comment

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

Send query param in post request doesn't make sense semantically: explanation

I have another idea:
The below is the post body.

type sendBody struct {
	Name             string    `json:"name"`
	Password         string    `json:"password"`
	Amount           sdk.Coins `json:"amount"`
	ChainID          string    `json:"chain_id"`
	AccountNumber    int64     `json:"account_number"`
	Sequence         int64     `json:"sequence"`
	Gas              int64     `json:"gas"`
	Fee		 string    `json:"fee"`
}

If both the two fields ("name" and "password") are not empty, then the transaction will be signed and broadcasted. If not, only generate a transaction and return the transaction bytes to user.
What do you think about this idea? @jackzampolin @fedekunze

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with the explanation above. I like your idea more but I'd propose a slight change to it, since currently name and password are also used for testing automation purposes:

type sendBody struct {
	Name             string    `json:"name"`
	Password         string    `json:"password"`
	Amount           sdk.Coins `json:"amount"`
	ChainID          string    `json:"chain_id"`
	AccountNumber    int64     `json:"account_number"`
	Sequence         int64     `json:"sequence"`
	Gas              int64     `json:"gas"`
	Fee		 string    `json:"fee"`
        Signed		 bool      `json:"signed"` // true by default
}

@jackzampolin thoughts ?


// WithClientMgr - return a copy of the context with an updated ClientMgr
func (ctx CLIContext) WithClientMgr(clientMgr *ClientManager) CLIContext {
ctx.ClientMgr = clientMgr
Copy link
Collaborator

@fedekunze fedekunze Aug 22, 2018

Choose a reason for hiding this comment

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

change ctx.ClientMgr to ctx.ClientManager

return nil, errors.New("missing node URIs")
}

func (mgr *ClientManager) getClient() rpcclient.Client {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(mgr *ClientManager) ––> (manager *ClientManager)

@@ -277,6 +284,7 @@ func (ctx CLIContext) ensureBroadcastTx(txBytes []byte) error {
return nil
}

// nolint: gocyclo
Copy link
Collaborator

Choose a reason for hiding this comment

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

refactor the function and split it into smaller ones instead

@@ -236,6 +239,85 @@ func AddNewKeyRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Write(bz)
}

// AddNewKeyRequest is the handler of adding new key in swagger rest server
// nolint: gocyclo
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here. Refactor and split

httputils.NewError(gtx, http.StatusBadRequest, err)
return
}
err = json.Unmarshal(body, &m)
Copy link
Collaborator

@fedekunze fedekunze Aug 22, 2018

Choose a reason for hiding this comment

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

Use cdc.UnmarshalJSON for consistency

var kb keys.Keybase
var m DeleteKeyBody

if err := gtx.BindJSON(&m); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use cdc.UnmarshalJSON

httputils.NewError(gtx, http.StatusInternalServerError, err)
return
}
output, err := json.MarshalIndent(keysOutput, "", " ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

cdc.MarshalJSON

httputils.NewError(gtx, http.StatusInternalServerError, err)
return
}
output, err := json.MarshalIndent(keyOutput, "", " ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

cdc.MarshalJSON

var kb keys.Keybase
var m UpdateKeyBody

if err := gtx.BindJSON(&m); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

cdc.UnmarshalJSON

@jackzampolin
Copy link
Member

Another issue thats applicable here: #2113

@abelliumnt
Copy link
Author

I have refactor the code according to your feedback. Please take a look at the newest change.

@fedekunze
Copy link
Collaborator

@HaoyangLiu random question... why did you selected bianjie/lcd as base branch instead of develop ?

// Which is much friendly for further development
func ServeSwaggerCommand(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "rest-server-swagger",
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a different name here? This is going to sit in the gaiacli command, so maybe something like gaiacli lite serve?

@abelliumnt
Copy link
Author

@fedekunze That is a long story. Previously, adrianbrink suggested me to create a PR to
adrian/lcd-implementation branch, then create PR from adrian/lcd-implementation to develop. I just follow this. So how above I create another PR to develop and add missed APIs (GET /stake/pool and GET /stake/parameters)? @fedekunze @jaekwon @jackzampolin

@abelliumnt
Copy link
Author

I have created another PR to develop, please move to the new PR: #2147

@abelliumnt abelliumnt closed this Aug 25, 2018
@abelliumnt abelliumnt reopened this Aug 26, 2018
@fedekunze
Copy link
Collaborator

@HaoyangLiu why was this reopened ?

@abelliumnt
Copy link
Author

Hi @fedekunze, I'm sorry for misleading. I reopen it just in case someone may miss these two PRs about lcd. Please move to new PR #2147. This one will be closed soon.

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.

4 participants