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-10-13 13:11:16 +04:00
|
|
|
"encoding/json"
|
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"
|
2015-05-12 17:40:29 -07:00
|
|
|
"strings"
|
2014-07-08 15:33:26 -07:00
|
|
|
|
2017-01-28 08:27:13 -08:00
|
|
|
abci "github.com/tendermint/abci/types"
|
2017-02-22 14:53:59 +04:00
|
|
|
crypto "github.com/tendermint/go-crypto"
|
|
|
|
wire "github.com/tendermint/go-wire"
|
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"
|
2015-11-01 11:34:08 -08:00
|
|
|
"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"
|
2017-10-30 15:34:49 -04:00
|
|
|
"github.com/tendermint/tendermint/p2p/trust"
|
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"
|
|
|
|
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) {
|
|
|
|
return dbm.NewDB(ctx.ID, ctx.Config.DBBackend, ctx.Config.DBDir()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
types.LoadOrGenPrivValidatorFS(config.PrivValidatorFile()),
|
|
|
|
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
|
|
|
|
DefaultGenesisDocProviderFunc(config),
|
|
|
|
DefaultDBProvider,
|
|
|
|
logger)
|
|
|
|
}
|
|
|
|
|
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
|
2017-10-30 18:45:54 -04:00
|
|
|
privKey crypto.PrivKeyEd25519 // local node's p2p key
|
|
|
|
sw *p2p.Switch // p2p connections
|
|
|
|
addrBook *p2p.AddrBook // known peers
|
|
|
|
trustMetricStore *trust.TrustMetricStore // trust metrics for all 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
|
2017-03-04 23:25:12 -05:00
|
|
|
blockStore *bc.BlockStore // store the blockchain to disk
|
|
|
|
bcReactor *bc.BlockchainReactor // for fast-syncing
|
|
|
|
mempoolReactor *mempl.MempoolReactor // for gossipping transactions
|
|
|
|
consensusState *consensus.ConsensusState // latest consensus state
|
|
|
|
consensusReactor *consensus.ConsensusReactor // for participating in the consensus
|
2017-11-19 02:02:58 +00:00
|
|
|
evidencePool *evidence.EvidencePool // tracking evidence
|
2017-03-04 23:25:12 -05:00
|
|
|
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,
|
|
|
|
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")
|
2017-12-27 22:09:48 -05:00
|
|
|
handshaker := consensus.NewHandshaker(stateDB, state, blockStore)
|
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)
|
|
|
|
|
2015-07-15 14:17:20 -07:00
|
|
|
// Generate node PrivKey
|
2015-11-01 11:34:08 -08:00
|
|
|
privKey := crypto.GenPrivKeyEd25519()
|
2015-07-15 14:17:20 -07: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()) {
|
2017-05-15 11:02:40 +02:00
|
|
|
consensusLogger.Info("This node is a validator")
|
|
|
|
} else {
|
|
|
|
consensusLogger.Info("This node is not a validator")
|
|
|
|
}
|
|
|
|
|
2015-07-20 14:40:41 -07:00
|
|
|
// Make MempoolReactor
|
2017-05-15 19:33:45 +02:00
|
|
|
mempoolLogger := logger.With("module", "mempool")
|
2017-07-25 13:57:11 -04:00
|
|
|
mempool := mempl.NewMempool(config.Mempool, proxyApp.Mempool(), state.LastBlockHeight)
|
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-27 22:39:58 -05:00
|
|
|
evidencePool := evidence.NewEvidencePool(state.ConsensusParams.EvidenceParams, evidenceStore, state.Copy())
|
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
|
2017-11-19 02:02:58 +00:00
|
|
|
consensusState := consensus.NewConsensusState(config.Consensus, state.Copy(),
|
2017-12-27 22:09:48 -05:00
|
|
|
blockExec, blockStore, mempool, evidencePool)
|
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
|
|
|
}
|
2016-11-16 20:52:08 -05:00
|
|
|
consensusReactor := consensus.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
|
|
|
|
2017-05-01 22:14:37 -04:00
|
|
|
sw := p2p.NewSwitch(config.P2P)
|
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
|
2017-03-04 23:25:12 -05:00
|
|
|
var addrBook *p2p.AddrBook
|
2017-10-30 18:45:54 -04:00
|
|
|
var trustMetricStore *trust.TrustMetricStore
|
2017-05-01 20:09:29 -04:00
|
|
|
if config.P2P.PexReactor {
|
2017-05-04 21:57:58 +02:00
|
|
|
addrBook = p2p.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
|
2017-05-12 23:07:53 +02:00
|
|
|
addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
|
2017-10-30 18:45:54 -04:00
|
|
|
|
|
|
|
// Get the trust metric history data
|
|
|
|
trustHistoryDB, err := dbProvider(&DBContext{"trusthistory", config})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
trustMetricStore = trust.NewTrustMetricStore(trustHistoryDB, trust.DefaultConfig())
|
|
|
|
trustMetricStore.SetLogger(p2pLogger)
|
|
|
|
|
2016-11-30 22:58:47 -05:00
|
|
|
pexReactor := p2p.NewPEXReactor(addrBook)
|
2017-05-12 23:07:53 +02:00
|
|
|
pexReactor.SetLogger(p2pLogger)
|
2016-11-30 22:58:47 -05:00
|
|
|
sw.AddReactor("PEX", pexReactor)
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
return 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
|
|
|
})
|
|
|
|
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
|
2017-01-28 08:27:13 -08:00
|
|
|
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-02 01:47:55 -05:00
|
|
|
if resQuery.IsErr() {
|
|
|
|
return 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 18:58:05 -05:00
|
|
|
blockExec.SetEventBus(eventBus)
|
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 != "" {
|
|
|
|
txIndexer = kv.NewTxIndex(store, kv.IndexTags(strings.Split(config.TxIndex.IndexTags, ",")))
|
|
|
|
} 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)
|
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,
|
|
|
|
|
2017-10-30 18:45:54 -04:00
|
|
|
privKey: privKey,
|
|
|
|
sw: sw,
|
|
|
|
addrBook: addrBook,
|
|
|
|
trustMetricStore: trustMetricStore,
|
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-10-23 10:03:54 -04:00
|
|
|
// Run the RPC server first
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
// Start the switch
|
2017-04-18 20:10:02 -04:00
|
|
|
n.sw.SetNodeInfo(n.makeNodeInfo())
|
2015-07-15 14:17:20 -07:00
|
|
|
n.sw.SetNodePrivKey(n.privKey)
|
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
|
|
|
|
}
|
|
|
|
|
2017-03-04 23:25:12 -05:00
|
|
|
// If seeds exist, add them to the address book and dial out
|
2017-05-01 20:09:29 -04:00
|
|
|
if n.config.P2P.Seeds != "" {
|
2017-03-04 23:25:12 -05:00
|
|
|
// dial out
|
2017-05-01 20:09:29 -04:00
|
|
|
seeds := strings.Split(n.config.P2P.Seeds, ",")
|
2017-03-05 23:13:34 -05:00
|
|
|
if err := n.DialSeeds(seeds); 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()
|
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()
|
2017-05-24 13:56:12 -04:00
|
|
|
listenAddrs := strings.Split(n.config.RPC.ListenAddress, ",")
|
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")
|
2017-12-09 23:40:51 -06:00
|
|
|
wm := rpcserver.NewWebsocketManager(rpccore.Routes, 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)
|
2017-05-02 11:53:32 +04:00
|
|
|
rpcserver.RegisterRPCFuncs(mux, rpccore.Routes, rpcLogger)
|
|
|
|
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.
|
2015-03-19 02:08:07 -07:00
|
|
|
func (n *Node) ConsensusState() *consensus.ConsensusState {
|
|
|
|
return n.consensusState
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// ConsensusReactor returns the Node's ConsensusReactor.
|
2016-05-11 14:45:20 -04:00
|
|
|
func (n *Node) ConsensusReactor() *consensus.ConsensusReactor {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-04-18 20:10:02 -04:00
|
|
|
func (n *Node) makeNodeInfo() *p2p.NodeInfo {
|
|
|
|
txIndexerStatus := "on"
|
|
|
|
if _, ok := n.txIndexer.(*null.TxIndex); ok {
|
|
|
|
txIndexerStatus = "off"
|
|
|
|
}
|
2015-11-01 11:34:08 -08:00
|
|
|
nodeInfo := &p2p.NodeInfo{
|
2017-03-21 22:46:15 +01:00
|
|
|
PubKey: n.privKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
|
2017-05-01 20:09:29 -04:00
|
|
|
Moniker: n.config.Moniker,
|
2017-10-05 16:50:05 +04:00
|
|
|
Network: n.genesisDoc.ChainID,
|
2016-01-20 13:12:42 -05:00
|
|
|
Version: version.Version,
|
2015-11-01 11:34:08 -08:00
|
|
|
Other: []string{
|
2017-01-15 16:59:10 -08:00
|
|
|
cmn.Fmt("wire_version=%v", wire.Version),
|
|
|
|
cmn.Fmt("p2p_version=%v", p2p.Version),
|
|
|
|
cmn.Fmt("consensus_version=%v", consensus.Version),
|
|
|
|
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
|
|
|
|
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.
|
2016-04-13 18:23:25 -04:00
|
|
|
func (n *Node) NodeInfo() *p2p.NodeInfo {
|
|
|
|
return n.sw.NodeInfo()
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:29:36 -04:00
|
|
|
// DialSeeds dials the given seeds on the Switch.
|
2017-03-05 23:13:34 -05:00
|
|
|
func (n *Node) DialSeeds(seeds []string) error {
|
|
|
|
return n.sw.DialSeeds(n.addrBook, seeds)
|
2016-04-13 18:23:25 -04:00
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
} else {
|
|
|
|
var genDoc *types.GenesisDoc
|
|
|
|
err := json.Unmarshal(bytes, &genDoc)
|
2017-10-17 13:33:57 +04: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) {
|
2017-10-13 13:11:16 +04:00
|
|
|
bytes, err := json.Marshal(genDoc)
|
|
|
|
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)
|
|
|
|
}
|