tendermint/rpc/core/pipe.go

109 lines
2.3 KiB
Go
Raw Normal View History

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