2015-03-26 21:30:42 -07:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2017-02-22 14:53:59 +04:00
|
|
|
crypto "github.com/tendermint/go-crypto"
|
2015-04-01 17:30:16 -07:00
|
|
|
"github.com/tendermint/tendermint/consensus"
|
2017-10-10 12:39:21 +04:00
|
|
|
cstypes "github.com/tendermint/tendermint/consensus/types"
|
2017-04-08 22:04:06 -04:00
|
|
|
p2p "github.com/tendermint/tendermint/p2p"
|
2016-08-22 16:00:48 -04:00
|
|
|
"github.com/tendermint/tendermint/proxy"
|
2017-08-21 18:11:16 -04:00
|
|
|
sm "github.com/tendermint/tendermint/state"
|
2017-04-18 19:56:41 -04:00
|
|
|
"github.com/tendermint/tendermint/state/txindex"
|
2015-08-10 20:38:45 -07:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2017-10-04 16:40:45 -04:00
|
|
|
"github.com/tendermint/tmlibs/log"
|
2015-03-26 21:30:42 -07:00
|
|
|
)
|
|
|
|
|
2017-02-20 20:09:15 -05:00
|
|
|
//----------------------------------------------
|
|
|
|
// These interfaces are used by RPC and must be thread safe
|
2016-10-14 21:36:42 -04:00
|
|
|
|
|
|
|
type Consensus interface {
|
2017-08-21 18:11:16 -04:00
|
|
|
GetState() *sm.State
|
2016-10-14 21:36:42 -04:00
|
|
|
GetValidators() (int, []*types.Validator)
|
2017-10-10 12:39:21 +04:00
|
|
|
GetRoundState() *cstypes.RoundState
|
2016-10-14 21:36:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2P interface {
|
|
|
|
Listeners() []p2p.Listener
|
|
|
|
Peers() p2p.IPeerSet
|
|
|
|
NumPeers() (outbound, inbound, dialig int)
|
|
|
|
NodeInfo() *p2p.NodeInfo
|
|
|
|
IsListening() bool
|
2017-03-05 23:13:34 -05:00
|
|
|
DialSeeds(*p2p.AddrBook, []string) error
|
2016-10-14 21:36:42 -04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:09:15 -05:00
|
|
|
//----------------------------------------------
|
2017-08-09 23:51:09 -04:00
|
|
|
// These package level globals come with setters
|
|
|
|
// that are expected to be called only once, on startup
|
2017-02-20 20:09:15 -05:00
|
|
|
|
2016-10-14 21:36:42 -04:00
|
|
|
var (
|
|
|
|
// external, thread safe interfaces
|
|
|
|
eventSwitch types.EventSwitch
|
|
|
|
proxyAppQuery proxy.AppConnQuery
|
|
|
|
|
2017-02-20 20:09:15 -05:00
|
|
|
// interfaces defined in types and above
|
|
|
|
blockStore types.BlockStore
|
|
|
|
mempool types.Mempool
|
2016-10-14 21:36:42 -04:00
|
|
|
consensusState Consensus
|
|
|
|
p2pSwitch P2P
|
|
|
|
|
|
|
|
// objects
|
2017-07-17 09:44:23 +03:00
|
|
|
pubKey crypto.PubKey
|
|
|
|
genDoc *types.GenesisDoc // cache the genesis structure
|
|
|
|
addrBook *p2p.AddrBook
|
|
|
|
txIndexer txindex.TxIndexer
|
|
|
|
consensusReactor *consensus.ConsensusReactor
|
2017-05-02 11:53:32 +04:00
|
|
|
|
|
|
|
logger log.Logger
|
2016-10-14 21:36:42 -04:00
|
|
|
)
|
2016-05-11 23:33:09 -04:00
|
|
|
|
2016-10-10 02:58:13 -04:00
|
|
|
func SetEventSwitch(evsw types.EventSwitch) {
|
2016-06-27 20:43:09 -04:00
|
|
|
eventSwitch = evsw
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:09:15 -05:00
|
|
|
func SetBlockStore(bs types.BlockStore) {
|
2015-03-26 21:30:42 -07:00
|
|
|
blockStore = bs
|
|
|
|
}
|
|
|
|
|
2017-02-20 20:09:15 -05:00
|
|
|
func SetMempool(mem types.Mempool) {
|
|
|
|
mempool = mem
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:09:15 -05:00
|
|
|
func SetConsensusState(cs Consensus) {
|
|
|
|
consensusState = cs
|
2015-03-26 21:30:42 -07:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:36:42 -04:00
|
|
|
func SetSwitch(sw P2P) {
|
2015-03-26 21:30:42 -07:00
|
|
|
p2pSwitch = sw
|
|
|
|
}
|
2015-03-31 04:53:34 -07:00
|
|
|
|
2016-10-14 21:36:42 -04:00
|
|
|
func SetPubKey(pk crypto.PubKey) {
|
|
|
|
pubKey = pk
|
2015-03-31 04:53:34 -07:00
|
|
|
}
|
2015-06-14 18:18:17 -04:00
|
|
|
|
2015-12-01 20:12:01 -08:00
|
|
|
func SetGenesisDoc(doc *types.GenesisDoc) {
|
2015-06-14 18:18:17 -04:00
|
|
|
genDoc = doc
|
|
|
|
}
|
2016-08-22 16:00:48 -04:00
|
|
|
|
2017-03-05 23:13:34 -05:00
|
|
|
func SetAddrBook(book *p2p.AddrBook) {
|
|
|
|
addrBook = book
|
|
|
|
}
|
|
|
|
|
2016-08-22 16:00:48 -04:00
|
|
|
func SetProxyAppQuery(appConn proxy.AppConnQuery) {
|
|
|
|
proxyAppQuery = appConn
|
|
|
|
}
|
2017-02-22 14:53:59 +04:00
|
|
|
|
2017-04-18 19:56:41 -04:00
|
|
|
func SetTxIndexer(indexer txindex.TxIndexer) {
|
2017-02-22 14:53:59 +04:00
|
|
|
txIndexer = indexer
|
|
|
|
}
|
2017-05-02 11:53:32 +04:00
|
|
|
|
2017-07-17 09:44:23 +03:00
|
|
|
func SetConsensusReactor(conR *consensus.ConsensusReactor) {
|
|
|
|
consensusReactor = conR
|
2017-07-10 19:30:54 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 11:53:32 +04:00
|
|
|
func SetLogger(l log.Logger) {
|
|
|
|
logger = l
|
|
|
|
}
|