2015-04-07 11:44:25 -07:00
|
|
|
package node
|
2014-07-08 00:02:04 -07:00
|
|
|
|
|
|
|
import (
|
2015-06-14 18:18:17 -04:00
|
|
|
"bytes"
|
2017-01-28 08:27:13 -08:00
|
|
|
"errors"
|
2017-09-20 18:29:36 -04:00
|
|
|
"fmt"
|
2015-04-20 15:29:01 -07:00
|
|
|
"net"
|
2015-04-10 02:12:17 -07:00
|
|
|
"net/http"
|
2014-07-08 15:33:26 -07:00
|
|
|
|
2018-06-11 17:14:42 +04:00
|
|
|
prometheus "github.com/go-kit/kit/metrics/prometheus"
|
|
|
|
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
2018-06-13 22:40:55 +04:00
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2018-06-11 17:14:42 +04:00
|
|
|
|
2017-01-28 08:27:13 -08:00
|
|
|
abci "github.com/tendermint/abci/types"
|
2018-04-05 08:17:10 -07:00
|
|
|
amino "github.com/tendermint/go-amino"
|
2017-02-22 14:53:59 +04:00
|
|
|
crypto "github.com/tendermint/go-crypto"
|
2017-09-20 18:29:36 -04:00
|
|
|
cmn "github.com/tendermint/tmlibs/common"
|
|
|
|
dbm "github.com/tendermint/tmlibs/db"
|
|
|
|
"github.com/tendermint/tmlibs/log"
|
|
|
|
|
2015-11-01 11:34:08 -08:00
|
|
|
bc "github.com/tendermint/tendermint/blockchain"
|
2017-05-01 20:09:29 -04:00
|
|
|
cfg "github.com/tendermint/tendermint/config"
|
2018-01-21 11:45:04 -05:00
|
|
|
cs "github.com/tendermint/tendermint/consensus"
|
2017-11-20 04:22:25 +00:00
|
|
|
"github.com/tendermint/tendermint/evidence"
|
2015-04-01 17:30:16 -07:00
|
|
|
mempl "github.com/tendermint/tendermint/mempool"
|
2017-09-20 18:29:36 -04:00
|
|
|
"github.com/tendermint/tendermint/p2p"
|
2018-01-20 21:44:09 -05:00
|
|
|
"github.com/tendermint/tendermint/p2p/pex"
|
2018-06-01 19:17:37 +02:00
|
|
|
"github.com/tendermint/tendermint/privval"
|
2015-12-01 20:12:01 -08:00
|
|
|
"github.com/tendermint/tendermint/proxy"
|
2017-04-26 19:57:33 -04:00
|
|
|
rpccore "github.com/tendermint/tendermint/rpc/core"
|
2018-04-05 21:19:14 -07:00
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
2017-04-26 19:57:33 -04:00
|
|
|
grpccore "github.com/tendermint/tendermint/rpc/grpc"
|
|
|
|
rpc "github.com/tendermint/tendermint/rpc/lib"
|
|
|
|
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
|
2015-04-01 17:30:16 -07:00
|
|
|
sm "github.com/tendermint/tendermint/state"
|
2017-04-18 19:56:41 -04:00
|
|
|
"github.com/tendermint/tendermint/state/txindex"
|
|
|
|
"github.com/tendermint/tendermint/state/txindex/kv"
|
|
|
|
"github.com/tendermint/tendermint/state/txindex/null"
|
2015-04-20 15:29:01 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2016-01-20 13:12:42 -05:00
|
|
|
"github.com/tendermint/tendermint/version"
|
2014-07-08 00:02:04 -07:00
|
|
|
|
2017-01-28 08:27:13 -08:00
|
|
|
_ "net/http/pprof"
|
|
|
|
)
|
2015-04-27 07:25:11 -07:00
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// DBContext specifies config information for loading a new DB.
|
|
|
|
type DBContext struct {
|
|
|
|
ID string
|
|
|
|
Config *cfg.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
// DBProvider takes a DBContext and returns an instantiated DB.
|
|
|
|
type DBProvider func(*DBContext) (dbm.DB, error)
|
|
|
|
|
|
|
|
// DefaultDBProvider returns a database using the DBBackend and DBDir
|
|
|
|
// specified in the ctx.Config.
|
|
|
|
func DefaultDBProvider(ctx *DBContext) (dbm.DB, error) {
|
2018-02-03 03:50:59 -05:00
|
|
|
dbType := dbm.DBBackendType(ctx.Config.DBBackend)
|
|
|
|
return dbm.NewDB(ctx.ID, dbType, ctx.Config.DBDir()), nil
|
2017-09-20 18:29:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GenesisDocProvider returns a GenesisDoc.
|
|
|
|
// It allows the GenesisDoc to be pulled from sources other than the
|
|
|
|
// filesystem, for instance from a distributed key-value store cluster.
|
|
|
|
type GenesisDocProvider func() (*types.GenesisDoc, error)
|
|
|
|
|
|
|
|
// DefaultGenesisDocProviderFunc returns a GenesisDocProvider that loads
|
|
|
|
// the GenesisDoc from the config.GenesisFile() on the filesystem.
|
|
|
|
func DefaultGenesisDocProviderFunc(config *cfg.Config) GenesisDocProvider {
|
|
|
|
return func() (*types.GenesisDoc, error) {
|
|
|
|
return types.GenesisDocFromFile(config.GenesisFile())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 17:08:17 -04:00
|
|
|
// NodeProvider takes a config and a logger and returns a ready to go Node.
|
|
|
|
type NodeProvider func(*cfg.Config, log.Logger) (*Node, error)
|
|
|
|
|
|
|
|
// DefaultNewNode returns a Tendermint node with default settings for the
|
|
|
|
// PrivValidator, ClientCreator, GenesisDoc, and DBProvider.
|
|
|
|
// It implements NodeProvider.
|
|
|
|
func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
|
|
|
|
return NewNode(config,
|
2018-06-01 19:17:37 +02:00
|
|
|
privval.LoadOrGenFilePV(config.PrivValidatorFile()),
|
2017-09-21 17:08:17 -04:00
|
|
|
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
|
|
|
|
DefaultGenesisDocProviderFunc(config),
|
|
|
|
DefaultDBProvider,
|
2018-06-15 14:23:34 +04:00
|
|
|
DefaultMetricsProvider,
|
2018-02-07 18:35:01 +01:00
|
|
|
logger,
|
|
|
|
)
|
2017-09-21 17:08:17 -04:00
|
|
|
}
|
|
|
|
|
2018-06-15 15:10:25 +04:00
|
|
|
// MetricsProvider returns a consensus and p2p Metrics.
|
2018-06-15 15:57:11 +04:00
|
|
|
type MetricsProvider func() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics)
|
2018-06-15 14:23:34 +04:00
|
|
|
|
2018-06-15 17:21:04 +04:00
|
|
|
// DefaultMetricsProvider returns consensus, p2p and mempool Metrics build
|
|
|
|
// using Prometheus client library.
|
2018-06-15 15:57:11 +04:00
|
|
|
func DefaultMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
|
2018-06-15 14:23:34 +04:00
|
|
|
return &cs.Metrics{
|
2018-06-15 15:10:25 +04:00
|
|
|
Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "height",
|
|
|
|
Help: "Height of the chain.",
|
|
|
|
}, []string{}),
|
|
|
|
Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "rounds",
|
|
|
|
Help: "Number of rounds.",
|
|
|
|
}, []string{}),
|
|
|
|
|
|
|
|
Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "validators",
|
|
|
|
Help: "Number of validators who signed.",
|
|
|
|
}, []string{}),
|
|
|
|
ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "validators_power",
|
|
|
|
Help: "Total power of all validators.",
|
|
|
|
}, []string{}),
|
|
|
|
MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "missing_validators",
|
|
|
|
Help: "Number of validators who did not sign.",
|
|
|
|
}, []string{}),
|
|
|
|
MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "missing_validators_power",
|
|
|
|
Help: "Total power of the missing validators.",
|
|
|
|
}, []string{}),
|
|
|
|
ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "byzantine_validators",
|
|
|
|
Help: "Number of validators who tried to double sign.",
|
|
|
|
}, []string{}),
|
|
|
|
ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "byzantine_validators_power",
|
|
|
|
Help: "Total power of the byzantine validators.",
|
|
|
|
}, []string{}),
|
|
|
|
|
|
|
|
BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "block_interval_seconds",
|
|
|
|
Help: "Time between this and the last block.",
|
|
|
|
Buckets: []float64{1, 2.5, 5, 10, 60},
|
|
|
|
}, []string{}),
|
|
|
|
|
|
|
|
NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "num_txs",
|
|
|
|
Help: "Number of transactions.",
|
|
|
|
}, []string{}),
|
|
|
|
BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "block_size_bytes",
|
|
|
|
Help: "Size of the block.",
|
|
|
|
}, []string{}),
|
|
|
|
TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "consensus",
|
|
|
|
Name: "total_txs",
|
|
|
|
Help: "Total number of transactions.",
|
|
|
|
}, []string{}),
|
|
|
|
}, &p2p.Metrics{
|
|
|
|
Peers: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "p2p",
|
|
|
|
Name: "peers",
|
|
|
|
Help: "Number of peers.",
|
|
|
|
}, []string{}),
|
2018-06-15 15:57:11 +04:00
|
|
|
}, &mempl.Metrics{
|
|
|
|
Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
|
|
|
|
Subsystem: "mempool",
|
|
|
|
Name: "size",
|
|
|
|
Help: "Size of the mempool (number of uncommitted transactions).",
|
|
|
|
}, []string{}),
|
2018-06-15 15:10:25 +04:00
|
|
|
}
|
2018-06-15 14:23:34 +04:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:21:04 +04:00
|
|
|
// NopMetricsProvider returns consensus, p2p and mempool Metrics as no-op.
|
|
|
|
func NopMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
|
|
|
|
return cs.NopMetrics(), p2p.NopMetrics(), mempl.NopMetrics()
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Node is the highest level interface to a full Tendermint node.
|
|
|
|
// It includes all configuration information and running services.
|
2014-07-09 18:33:44 -07:00
|
|
|
type Node struct {
|
2017-01-15 16:59:10 -08:00
|
|
|
cmn.BaseService
|
|
|
|
|
2017-03-04 23:25:12 -05:00
|
|
|
// config
|
2017-05-04 20:07:08 +02:00
|
|
|
config *cfg.Config
|
2017-09-18 18:12:31 -04:00
|
|
|
genesisDoc *types.GenesisDoc // initial validator set
|
|
|
|
privValidator types.PrivValidator // local node's validator key
|
2017-03-04 23:25:12 -05:00
|
|
|
|
|
|
|
// network
|
2018-03-20 21:41:08 +01:00
|
|
|
sw *p2p.Switch // p2p connections
|
|
|
|
addrBook pex.AddrBook // known peers
|
2017-03-04 23:25:12 -05:00
|
|
|
|
|
|
|
// services
|
2017-12-27 22:09:48 -05:00
|
|
|
eventBus *types.EventBus // pub/sub for services
|
|
|
|
stateDB dbm.DB
|
2018-01-21 11:45:04 -05:00
|
|
|
blockStore *bc.BlockStore // store the blockchain to disk
|
|
|
|
bcReactor *bc.BlockchainReactor // for fast-syncing
|
|
|
|
mempoolReactor *mempl.MempoolReactor // for gossipping transactions
|
|
|
|
consensusState *cs.ConsensusState // latest consensus state
|
|
|
|
consensusReactor *cs.ConsensusReactor // for participating in the consensus
|
|
|
|
evidencePool *evidence.EvidencePool // tracking evidence
|
|
|
|
proxyApp proxy.AppConns // connection to the application
|
|
|
|
rpcListeners []net.Listener // rpc servers
|
2017-04-18 19:56:41 -04:00
|
|
|
txIndexer txindex.TxIndexer
|
2017-11-28 21:24:37 -06:00
|
|
|
indexerService *txindex.IndexerService
|
2014-07-09 18:33:44 -07:00
|
|
|
}
|
2014-07-08 00:02:04 -07:00
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// NewNode returns a new, ready to go, Tendermint Node.
|
|
|
|
func NewNode(config *cfg.Config,
|
|
|
|
privValidator types.PrivValidator,
|
|
|
|
clientCreator proxy.ClientCreator,
|
2017-09-21 21:44:36 -04:00
|
|
|
genesisDocProvider GenesisDocProvider,
|
2017-09-20 18:29:36 -04:00
|
|
|
dbProvider DBProvider,
|
2018-06-15 14:23:34 +04:00
|
|
|
metricsProvider MetricsProvider,
|
2017-09-20 18:29:36 -04:00
|
|
|
logger log.Logger) (*Node, error) {
|
|
|
|
|
2014-10-22 17:20:44 -07:00
|
|
|
// Get BlockStore
|
2017-09-20 18:29:36 -04:00
|
|
|
blockStoreDB, err := dbProvider(&DBContext{"blockstore", config})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-03-25 00:15:18 -07:00
|
|
|
blockStore := bc.NewBlockStore(blockStoreDB)
|
2014-10-22 17:20:44 -07:00
|
|
|
|
|
|
|
// Get State
|
2017-09-20 18:29:36 -04:00
|
|
|
stateDB, err := dbProvider(&DBContext{"state", config})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-05 16:50:05 +04:00
|
|
|
|
2017-10-13 13:11:16 +04:00
|
|
|
// Get genesis doc
|
2017-12-28 18:26:13 -05:00
|
|
|
// TODO: move to state package?
|
2017-10-13 13:11:16 +04:00
|
|
|
genDoc, err := loadGenesisDoc(stateDB)
|
2017-10-05 16:50:05 +04:00
|
|
|
if err != nil {
|
2017-10-13 13:11:16 +04:00
|
|
|
genDoc, err = genesisDocProvider()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// save genesis doc to prevent a certain class of user errors (e.g. when it
|
|
|
|
// was changed, accidentally or not). Also good for audit trail.
|
2017-10-17 13:33:57 +04:00
|
|
|
saveGenesisDoc(stateDB, genDoc)
|
2017-10-05 16:50:05 +04:00
|
|
|
}
|
|
|
|
|
2017-12-28 18:26:13 -05:00
|
|
|
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-09-20 18:29:36 -04:00
|
|
|
}
|
2017-05-12 23:07:53 +02:00
|
|
|
|
2016-08-23 21:44:07 -04:00
|
|
|
// Create the proxyApp, which manages connections (consensus, mempool, query)
|
2017-12-27 22:09:48 -05:00
|
|
|
// and sync tendermint and the app by performing a handshake
|
|
|
|
// and replaying any necessary blocks
|
2017-11-19 02:02:58 +00:00
|
|
|
consensusLogger := logger.With("module", "consensus")
|
2018-05-31 22:18:17 -04:00
|
|
|
handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc)
|
2017-05-12 23:07:53 +02:00
|
|
|
handshaker.SetLogger(consensusLogger)
|
|
|
|
proxyApp := proxy.NewAppConns(clientCreator, handshaker)
|
|
|
|
proxyApp.SetLogger(logger.With("module", "proxy"))
|
2017-11-06 13:20:39 -05:00
|
|
|
if err := proxyApp.Start(); err != nil {
|
2017-09-20 18:29:36 -04:00
|
|
|
return nil, fmt.Errorf("Error starting proxy app connections: %v", err)
|
2016-09-11 16:02:29 -04:00
|
|
|
}
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2017-02-17 10:51:05 -05:00
|
|
|
// reload the state (it may have been updated by the handshake)
|
2017-02-22 14:53:59 +04:00
|
|
|
state = sm.LoadState(stateDB)
|
|
|
|
|
2018-02-28 09:35:52 -05:00
|
|
|
// If an address is provided, listen on the socket for a
|
|
|
|
// connection from an external signing process.
|
|
|
|
if config.PrivValidatorListenAddr != "" {
|
2018-02-19 19:20:01 +01:00
|
|
|
var (
|
2018-02-28 09:35:52 -05:00
|
|
|
// TODO: persist this key so external signer
|
|
|
|
// can actually authenticate us
|
2018-02-19 19:20:01 +01:00
|
|
|
privKey = crypto.GenPrivKeyEd25519()
|
2018-06-01 19:17:37 +02:00
|
|
|
pvsc = privval.NewSocketPV(
|
|
|
|
logger.With("module", "privval"),
|
2018-02-28 09:35:52 -05:00
|
|
|
config.PrivValidatorListenAddr,
|
2018-03-16 13:32:17 +01:00
|
|
|
privKey,
|
2018-02-19 19:20:01 +01:00
|
|
|
)
|
2018-02-07 18:35:01 +01:00
|
|
|
)
|
2018-02-19 19:20:01 +01:00
|
|
|
|
2018-02-23 00:40:29 +01:00
|
|
|
if err := pvsc.Start(); err != nil {
|
|
|
|
return nil, fmt.Errorf("Error starting private validator client: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
privValidator = pvsc
|
2018-02-07 18:35:01 +01:00
|
|
|
}
|
|
|
|
|
2016-03-24 18:08:18 -07:00
|
|
|
// Decide whether to fast-sync or not
|
|
|
|
// We don't fast-sync when the only validator is us.
|
2017-05-01 20:09:29 -04:00
|
|
|
fastSync := config.FastSync
|
2016-03-24 18:08:18 -07:00
|
|
|
if state.Validators.Size() == 1 {
|
|
|
|
addr, _ := state.Validators.GetByIndex(0)
|
2017-09-21 16:32:02 -04:00
|
|
|
if bytes.Equal(privValidator.GetAddress(), addr) {
|
2016-03-24 18:08:18 -07:00
|
|
|
fastSync = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 11:02:40 +02:00
|
|
|
// Log whether this node is a validator or an observer
|
2017-09-21 16:32:02 -04:00
|
|
|
if state.Validators.HasAddress(privValidator.GetAddress()) {
|
2018-01-04 13:52:41 -05:00
|
|
|
consensusLogger.Info("This node is a validator", "addr", privValidator.GetAddress(), "pubKey", privValidator.GetPubKey())
|
2017-05-15 11:02:40 +02:00
|
|
|
} else {
|
2018-01-04 13:52:41 -05:00
|
|
|
consensusLogger.Info("This node is not a validator", "addr", privValidator.GetAddress(), "pubKey", privValidator.GetPubKey())
|
2017-05-15 11:02:40 +02:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:21:04 +04:00
|
|
|
// metrics
|
|
|
|
var (
|
|
|
|
csMetrics *cs.Metrics
|
|
|
|
p2pMetrics *p2p.Metrics
|
|
|
|
memplMetrics *mempl.Metrics
|
|
|
|
)
|
|
|
|
if config.BaseConfig.Monitoring {
|
|
|
|
csMetrics, p2pMetrics, memplMetrics = metricsProvider()
|
|
|
|
} else {
|
|
|
|
csMetrics, p2pMetrics, memplMetrics = NopMetricsProvider()
|
|
|
|
}
|
2018-06-15 15:57:11 +04:00
|
|
|
|
2015-07-20 14:40:41 -07:00
|
|
|
// Make MempoolReactor
|
2017-05-15 19:33:45 +02:00
|
|
|
mempoolLogger := logger.With("module", "mempool")
|
2018-06-15 15:57:11 +04:00
|
|
|
mempool := mempl.NewMempool(config.Mempool, proxyApp.Mempool(), state.LastBlockHeight, memplMetrics)
|
2018-01-19 00:57:00 -05:00
|
|
|
mempool.InitWAL() // no need to have the mempool wal during tests
|
2017-05-12 23:07:53 +02:00
|
|
|
mempool.SetLogger(mempoolLogger)
|
2017-05-01 20:09:29 -04:00
|
|
|
mempoolReactor := mempl.NewMempoolReactor(config.Mempool, mempool)
|
2017-05-12 23:07:53 +02:00
|
|
|
mempoolReactor.SetLogger(mempoolLogger)
|
2014-10-22 17:20:44 -07:00
|
|
|
|
2017-08-04 21:46:17 -04:00
|
|
|
if config.Consensus.WaitForTxs() {
|
2017-07-25 13:57:11 -04:00
|
|
|
mempool.EnableTxsAvailable()
|
2017-07-13 13:19:44 -04:00
|
|
|
}
|
|
|
|
|
2017-11-19 02:02:58 +00:00
|
|
|
// Make Evidence Reactor
|
|
|
|
evidenceDB, err := dbProvider(&DBContext{"evidence", config})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
evidenceLogger := logger.With("module", "evidence")
|
|
|
|
evidenceStore := evidence.NewEvidenceStore(evidenceDB)
|
2017-12-28 21:08:39 -05:00
|
|
|
evidencePool := evidence.NewEvidencePool(stateDB, evidenceStore)
|
2017-11-19 02:02:58 +00:00
|
|
|
evidencePool.SetLogger(evidenceLogger)
|
2017-12-26 20:34:57 -05:00
|
|
|
evidenceReactor := evidence.NewEvidenceReactor(evidencePool)
|
2017-11-19 02:02:58 +00:00
|
|
|
evidenceReactor.SetLogger(evidenceLogger)
|
|
|
|
|
2017-12-27 22:09:48 -05:00
|
|
|
blockExecLogger := logger.With("module", "state")
|
|
|
|
// make block executor for consensus and blockchain reactors to execute blocks
|
2017-12-28 18:26:13 -05:00
|
|
|
blockExec := sm.NewBlockExecutor(stateDB, blockExecLogger, proxyApp.Consensus(), mempool, evidencePool)
|
2017-12-27 22:09:48 -05:00
|
|
|
|
|
|
|
// Make BlockchainReactor
|
|
|
|
bcReactor := bc.NewBlockchainReactor(state.Copy(), blockExec, blockStore, fastSync)
|
|
|
|
bcReactor.SetLogger(logger.With("module", "blockchain"))
|
|
|
|
|
2015-07-20 14:40:41 -07:00
|
|
|
// Make ConsensusReactor
|
2018-01-21 11:45:04 -05:00
|
|
|
consensusState := cs.NewConsensusState(config.Consensus, state.Copy(),
|
2018-06-15 14:23:34 +04:00
|
|
|
blockExec, blockStore, mempool, evidencePool, csMetrics)
|
2017-05-12 23:07:53 +02:00
|
|
|
consensusState.SetLogger(consensusLogger)
|
2014-10-24 14:37:12 -07:00
|
|
|
if privValidator != nil {
|
2016-11-16 20:52:08 -05:00
|
|
|
consensusState.SetPrivValidator(privValidator)
|
2014-10-24 14:37:12 -07:00
|
|
|
}
|
2018-01-21 11:45:04 -05:00
|
|
|
consensusReactor := cs.NewConsensusReactor(consensusState, fastSync)
|
2017-05-12 23:07:53 +02:00
|
|
|
consensusReactor.SetLogger(consensusLogger)
|
|
|
|
|
|
|
|
p2pLogger := logger.With("module", "p2p")
|
2014-10-22 17:20:44 -07:00
|
|
|
|
2018-06-15 15:10:25 +04:00
|
|
|
sw := p2p.NewSwitch(config.P2P, p2pMetrics)
|
2017-05-12 23:07:53 +02:00
|
|
|
sw.SetLogger(p2pLogger)
|
2015-03-30 22:28:34 -07:00
|
|
|
sw.AddReactor("MEMPOOL", mempoolReactor)
|
|
|
|
sw.AddReactor("BLOCKCHAIN", bcReactor)
|
|
|
|
sw.AddReactor("CONSENSUS", consensusReactor)
|
2017-11-19 02:02:58 +00:00
|
|
|
sw.AddReactor("EVIDENCE", evidenceReactor)
|
2014-07-08 00:02:04 -07:00
|
|
|
|
2016-11-30 22:58:47 -05:00
|
|
|
// Optionally, start the pex reactor
|
2018-03-20 21:41:08 +01:00
|
|
|
//
|
|
|
|
// TODO:
|
|
|
|
//
|
|
|
|
// We need to set Seeds and PersistentPeers on the switch,
|
|
|
|
// since it needs to be able to use these (and their DNS names)
|
|
|
|
// even if the PEX is off. We can include the DNS name in the NetAddress,
|
|
|
|
// but it would still be nice to have a clear list of the current "PersistentPeers"
|
|
|
|
// somewhere that we can return with net_info.
|
|
|
|
//
|
|
|
|
// If PEX is on, it should handle dialing the seeds. Otherwise the switch does it.
|
2018-04-30 08:31:03 -04:00
|
|
|
// Note we currently use the addrBook regardless at least for AddOurAddress
|
2018-04-30 18:23:02 -04:00
|
|
|
addrBook := pex.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
|
2018-04-30 08:31:03 -04:00
|
|
|
addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
|
2017-05-01 20:09:29 -04:00
|
|
|
if config.P2P.PexReactor {
|
2018-03-20 21:41:08 +01:00
|
|
|
// TODO persistent peers ? so we can have their DNS addrs saved
|
2018-01-20 21:44:09 -05:00
|
|
|
pexReactor := pex.NewPEXReactor(addrBook,
|
2018-03-07 12:14:53 +04:00
|
|
|
&pex.PEXReactorConfig{
|
2018-03-29 12:06:15 +02:00
|
|
|
Seeds: cmn.SplitAndTrim(config.P2P.Seeds, ",", " "),
|
2018-03-07 12:14:53 +04:00
|
|
|
SeedMode: config.P2P.SeedMode,
|
2018-03-29 12:06:15 +02:00
|
|
|
PrivatePeerIDs: cmn.SplitAndTrim(config.P2P.PrivatePeerIDs, ",", " ")})
|
2017-05-12 23:07:53 +02:00
|
|
|
pexReactor.SetLogger(p2pLogger)
|
2016-11-30 22:58:47 -05:00
|
|
|
sw.AddReactor("PEX", pexReactor)
|
|
|
|
}
|
|
|
|
|
2018-03-05 16:51:52 +04:00
|
|
|
sw.SetAddrBook(addrBook)
|
|
|
|
|
2017-01-28 08:27:13 -08:00
|
|
|
// Filter peers by addr or pubkey with an ABCI query.
|
|
|
|
// If the query return code is OK, add peer.
|
|
|
|
// XXX: Query format subject to change
|
2017-05-01 20:09:29 -04:00
|
|
|
if config.FilterPeers {
|
2016-09-10 15:16:23 -04:00
|
|
|
// NOTE: addr is ip:port
|
2016-09-08 18:56:02 -04:00
|
|
|
sw.SetAddrFilter(func(addr net.Addr) error {
|
2017-01-28 08:27:13 -08:00
|
|
|
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/addr/%s", addr.String())})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-02 01:47:55 -05:00
|
|
|
if resQuery.IsErr() {
|
2018-01-06 01:26:51 -05:00
|
|
|
return fmt.Errorf("Error querying abci app: %v", resQuery)
|
2016-09-08 18:56:02 -04:00
|
|
|
}
|
2017-12-02 01:47:55 -05:00
|
|
|
return nil
|
2016-09-08 18:56:02 -04:00
|
|
|
})
|
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config
if AuthEnc is true, dialed peers must have a node ID in the address and
it must match the persistent pubkey from the secret handshake.
Refs #1157
* fixes after my own review
* fix docs
* fix build failure
```
p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal
```
* p2p: introduce peerConn to simplify peer creation
* Introduce `peerConn` containing the known fields of `peer`
* `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked
* Eliminates some mutable variables and makes the code flow better
* Simplifies the `newXxxPeer` funcs
* Use ID instead of PubKey where possible.
* SetPubKeyFilter -> SetIDFilter
* nodeInfo.Validate takes ID
* remove peer.PubKey()
* persistent node ids
* fixes from review
* test: use ip_plus_id.sh more
* fix invalid memory panic during fast_sync test
```
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e]
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]:
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0
xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0
xc420933e00, 0xc423f48801, 0x28, 0x2)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x
0, 0x0)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00)
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError
2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7
```
2018-02-27 06:54:40 -05:00
|
|
|
sw.SetIDFilter(func(id p2p.ID) error {
|
2018-06-06 16:13:51 -07:00
|
|
|
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/id/%s", id)})
|
2017-01-28 08:27:13 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-02 01:47:55 -05:00
|
|
|
if resQuery.IsErr() {
|
2018-01-06 01:26:51 -05:00
|
|
|
return fmt.Errorf("Error querying abci app: %v", resQuery)
|
2016-09-08 18:56:02 -04:00
|
|
|
}
|
2017-12-02 01:47:55 -05:00
|
|
|
return nil
|
2016-09-08 18:56:02 -04:00
|
|
|
})
|
|
|
|
}
|
2016-08-25 14:17:15 -04:00
|
|
|
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
eventBus := types.NewEventBus()
|
|
|
|
eventBus.SetLogger(logger.With("module", "events"))
|
|
|
|
|
|
|
|
// services which will be publishing and/or subscribing for messages (events)
|
2017-12-28 19:35:56 -05:00
|
|
|
// consensusReactor will set it on consensusState and blockExecutor
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
consensusReactor.SetEventBus(eventBus)
|
2015-04-02 17:35:27 -07:00
|
|
|
|
2017-11-15 15:07:08 -06:00
|
|
|
// Transaction indexing
|
|
|
|
var txIndexer txindex.TxIndexer
|
|
|
|
switch config.TxIndex.Indexer {
|
|
|
|
case "kv":
|
|
|
|
store, err := dbProvider(&DBContext{"tx_index", config})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-30 20:02:39 -06:00
|
|
|
if config.TxIndex.IndexTags != "" {
|
2018-03-29 12:06:15 +02:00
|
|
|
txIndexer = kv.NewTxIndex(store, kv.IndexTags(cmn.SplitAndTrim(config.TxIndex.IndexTags, ",", " ")))
|
2017-11-30 20:02:39 -06:00
|
|
|
} else if config.TxIndex.IndexAllTags {
|
|
|
|
txIndexer = kv.NewTxIndex(store, kv.IndexAllTags())
|
|
|
|
} else {
|
|
|
|
txIndexer = kv.NewTxIndex(store)
|
|
|
|
}
|
2017-11-15 15:07:08 -06:00
|
|
|
default:
|
|
|
|
txIndexer = &null.TxIndex{}
|
|
|
|
}
|
|
|
|
|
2017-11-28 21:24:37 -06:00
|
|
|
indexerService := txindex.NewIndexerService(txIndexer, eventBus)
|
2018-05-14 11:10:59 +04:00
|
|
|
indexerService.SetLogger(logger.With("module", "txindex"))
|
2017-11-15 15:07:08 -06:00
|
|
|
|
2015-09-24 15:48:44 -04:00
|
|
|
// run the profile server
|
2017-05-01 20:09:29 -04:00
|
|
|
profileHost := config.ProfListenAddress
|
2015-09-24 15:48:44 -04:00
|
|
|
if profileHost != "" {
|
|
|
|
go func() {
|
2017-06-14 12:50:49 +04:00
|
|
|
logger.Error("Profile server", "err", http.ListenAndServe(profileHost, nil))
|
2015-09-24 15:48:44 -04:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2017-01-15 16:59:10 -08:00
|
|
|
node := &Node{
|
2017-03-04 23:25:12 -05:00
|
|
|
config: config,
|
2017-10-05 16:50:05 +04:00
|
|
|
genesisDoc: genDoc,
|
2017-03-04 23:25:12 -05:00
|
|
|
privValidator: privValidator,
|
|
|
|
|
2018-03-20 21:41:08 +01:00
|
|
|
sw: sw,
|
|
|
|
addrBook: addrBook,
|
2017-03-04 23:25:12 -05:00
|
|
|
|
2017-12-27 22:09:48 -05:00
|
|
|
stateDB: stateDB,
|
2015-01-06 15:51:41 -08:00
|
|
|
blockStore: blockStore,
|
2015-03-25 00:15:18 -07:00
|
|
|
bcReactor: bcReactor,
|
2014-10-22 17:20:44 -07:00
|
|
|
mempoolReactor: mempoolReactor,
|
2015-01-11 14:27:46 -08:00
|
|
|
consensusState: consensusState,
|
2014-10-22 17:20:44 -07:00
|
|
|
consensusReactor: consensusReactor,
|
2017-11-19 02:02:58 +00:00
|
|
|
evidencePool: evidencePool,
|
2016-08-22 16:00:08 -04:00
|
|
|
proxyApp: proxyApp,
|
2017-02-22 14:53:59 +04:00
|
|
|
txIndexer: txIndexer,
|
2017-11-28 21:24:37 -06:00
|
|
|
indexerService: indexerService,
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
eventBus: eventBus,
|
2014-07-09 18:33:44 -07:00
|
|
|
}
|
2017-05-02 11:53:32 +04:00
|
|
|
node.BaseService = *cmn.NewBaseService(logger, "Node", node)
|
2017-09-20 18:29:36 -04:00
|
|
|
return node, nil
|
2014-07-09 18:33:44 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// OnStart starts the Node. It implements cmn.Service.
|
2017-01-15 16:59:10 -08:00
|
|
|
func (n *Node) OnStart() error {
|
2017-11-06 13:20:39 -05:00
|
|
|
err := n.eventBus.Start()
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-15 16:59:10 -08:00
|
|
|
// Create & add listener
|
2017-07-19 15:03:36 -04:00
|
|
|
protocol, address := cmn.ProtocolAndAddress(n.config.P2P.ListenAddress)
|
2017-05-02 11:53:32 +04:00
|
|
|
l := p2p.NewDefaultListener(protocol, address, n.config.P2P.SkipUPNP, n.Logger.With("module", "p2p"))
|
2017-01-15 16:59:10 -08:00
|
|
|
n.sw.AddListener(l)
|
|
|
|
|
2017-12-29 01:53:41 -05:00
|
|
|
// Generate node PrivKey
|
2018-02-28 09:35:52 -05:00
|
|
|
// TODO: pass in like privValidator
|
2018-01-21 00:33:53 -05:00
|
|
|
nodeKey, err := p2p.LoadOrGenNodeKey(n.config.NodeKeyFile())
|
2018-01-01 20:21:42 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
n.Logger.Info("P2P Node ID", "ID", nodeKey.ID(), "file", n.config.NodeKeyFile())
|
2017-12-29 01:53:41 -05:00
|
|
|
|
2018-04-11 11:11:11 +03:00
|
|
|
nodeInfo := n.makeNodeInfo(nodeKey.ID())
|
2018-03-22 16:58:57 +01:00
|
|
|
n.sw.SetNodeInfo(nodeInfo)
|
2018-01-01 20:21:42 -05:00
|
|
|
n.sw.SetNodeKey(nodeKey)
|
2018-03-22 16:58:57 +01:00
|
|
|
|
|
|
|
// Add ourselves to addrbook to prevent dialing ourselves
|
|
|
|
n.addrBook.AddOurAddress(nodeInfo.NetAddress())
|
|
|
|
|
2018-04-27 10:29:05 -04:00
|
|
|
// Start the RPC server before the P2P server
|
2018-04-26 23:49:48 -04:00
|
|
|
// so we can eg. receive txs for the first block
|
|
|
|
if n.config.RPC.ListenAddress != "" {
|
|
|
|
listeners, err := n.startRPC()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
n.rpcListeners = listeners
|
|
|
|
}
|
|
|
|
|
2018-04-27 10:29:05 -04:00
|
|
|
// Start the switch (the P2P server).
|
2017-11-06 13:20:39 -05:00
|
|
|
err = n.sw.Start()
|
2017-01-15 16:59:10 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-01-09 16:18:05 -06:00
|
|
|
// Always connect to persistent peers
|
|
|
|
if n.config.P2P.PersistentPeers != "" {
|
2018-03-29 12:06:15 +02:00
|
|
|
err = n.sw.DialPeersAsync(n.addrBook, cmn.SplitAndTrim(n.config.P2P.PersistentPeers, ",", " "), true)
|
2017-12-28 12:54:39 -06:00
|
|
|
if err != nil {
|
2017-03-04 23:25:12 -05:00
|
|
|
return err
|
|
|
|
}
|
2017-01-15 16:59:10 -08:00
|
|
|
}
|
|
|
|
|
2017-11-28 21:24:37 -06:00
|
|
|
// start tx indexer
|
2017-12-10 17:44:22 +00:00
|
|
|
return n.indexerService.Start()
|
2014-07-09 18:33:44 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// OnStop stops the Node. It implements cmn.Service.
|
2017-01-15 16:59:10 -08:00
|
|
|
func (n *Node) OnStop() {
|
|
|
|
n.BaseService.OnStop()
|
|
|
|
|
2017-05-02 11:53:32 +04:00
|
|
|
n.Logger.Info("Stopping Node")
|
2014-07-16 21:13:02 -07:00
|
|
|
// TODO: gracefully disconnect from peers.
|
|
|
|
n.sw.Stop()
|
2017-03-03 19:28:17 -05:00
|
|
|
|
|
|
|
for _, l := range n.rpcListeners {
|
2017-05-02 11:53:32 +04:00
|
|
|
n.Logger.Info("Closing rpc listener", "listener", l)
|
2017-03-03 19:28:17 -05:00
|
|
|
if err := l.Close(); err != nil {
|
2017-06-14 12:50:49 +04:00
|
|
|
n.Logger.Error("Error closing listener", "listener", l, "err", err)
|
2017-03-03 19:28:17 -05:00
|
|
|
}
|
|
|
|
}
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
|
|
|
|
n.eventBus.Stop()
|
2017-11-28 21:24:37 -06:00
|
|
|
n.indexerService.Stop()
|
2018-03-06 16:11:17 +01:00
|
|
|
|
2018-06-01 19:17:37 +02:00
|
|
|
if pvsc, ok := n.privValidator.(*privval.SocketPV); ok {
|
2018-03-06 16:11:17 +01:00
|
|
|
if err := pvsc.Stop(); err != nil {
|
|
|
|
n.Logger.Error("Error stopping priv validator socket client", "err", err)
|
|
|
|
}
|
|
|
|
}
|
2014-07-16 21:13:02 -07:00
|
|
|
}
|
|
|
|
|
2017-10-03 19:11:55 -04:00
|
|
|
// RunForever waits for an interrupt signal and stops the node.
|
2017-03-05 23:13:34 -05:00
|
|
|
func (n *Node) RunForever() {
|
|
|
|
// Sleep forever and then...
|
|
|
|
cmn.TrapSignal(func() {
|
|
|
|
n.Stop()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// AddListener adds a listener to accept inbound peer connections.
|
|
|
|
// It should be called before starting the Node.
|
2015-04-20 15:29:01 -07:00
|
|
|
// The first listener is the primary listener (in NodeInfo)
|
2014-07-10 22:14:23 -07:00
|
|
|
func (n *Node) AddListener(l p2p.Listener) {
|
2015-04-01 14:52:25 -07:00
|
|
|
n.sw.AddListener(l)
|
2014-07-09 18:33:44 -07:00
|
|
|
}
|
2014-07-08 00:02:04 -07:00
|
|
|
|
2017-02-22 14:41:10 +01:00
|
|
|
// ConfigureRPC sets all variables in rpccore so they will serve
|
|
|
|
// rpc calls from this node
|
|
|
|
func (n *Node) ConfigureRPC() {
|
2017-12-27 22:09:48 -05:00
|
|
|
rpccore.SetStateDB(n.stateDB)
|
2016-01-20 13:12:42 -05:00
|
|
|
rpccore.SetBlockStore(n.blockStore)
|
|
|
|
rpccore.SetConsensusState(n.consensusState)
|
2016-10-14 21:36:42 -04:00
|
|
|
rpccore.SetMempool(n.mempoolReactor.Mempool)
|
2017-11-19 02:02:58 +00:00
|
|
|
rpccore.SetEvidencePool(n.evidencePool)
|
2016-01-20 13:12:42 -05:00
|
|
|
rpccore.SetSwitch(n.sw)
|
2017-09-21 16:32:02 -04:00
|
|
|
rpccore.SetPubKey(n.privValidator.GetPubKey())
|
2016-01-20 13:12:42 -05:00
|
|
|
rpccore.SetGenesisDoc(n.genesisDoc)
|
2017-03-05 23:13:34 -05:00
|
|
|
rpccore.SetAddrBook(n.addrBook)
|
2016-08-22 16:00:48 -04:00
|
|
|
rpccore.SetProxyAppQuery(n.proxyApp.Query())
|
2017-02-22 14:53:59 +04:00
|
|
|
rpccore.SetTxIndexer(n.txIndexer)
|
2017-07-17 09:44:23 +03:00
|
|
|
rpccore.SetConsensusReactor(n.consensusReactor)
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
rpccore.SetEventBus(n.eventBus)
|
2017-05-02 11:53:32 +04:00
|
|
|
rpccore.SetLogger(n.Logger.With("module", "rpc"))
|
2017-02-22 14:41:10 +01:00
|
|
|
}
|
2015-04-10 02:12:17 -07:00
|
|
|
|
2017-02-22 14:41:10 +01:00
|
|
|
func (n *Node) startRPC() ([]net.Listener, error) {
|
|
|
|
n.ConfigureRPC()
|
2018-03-29 12:06:15 +02:00
|
|
|
listenAddrs := cmn.SplitAndTrim(n.config.RPC.ListenAddress, ",", " ")
|
2018-04-05 21:19:14 -07:00
|
|
|
coreCodec := amino.NewCodec()
|
|
|
|
ctypes.RegisterAmino(coreCodec)
|
2016-02-19 00:21:02 +00:00
|
|
|
|
2017-05-26 14:20:23 -04:00
|
|
|
if n.config.RPC.Unsafe {
|
|
|
|
rpccore.AddUnsafeRoutes()
|
|
|
|
}
|
|
|
|
|
2016-02-19 00:21:02 +00:00
|
|
|
// we may expose the rpc over both a unix and tcp socket
|
|
|
|
listeners := make([]net.Listener, len(listenAddrs))
|
|
|
|
for i, listenAddr := range listenAddrs {
|
|
|
|
mux := http.NewServeMux()
|
2017-05-15 19:33:45 +02:00
|
|
|
rpcLogger := n.Logger.With("module", "rpc-server")
|
2018-04-05 21:19:14 -07:00
|
|
|
wm := rpcserver.NewWebsocketManager(rpccore.Routes, coreCodec, rpcserver.EventSubscriber(n.eventBus))
|
2017-08-10 17:39:38 -04:00
|
|
|
wm.SetLogger(rpcLogger.With("protocol", "websocket"))
|
2016-02-19 00:21:02 +00:00
|
|
|
mux.HandleFunc("/websocket", wm.WebsocketHandler)
|
2018-06-15 17:21:04 +04:00
|
|
|
if n.config.BaseConfig.Monitoring {
|
|
|
|
mux.Handle("/metrics", promhttp.Handler())
|
|
|
|
}
|
2018-04-05 21:19:14 -07:00
|
|
|
rpcserver.RegisterRPCFuncs(mux, rpccore.Routes, coreCodec, rpcLogger)
|
2017-05-02 11:53:32 +04:00
|
|
|
listener, err := rpcserver.StartHTTPServer(listenAddr, mux, rpcLogger)
|
2016-02-19 00:21:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
listeners[i] = listener
|
|
|
|
}
|
2016-06-21 13:19:49 -04:00
|
|
|
|
|
|
|
// we expose a simplified api over grpc for convenience to app devs
|
2017-05-24 13:56:12 -04:00
|
|
|
grpcListenAddr := n.config.RPC.GRPCListenAddress
|
2016-06-21 13:19:49 -04:00
|
|
|
if grpcListenAddr != "" {
|
|
|
|
listener, err := grpccore.StartGRPCServer(grpcListenAddr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
listeners = append(listeners, listener)
|
|
|
|
}
|
|
|
|
|
2016-02-19 00:21:02 +00:00
|
|
|
return listeners, nil
|
2015-03-19 02:08:07 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// Switch returns the Node's Switch.
|
2015-03-25 18:06:57 -07:00
|
|
|
func (n *Node) Switch() *p2p.Switch {
|
|
|
|
return n.sw
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// BlockStore returns the Node's BlockStore.
|
2015-05-15 16:27:22 +02:00
|
|
|
func (n *Node) BlockStore() *bc.BlockStore {
|
|
|
|
return n.blockStore
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// ConsensusState returns the Node's ConsensusState.
|
2018-01-21 11:45:04 -05:00
|
|
|
func (n *Node) ConsensusState() *cs.ConsensusState {
|
2015-03-19 02:08:07 -07:00
|
|
|
return n.consensusState
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// ConsensusReactor returns the Node's ConsensusReactor.
|
2018-01-21 11:45:04 -05:00
|
|
|
func (n *Node) ConsensusReactor() *cs.ConsensusReactor {
|
2016-05-11 14:45:20 -04:00
|
|
|
return n.consensusReactor
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// MempoolReactor returns the Node's MempoolReactor.
|
2015-03-19 02:08:07 -07:00
|
|
|
func (n *Node) MempoolReactor() *mempl.MempoolReactor {
|
|
|
|
return n.mempoolReactor
|
|
|
|
}
|
|
|
|
|
2017-11-19 02:02:58 +00:00
|
|
|
// EvidencePool returns the Node's EvidencePool.
|
|
|
|
func (n *Node) EvidencePool() *evidence.EvidencePool {
|
|
|
|
return n.evidencePool
|
|
|
|
}
|
|
|
|
|
new pubsub package
comment out failing consensus tests for now
rewrite rpc httpclient to use new pubsub package
import pubsub as tmpubsub, query as tmquery
make event IDs constants
EventKey -> EventTypeKey
rename EventsPubsub to PubSub
mempool does not use pubsub
rename eventsSub to pubsub
new subscribe API
fix channel size issues and consensus tests bugs
refactor rpc client
add missing discardFromChan method
add mutex
rename pubsub to eventBus
remove IsRunning from WSRPCConnection interface (not needed)
add a comment in broadcastNewRoundStepsAndVotes
rename registerEventCallbacks to broadcastNewRoundStepsAndVotes
See https://dave.cheney.net/2014/03/19/channel-axioms
stop eventBuses after reactor tests
remove unnecessary Unsubscribe
return subscribe helper function
move discardFromChan to where it is used
subscribe now returns an err
this gives us ability to refuse to subscribe if pubsub is at its max
capacity.
use context for control overflow
cache queries
handle err when subscribing in replay_test
rename testClientID to testSubscriber
extract var
set channel buffer capacity to 1 in replay_file
fix byzantine_test
unsubscribe from single event, not all events
refactor httpclient to return events to appropriate channels
return failing testReplayCrashBeforeWriteVote test
fix TestValidatorSetChanges
refactor code a bit
fix testReplayCrashBeforeWriteVote
add comment
fix TestValidatorSetChanges
fixes from Bucky's review
update comment [ci skip]
test TxEventBuffer
update changelog
fix TestValidatorSetChanges (2nd attempt)
only do wg.Done when no errors
benchmark event bus
create pubsub server inside NewEventBus
only expose config params (later if needed)
set buffer capacity to 0 so we are not testing cache
new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ}
This should allow to subscribe to all transactions! or a specific one
using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'"
use TimeoutCommit instead of afterPublishEventNewBlockTimeout
TimeoutCommit is the time a node waits after committing a block, before
it goes into the next height. So it will finish everything from the last
block, but then wait a bit. The idea is this gives it time to hear more
votes from other validators, to strengthen the commit it includes in the
next block. But it also gives it time to hear about new transactions.
waitForBlockWithUpdatedVals
rewrite WAL crash tests
Task:
test that we can recover from any WAL crash.
Solution:
the old tests were relying on event hub being run in the same thread (we
were injecting the private validator's last signature).
when considering a rewrite, we considered two possible solutions: write
a "fuzzy" testing system where WAL is crashing upon receiving a new
message, or inject failures and trigger them in tests using something
like https://github.com/coreos/gofail.
remove sleep
no cs.Lock around wal.Save
test different cases (empty block, non-empty block, ...)
comments
add comments
test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks
fixes as per Bucky's last review
reset subscriptions on UnsubscribeAll
use a simple counter to track message for which we panicked
also, set a smaller part size for all test cases
2017-06-26 19:00:30 +04:00
|
|
|
// EventBus returns the Node's EventBus.
|
|
|
|
func (n *Node) EventBus() *types.EventBus {
|
|
|
|
return n.eventBus
|
2015-04-17 13:18:50 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// PrivValidator returns the Node's PrivValidator.
|
|
|
|
// XXX: for convenience only!
|
2017-09-18 18:12:31 -04:00
|
|
|
func (n *Node) PrivValidator() types.PrivValidator {
|
2016-05-11 14:45:20 -04:00
|
|
|
return n.privValidator
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// GenesisDoc returns the Node's GenesisDoc.
|
2016-10-14 21:36:42 -04:00
|
|
|
func (n *Node) GenesisDoc() *types.GenesisDoc {
|
|
|
|
return n.genesisDoc
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// ProxyApp returns the Node's AppConns, representing its connections to the ABCI application.
|
2016-10-14 21:36:42 -04:00
|
|
|
func (n *Node) ProxyApp() proxy.AppConns {
|
|
|
|
return n.proxyApp
|
|
|
|
}
|
|
|
|
|
2018-04-11 11:11:11 +03:00
|
|
|
func (n *Node) makeNodeInfo(nodeID p2p.ID) p2p.NodeInfo {
|
2017-04-18 20:10:02 -04:00
|
|
|
txIndexerStatus := "on"
|
|
|
|
if _, ok := n.txIndexer.(*null.TxIndex); ok {
|
|
|
|
txIndexerStatus = "off"
|
|
|
|
}
|
2018-01-14 00:10:29 -05:00
|
|
|
nodeInfo := p2p.NodeInfo{
|
2018-04-11 11:11:11 +03:00
|
|
|
ID: nodeID,
|
2017-10-05 16:50:05 +04:00
|
|
|
Network: n.genesisDoc.ChainID,
|
2016-01-20 13:12:42 -05:00
|
|
|
Version: version.Version,
|
2018-01-21 11:45:04 -05:00
|
|
|
Channels: []byte{
|
|
|
|
bc.BlockchainChannel,
|
|
|
|
cs.StateChannel, cs.DataChannel, cs.VoteChannel, cs.VoteSetBitsChannel,
|
|
|
|
mempl.MempoolChannel,
|
|
|
|
evidence.EvidenceChannel,
|
|
|
|
},
|
2018-01-13 23:48:41 -05:00
|
|
|
Moniker: n.config.Moniker,
|
2015-11-01 11:34:08 -08:00
|
|
|
Other: []string{
|
2018-04-05 08:17:10 -07:00
|
|
|
cmn.Fmt("amino_version=%v", amino.Version),
|
2017-01-15 16:59:10 -08:00
|
|
|
cmn.Fmt("p2p_version=%v", p2p.Version),
|
2018-01-21 11:45:04 -05:00
|
|
|
cmn.Fmt("consensus_version=%v", cs.Version),
|
2017-01-15 16:59:10 -08:00
|
|
|
cmn.Fmt("rpc_version=%v/%v", rpc.Version, rpccore.Version),
|
2017-04-18 20:55:40 -04:00
|
|
|
cmn.Fmt("tx_index=%v", txIndexerStatus),
|
2015-09-15 19:11:45 -04:00
|
|
|
},
|
2015-04-20 15:29:01 -07:00
|
|
|
}
|
2015-07-10 15:50:58 +00:00
|
|
|
|
2018-01-21 11:45:04 -05:00
|
|
|
if n.config.P2P.PexReactor {
|
|
|
|
nodeInfo.Channels = append(nodeInfo.Channels, pex.PexChannel)
|
|
|
|
}
|
|
|
|
|
2017-11-17 01:20:15 +00:00
|
|
|
rpcListenAddr := n.config.RPC.ListenAddress
|
|
|
|
nodeInfo.Other = append(nodeInfo.Other, cmn.Fmt("rpc_addr=%v", rpcListenAddr))
|
2015-07-10 15:50:58 +00:00
|
|
|
|
2017-04-18 20:10:02 -04:00
|
|
|
if !n.sw.IsListening() {
|
2015-04-20 15:29:01 -07:00
|
|
|
return nodeInfo
|
|
|
|
}
|
2015-07-10 15:50:58 +00:00
|
|
|
|
2017-04-18 20:10:02 -04:00
|
|
|
p2pListener := n.sw.Listeners()[0]
|
2015-04-20 15:29:01 -07:00
|
|
|
p2pHost := p2pListener.ExternalAddress().IP.String()
|
|
|
|
p2pPort := p2pListener.ExternalAddress().Port
|
2017-01-15 16:59:10 -08:00
|
|
|
nodeInfo.ListenAddr = cmn.Fmt("%v:%v", p2pHost, p2pPort)
|
2017-11-17 01:20:15 +00:00
|
|
|
|
2015-04-20 15:29:01 -07:00
|
|
|
return nodeInfo
|
|
|
|
}
|
|
|
|
|
2017-01-14 00:47:13 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// NodeInfo returns the Node's Info from the Switch.
|
2018-01-14 00:10:29 -05:00
|
|
|
func (n *Node) NodeInfo() p2p.NodeInfo {
|
2016-04-13 18:23:25 -04:00
|
|
|
return n.sw.NodeInfo()
|
|
|
|
}
|
|
|
|
|
2017-04-28 23:59:02 -04:00
|
|
|
//------------------------------------------------------------------------------
|
2017-10-13 13:11:16 +04:00
|
|
|
|
|
|
|
var (
|
|
|
|
genesisDocKey = []byte("genesisDoc")
|
|
|
|
)
|
|
|
|
|
2017-10-17 13:33:57 +04:00
|
|
|
// panics if failed to unmarshal bytes
|
2017-10-13 13:11:16 +04:00
|
|
|
func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) {
|
|
|
|
bytes := db.Get(genesisDocKey)
|
|
|
|
if len(bytes) == 0 {
|
|
|
|
return nil, errors.New("Genesis doc not found")
|
|
|
|
}
|
2018-04-02 10:21:17 +02:00
|
|
|
var genDoc *types.GenesisDoc
|
2018-04-07 19:47:19 +03:00
|
|
|
err := cdc.UnmarshalJSON(bytes, &genDoc)
|
2018-04-02 10:21:17 +02:00
|
|
|
if err != nil {
|
|
|
|
cmn.PanicCrisis(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes))
|
|
|
|
}
|
|
|
|
return genDoc, nil
|
2017-10-13 13:11:16 +04:00
|
|
|
}
|
|
|
|
|
2017-10-17 13:33:57 +04:00
|
|
|
// panics if failed to marshal the given genesis document
|
|
|
|
func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) {
|
2018-04-07 19:47:19 +03:00
|
|
|
bytes, err := cdc.MarshalJSON(genDoc)
|
2017-10-13 13:11:16 +04:00
|
|
|
if err != nil {
|
2017-10-17 13:33:57 +04:00
|
|
|
cmn.PanicCrisis(fmt.Sprintf("Failed to save genesis doc due to marshaling error: %v", err))
|
2017-10-13 13:11:16 +04:00
|
|
|
}
|
|
|
|
db.SetSync(genesisDocKey, bytes)
|
|
|
|
}
|