Merge remote-tracking branch 'origin/master' into wb/proposer-based-timestamps

This commit is contained in:
William Banfield
2021-11-24 11:54:43 -05:00
583 changed files with 16589 additions and 48821 deletions
-1
View File
@@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/internal/test/factory"
+3 -6
View File
@@ -94,7 +94,7 @@ Check out other examples in example_test.go
## 2. Pure functions to verify a new header (see verifier.go)
Verify function verifies a new header against some trusted header. See
https://github.com/tendermint/spec/blob/master/spec/consensus/light-client/verification.md
https://github.com/tendermint/spec/blob/master/spec/light-client/verification/README.md
for details.
There are two methods of verification: sequential and bisection
@@ -118,10 +118,7 @@ as a wrapper, which verifies all the headers, using a light client connected to
some other node.
See
https://docs.tendermint.com/master/tendermint-core/light-client-protocol.html
for usage example.
Or see
https://github.com/tendermint/spec/tree/master/spec/consensus/light-client
for the full spec
https://github.com/tendermint/spec/tree/master/spec/light-client
for the light client specification.
*/
package light
+6 -3
View File
@@ -2,7 +2,6 @@ package light_test
import (
"context"
"io/ioutil"
stdlog "log"
"os"
"time"
@@ -22,7 +21,11 @@ import (
func ExampleClient() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig("ExampleClient_VerifyLightBlockAtHeight")
conf, err := rpctest.CreateConfig("ExampleClient_VerifyLightBlockAtHeight")
if err != nil {
stdlog.Fatal(err)
}
logger := log.TestingLogger()
// Start a test application
@@ -34,7 +37,7 @@ func ExampleClient() {
}
defer func() { _ = closer(ctx) }()
dbDir, err := ioutil.TempDir("", "light-client-example")
dbDir, err := os.MkdirTemp("", "light-client-example")
if err != nil {
stdlog.Fatal(err)
}
+6 -5
View File
@@ -2,7 +2,6 @@ package light_test
import (
"context"
"io/ioutil"
"os"
"testing"
"time"
@@ -29,7 +28,8 @@ func TestClientIntegration_Update(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig(t.Name())
conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// Start a test application
app := kvstore.NewApplication()
@@ -40,7 +40,7 @@ func TestClientIntegration_Update(t *testing.T) {
// give Tendermint time to generate some blocks
time.Sleep(5 * time.Second)
dbDir, err := ioutil.TempDir("", "light-client-test-update-example")
dbDir, err := os.MkdirTemp("", "light-client-test-update-example")
require.NoError(t, err)
defer os.RemoveAll(dbDir)
@@ -89,7 +89,8 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conf := rpctest.CreateConfig(t.Name())
conf, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// Start a test application
app := kvstore.NewApplication()
@@ -98,7 +99,7 @@ func TestClientIntegration_VerifyLightBlockAtHeight(t *testing.T) {
require.NoError(t, err)
defer func() { require.NoError(t, closer(ctx)) }()
dbDir, err := ioutil.TempDir("", "light-client-test-verify-example")
dbDir, err := os.MkdirTemp("", "light-client-test-verify-example")
require.NoError(t, err)
defer os.RemoveAll(dbDir)
+2 -2
View File
@@ -1,7 +1,7 @@
package mbt
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
@@ -22,7 +22,7 @@ func TestVerify(t *testing.T) {
filename := filename
t.Run(filename, func(t *testing.T) {
jsonBlob, err := ioutil.ReadFile(filename)
jsonBlob, err := os.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -12,7 +12,7 @@ import (
"github.com/tendermint/tendermint/light/provider"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)
@@ -300,11 +300,11 @@ func (p *http) noBlock(e error) error {
func (p *http) parseRPCError(e *rpctypes.RPCError) error {
switch {
// 1) check if the error indicates that the peer doesn't have the block
case strings.Contains(e.Data, ctypes.ErrHeightNotAvailable.Error()):
case strings.Contains(e.Data, coretypes.ErrHeightNotAvailable.Error()):
return p.noBlock(provider.ErrLightBlockNotFound)
// 2) check if the height requested is too high
case strings.Contains(e.Data, ctypes.ErrHeightExceedsChainHead.Error()):
case strings.Contains(e.Data, coretypes.ErrHeightExceedsChainHead.Error()):
return p.noBlock(provider.ErrHeightTooHigh)
// 3) check if the provider closed the connection
+2 -1
View File
@@ -35,7 +35,8 @@ func TestNewProvider(t *testing.T) {
func TestProvider(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := rpctest.CreateConfig(t.Name())
cfg, err := rpctest.CreateConfig(t.Name())
require.NoError(t, err)
// start a tendermint node in the background to test against
app := kvstore.NewApplication()
+6 -6
View File
@@ -49,8 +49,8 @@ func NewProxy(
// routes to proxy via Client, and starts up an HTTP server on the TCP network
// address p.Addr.
// See http#Server#ListenAndServe.
func (p *Proxy) ListenAndServe() error {
listener, mux, err := p.listen()
func (p *Proxy) ListenAndServe(ctx context.Context) error {
listener, mux, err := p.listen(ctx)
if err != nil {
return err
}
@@ -67,8 +67,8 @@ func (p *Proxy) ListenAndServe() error {
// ListenAndServeTLS acts identically to ListenAndServe, except that it expects
// HTTPS connections.
// See http#Server#ListenAndServeTLS.
func (p *Proxy) ListenAndServeTLS(certFile, keyFile string) error {
listener, mux, err := p.listen()
func (p *Proxy) ListenAndServeTLS(ctx context.Context, certFile, keyFile string) error {
listener, mux, err := p.listen(ctx)
if err != nil {
return err
}
@@ -84,7 +84,7 @@ func (p *Proxy) ListenAndServeTLS(certFile, keyFile string) error {
)
}
func (p *Proxy) listen() (net.Listener, *http.ServeMux, error) {
func (p *Proxy) listen(ctx context.Context) (net.Listener, *http.ServeMux, error) {
mux := http.NewServeMux()
// 1) Register regular routes.
@@ -107,7 +107,7 @@ func (p *Proxy) listen() (net.Listener, *http.ServeMux, error) {
// 3) Start a client.
if !p.Client.IsRunning() {
if err := p.Client.Start(); err != nil {
if err := p.Client.Start(ctx); err != nil {
return nil, mux, fmt.Errorf("can't start client: %w", err)
}
}
+51 -51
View File
@@ -4,7 +4,7 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
lrpc "github.com/tendermint/tendermint/light/rpc"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/rpc/coretypes"
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
@@ -52,91 +52,91 @@ func RPCRoutes(c *lrpc.Client) map[string]*rpcserver.RPCFunc {
}
}
type rpcHealthFunc func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error)
type rpcHealthFunc func(ctx *rpctypes.Context) (*coretypes.ResultHealth, error)
func makeHealthFunc(c *lrpc.Client) rpcHealthFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultHealth, error) {
return c.Health(ctx.Context())
}
}
type rpcStatusFunc func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error)
type rpcStatusFunc func(ctx *rpctypes.Context) (*coretypes.ResultStatus, error)
// nolint: interfacer
func makeStatusFunc(c *lrpc.Client) rpcStatusFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultStatus, error) {
return c.Status(ctx.Context())
}
}
type rpcNetInfoFunc func(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error)
type rpcNetInfoFunc func(ctx *rpctypes.Context) (*coretypes.ResultNetInfo, error)
func makeNetInfoFunc(c *lrpc.Client) rpcNetInfoFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultNetInfo, error) {
return c.NetInfo(ctx.Context())
}
}
type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) //nolint:lll
func makeBlockchainInfoFunc(c *lrpc.Client) rpcBlockchainInfoFunc {
return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) {
return c.BlockchainInfo(ctx.Context(), minHeight, maxHeight)
}
}
type rpcGenesisFunc func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error)
type rpcGenesisFunc func(ctx *rpctypes.Context) (*coretypes.ResultGenesis, error)
func makeGenesisFunc(c *lrpc.Client) rpcGenesisFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultGenesis, error) {
return c.Genesis(ctx.Context())
}
}
type rpcGenesisChunkedFunc func(ctx *rpctypes.Context, chunk uint) (*ctypes.ResultGenesisChunk, error)
type rpcGenesisChunkedFunc func(ctx *rpctypes.Context, chunk uint) (*coretypes.ResultGenesisChunk, error)
func makeGenesisChunkedFunc(c *lrpc.Client) rpcGenesisChunkedFunc {
return func(ctx *rpctypes.Context, chunk uint) (*ctypes.ResultGenesisChunk, error) {
return func(ctx *rpctypes.Context, chunk uint) (*coretypes.ResultGenesisChunk, error) {
return c.GenesisChunked(ctx.Context(), chunk)
}
}
type rpcBlockFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error)
type rpcBlockFunc func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultBlock, error)
func makeBlockFunc(c *lrpc.Client) rpcBlockFunc {
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) {
return func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultBlock, error) {
return c.Block(ctx.Context(), height)
}
}
type rpcBlockByHashFunc func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error)
type rpcBlockByHashFunc func(ctx *rpctypes.Context, hash []byte) (*coretypes.ResultBlock, error)
func makeBlockByHashFunc(c *lrpc.Client) rpcBlockByHashFunc {
return func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) {
return func(ctx *rpctypes.Context, hash []byte) (*coretypes.ResultBlock, error) {
return c.BlockByHash(ctx.Context(), hash)
}
}
type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error)
type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultBlockResults, error)
func makeBlockResultsFunc(c *lrpc.Client) rpcBlockResultsFunc {
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) {
return func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultBlockResults, error) {
return c.BlockResults(ctx.Context(), height)
}
}
type rpcCommitFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error)
type rpcCommitFunc func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultCommit, error)
func makeCommitFunc(c *lrpc.Client) rpcCommitFunc {
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) {
return func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultCommit, error) {
return c.Commit(ctx.Context(), height)
}
}
type rpcTxFunc func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)
type rpcTxFunc func(ctx *rpctypes.Context, hash []byte, prove bool) (*coretypes.ResultTx, error)
func makeTxFunc(c *lrpc.Client) rpcTxFunc {
return func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) {
return func(ctx *rpctypes.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) {
return c.Tx(ctx.Context(), hash, prove)
}
}
@@ -147,7 +147,7 @@ type rpcTxSearchFunc func(
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultTxSearch, error)
) (*coretypes.ResultTxSearch, error)
func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc {
return func(
@@ -156,7 +156,7 @@ func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc {
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultTxSearch, error) {
) (*coretypes.ResultTxSearch, error) {
return c.TxSearch(ctx.Context(), query, prove, page, perPage, orderBy)
}
}
@@ -167,7 +167,7 @@ type rpcBlockSearchFunc func(
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error)
) (*coretypes.ResultBlockSearch, error)
func makeBlockSearchFunc(c *lrpc.Client) rpcBlockSearchFunc {
return func(
@@ -176,90 +176,90 @@ func makeBlockSearchFunc(c *lrpc.Client) rpcBlockSearchFunc {
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error) {
) (*coretypes.ResultBlockSearch, error) {
return c.BlockSearch(ctx.Context(), query, page, perPage, orderBy)
}
}
type rpcValidatorsFunc func(ctx *rpctypes.Context, height *int64,
page, perPage *int) (*ctypes.ResultValidators, error)
page, perPage *int) (*coretypes.ResultValidators, error)
func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc {
return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) {
return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) {
return c.Validators(ctx.Context(), height, page, perPage)
}
}
type rpcDumpConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error)
type rpcDumpConsensusStateFunc func(ctx *rpctypes.Context) (*coretypes.ResultDumpConsensusState, error)
func makeDumpConsensusStateFunc(c *lrpc.Client) rpcDumpConsensusStateFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultDumpConsensusState, error) {
return c.DumpConsensusState(ctx.Context())
}
}
type rpcConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error)
type rpcConsensusStateFunc func(ctx *rpctypes.Context) (*coretypes.ResultConsensusState, error)
func makeConsensusStateFunc(c *lrpc.Client) rpcConsensusStateFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultConsensusState, error) {
return c.ConsensusState(ctx.Context())
}
}
type rpcConsensusParamsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error)
type rpcConsensusParamsFunc func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultConsensusParams, error)
func makeConsensusParamsFunc(c *lrpc.Client) rpcConsensusParamsFunc {
return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) {
return func(ctx *rpctypes.Context, height *int64) (*coretypes.ResultConsensusParams, error) {
return c.ConsensusParams(ctx.Context(), height)
}
}
type rpcUnconfirmedTxsFunc func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)
type rpcUnconfirmedTxsFunc func(ctx *rpctypes.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error)
func makeUnconfirmedTxsFunc(c *lrpc.Client) rpcUnconfirmedTxsFunc {
return func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) {
return func(ctx *rpctypes.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error) {
return c.UnconfirmedTxs(ctx.Context(), limit)
}
}
type rpcNumUnconfirmedTxsFunc func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error)
type rpcNumUnconfirmedTxsFunc func(ctx *rpctypes.Context) (*coretypes.ResultUnconfirmedTxs, error)
func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultUnconfirmedTxs, error) {
return c.NumUnconfirmedTxs(ctx.Context())
}
}
type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error)
func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc {
return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
return func(ctx *rpctypes.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
return c.BroadcastTxCommit(ctx.Context(), tx)
}
}
type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error)
func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc {
return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
return func(ctx *rpctypes.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.BroadcastTxSync(ctx.Context(), tx)
}
}
type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error)
func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc {
return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
return func(ctx *rpctypes.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.BroadcastTxAsync(ctx.Context(), tx)
}
}
type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string,
data bytes.HexBytes, height int64, prove bool) (*ctypes.ResultABCIQuery, error)
data bytes.HexBytes, height int64, prove bool) (*coretypes.ResultABCIQuery, error)
func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc {
return func(ctx *rpctypes.Context, path string, data bytes.HexBytes,
height int64, prove bool) (*ctypes.ResultABCIQuery, error) {
height int64, prove bool) (*coretypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(ctx.Context(), path, data, rpcclient.ABCIQueryOptions{
Height: height,
@@ -268,19 +268,19 @@ func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc {
}
}
type rpcABCIInfoFunc func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error)
type rpcABCIInfoFunc func(ctx *rpctypes.Context) (*coretypes.ResultABCIInfo, error)
func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc {
return func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
return func(ctx *rpctypes.Context) (*coretypes.ResultABCIInfo, error) {
return c.ABCIInfo(ctx.Context())
}
}
type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error)
// nolint: interfacer
func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc {
return func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
return func(ctx *rpctypes.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error) {
return c.BroadcastEvidence(ctx.Context(), ev)
}
}
+50 -46
View File
@@ -16,7 +16,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math"
service "github.com/tendermint/tendermint/libs/service"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/rpc/coretypes"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)
@@ -98,9 +98,9 @@ func NewClient(next rpcclient.Client, lc LightClient, opts ...Option) *Client {
return c
}
func (c *Client) OnStart() error {
func (c *Client) OnStart(ctx context.Context) error {
if !c.next.IsRunning() {
return c.next.Start()
return c.next.Start(ctx)
}
return nil
}
@@ -113,22 +113,22 @@ func (c *Client) OnStop() {
}
}
func (c *Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
func (c *Client) Status(ctx context.Context) (*coretypes.ResultStatus, error) {
return c.next.Status(ctx)
}
func (c *Client) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
func (c *Client) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) {
return c.next.ABCIInfo(ctx)
}
// ABCIQuery requests proof by default.
func (c *Client) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (c *Client) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes) (*coretypes.ResultABCIQuery, error) { //nolint:lll
return c.ABCIQueryWithOptions(ctx, path, data, rpcclient.DefaultABCIQueryOptions)
}
// ABCIQueryWithOptions returns an error if opts.Prove is false.
func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes,
opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
opts rpcclient.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) {
// always request the proof
opts.Prove = true
@@ -150,7 +150,7 @@ func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmb
return nil, errors.New("no proof ops")
}
if resp.Height <= 0 {
return nil, ctypes.ErrZeroOrNegativeHeight
return nil, coretypes.ErrZeroOrNegativeHeight
}
// Update the light client if we're behind.
@@ -185,46 +185,50 @@ func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmb
}
}
return &ctypes.ResultABCIQuery{Response: resp}, nil
return &coretypes.ResultABCIQuery{Response: resp}, nil
}
func (c *Client) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
func (c *Client) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
return c.next.BroadcastTxCommit(ctx, tx)
}
func (c *Client) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (c *Client) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.next.BroadcastTxAsync(ctx, tx)
}
func (c *Client) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func (c *Client) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) {
return c.next.BroadcastTxSync(ctx, tx)
}
func (c *Client) UnconfirmedTxs(ctx context.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) {
func (c *Client) UnconfirmedTxs(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error) {
return c.next.UnconfirmedTxs(ctx, limit)
}
func (c *Client) NumUnconfirmedTxs(ctx context.Context) (*ctypes.ResultUnconfirmedTxs, error) {
func (c *Client) NumUnconfirmedTxs(ctx context.Context) (*coretypes.ResultUnconfirmedTxs, error) {
return c.next.NumUnconfirmedTxs(ctx)
}
func (c *Client) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
func (c *Client) CheckTx(ctx context.Context, tx types.Tx) (*coretypes.ResultCheckTx, error) {
return c.next.CheckTx(ctx, tx)
}
func (c *Client) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error) {
func (c *Client) RemoveTx(ctx context.Context, txKey types.TxKey) error {
return c.next.RemoveTx(ctx, txKey)
}
func (c *Client) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error) {
return c.next.NetInfo(ctx)
}
func (c *Client) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error) {
func (c *Client) DumpConsensusState(ctx context.Context) (*coretypes.ResultDumpConsensusState, error) {
return c.next.DumpConsensusState(ctx)
}
func (c *Client) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error) {
func (c *Client) ConsensusState(ctx context.Context) (*coretypes.ResultConsensusState, error) {
return c.next.ConsensusState(ctx)
}
func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error) {
func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*coretypes.ResultConsensusParams, error) {
res, err := c.next.ConsensusParams(ctx, height)
if err != nil {
return nil, err
@@ -235,7 +239,7 @@ func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.Re
return nil, err
}
if res.BlockHeight <= 0 {
return nil, ctypes.ErrZeroOrNegativeHeight
return nil, coretypes.ErrZeroOrNegativeHeight
}
// Update the light client if we're behind.
@@ -253,13 +257,13 @@ func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.Re
return res, nil
}
func (c *Client) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
func (c *Client) Health(ctx context.Context) (*coretypes.ResultHealth, error) {
return c.next.Health(ctx)
}
// BlockchainInfo calls rpcclient#BlockchainInfo and then verifies every header
// returned.
func (c *Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
func (c *Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) { //nolint:lll
res, err := c.next.BlockchainInfo(ctx, minHeight, maxHeight)
if err != nil {
return nil, err
@@ -298,16 +302,16 @@ func (c *Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64)
return res, nil
}
func (c *Client) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error) {
func (c *Client) Genesis(ctx context.Context) (*coretypes.ResultGenesis, error) {
return c.next.Genesis(ctx)
}
func (c *Client) GenesisChunked(ctx context.Context, id uint) (*ctypes.ResultGenesisChunk, error) {
func (c *Client) GenesisChunked(ctx context.Context, id uint) (*coretypes.ResultGenesisChunk, error) {
return c.next.GenesisChunked(ctx, id)
}
// Block calls rpcclient#Block and then verifies the result.
func (c *Client) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
func (c *Client) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
res, err := c.next.Block(ctx, height)
if err != nil {
return nil, err
@@ -341,7 +345,7 @@ func (c *Client) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock,
}
// BlockByHash calls rpcclient#BlockByHash and then verifies the result.
func (c *Client) BlockByHash(ctx context.Context, hash tmbytes.HexBytes) (*ctypes.ResultBlock, error) {
func (c *Client) BlockByHash(ctx context.Context, hash tmbytes.HexBytes) (*coretypes.ResultBlock, error) {
res, err := c.next.BlockByHash(ctx, hash)
if err != nil {
return nil, err
@@ -376,7 +380,7 @@ func (c *Client) BlockByHash(ctx context.Context, hash tmbytes.HexBytes) (*ctype
// BlockResults returns the block results for the given height. If no height is
// provided, the results of the block preceding the latest are returned.
func (c *Client) BlockResults(ctx context.Context, height *int64) (*ctypes.ResultBlockResults, error) {
func (c *Client) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) {
var h int64
if height == nil {
res, err := c.next.Status(ctx)
@@ -397,7 +401,7 @@ func (c *Client) BlockResults(ctx context.Context, height *int64) (*ctypes.Resul
// Validate res.
if res.Height <= 0 {
return nil, ctypes.ErrZeroOrNegativeHeight
return nil, coretypes.ErrZeroOrNegativeHeight
}
// Update the light client if we're behind.
@@ -438,7 +442,7 @@ func (c *Client) BlockResults(ctx context.Context, height *int64) (*ctypes.Resul
return res, nil
}
func (c *Client) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
func (c *Client) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) {
// Update the light client if we're behind and retrieve the light block at the requested height
// or at the latest height if no height is provided.
l, err := c.updateLightClientIfNeededTo(ctx, height)
@@ -446,7 +450,7 @@ func (c *Client) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommi
return nil, err
}
return &ctypes.ResultCommit{
return &coretypes.ResultCommit{
SignedHeader: *l.SignedHeader,
CanonicalCommit: true,
}, nil
@@ -454,7 +458,7 @@ func (c *Client) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommi
// Tx calls rpcclient#Tx method and then verifies the proof if such was
// requested.
func (c *Client) Tx(ctx context.Context, hash tmbytes.HexBytes, prove bool) (*ctypes.ResultTx, error) {
func (c *Client) Tx(ctx context.Context, hash tmbytes.HexBytes, prove bool) (*coretypes.ResultTx, error) {
res, err := c.next.Tx(ctx, hash, prove)
if err != nil || !prove {
return res, err
@@ -462,7 +466,7 @@ func (c *Client) Tx(ctx context.Context, hash tmbytes.HexBytes, prove bool) (*ct
// Validate res.
if res.Height <= 0 {
return nil, ctypes.ErrZeroOrNegativeHeight
return nil, coretypes.ErrZeroOrNegativeHeight
}
// Update the light client if we're behind.
@@ -481,7 +485,7 @@ func (c *Client) TxSearch(
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultTxSearch, error) {
) (*coretypes.ResultTxSearch, error) {
return c.next.TxSearch(ctx, query, prove, page, perPage, orderBy)
}
@@ -490,7 +494,7 @@ func (c *Client) BlockSearch(
query string,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error) {
) (*coretypes.ResultBlockSearch, error) {
return c.next.BlockSearch(ctx, query, page, perPage, orderBy)
}
@@ -499,7 +503,7 @@ func (c *Client) Validators(
ctx context.Context,
height *int64,
pagePtr, perPagePtr *int,
) (*ctypes.ResultValidators, error) {
) (*coretypes.ResultValidators, error) {
// Update the light client if we're behind and retrieve the light block at the
// requested height or at the latest height if no height is provided.
@@ -518,19 +522,19 @@ func (c *Client) Validators(
skipCount := validateSkipCount(page, perPage)
v := l.ValidatorSet.Validators[skipCount : skipCount+tmmath.MinInt(perPage, totalCount-skipCount)]
return &ctypes.ResultValidators{
return &coretypes.ResultValidators{
BlockHeight: l.Height,
Validators: v,
Count: len(v),
Total: totalCount}, nil
}
func (c *Client) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
func (c *Client) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*coretypes.ResultBroadcastEvidence, error) {
return c.next.BroadcastEvidence(ctx, ev)
}
func (c *Client) Subscribe(ctx context.Context, subscriber, query string,
outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) {
outCapacity ...int) (out <-chan coretypes.ResultEvent, err error) {
return c.next.Subscribe(ctx, subscriber, query, outCapacity...)
}
@@ -565,7 +569,7 @@ func (c *Client) RegisterOpDecoder(typ string, dec merkle.OpDecoder) {
// SubscribeWS subscribes for events using the given query and remote address as
// a subscriber, but does not verify responses (UNSAFE)!
// TODO: verify data
func (c *Client) SubscribeWS(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, error) {
func (c *Client) SubscribeWS(ctx *rpctypes.Context, query string) (*coretypes.ResultSubscribe, error) {
out, err := c.next.Subscribe(context.Background(), ctx.RemoteAddr(), query)
if err != nil {
return nil, err
@@ -588,27 +592,27 @@ func (c *Client) SubscribeWS(ctx *rpctypes.Context, query string) (*ctypes.Resul
}
}()
return &ctypes.ResultSubscribe{}, nil
return &coretypes.ResultSubscribe{}, nil
}
// UnsubscribeWS calls original client's Unsubscribe using remote address as a
// subscriber.
func (c *Client) UnsubscribeWS(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe, error) {
func (c *Client) UnsubscribeWS(ctx *rpctypes.Context, query string) (*coretypes.ResultUnsubscribe, error) {
err := c.next.Unsubscribe(context.Background(), ctx.RemoteAddr(), query)
if err != nil {
return nil, err
}
return &ctypes.ResultUnsubscribe{}, nil
return &coretypes.ResultUnsubscribe{}, nil
}
// UnsubscribeAllWS calls original client's UnsubscribeAll using remote address
// as a subscriber.
func (c *Client) UnsubscribeAllWS(ctx *rpctypes.Context) (*ctypes.ResultUnsubscribe, error) {
func (c *Client) UnsubscribeAllWS(ctx *rpctypes.Context) (*coretypes.ResultUnsubscribe, error) {
err := c.next.UnsubscribeAll(context.Background(), ctx.RemoteAddr())
if err != nil {
return nil, err
}
return &ctypes.ResultUnsubscribe{}, nil
return &coretypes.ResultUnsubscribe{}, nil
}
// XXX: Copied from rpc/core/env.go
@@ -620,7 +624,7 @@ const (
func validatePage(pagePtr *int, perPage, totalCount int) (int, error) {
if perPage < 1 {
panic(fmt.Errorf("%w (%d)", ctypes.ErrZeroOrNegativePerPage, perPage))
panic(fmt.Errorf("%w (%d)", coretypes.ErrZeroOrNegativePerPage, perPage))
}
if pagePtr == nil { // no page parameter
@@ -633,7 +637,7 @@ func validatePage(pagePtr *int, perPage, totalCount int) (int, error) {
}
page := *pagePtr
if page <= 0 || page > pages {
return 1, fmt.Errorf("%w expected range: [1, %d], given %d", ctypes.ErrPageOutOfRange, pages, page)
return 1, fmt.Errorf("%w expected range: [1, %d], given %d", coretypes.ErrPageOutOfRange, pages, page)
}
return page, nil
-1
View File
@@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/crypto"