Skip to content

Commit

Permalink
fix: approval expired height bug (#191)
Browse files Browse the repository at this point in the history
* fix: fix approval expired height bug (#189)

---------

Co-authored-by: will-2012 <[email protected]>
  • Loading branch information
joeylichang and will-2012 authored Mar 13, 2023
1 parent e332362 commit 85ded70
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,27 @@ make install-tools
```shell
bash build.sh &&
cd build &&
./gnfd-sp --version

# show version
./gnfd-sp version
Greenfield Storage Provider
__ _ __
_____/ /_____ _________ _____ ____ ____ _________ _ __(_)___/ /__ _____
/ ___/ __/ __ \/ ___/ __ / __ / _ \ / __ \/ ___/ __ \ | / / / __ / _ \/ ___/
(__ ) /_/ /_/ / / / /_/ / /_/ / __/ / /_/ / / / /_/ / |/ / / /_/ / __/ /
/____/\__/\____/_/ \__,_/\__, /\___/ / .___/_/ \____/|___/_/\__,_/\___/_/
/____/ /_/

Version : v0.0.3
Branch : master
Commit : e332362ec59724e143725dc5a5a0dacae3be73be
Build : go1.19.1 darwin amd64 2023-03-13 14:11

# show help
./gnfd-sp help
```

## Deployment
[Deploy SP](docs/tutorial/01-deployment.md)

[Setup Local Test](docs/tutorial/03-localup.md)
4 changes: 2 additions & 2 deletions model/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ const (
const (
// DefaultStreamBufSize defines gateway stream forward payload buf size
DefaultStreamBufSize = 64 * 1024
// DefaultExpiredHeight defines approval expired height
DefaultExpiredHeight = 100
// DefaultTimeoutHeight defines approval timeout height
DefaultTimeoutHeight = 100
)

// define downloader constants
Expand Down
4 changes: 2 additions & 2 deletions pkg/greenfield/query_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// GetCurrentHeight the block height sub one as the stable height.
func (greenfield *Greenfield) GetCurrentHeight(ctx context.Context) (int64, error) {
func (greenfield *Greenfield) GetCurrentHeight(ctx context.Context) (uint64, error) {
status, err := greenfield.getCurrentClient().GnfdCompositeClient().RpcClient.TmClient.Status(ctx)
if err != nil {
log.Errorw("failed to query status", "error", err)
Expand All @@ -27,7 +27,7 @@ func (greenfield *Greenfield) GetCurrentHeight(ctx context.Context) (int64, erro
if height > 0 {
height = height - 1
}
return height, nil
return uint64(height), nil
}

// HasAccount returns an indication of the existence of address.
Expand Down
11 changes: 9 additions & 2 deletions service/gateway/admin_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func (g *Gateway) getApprovalHandler(w http.ResponseWriter, r *http.Request) {
return
}

currentHeight, err := g.chain.GetCurrentHeight(context.Background())
if err != nil {
log.Errorw("failed to query current height", "error", err)
errDescription = makeErrorDescription(err)
return
}

switch actionName {
case createBucketApprovalAction:
var (
Expand All @@ -75,7 +82,7 @@ func (g *Gateway) getApprovalHandler(w http.ResponseWriter, r *http.Request) {
errDescription = InvalidHeader
return
}
msg.PrimarySpApproval = &types.Approval{ExpiredHeight: model.DefaultExpiredHeight}
msg.PrimarySpApproval = &types.Approval{ExpiredHeight: currentHeight + model.DefaultTimeoutHeight}
approvalSignature, err = g.signer.SignBucketApproval(context.Background(), &msg)
if err != nil {
log.Errorw("failed to sign create bucket approval", "error", err)
Expand All @@ -100,7 +107,7 @@ func (g *Gateway) getApprovalHandler(w http.ResponseWriter, r *http.Request) {
errDescription = InvalidHeader
return
}
msg.PrimarySpApproval = &types.Approval{ExpiredHeight: model.DefaultExpiredHeight}
msg.PrimarySpApproval = &types.Approval{ExpiredHeight: currentHeight + model.DefaultTimeoutHeight}
approvalSignature, err = g.signer.SignObjectApproval(context.Background(), &msg)
if err != nil {
log.Errorw("failed to sign create object approval", "error", err)
Expand Down

0 comments on commit 85ded70

Please sign in to comment.