mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
proxy: NewAppConns takes a NewTMSPClient func
This commit is contained in:
parent
206d00ed8c
commit
035ca7ef61
26
node/node.go
26
node/node.go
@ -44,7 +44,14 @@ type Node struct {
|
|||||||
proxyApp proxy.AppConns
|
proxyApp proxy.AppConns
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNode(config cfg.Config, privValidator *types.PrivValidator) *Node {
|
func NewNodeDefault(config cfg.Config) *Node {
|
||||||
|
// Get PrivValidator
|
||||||
|
privValidatorFile := config.GetString("priv_validator_file")
|
||||||
|
privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
|
||||||
|
return NewNode(config, privValidator, proxy.NewTMSPClientDefault)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNode(config cfg.Config, privValidator *types.PrivValidator, newTMSPClient proxy.NewTMSPClient) *Node {
|
||||||
|
|
||||||
EnsureDir(config.GetString("db_dir"), 0700) // incase we use memdb, cswal still gets written here
|
EnsureDir(config.GetString("db_dir"), 0700) // incase we use memdb, cswal still gets written here
|
||||||
|
|
||||||
@ -60,7 +67,7 @@ func NewNode(config cfg.Config, privValidator *types.PrivValidator) *Node {
|
|||||||
|
|
||||||
// Create the proxyApp, which houses three connections:
|
// Create the proxyApp, which houses three connections:
|
||||||
// query, consensus, and mempool
|
// query, consensus, and mempool
|
||||||
proxyApp := proxy.NewAppConns(config, state, blockStore)
|
proxyApp := proxy.NewAppConns(config, newTMSPClient, state, blockStore)
|
||||||
|
|
||||||
// add the chainid and number of validators to the global config
|
// add the chainid and number of validators to the global config
|
||||||
config.Set("chain_id", state.ChainID)
|
config.Set("chain_id", state.ChainID)
|
||||||
@ -299,9 +306,12 @@ func getState(config cfg.Config, stateDB dbm.DB) *sm.State {
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Users wishing to use an external signer for their validators
|
// Users wishing to:
|
||||||
|
// * use an external signer for their validators
|
||||||
|
// * supply an in-proc tmsp app
|
||||||
// should fork tendermint/tendermint and implement RunNode to
|
// should fork tendermint/tendermint and implement RunNode to
|
||||||
// load their custom priv validator and call NewNode
|
// call NewNode with their custom priv validator and/or custom
|
||||||
|
// proxy.NewTMSPClient function.
|
||||||
func RunNode(config cfg.Config) {
|
func RunNode(config cfg.Config) {
|
||||||
// Wait until the genesis doc becomes available
|
// Wait until the genesis doc becomes available
|
||||||
genDocFile := config.GetString("genesis_file")
|
genDocFile := config.GetString("genesis_file")
|
||||||
@ -324,12 +334,8 @@ func RunNode(config cfg.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get PrivValidator
|
|
||||||
privValidatorFile := config.GetString("priv_validator_file")
|
|
||||||
privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
|
|
||||||
|
|
||||||
// Create & start node
|
// Create & start node
|
||||||
n := NewNode(config, privValidator)
|
n := NewNodeDefault(config)
|
||||||
|
|
||||||
protocol, address := ProtocolAndAddress(config.GetString("node_laddr"))
|
protocol, address := ProtocolAndAddress(config.GetString("node_laddr"))
|
||||||
l := p2p.NewDefaultListener(protocol, address, config.GetBool("skip_upnp"))
|
l := p2p.NewDefaultListener(protocol, address, config.GetBool("skip_upnp"))
|
||||||
@ -384,7 +390,7 @@ func newConsensusState(config cfg.Config) *consensus.ConsensusState {
|
|||||||
|
|
||||||
// Create two proxyAppConn connections,
|
// Create two proxyAppConn connections,
|
||||||
// one for the consensus and one for the mempool.
|
// one for the consensus and one for the mempool.
|
||||||
proxyApp := proxy.NewAppConns(config, state, blockStore)
|
proxyApp := proxy.NewAppConns(config, proxy.NewTMSPClientDefault, state, blockStore)
|
||||||
|
|
||||||
// add the chainid to the global config
|
// add the chainid to the global config
|
||||||
config.Set("chain_id", state.ChainID)
|
config.Set("chain_id", state.ChainID)
|
||||||
|
@ -6,18 +6,13 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/go-p2p"
|
"github.com/tendermint/go-p2p"
|
||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeStartStop(t *testing.T) {
|
func TestNodeStartStop(t *testing.T) {
|
||||||
config := tendermint_test.ResetConfig("node_node_test")
|
config := tendermint_test.ResetConfig("node_node_test")
|
||||||
|
|
||||||
// Get PrivValidator
|
|
||||||
privValidatorFile := config.GetString("priv_validator_file")
|
|
||||||
privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
|
|
||||||
|
|
||||||
// Create & start node
|
// Create & start node
|
||||||
n := NewNode(config, privValidator)
|
n := NewNodeDefault(config)
|
||||||
protocol, address := ProtocolAndAddress(config.GetString("node_laddr"))
|
protocol, address := ProtocolAndAddress(config.GetString("node_laddr"))
|
||||||
l := p2p.NewDefaultListener(protocol, address, config.GetBool("skip_upnp"))
|
l := p2p.NewDefaultListener(protocol, address, config.GetBool("skip_upnp"))
|
||||||
n.AddListener(l)
|
n.AddListener(l)
|
||||||
|
@ -53,7 +53,7 @@ func TestEcho(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
// Start client
|
// Start client
|
||||||
cli, err := NewTMSPClient(sockPath, SOCKET)
|
cli, err := NewTMSPClientDefault(sockPath, SOCKET)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
Exit(err.Error())
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func BenchmarkEcho(b *testing.B) {
|
|||||||
}
|
}
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
// Start client
|
// Start client
|
||||||
cli, err := NewTMSPClient(sockPath, SOCKET)
|
cli, err := NewTMSPClientDefault(sockPath, SOCKET)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
Exit(err.Error())
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ func TestInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
// Start client
|
// Start client
|
||||||
cli, err := NewTMSPClient(sockPath, SOCKET)
|
cli, err := NewTMSPClientDefault(sockPath, SOCKET)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Exit(err.Error())
|
Exit(err.Error())
|
||||||
}
|
}
|
||||||
|
43
proxy/client.go
Normal file
43
proxy/client.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package proxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
tmspcli "github.com/tendermint/tmsp/client"
|
||||||
|
"github.com/tendermint/tmsp/example/dummy"
|
||||||
|
nilapp "github.com/tendermint/tmsp/example/nil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Function type to get a connected tmsp client
|
||||||
|
// Allows consumers to provide their own in-proc apps,
|
||||||
|
// or to implement alternate address schemes and transports
|
||||||
|
type NewTMSPClient func(addr, transport string) (tmspcli.Client, error)
|
||||||
|
|
||||||
|
// Get a connected tmsp client.
|
||||||
|
// Offers some default in-proc apps, else socket/grpc.
|
||||||
|
func NewTMSPClientDefault(addr, transport string) (tmspcli.Client, error) {
|
||||||
|
var client tmspcli.Client
|
||||||
|
|
||||||
|
// use local app (for testing)
|
||||||
|
// TODO: local proxy app conn
|
||||||
|
switch addr {
|
||||||
|
case "nilapp":
|
||||||
|
app := nilapp.NewNilApplication()
|
||||||
|
mtx := new(sync.Mutex) // TODO
|
||||||
|
client = tmspcli.NewLocalClient(mtx, app)
|
||||||
|
case "dummy":
|
||||||
|
app := dummy.NewDummyApplication()
|
||||||
|
mtx := new(sync.Mutex) // TODO
|
||||||
|
client = tmspcli.NewLocalClient(mtx, app)
|
||||||
|
default:
|
||||||
|
// Run forever in a loop
|
||||||
|
mustConnect := false
|
||||||
|
remoteApp, err := tmspcli.NewClient(addr, transport, mustConnect)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Failed to connect to proxy for mempool: %v", err)
|
||||||
|
}
|
||||||
|
client = remoteApp
|
||||||
|
}
|
||||||
|
return client, nil
|
||||||
|
}
|
@ -1,56 +1,22 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
cfg "github.com/tendermint/go-config"
|
cfg "github.com/tendermint/go-config"
|
||||||
tmspcli "github.com/tendermint/tmsp/client"
|
|
||||||
"github.com/tendermint/tmsp/example/dummy"
|
|
||||||
nilapp "github.com/tendermint/tmsp/example/nil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get a connected tmsp client
|
// Tendermint's interface to the application consists of multiple connections
|
||||||
func NewTMSPClient(addr, transport string) (tmspcli.Client, error) {
|
|
||||||
var client tmspcli.Client
|
|
||||||
|
|
||||||
// use local app (for testing)
|
|
||||||
// TODO: local proxy app conn
|
|
||||||
switch addr {
|
|
||||||
case "nilapp":
|
|
||||||
app := nilapp.NewNilApplication()
|
|
||||||
mtx := new(sync.Mutex) // TODO
|
|
||||||
client = tmspcli.NewLocalClient(mtx, app)
|
|
||||||
case "dummy":
|
|
||||||
app := dummy.NewDummyApplication()
|
|
||||||
mtx := new(sync.Mutex) // TODO
|
|
||||||
client = tmspcli.NewLocalClient(mtx, app)
|
|
||||||
default:
|
|
||||||
// Run forever in a loop
|
|
||||||
mustConnect := false
|
|
||||||
remoteApp, err := tmspcli.NewClient(addr, transport, mustConnect)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Failed to connect to proxy for mempool: %v", err)
|
|
||||||
}
|
|
||||||
client = remoteApp
|
|
||||||
}
|
|
||||||
return client, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------
|
|
||||||
|
|
||||||
type AppConns interface {
|
type AppConns interface {
|
||||||
Mempool() AppConnMempool
|
Mempool() AppConnMempool
|
||||||
Consensus() AppConnConsensus
|
Consensus() AppConnConsensus
|
||||||
Query() AppConnQuery
|
Query() AppConnQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAppConns(config cfg.Config, state State, blockStore BlockStore) AppConns {
|
func NewAppConns(config cfg.Config, newTMSPClient NewTMSPClient, state State, blockStore BlockStore) AppConns {
|
||||||
return NewMultiAppConn(config, state, blockStore)
|
return NewMultiAppConn(config, newTMSPClient, state, blockStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
// a multiAppConn is made of a few appConns (mempool, consensus)
|
// a multiAppConn is made of a few appConns (mempool, consensus, query)
|
||||||
// and manages their underlying tmsp clients, ensuring they reboot together
|
// and manages their underlying tmsp clients, ensuring they reboot together
|
||||||
type multiAppConn struct {
|
type multiAppConn struct {
|
||||||
QuitService
|
QuitService
|
||||||
@ -63,14 +29,17 @@ type multiAppConn struct {
|
|||||||
mempoolConn *appConnMempool
|
mempoolConn *appConnMempool
|
||||||
consensusConn *appConnConsensus
|
consensusConn *appConnConsensus
|
||||||
queryConn *appConnQuery
|
queryConn *appConnQuery
|
||||||
|
|
||||||
|
newTMSPClient NewTMSPClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make all necessary tmsp connections to the application
|
// Make all necessary tmsp connections to the application
|
||||||
func NewMultiAppConn(config cfg.Config, state State, blockStore BlockStore) *multiAppConn {
|
func NewMultiAppConn(config cfg.Config, newTMSPClient NewTMSPClient, state State, blockStore BlockStore) *multiAppConn {
|
||||||
multiAppConn := &multiAppConn{
|
multiAppConn := &multiAppConn{
|
||||||
config: config,
|
config: config,
|
||||||
state: state,
|
state: state,
|
||||||
blockStore: blockStore,
|
blockStore: blockStore,
|
||||||
|
newTMSPClient: newTMSPClient,
|
||||||
}
|
}
|
||||||
multiAppConn.QuitService = *NewQuitService(log, "multiAppConn", multiAppConn)
|
multiAppConn.QuitService = *NewQuitService(log, "multiAppConn", multiAppConn)
|
||||||
multiAppConn.Start()
|
multiAppConn.Start()
|
||||||
@ -98,21 +67,21 @@ func (app *multiAppConn) OnStart() error {
|
|||||||
transport := app.config.GetString("tmsp")
|
transport := app.config.GetString("tmsp")
|
||||||
|
|
||||||
// query connection
|
// query connection
|
||||||
querycli, err := NewTMSPClient(addr, transport)
|
querycli, err := app.newTMSPClient(addr, transport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
app.queryConn = NewAppConnQuery(querycli)
|
app.queryConn = NewAppConnQuery(querycli)
|
||||||
|
|
||||||
// mempool connection
|
// mempool connection
|
||||||
memcli, err := NewTMSPClient(addr, transport)
|
memcli, err := app.newTMSPClient(addr, transport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
app.mempoolConn = NewAppConnMempool(memcli)
|
app.mempoolConn = NewAppConnMempool(memcli)
|
||||||
|
|
||||||
// consensus connection
|
// consensus connection
|
||||||
concli, err := NewTMSPClient(addr, transport)
|
concli, err := app.newTMSPClient(addr, transport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/tendermint/tendermint/config/tendermint_test"
|
"github.com/tendermint/tendermint/config/tendermint_test"
|
||||||
nm "github.com/tendermint/tendermint/node"
|
nm "github.com/tendermint/tendermint/node"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// global variables for use across all tests
|
// global variables for use across all tests
|
||||||
@ -52,9 +51,7 @@ func init() {
|
|||||||
// create a new node and sleep forever
|
// create a new node and sleep forever
|
||||||
func newNode(ready chan struct{}) {
|
func newNode(ready chan struct{}) {
|
||||||
// Create & start node
|
// Create & start node
|
||||||
privValidatorFile := config.GetString("priv_validator_file")
|
node = nm.NewNodeDefault(config)
|
||||||
privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
|
|
||||||
node = nm.NewNode(config, privValidator)
|
|
||||||
protocol, address := nm.ProtocolAndAddress(config.GetString("node_laddr"))
|
protocol, address := nm.ProtocolAndAddress(config.GetString("node_laddr"))
|
||||||
l := p2p.NewDefaultListener(protocol, address, true)
|
l := p2p.NewDefaultListener(protocol, address, true)
|
||||||
node.AddListener(l)
|
node.AddListener(l)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user