|
|
@ -9,14 +9,12 @@ import ( |
|
|
|
"github.com/pkg/errors" |
|
|
|
"github.com/spf13/cobra" |
|
|
|
|
|
|
|
amino "github.com/tendermint/go-amino" |
|
|
|
"github.com/tendermint/go-amino" |
|
|
|
dbm "github.com/tendermint/tm-db" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/libs/log" |
|
|
|
tmos "github.com/tendermint/tendermint/libs/os" |
|
|
|
lite "github.com/tendermint/tendermint/lite2" |
|
|
|
"github.com/tendermint/tendermint/lite2/provider" |
|
|
|
httpp "github.com/tendermint/tendermint/lite2/provider/http" |
|
|
|
lproxy "github.com/tendermint/tendermint/lite2/proxy" |
|
|
|
lrpc "github.com/tendermint/tendermint/lite2/rpc" |
|
|
|
dbs "github.com/tendermint/tendermint/lite2/store/db" |
|
|
@ -54,9 +52,9 @@ lite cosmoshub-3 -p 52.57.29.196:26657 -w public-seed-node.cosmoshub.certus.one: |
|
|
|
var ( |
|
|
|
listenAddr string |
|
|
|
primaryAddr string |
|
|
|
witnessAddrsJoined string |
|
|
|
chainID string |
|
|
|
home string |
|
|
|
witnessesAddrs string |
|
|
|
maxOpenConnections int |
|
|
|
|
|
|
|
trustingPeriod time.Duration |
|
|
@ -71,7 +69,7 @@ func init() { |
|
|
|
"Serve the proxy on the given address") |
|
|
|
LiteCmd.Flags().StringVarP(&primaryAddr, "primary", "p", "", |
|
|
|
"Connect to a Tendermint node at this address") |
|
|
|
LiteCmd.Flags().StringVarP(&witnessesAddrs, "witnesses", "w", "", |
|
|
|
LiteCmd.Flags().StringVarP(&witnessAddrsJoined, "witnesses", "w", "", |
|
|
|
"Tendermint nodes to cross-check the primary node, comma-separated") |
|
|
|
LiteCmd.Flags().StringVar(&home, "home-dir", ".tendermint-lite", "Specify the home directory") |
|
|
|
LiteCmd.Flags().IntVar( |
|
|
@ -98,26 +96,10 @@ func runProxy(cmd *cobra.Command, args []string) error { |
|
|
|
logger = log.NewFilter(logger, option) |
|
|
|
|
|
|
|
chainID = args[0] |
|
|
|
logger.Info("Creating client...", "chainID", chainID) |
|
|
|
|
|
|
|
logger.Info("Creating HTTP client for primary...", "addr", primaryAddr) |
|
|
|
rpcClient, err := rpcclient.NewHTTP(primaryAddr, "/websocket") |
|
|
|
if err != nil { |
|
|
|
return errors.Wrapf(err, "http client for %s", primaryAddr) |
|
|
|
} |
|
|
|
primary := httpp.NewWithClient(chainID, rpcClient) |
|
|
|
|
|
|
|
// TODO: use NewNetClient once we have it
|
|
|
|
addrs := strings.Split(witnessesAddrs, ",") |
|
|
|
witnesses := make([]provider.Provider, len(addrs)) |
|
|
|
for i, addr := range addrs { |
|
|
|
p, err := httpp.New(chainID, addr) |
|
|
|
if err != nil { |
|
|
|
return errors.Wrapf(err, "http provider for %s", addr) |
|
|
|
} |
|
|
|
witnesses[i] = p |
|
|
|
} |
|
|
|
witnessesAddrs := strings.Split(witnessAddrsJoined, ",") |
|
|
|
|
|
|
|
logger.Info("Creating client...", "chainID", chainID) |
|
|
|
db, err := dbm.NewGoLevelDB("lite-client-db", home) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
@ -125,24 +107,24 @@ func runProxy(cmd *cobra.Command, args []string) error { |
|
|
|
|
|
|
|
var c *lite.Client |
|
|
|
if trustedHeight > 0 && len(trustedHash) > 0 { // fresh installation
|
|
|
|
c, err = lite.NewClient( |
|
|
|
c, err = lite.NewHTTPClient( |
|
|
|
chainID, |
|
|
|
lite.TrustOptions{ |
|
|
|
Period: trustingPeriod, |
|
|
|
Height: trustedHeight, |
|
|
|
Hash: trustedHash, |
|
|
|
}, |
|
|
|
primary, |
|
|
|
witnesses, |
|
|
|
primaryAddr, |
|
|
|
witnessesAddrs, |
|
|
|
dbs.New(db, chainID), |
|
|
|
lite.Logger(logger), |
|
|
|
) |
|
|
|
} else { // continue from latest state
|
|
|
|
c, err = lite.NewClientFromTrustedStore( |
|
|
|
c, err = lite.NewHTTPClientFromTrustedStore( |
|
|
|
chainID, |
|
|
|
trustingPeriod, |
|
|
|
primary, |
|
|
|
witnesses, |
|
|
|
primaryAddr, |
|
|
|
witnessesAddrs, |
|
|
|
dbs.New(db, chainID), |
|
|
|
lite.Logger(logger), |
|
|
|
) |
|
|
@ -158,6 +140,10 @@ func runProxy(cmd *cobra.Command, args []string) error { |
|
|
|
} |
|
|
|
defer c.Stop() |
|
|
|
|
|
|
|
rpcClient, err := rpcclient.NewHTTP(primaryAddr, "/websocket") |
|
|
|
if err != nil { |
|
|
|
return errors.Wrapf(err, "http client for %s", primaryAddr) |
|
|
|
} |
|
|
|
p := lproxy.Proxy{ |
|
|
|
Addr: listenAddr, |
|
|
|
Config: &rpcserver.Config{MaxOpenConnections: maxOpenConnections}, |
|
|
|