Skip to content

Commit

Permalink
feat!: wrap ShareProof in ResultShareProof (#1313)
Browse files Browse the repository at this point in the history
## Description

This PR wraps the `ShareProof` into a `ResultShareProof` in the API.
However, It doesn't change the custom query response since it's internal
data and there is no need to wrap it.

Closes #1306
  • Loading branch information
rach-id committed Apr 19, 2024
1 parent bf68e4f commit c89f6f9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion light/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (c *Client) ProveShares(
height uint64,
startShare uint64,
endShare uint64,
) (types.ShareProof, error) {
) (*ctypes.ResultShareProof, error) {
res, err := c.next.ProveShares(ctx, height, startShare, endShare)
return res, err
}
Expand Down
8 changes: 4 additions & 4 deletions rpc/client/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,18 @@ func (c *baseRPCClient) ProveShares(
height uint64,
startShare uint64,
endShare uint64,
) (types.ShareProof, error) {
result := new(types.ShareProof)
) (*ctypes.ResultShareProof, error) {
result := new(ctypes.ResultShareProof)
params := map[string]interface{}{
"height": height,
"startShare": startShare,
"endShare": endShare,
}
_, err := c.caller.Call(ctx, "prove_shares", params, result)
if err != nil {
return types.ShareProof{}, err
return nil, err
}
return *result, nil
return result, nil
}

func (c *baseRPCClient) TxSearch(
Expand Down
2 changes: 1 addition & 1 deletion rpc/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type SignClient interface {
Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error)
Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)

ProveShares(_ context.Context, height uint64, startShare uint64, endShare uint64) (types.ShareProof, error)
ProveShares(_ context.Context, height uint64, startShare uint64, endShare uint64) (*ctypes.ResultShareProof, error)

// TxSearch defines a method to search for a paginated set of transactions by
// DeliverTx event search criteria.
Expand Down
2 changes: 1 addition & 1 deletion rpc/client/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (c *Local) ProveShares(
height uint64,
startShare uint64,
endShare uint64,
) (types.ShareProof, error) {
) (*ctypes.ResultShareProof, error) {
return core.ProveShares(c.ctx, int64(height), startShare, endShare)
}

Expand Down
32 changes: 17 additions & 15 deletions rpc/core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error

var shareProof types.ShareProof
if prove {
shareProof, err = proveTx(height, index)
proof, err := proveTx(height, index)
if err != nil {
return nil, err
}
shareProof = proof.Proof
}

return &ctypes.ResultTx{
Expand Down Expand Up @@ -125,10 +126,11 @@ func TxSearch(

var shareProof types.ShareProof
if prove {
shareProof, err = proveTx(r.Height, r.Index)
proof, err := proveTx(r.Height, r.Index)
if err != nil {
return nil, err
}
shareProof = proof.Proof
}

apiResults = append(apiResults, &ctypes.ResultTx{
Expand All @@ -144,32 +146,32 @@ func TxSearch(
return &ctypes.ResultTxSearch{Txs: apiResults, TotalCount: totalCount}, nil
}

func proveTx(height int64, index uint32) (types.ShareProof, error) {
func proveTx(height int64, index uint32) (*ctypes.ResultShareProof, error) {
var (
pShareProof cmtproto.ShareProof
shareProof types.ShareProof
)
env := GetEnvironment()
rawBlock, err := loadRawBlock(env.BlockStore, height)
if err != nil {
return shareProof, err
return nil, err
}
res, err := env.ProxyAppQuery.QuerySync(abcitypes.RequestQuery{
Data: rawBlock,
Path: fmt.Sprintf(consts.TxInclusionProofQueryPath, index),
})
if err != nil {
return shareProof, err
return nil, err
}
err = pShareProof.Unmarshal(res.Value)
if err != nil {
return shareProof, err
return nil, err
}
shareProof, err = types.ShareProofFromProto(pShareProof)
if err != nil {
return shareProof, err
return nil, err
}
return shareProof, nil
return &ctypes.ResultShareProof{Proof: shareProof}, nil
}

// ProveShares creates an NMT proof for a set of shares to a set of rows. It is
Expand All @@ -179,37 +181,37 @@ func ProveShares(
height int64,
startShare uint64,
endShare uint64,
) (types.ShareProof, error) {
) (*ctypes.ResultShareProof, error) {
var (
pShareProof cmtproto.ShareProof
shareProof types.ShareProof
)
env := GetEnvironment()
rawBlock, err := loadRawBlock(env.BlockStore, height)
if err != nil {
return shareProof, err
return nil, err
}
res, err := env.ProxyAppQuery.QuerySync(abcitypes.RequestQuery{
Data: rawBlock,
Path: fmt.Sprintf(consts.ShareInclusionProofQueryPath, startShare, endShare),
})
if err != nil {
return shareProof, err
return nil, err
}
if res.Value == nil && res.Log != "" {
// we can make the assumption that for custom queries, if the value is nil
// and some logs have been emitted, then an error happened.
return types.ShareProof{}, errors.New(res.Log)
return nil, errors.New(res.Log)
}
err = pShareProof.Unmarshal(res.Value)
if err != nil {
return shareProof, err
return nil, err
}
shareProof, err = types.ShareProofFromProto(pShareProof)
if err != nil {
return shareProof, err
return nil, err
}
return shareProof, nil
return &ctypes.ResultShareProof{Proof: shareProof}, nil
}

func loadRawBlock(bs state.BlockStore, height int64) ([]byte, error) {
Expand Down
5 changes: 5 additions & 0 deletions rpc/core/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,8 @@ type ResultEvent struct {
Data types.TMEventData `json:"data"`
Events map[string][]string `json:"events"`
}

// ResultShareProof API proof response of a set of shares
type ResultShareProof struct {
Proof types.ShareProof `json:"proof"`
}

0 comments on commit c89f6f9

Please sign in to comment.