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

feat(tm2): store tx results and add endpoint to query them #1546

Merged
merged 12 commits into from
Apr 17, 2024
20 changes: 2 additions & 18 deletions tm2/pkg/bft/rpc/client/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,10 @@
return result, nil
}

func (c *baseRPCClient) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
func (c *baseRPCClient) Tx(hash []byte) (*ctypes.ResultTx, error) {

Check warning on line 310 in tm2/pkg/bft/rpc/client/httpclient.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/client/httpclient.go#L310

Added line #L310 was not covered by tests
result := new(ctypes.ResultTx)
params := map[string]interface{}{
"hash": hash,
"prove": prove,
"hash": hash,

Check warning on line 313 in tm2/pkg/bft/rpc/client/httpclient.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/client/httpclient.go#L313

Added line #L313 was not covered by tests
}
_, err := c.caller.Call("tx", params, result)
if err != nil {
Expand All @@ -320,21 +319,6 @@
return result, nil
}

func (c *baseRPCClient) TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error) {
result := new(ctypes.ResultTxSearch)
params := map[string]interface{}{
"query": query,
"prove": prove,
"page": page,
"per_page": perPage,
}
_, err := c.caller.Call("tx_search", params, result)
if err != nil {
return nil, errors.Wrap(err, "TxSearch")
}
return result, nil
}

func (c *baseRPCClient) Validators(height *int64) (*ctypes.ResultValidators, error) {
result := new(ctypes.ResultValidators)
params := map[string]interface{}{}
Expand Down
6 changes: 5 additions & 1 deletion tm2/pkg/bft/rpc/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (
// first synchronously consumes the events from the node's synchronous event
// switch, or reads logged events from the filesystem.
type Client interface {
// service.Service
ABCIClient
HistoryClient
NetworkClient
SignClient
StatusClient
MempoolClient
TxClient
}

// ABCIClient groups together the functionality that principally affects the
Expand Down Expand Up @@ -94,3 +94,7 @@ type MempoolClient interface {
UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error)
NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error)
}

type TxClient interface {
Tx(hash []byte) (*ctypes.ResultTx, error)
}
10 changes: 2 additions & 8 deletions tm2/pkg/bft/rpc/client/localclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@
return core.Validators(c.ctx, height)
}

/*
func (c *Local) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
return core.Tx(c.ctx, hash, prove)
}

func (c *Local) TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error) {
return core.TxSearch(c.ctx, query, prove, page, perPage)
func (c *Local) Tx(hash []byte) (*ctypes.ResultTx, error) {
return core.Tx(c.ctx, hash)

Check warning on line 141 in tm2/pkg/bft/rpc/client/localclient.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/rpc/client/localclient.go#L140-L141

Added lines #L140 - L141 were not covered by tests
}
*/
1 change: 1 addition & 0 deletions tm2/pkg/bft/rpc/client/mock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Client struct {
client.HistoryClient
client.StatusClient
client.MempoolClient
client.TxClient
service.Service
}

Expand Down
31 changes: 10 additions & 21 deletions tm2/pkg/bft/rpc/client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,7 @@ func TestNumUnconfirmedTxs(t *testing.T) {
mempool.Flush()
}

/*
func TestTx(t *testing.T) {
t.Parallel()

// first we broadcast a tx
c := getHTTPClient()
_, _, tx := MakeTxKV()
Expand All @@ -384,24 +381,21 @@ func TestTx(t *testing.T) {
cases := []struct {
valid bool
hash []byte
prove bool
}{
// only valid if correct hash provided
{true, txHash, false},
{true, txHash, true},
{false, anotherTxHash, false},
{false, anotherTxHash, true},
{false, nil, false},
{false, nil, true},
{true, txHash},
{true, txHash},
{false, anotherTxHash},
{false, anotherTxHash},
{false, nil},
{false, nil},
gfanton marked this conversation as resolved.
Show resolved Hide resolved
}

for i, c := range GetClients() {
for j, tc := range cases {
t.Logf("client %d, case %d", i, j)

for _, c := range GetClients() {
for _, tc := range cases {
// now we query for the tx.
// since there's only one tx, we know index=0.
ptx, err := c.Tx(tc.hash, tc.prove)
ptx, err := c.Tx(tc.hash)

if !tc.valid {
require.NotNil(t, err)
Expand All @@ -412,17 +406,12 @@ func TestTx(t *testing.T) {
assert.Zero(t, ptx.Index)
assert.True(t, ptx.TxResult.IsOK())
assert.EqualValues(t, txHash, ptx.Hash)

// time to verify the proof
proof := ptx.Proof
if tc.prove && assert.EqualValues(t, tx, proof.Data) {
assert.NoError(t, proof.Proof.Verify(proof.RootHash, txHash))
}
}
}
}
}

/*
func TestTxSearch(t *testing.T) {
t.Parallel()

Expand Down
19 changes: 9 additions & 10 deletions tm2/pkg/bft/rpc/core/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import (
// NOTE: Amino is registered in rpc/core/types/codec.go.
var Routes = map[string]*rpc.RPCFunc{
// info API
"health": rpc.NewRPCFunc(Health, ""),
"status": rpc.NewRPCFunc(Status, ""),
"net_info": rpc.NewRPCFunc(NetInfo, ""),
"blockchain": rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"),
"genesis": rpc.NewRPCFunc(Genesis, ""),
"block": rpc.NewRPCFunc(Block, "height"),
"block_results": rpc.NewRPCFunc(BlockResults, "height"),
"commit": rpc.NewRPCFunc(Commit, "height"),
//"tx": rpc.NewRPCFunc(Tx, "hash,prove"),
//"tx_search": rpc.NewRPCFunc(TxSearch, "query,prove,page,per_page"),
thehowl marked this conversation as resolved.
Show resolved Hide resolved
"health": rpc.NewRPCFunc(Health, ""),
"status": rpc.NewRPCFunc(Status, ""),
"net_info": rpc.NewRPCFunc(NetInfo, ""),
"blockchain": rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"),
"genesis": rpc.NewRPCFunc(Genesis, ""),
"block": rpc.NewRPCFunc(Block, "height"),
"block_results": rpc.NewRPCFunc(BlockResults, "height"),
"commit": rpc.NewRPCFunc(Commit, "height"),
"tx": rpc.NewRPCFunc(Tx, "hash"),
"validators": rpc.NewRPCFunc(Validators, "height"),
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
"consensus_state": rpc.NewRPCFunc(ConsensusState, ""),
Expand Down
Loading
Loading