|
@ -1,11 +1,14 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"context" |
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"net/http" |
|
|
"os" |
|
|
"os" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
"strconv" |
|
|
"strconv" |
|
|
|
|
|
"strings" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/spf13/viper" |
|
|
"github.com/spf13/viper" |
|
@ -16,10 +19,16 @@ import ( |
|
|
tmflags "github.com/tendermint/tendermint/libs/cli/flags" |
|
|
tmflags "github.com/tendermint/tendermint/libs/cli/flags" |
|
|
"github.com/tendermint/tendermint/libs/log" |
|
|
"github.com/tendermint/tendermint/libs/log" |
|
|
tmnet "github.com/tendermint/tendermint/libs/net" |
|
|
tmnet "github.com/tendermint/tendermint/libs/net" |
|
|
|
|
|
"github.com/tendermint/tendermint/light" |
|
|
|
|
|
lproxy "github.com/tendermint/tendermint/light/proxy" |
|
|
|
|
|
lrpc "github.com/tendermint/tendermint/light/rpc" |
|
|
|
|
|
dbs "github.com/tendermint/tendermint/light/store/db" |
|
|
"github.com/tendermint/tendermint/node" |
|
|
"github.com/tendermint/tendermint/node" |
|
|
"github.com/tendermint/tendermint/p2p" |
|
|
"github.com/tendermint/tendermint/p2p" |
|
|
"github.com/tendermint/tendermint/privval" |
|
|
"github.com/tendermint/tendermint/privval" |
|
|
"github.com/tendermint/tendermint/proxy" |
|
|
"github.com/tendermint/tendermint/proxy" |
|
|
|
|
|
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server" |
|
|
|
|
|
e2e "github.com/tendermint/tendermint/test/e2e/pkg" |
|
|
mcs "github.com/tendermint/tendermint/test/maverick/consensus" |
|
|
mcs "github.com/tendermint/tendermint/test/maverick/consensus" |
|
|
maverick "github.com/tendermint/tendermint/test/maverick/node" |
|
|
maverick "github.com/tendermint/tendermint/test/maverick/node" |
|
|
) |
|
|
) |
|
@ -66,7 +75,11 @@ func run(configFile string) error { |
|
|
err = startApp(cfg) |
|
|
err = startApp(cfg) |
|
|
case "builtin": |
|
|
case "builtin": |
|
|
if len(cfg.Misbehaviors) == 0 { |
|
|
if len(cfg.Misbehaviors) == 0 { |
|
|
err = startNode(cfg) |
|
|
|
|
|
|
|
|
if cfg.Mode == string(e2e.ModeLight) { |
|
|
|
|
|
err = startLightClient(cfg) |
|
|
|
|
|
} else { |
|
|
|
|
|
err = startNode(cfg) |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
err = startMaverick(cfg) |
|
|
err = startMaverick(cfg) |
|
|
} |
|
|
} |
|
@ -131,6 +144,64 @@ func startNode(cfg *Config) error { |
|
|
return n.Start() |
|
|
return n.Start() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func startLightClient(cfg *Config) error { |
|
|
|
|
|
tmcfg, nodeLogger, _, err := setupNode() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dbContext := &node.DBContext{ID: "light", Config: tmcfg} |
|
|
|
|
|
lightDB, err := node.DefaultDBProvider(dbContext) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
providers := rpcEndpoints(tmcfg.P2P.PersistentPeers) |
|
|
|
|
|
|
|
|
|
|
|
c, err := light.NewHTTPClient( |
|
|
|
|
|
context.Background(), |
|
|
|
|
|
cfg.ChainID, |
|
|
|
|
|
light.TrustOptions{ |
|
|
|
|
|
Period: tmcfg.StateSync.TrustPeriod, |
|
|
|
|
|
Height: tmcfg.StateSync.TrustHeight, |
|
|
|
|
|
Hash: tmcfg.StateSync.TrustHashBytes(), |
|
|
|
|
|
}, |
|
|
|
|
|
providers[0], |
|
|
|
|
|
providers[1:], |
|
|
|
|
|
dbs.New(lightDB, "light"), |
|
|
|
|
|
light.Logger(nodeLogger), |
|
|
|
|
|
) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rpccfg := rpcserver.DefaultConfig() |
|
|
|
|
|
rpccfg.MaxBodyBytes = tmcfg.RPC.MaxBodyBytes |
|
|
|
|
|
rpccfg.MaxHeaderBytes = tmcfg.RPC.MaxHeaderBytes |
|
|
|
|
|
rpccfg.MaxOpenConnections = tmcfg.RPC.MaxOpenConnections |
|
|
|
|
|
// If necessary adjust global WriteTimeout to ensure it's greater than
|
|
|
|
|
|
// TimeoutBroadcastTxCommit.
|
|
|
|
|
|
// See https://github.com/tendermint/tendermint/issues/3435
|
|
|
|
|
|
if rpccfg.WriteTimeout <= tmcfg.RPC.TimeoutBroadcastTxCommit { |
|
|
|
|
|
rpccfg.WriteTimeout = tmcfg.RPC.TimeoutBroadcastTxCommit + 1*time.Second |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p, err := lproxy.NewProxy(c, tmcfg.RPC.ListenAddress, providers[0], rpccfg, nodeLogger, |
|
|
|
|
|
lrpc.KeyPathFn(lrpc.DefaultMerkleKeyPathFn())) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logger.Info("Starting proxy...", "laddr", tmcfg.RPC.ListenAddress) |
|
|
|
|
|
if err := p.ListenAndServe(); err != http.ErrServerClosed { |
|
|
|
|
|
// Error starting or closing listener:
|
|
|
|
|
|
logger.Error("proxy ListenAndServe", "err", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: Temporarily disconnected maverick until it is redesigned
|
|
|
// startMaverick starts a Maverick node that runs the application directly. It assumes the Tendermint
|
|
|
// startMaverick starts a Maverick node that runs the application directly. It assumes the Tendermint
|
|
|
// configuration is in $TMHOME/config/tendermint.toml.
|
|
|
// configuration is in $TMHOME/config/tendermint.toml.
|
|
|
func startMaverick(cfg *Config) error { |
|
|
func startMaverick(cfg *Config) error { |
|
@ -238,3 +309,19 @@ func setupNode() (*config.Config, log.Logger, *p2p.NodeKey, error) { |
|
|
|
|
|
|
|
|
return tmcfg, nodeLogger, nodeKey, nil |
|
|
return tmcfg, nodeLogger, nodeKey, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// rpcEndpoints takes a list of persistent peers and splits them into a list of rpc endpoints
|
|
|
|
|
|
// using 26657 as the port number
|
|
|
|
|
|
func rpcEndpoints(peers string) []string { |
|
|
|
|
|
arr := strings.Split(peers, ",") |
|
|
|
|
|
endpoints := make([]string, len(arr)) |
|
|
|
|
|
for i, v := range arr { |
|
|
|
|
|
urlString := strings.SplitAfter(v, "@")[1] |
|
|
|
|
|
hostName := strings.Split(urlString, ":26656")[0] |
|
|
|
|
|
// use RPC port instead
|
|
|
|
|
|
port := 26657 |
|
|
|
|
|
rpcEndpoint := "http://" + hostName + ":" + fmt.Sprint(port) |
|
|
|
|
|
endpoints[i] = rpcEndpoint |
|
|
|
|
|
} |
|
|
|
|
|
return endpoints |
|
|
|
|
|
} |