Browse Source

rpc/client: split out client packages (#4628)

* rpc/client: initial split into directories

* lite2: split out test package

* rpc/client: simplify client constructurs

* updated docs

* updated changelog
pull/4636/head
Erik Grinaker 4 years ago
committed by GitHub
parent
commit
fdf9c7ae64
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 159 additions and 145 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +3
    -3
      cmd/tendermint/commands/debug/dump.go
  3. +2
    -2
      cmd/tendermint/commands/debug/kill.go
  4. +4
    -4
      cmd/tendermint/commands/debug/util.go
  5. +2
    -2
      cmd/tendermint/commands/lite.go
  6. +3
    -2
      lite/client/provider.go
  7. +3
    -2
      lite/proxy/query_test.go
  8. +12
    -11
      lite2/client_benchmark_test.go
  9. +47
    -46
      lite2/client_test.go
  10. +6
    -5
      lite2/example_test.go
  11. +1
    -1
      lite2/helpers_test.go
  12. +11
    -10
      lite2/provider/http/http.go
  13. +4
    -3
      lite2/provider/http/http_test.go
  14. +10
    -9
      lite2/verifier_test.go
  15. +3
    -3
      rpc/client/examples_test.go
  16. +27
    -26
      rpc/client/http/http.go
  17. +6
    -5
      rpc/client/local/local.go
  18. +11
    -9
      rpc/client/rpc_test.go
  19. +3
    -2
      rpc/swagger/swagger.yaml

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -14,6 +14,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- Go API
- [rpc/client] [\#4628](https://github.com/tendermint/tendermint/pull/4628) Split out HTTP and local clients into `http` and `local` packages (@erikgrinaker).
- [lite2] [\#4616](https://github.com/tendermint/tendermint/pull/4616) Make `maxClockDrift` an option (@melekes).
`Verify/VerifyAdjacent/VerifyNonAdjacent` now accept `maxClockDrift time.Duration`.


+ 3
- 3
cmd/tendermint/commands/debug/dump.go View File

@ -13,7 +13,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/cli"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)
var dumpCmd = &cobra.Command{
@ -59,7 +59,7 @@ func dumpCmdHandler(_ *cobra.Command, args []string) error {
}
}
rpc, err := rpcclient.NewHTTP(nodeRPCAddr, "/websocket")
rpc, err := rpchttp.New(nodeRPCAddr, "/websocket")
if err != nil {
return errors.Wrap(err, "failed to create new http client")
}
@ -79,7 +79,7 @@ func dumpCmdHandler(_ *cobra.Command, args []string) error {
return nil
}
func dumpDebugData(outDir string, conf *cfg.Config, rpc *rpcclient.HTTP) {
func dumpDebugData(outDir string, conf *cfg.Config, rpc *rpchttp.HTTP) {
start := time.Now().UTC()
tmpDir, err := ioutil.TempDir(outDir, "tendermint_debug_tmp")


+ 2
- 2
cmd/tendermint/commands/debug/kill.go View File

@ -16,7 +16,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/cli"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)
var killCmd = &cobra.Command{
@ -44,7 +44,7 @@ func killCmdHandler(cmd *cobra.Command, args []string) error {
return errors.New("invalid output file")
}
rpc, err := rpcclient.NewHTTP(nodeRPCAddr, "/websocket")
rpc, err := rpchttp.New(nodeRPCAddr, "/websocket")
if err != nil {
return errors.Wrap(err, "failed to create new http client")
}


+ 4
- 4
cmd/tendermint/commands/debug/util.go View File

@ -11,12 +11,12 @@ import (
"github.com/pkg/errors"
cfg "github.com/tendermint/tendermint/config"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)
// dumpStatus gets node status state dump from the Tendermint RPC and writes it
// to file. It returns an error upon failure.
func dumpStatus(rpc *rpcclient.HTTP, dir, filename string) error {
func dumpStatus(rpc *rpchttp.HTTP, dir, filename string) error {
status, err := rpc.Status()
if err != nil {
return errors.Wrap(err, "failed to get node status")
@ -27,7 +27,7 @@ func dumpStatus(rpc *rpcclient.HTTP, dir, filename string) error {
// dumpNetInfo gets network information state dump from the Tendermint RPC and
// writes it to file. It returns an error upon failure.
func dumpNetInfo(rpc *rpcclient.HTTP, dir, filename string) error {
func dumpNetInfo(rpc *rpchttp.HTTP, dir, filename string) error {
netInfo, err := rpc.NetInfo()
if err != nil {
return errors.Wrap(err, "failed to get node network information")
@ -38,7 +38,7 @@ func dumpNetInfo(rpc *rpcclient.HTTP, dir, filename string) error {
// dumpConsensusState gets consensus state dump from the Tendermint RPC and
// writes it to file. It returns an error upon failure.
func dumpConsensusState(rpc *rpcclient.HTTP, dir, filename string) error {
func dumpConsensusState(rpc *rpchttp.HTTP, dir, filename string) error {
consDump, err := rpc.DumpConsensusState()
if err != nil {
return errors.Wrap(err, "failed to get node consensus dump")


+ 2
- 2
cmd/tendermint/commands/lite.go View File

@ -18,7 +18,7 @@ import (
lproxy "github.com/tendermint/tendermint/lite2/proxy"
lrpc "github.com/tendermint/tendermint/lite2/rpc"
dbs "github.com/tendermint/tendermint/lite2/store/db"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
)
@ -133,7 +133,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
return err
}
rpcClient, err := rpcclient.NewHTTP(primaryAddr, "/websocket")
rpcClient, err := rpchttp.New(primaryAddr, "/websocket")
if err != nil {
return errors.Wrapf(err, "http client for %s", primaryAddr)
}


+ 3
- 2
lite/client/provider.go View File

@ -1,5 +1,5 @@
/*
Package client defines a provider that uses a rpcclient
Package client defines a provider that uses a rpchttp
to get information, which is used to get new headers
and validators directly from a Tendermint client.
*/
@ -12,6 +12,7 @@ import (
"github.com/tendermint/tendermint/lite"
lerr "github.com/tendermint/tendermint/lite/errors"
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/types"
)
@ -40,7 +41,7 @@ func NewProvider(chainID string, client SignStatusClient) lite.Provider {
// NewHTTPProvider can connect to a tendermint json-rpc endpoint
// at the given url, and uses that as a read-only provider.
func NewHTTPProvider(chainID, remote string) (lite.Provider, error) {
httpClient, err := rpcclient.NewHTTP(remote, "/websocket")
httpClient, err := rpchttp.New(remote, "/websocket")
if err != nil {
return nil, err
}


+ 3
- 2
lite/proxy/query_test.go View File

@ -15,6 +15,7 @@ import (
certclient "github.com/tendermint/tendermint/lite/client"
nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/rpc/client"
rpclocal "github.com/tendermint/tendermint/rpc/client/local"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
)
@ -47,7 +48,7 @@ func _TestAppProofs(t *testing.T) {
assert, require := assert.New(t), require.New(t)
prt := defaultProofRuntime()
cl := client.NewLocal(node)
cl := rpclocal.New(node)
client.WaitForHeight(cl, 1, nil)
// This sets up our trust on the node based on some past point.
@ -126,7 +127,7 @@ func _TestAppProofs(t *testing.T) {
func TestTxProofs(t *testing.T) {
assert, require := assert.New(t), require.New(t)
cl := client.NewLocal(node)
cl := rpclocal.New(node)
client.WaitForHeight(cl, 1, nil)
tx := kvstoreTx([]byte("key-a"), []byte("value-a"))


+ 12
- 11
lite2/client_benchmark_test.go View File

@ -1,4 +1,4 @@
package lite
package lite_test
import (
"testing"
@ -7,6 +7,7 @@ import (
dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/libs/log"
lite "github.com/tendermint/tendermint/lite2"
"github.com/tendermint/tendermint/lite2/provider"
mockp "github.com/tendermint/tendermint/lite2/provider/mock"
dbs "github.com/tendermint/tendermint/lite2/store/db"
@ -25,9 +26,9 @@ var (
)
func BenchmarkSequence(b *testing.B) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 24 * time.Hour,
Height: 1,
Hash: genesisHeader.Hash(),
@ -35,8 +36,8 @@ func BenchmarkSequence(b *testing.B) {
benchmarkFullNode,
[]provider.Provider{benchmarkFullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
SequentialVerification(),
lite.Logger(log.TestingLogger()),
lite.SequentialVerification(),
)
if err != nil {
b.Fatal(err)
@ -52,9 +53,9 @@ func BenchmarkSequence(b *testing.B) {
}
func BenchmarkBisection(b *testing.B) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 24 * time.Hour,
Height: 1,
Hash: genesisHeader.Hash(),
@ -62,7 +63,7 @@ func BenchmarkBisection(b *testing.B) {
benchmarkFullNode,
[]provider.Provider{benchmarkFullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
if err != nil {
b.Fatal(err)
@ -79,9 +80,9 @@ func BenchmarkBisection(b *testing.B) {
func BenchmarkBackwards(b *testing.B) {
trustedHeader, _ := benchmarkFullNode.SignedHeader(0)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 24 * time.Hour,
Height: trustedHeader.Height,
Hash: trustedHeader.Hash(),
@ -89,7 +90,7 @@ func BenchmarkBackwards(b *testing.B) {
benchmarkFullNode,
[]provider.Provider{benchmarkFullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
if err != nil {
b.Fatal(err)


+ 47
- 46
lite2/client_test.go View File

@ -1,4 +1,4 @@
package lite
package lite_test
import (
"sync"
@ -11,6 +11,7 @@ import (
dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/libs/log"
lite "github.com/tendermint/tendermint/lite2"
"github.com/tendermint/tendermint/lite2/provider"
mockp "github.com/tendermint/tendermint/lite2/provider/mock"
dbs "github.com/tendermint/tendermint/lite2/store/db"
@ -34,7 +35,7 @@ var (
h3 = keys.GenSignedHeaderLastBlockID(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals,
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys), types.BlockID{Hash: h2.Hash()})
trustPeriod = 4 * time.Hour
trustOptions = TrustOptions{
trustOptions = lite.TrustOptions{
Period: 4 * time.Hour,
Height: 1,
Hash: h1.Hash(),
@ -140,7 +141,7 @@ func TestClient_SequentialVerification(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
mockp.New(
@ -154,7 +155,7 @@ func TestClient_SequentialVerification(t *testing.T) {
tc.vals,
)},
dbs.New(dbm.NewMemDB(), chainID),
SequentialVerification(),
lite.SequentialVerification(),
)
if tc.initErr {
@ -263,7 +264,7 @@ func TestClient_SkippingVerification(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
mockp.New(
@ -277,7 +278,7 @@ func TestClient_SkippingVerification(t *testing.T) {
tc.vals,
)},
dbs.New(dbm.NewMemDB(), chainID),
SkippingVerification(DefaultTrustLevel),
lite.SkippingVerification(lite.DefaultTrustLevel),
)
if tc.initErr {
require.Error(t, err)
@ -297,13 +298,13 @@ func TestClient_SkippingVerification(t *testing.T) {
}
func TestClient_Cleanup(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{fullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
_, err = c.TrustedHeader(1)
@ -330,13 +331,13 @@ func TestClientRestoresTrustedHeaderAfterStartup1(t *testing.T) {
err := trustedStore.SaveSignedHeaderAndValidatorSet(h1, vals)
require.NoError(t, err)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{fullNode},
trustedStore,
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -372,9 +373,9 @@ func TestClientRestoresTrustedHeaderAfterStartup1(t *testing.T) {
valSet,
)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 4 * time.Hour,
Height: 1,
Hash: header1.Hash(),
@ -382,7 +383,7 @@ func TestClientRestoresTrustedHeaderAfterStartup1(t *testing.T) {
primary,
[]provider.Provider{primary},
trustedStore,
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -409,9 +410,9 @@ func TestClientRestoresTrustedHeaderAfterStartup2(t *testing.T) {
err := trustedStore.SaveSignedHeaderAndValidatorSet(h1, vals)
require.NoError(t, err)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 4 * time.Hour,
Height: 2,
Hash: h2.Hash(),
@ -419,7 +420,7 @@ func TestClientRestoresTrustedHeaderAfterStartup2(t *testing.T) {
fullNode,
[]provider.Provider{fullNode},
trustedStore,
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -460,9 +461,9 @@ func TestClientRestoresTrustedHeaderAfterStartup2(t *testing.T) {
valSet,
)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 4 * time.Hour,
Height: 2,
Hash: diffHeader2.Hash(),
@ -470,7 +471,7 @@ func TestClientRestoresTrustedHeaderAfterStartup2(t *testing.T) {
primary,
[]provider.Provider{primary},
trustedStore,
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -498,13 +499,13 @@ func TestClientRestoresTrustedHeaderAfterStartup3(t *testing.T) {
err = trustedStore.SaveSignedHeaderAndValidatorSet(h2, vals)
require.NoError(t, err)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{fullNode},
trustedStore,
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -555,9 +556,9 @@ func TestClientRestoresTrustedHeaderAfterStartup3(t *testing.T) {
valSet,
)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 4 * time.Hour,
Height: 1,
Hash: header1.Hash(),
@ -565,7 +566,7 @@ func TestClientRestoresTrustedHeaderAfterStartup3(t *testing.T) {
primary,
[]provider.Provider{primary},
trustedStore,
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -594,13 +595,13 @@ func TestClientRestoresTrustedHeaderAfterStartup3(t *testing.T) {
}
func TestClient_Update(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{fullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -619,13 +620,13 @@ func TestClient_Update(t *testing.T) {
}
func TestClient_Concurrency(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{fullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -663,14 +664,14 @@ func TestClient_Concurrency(t *testing.T) {
}
func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
deadNode,
[]provider.Provider{fullNode, fullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
MaxRetryAttempts(1),
lite.Logger(log.TestingLogger()),
lite.MaxRetryAttempts(1),
)
require.NoError(t, err)
@ -684,9 +685,9 @@ func TestClientReplacesPrimaryWithWitnessIfPrimaryIsUnavailable(t *testing.T) {
func TestClient_BackwardsVerification(t *testing.T) {
{
trustHeader, _ := largeFullNode.SignedHeader(6)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 4 * time.Minute,
Height: trustHeader.Height,
Hash: trustHeader.Hash(),
@ -694,7 +695,7 @@ func TestClient_BackwardsVerification(t *testing.T) {
largeFullNode,
[]provider.Provider{largeFullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -769,9 +770,9 @@ func TestClient_BackwardsVerification(t *testing.T) {
}
for _, tc := range testCases {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 1 * time.Hour,
Height: 3,
Hash: h3.Hash(),
@ -779,7 +780,7 @@ func TestClient_BackwardsVerification(t *testing.T) {
tc.provider,
[]provider.Provider{tc.provider},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)
@ -795,7 +796,7 @@ func TestClient_NewClientFromTrustedStore(t *testing.T) {
err := db.SaveSignedHeaderAndValidatorSet(h1, vals)
require.NoError(t, err)
c, err := NewClientFromTrustedStore(
c, err := lite.NewClientFromTrustedStore(
chainID,
trustPeriod,
deadNode,
@ -819,14 +820,14 @@ func TestClient_NewClientFromTrustedStore(t *testing.T) {
}
func TestNewClientErrorsIfAllWitnessesUnavailable(t *testing.T) {
_, err := NewClient(
_, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{deadNode, deadNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
MaxRetryAttempts(1),
lite.Logger(log.TestingLogger()),
lite.MaxRetryAttempts(1),
)
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "awaiting response from all witnesses exceeded dropout time")
@ -862,14 +863,14 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
},
)
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{badProvider1, badProvider2},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
MaxRetryAttempts(1),
lite.Logger(log.TestingLogger()),
lite.MaxRetryAttempts(1),
)
// witness should have behaved properly -> no error
require.NoError(t, err)
@ -889,13 +890,13 @@ func TestClientRemovesWitnessIfItSendsUsIncorrectHeader(t *testing.T) {
}
func TestClientTrustedValidatorSet(t *testing.T) {
c, err := NewClient(
c, err := lite.NewClient(
chainID,
trustOptions,
fullNode,
[]provider.Provider{fullNode},
dbs.New(dbm.NewMemDB(), chainID),
Logger(log.TestingLogger()),
lite.Logger(log.TestingLogger()),
)
require.NoError(t, err)


+ 6
- 5
lite2/example_test.go View File

@ -1,4 +1,4 @@
package lite
package lite_test
import (
"fmt"
@ -11,6 +11,7 @@ import (
dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/abci/example/kvstore"
lite "github.com/tendermint/tendermint/lite2"
"github.com/tendermint/tendermint/lite2/provider"
httpp "github.com/tendermint/tendermint/lite2/provider/http"
dbs "github.com/tendermint/tendermint/lite2/store/db"
@ -48,9 +49,9 @@ func ExampleClient_Update() {
stdlog.Fatal(err)
}
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 504 * time.Hour, // 21 days
Height: 2,
Hash: header.Hash(),
@ -117,9 +118,9 @@ func ExampleClient_VerifyHeaderAtHeight() {
stdlog.Fatal(err)
}
c, err := NewClient(
c, err := lite.NewClient(
chainID,
TrustOptions{
lite.TrustOptions{
Period: 504 * time.Hour, // 21 days
Height: 2,
Hash: header.Hash(),


lite2/test_helpers.go → lite2/helpers_test.go View File


+ 11
- 10
lite2/provider/http/http.go View File

@ -7,6 +7,7 @@ import (
"github.com/tendermint/tendermint/lite2/provider"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
"github.com/tendermint/tendermint/types"
)
@ -21,14 +22,14 @@ type SignStatusClient interface {
// http provider uses an RPC client (or SignStatusClient more generally) to
// obtain the necessary information.
type http struct {
chainID string
client SignStatusClient
SignStatusClient // embed so interface can be converted to SignStatusClient for tests
chainID string
}
// New creates a HTTP provider, which is using the rpcclient.HTTP
// New creates a HTTP provider, which is using the rpchttp.HTTP
// client under the hood.
func New(chainID, remote string) (provider.Provider, error) {
httpClient, err := rpcclient.NewHTTP(remote, "/websocket")
httpClient, err := rpchttp.New(remote, "/websocket")
if err != nil {
return nil, err
}
@ -38,8 +39,8 @@ func New(chainID, remote string) (provider.Provider, error) {
// NewWithClient allows you to provide custom SignStatusClient.
func NewWithClient(chainID string, client SignStatusClient) provider.Provider {
return &http{
chainID: chainID,
client: client,
SignStatusClient: client,
chainID: chainID,
}
}
@ -49,7 +50,7 @@ func (p *http) ChainID() string {
}
func (p *http) String() string {
return fmt.Sprintf("http{%s}", p.client.Remote())
return fmt.Sprintf("http{%s}", p.Remote())
}
// SignedHeader fetches a SignedHeader at the given height and checks the
@ -60,7 +61,7 @@ func (p *http) SignedHeader(height int64) (*types.SignedHeader, error) {
return nil, err
}
commit, err := p.client.Commit(h)
commit, err := p.SignStatusClient.Commit(h)
if err != nil {
// TODO: standartise errors on the RPC side
if strings.Contains(err.Error(), "height must be less than or equal") {
@ -90,7 +91,7 @@ func (p *http) ValidatorSet(height int64) (*types.ValidatorSet, error) {
}
const maxPerPage = 100
res, err := p.client.Validators(h, 0, maxPerPage)
res, err := p.SignStatusClient.Validators(h, 0, maxPerPage)
if err != nil {
// TODO: standartise errors on the RPC side
if strings.Contains(err.Error(), "height must be less than or equal") {
@ -106,7 +107,7 @@ func (p *http) ValidatorSet(height int64) (*types.ValidatorSet, error) {
// Check if there are more validators.
for len(res.Validators) == maxPerPage {
res, err = p.client.Validators(h, page, maxPerPage)
res, err = p.SignStatusClient.Validators(h, page, maxPerPage)
if err != nil {
return nil, err
}


+ 4
- 3
lite2/provider/http/http_test.go View File

@ -1,4 +1,4 @@
package http
package http_test
import (
"os"
@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/example/kvstore"
litehttp "github.com/tendermint/tendermint/lite2/provider/http"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
@ -33,12 +34,12 @@ func TestProvider(t *testing.T) {
}
chainID := genDoc.ChainID
t.Log("chainID:", chainID)
p, err := New(chainID, rpcAddr)
p, err := litehttp.New(chainID, rpcAddr)
require.Nil(t, err)
require.NotNil(t, p)
// let it produce some blocks
err = rpcclient.WaitForHeight(p.(*http).client, 6, nil)
err = rpcclient.WaitForHeight(p.(rpcclient.StatusClient), 6, nil)
require.Nil(t, err)
// let's get the highest block


+ 10
- 9
lite2/verifier_test.go View File

@ -1,4 +1,4 @@
package lite
package lite_test
import (
"fmt"
@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"
tmmath "github.com/tendermint/tendermint/libs/math"
lite "github.com/tendermint/tendermint/lite2"
"github.com/tendermint/tendermint/types"
)
@ -117,7 +118,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) {
vals,
3 * time.Hour,
bTime.Add(2 * time.Hour),
ErrInvalidHeader{Reason: types.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
lite.ErrInvalidHeader{Reason: types.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
"",
},
// vals does not match with what we have -> error
@ -155,7 +156,7 @@ func TestVerifyAdjacentHeaders(t *testing.T) {
for i, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
err := VerifyAdjacent(chainID, header, tc.newHeader, tc.newVals, tc.trustingPeriod, tc.now, maxClockDrift)
err := lite.VerifyAdjacent(chainID, header, tc.newHeader, tc.newVals, tc.trustingPeriod, tc.now, maxClockDrift)
switch {
case tc.expErr != nil && assert.Error(t, err):
assert.Equal(t, tc.expErr, err)
@ -231,7 +232,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) {
vals,
3 * time.Hour,
bTime.Add(2 * time.Hour),
ErrInvalidHeader{types.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
lite.ErrInvalidHeader{types.ErrNotEnoughVotingPowerSigned{Got: 50, Needed: 93}},
"",
},
// 3/3 new vals signed, 2/3 old vals present -> no error
@ -261,7 +262,7 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) {
lessThanOneThirdVals,
3 * time.Hour,
bTime.Add(2 * time.Hour),
ErrNewValSetCantBeTrusted{types.ErrNotEnoughVotingPowerSigned{Got: 20, Needed: 46}},
lite.ErrNewValSetCantBeTrusted{types.ErrNotEnoughVotingPowerSigned{Got: 20, Needed: 46}},
"",
},
}
@ -269,9 +270,9 @@ func TestVerifyNonAdjacentHeaders(t *testing.T) {
for i, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
err := VerifyNonAdjacent(chainID, header, vals, tc.newHeader, tc.newVals, tc.trustingPeriod,
err := lite.VerifyNonAdjacent(chainID, header, vals, tc.newHeader, tc.newVals, tc.trustingPeriod,
tc.now, maxClockDrift,
DefaultTrustLevel)
lite.DefaultTrustLevel)
switch {
case tc.expErr != nil && assert.Error(t, err):
@ -300,7 +301,7 @@ func TestVerifyReturnsErrorIfTrustLevelIsInvalid(t *testing.T) {
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys))
)
err := Verify(chainID, header, vals, header, vals, 2*time.Hour, time.Now(), maxClockDrift,
err := lite.Verify(chainID, header, vals, header, vals, 2*time.Hour, time.Now(), maxClockDrift,
tmmath.Fraction{Numerator: 2, Denominator: 1})
assert.Error(t, err)
}
@ -327,7 +328,7 @@ func TestValidateTrustLevel(t *testing.T) {
}
for _, tc := range testCases {
err := ValidateTrustLevel(tc.lvl)
err := lite.ValidateTrustLevel(tc.lvl)
if !tc.valid {
assert.Error(t, err)
} else {


+ 3
- 3
rpc/client/examples_test.go View File

@ -6,7 +6,7 @@ import (
"log"
"github.com/tendermint/tendermint/abci/example/kvstore"
"github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctest "github.com/tendermint/tendermint/rpc/test"
)
@ -19,7 +19,7 @@ func ExampleHTTP_simple() {
// Create our RPC client
rpcAddr := rpctest.GetConfig().RPC.ListenAddress
c, err := client.NewHTTP(rpcAddr, "/websocket")
c, err := rpchttp.New(rpcAddr, "/websocket")
if err != nil {
log.Fatal(err)
}
@ -72,7 +72,7 @@ func ExampleHTTP_batching() {
// Create our RPC client
rpcAddr := rpctest.GetConfig().RPC.ListenAddress
c, err := client.NewHTTP(rpcAddr, "/websocket")
c, err := rpchttp.New(rpcAddr, "/websocket")
if err != nil {
log.Fatal(err)
}


rpc/client/httpclient.go → rpc/client/http/http.go View File


rpc/client/localclient.go → rpc/client/local/local.go View File


+ 11
- 9
rpc/client/rpc_test.go View File

@ -23,15 +23,17 @@ import (
mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/rpc/client"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
rpclocal "github.com/tendermint/tendermint/rpc/client/local"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
)
func getHTTPClient() *client.HTTP {
func getHTTPClient() *rpchttp.HTTP {
rpcAddr := rpctest.GetConfig().RPC.ListenAddress
c, err := client.NewHTTP(rpcAddr, "/websocket")
c, err := rpchttp.New(rpcAddr, "/websocket")
if err != nil {
panic(err)
}
@ -39,9 +41,9 @@ func getHTTPClient() *client.HTTP {
return c
}
func getHTTPClientWithTimeout(timeout uint) *client.HTTP {
func getHTTPClientWithTimeout(timeout uint) *rpchttp.HTTP {
rpcAddr := rpctest.GetConfig().RPC.ListenAddress
c, err := client.NewHTTPWithTimeout(rpcAddr, "/websocket", timeout)
c, err := rpchttp.NewWithTimeout(rpcAddr, "/websocket", timeout)
if err != nil {
panic(err)
}
@ -49,8 +51,8 @@ func getHTTPClientWithTimeout(timeout uint) *client.HTTP {
return c
}
func getLocalClient() *client.Local {
return client.NewLocal(node)
func getLocalClient() *rpclocal.Local {
return rpclocal.New(node)
}
// GetClients returns a slice of clients for table-driven tests
@ -63,7 +65,7 @@ func GetClients() []client.Client {
func TestNilCustomHTTPClient(t *testing.T) {
require.Panics(t, func() {
_, _ = client.NewHTTPWithClient("http://example.com", "/websocket", nil)
_, _ = rpchttp.NewWithClient("http://example.com", "/websocket", nil)
})
require.Panics(t, func() {
_, _ = rpcclient.NewJSONRPCClientWithHTTPClient("http://example.com", nil)
@ -72,7 +74,7 @@ func TestNilCustomHTTPClient(t *testing.T) {
func TestCustomHTTPClient(t *testing.T) {
remote := rpctest.GetConfig().RPC.ListenAddress
c, err := client.NewHTTPWithClient(remote, "/websocket", http.DefaultClient)
c, err := rpchttp.NewWithClient(remote, "/websocket", http.DefaultClient)
require.Nil(t, err)
status, err := c.Status()
require.NoError(t, err)
@ -701,7 +703,7 @@ func TestBatchedJSONRPCCalls(t *testing.T) {
testBatchedJSONRPCCalls(t, c)
}
func testBatchedJSONRPCCalls(t *testing.T, c *client.HTTP) {
func testBatchedJSONRPCCalls(t *testing.T, c *rpchttp.HTTP) {
k1, v1, tx1 := MakeTxKV()
k2, v2, tx2 := MakeTxKV()


+ 3
- 2
rpc/swagger/swagger.yaml View File

@ -253,9 +253,10 @@ paths:
https://godoc.org/github.com/tendermint/tendermint/libs/pubsub/query.
```go
import rpchttp "github.com/tendermint/rpc/client/http"
import "github.com/tendermint/tendermint/types"
client := client.NewHTTP("tcp:0.0.0.0:26657", "/websocket")
client := rpchttp.New("tcp:0.0.0.0:26657", "/websocket")
err := client.Start()
if err != nil {
handle error
@ -309,7 +310,7 @@ paths:
operationId: unsubscribe
description: |
```go
client := client.NewHTTP("tcp:0.0.0.0:26657", "/websocket")
client := rpchttp.New("tcp:0.0.0.0:26657", "/websocket")
err := client.Start()
if err != nil {
handle error


Loading…
Cancel
Save