mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 21:36:26 +00:00
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
193 lines
6.2 KiB
Go
193 lines
6.2 KiB
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
abci "github.com/tendermint/abci/types"
|
|
"github.com/tendermint/go-wire/data"
|
|
tmpubsub "github.com/tendermint/tmlibs/pubsub"
|
|
tmquery "github.com/tendermint/tmlibs/pubsub/query"
|
|
)
|
|
|
|
// Reserved event types
|
|
const (
|
|
EventBond = "Bond"
|
|
EventCompleteProposal = "CompleteProposal"
|
|
EventDupeout = "Dupeout"
|
|
EventFork = "Fork"
|
|
EventLock = "Lock"
|
|
EventNewBlock = "NewBlock"
|
|
EventNewBlockHeader = "NewBlockHeader"
|
|
EventNewRound = "NewRound"
|
|
EventNewRoundStep = "NewRoundStep"
|
|
EventPolka = "Polka"
|
|
EventRebond = "Rebond"
|
|
EventRelock = "Relock"
|
|
EventTimeoutPropose = "TimeoutPropose"
|
|
EventTimeoutWait = "TimeoutWait"
|
|
EventTx = "Tx"
|
|
EventUnbond = "Unbond"
|
|
EventUnlock = "Unlock"
|
|
EventVote = "Vote"
|
|
EventProposalHeartbeat = "ProposalHeartbeat"
|
|
)
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// ENCODING / DECODING
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
var (
|
|
EventDataNameNewBlock = "new_block"
|
|
EventDataNameNewBlockHeader = "new_block_header"
|
|
EventDataNameTx = "tx"
|
|
EventDataNameRoundState = "round_state"
|
|
EventDataNameVote = "vote"
|
|
|
|
EventDataNameProposalHeartbeat = "proposer_heartbeat"
|
|
)
|
|
|
|
// implements events.EventData
|
|
type TMEventDataInner interface {
|
|
// empty interface
|
|
}
|
|
|
|
type TMEventData struct {
|
|
TMEventDataInner `json:"unwrap"`
|
|
}
|
|
|
|
func (tmr TMEventData) MarshalJSON() ([]byte, error) {
|
|
return tmEventDataMapper.ToJSON(tmr.TMEventDataInner)
|
|
}
|
|
|
|
func (tmr *TMEventData) UnmarshalJSON(data []byte) (err error) {
|
|
parsed, err := tmEventDataMapper.FromJSON(data)
|
|
if err == nil && parsed != nil {
|
|
tmr.TMEventDataInner = parsed.(TMEventDataInner)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (tmr TMEventData) Unwrap() TMEventDataInner {
|
|
tmrI := tmr.TMEventDataInner
|
|
for wrap, ok := tmrI.(TMEventData); ok; wrap, ok = tmrI.(TMEventData) {
|
|
tmrI = wrap.TMEventDataInner
|
|
}
|
|
return tmrI
|
|
}
|
|
|
|
func (tmr TMEventData) Empty() bool {
|
|
return tmr.TMEventDataInner == nil
|
|
}
|
|
|
|
const (
|
|
EventDataTypeNewBlock = byte(0x01)
|
|
EventDataTypeFork = byte(0x02)
|
|
EventDataTypeTx = byte(0x03)
|
|
EventDataTypeNewBlockHeader = byte(0x04)
|
|
|
|
EventDataTypeRoundState = byte(0x11)
|
|
EventDataTypeVote = byte(0x12)
|
|
|
|
EventDataTypeProposalHeartbeat = byte(0x20)
|
|
)
|
|
|
|
var tmEventDataMapper = data.NewMapper(TMEventData{}).
|
|
RegisterImplementation(EventDataNewBlock{}, EventDataNameNewBlock, EventDataTypeNewBlock).
|
|
RegisterImplementation(EventDataNewBlockHeader{}, EventDataNameNewBlockHeader, EventDataTypeNewBlockHeader).
|
|
RegisterImplementation(EventDataTx{}, EventDataNameTx, EventDataTypeTx).
|
|
RegisterImplementation(EventDataRoundState{}, EventDataNameRoundState, EventDataTypeRoundState).
|
|
RegisterImplementation(EventDataVote{}, EventDataNameVote, EventDataTypeVote).
|
|
RegisterImplementation(EventDataProposalHeartbeat{}, EventDataNameProposalHeartbeat, EventDataTypeProposalHeartbeat)
|
|
|
|
// Most event messages are basic types (a block, a transaction)
|
|
// but some (an input to a call tx or a receive) are more exotic
|
|
|
|
type EventDataNewBlock struct {
|
|
Block *Block `json:"block"`
|
|
}
|
|
|
|
// light weight event for benchmarking
|
|
type EventDataNewBlockHeader struct {
|
|
Header *Header `json:"header"`
|
|
}
|
|
|
|
// All txs fire EventDataTx
|
|
type EventDataTx struct {
|
|
Height int `json:"height"`
|
|
Tx Tx `json:"tx"`
|
|
Data data.Bytes `json:"data"`
|
|
Log string `json:"log"`
|
|
Code abci.CodeType `json:"code"`
|
|
Error string `json:"error"` // this is redundant information for now
|
|
}
|
|
|
|
type EventDataProposalHeartbeat struct {
|
|
Heartbeat *Heartbeat
|
|
}
|
|
|
|
// NOTE: This goes into the replay WAL
|
|
type EventDataRoundState struct {
|
|
Height int `json:"height"`
|
|
Round int `json:"round"`
|
|
Step string `json:"step"`
|
|
|
|
// private, not exposed to websockets
|
|
RoundState interface{} `json:"-"`
|
|
}
|
|
|
|
type EventDataVote struct {
|
|
Vote *Vote
|
|
}
|
|
|
|
func (_ EventDataNewBlock) AssertIsTMEventData() {}
|
|
func (_ EventDataNewBlockHeader) AssertIsTMEventData() {}
|
|
func (_ EventDataTx) AssertIsTMEventData() {}
|
|
func (_ EventDataRoundState) AssertIsTMEventData() {}
|
|
func (_ EventDataVote) AssertIsTMEventData() {}
|
|
func (_ EventDataProposalHeartbeat) AssertIsTMEventData() {}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PUBSUB
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
const (
|
|
// EventTypeKey is a reserved key, used to specify event type in tags.
|
|
EventTypeKey = "tm.events.type"
|
|
// TxHashKey is a reserved key, used to specify transaction's hash.
|
|
// see EventBus#PublishEventTx
|
|
TxHashKey = "tx.hash"
|
|
)
|
|
|
|
var (
|
|
EventQueryBond = queryForEvent(EventBond)
|
|
EventQueryUnbond = queryForEvent(EventUnbond)
|
|
EventQueryRebond = queryForEvent(EventRebond)
|
|
EventQueryDupeout = queryForEvent(EventDupeout)
|
|
EventQueryFork = queryForEvent(EventFork)
|
|
EventQueryNewBlock = queryForEvent(EventNewBlock)
|
|
EventQueryNewBlockHeader = queryForEvent(EventNewBlockHeader)
|
|
EventQueryNewRound = queryForEvent(EventNewRound)
|
|
EventQueryNewRoundStep = queryForEvent(EventNewRoundStep)
|
|
EventQueryTimeoutPropose = queryForEvent(EventTimeoutPropose)
|
|
EventQueryCompleteProposal = queryForEvent(EventCompleteProposal)
|
|
EventQueryPolka = queryForEvent(EventPolka)
|
|
EventQueryUnlock = queryForEvent(EventUnlock)
|
|
EventQueryLock = queryForEvent(EventLock)
|
|
EventQueryRelock = queryForEvent(EventRelock)
|
|
EventQueryTimeoutWait = queryForEvent(EventTimeoutWait)
|
|
EventQueryVote = queryForEvent(EventVote)
|
|
EventQueryProposalHeartbeat = queryForEvent(EventProposalHeartbeat)
|
|
)
|
|
|
|
func EventQueryTx(tx Tx) tmpubsub.Query {
|
|
return tmquery.MustParse(fmt.Sprintf("%s='%s' AND %s='%X'", EventTypeKey, EventTx, TxHashKey, tx.Hash()))
|
|
}
|
|
|
|
func queryForEvent(eventType string) tmpubsub.Query {
|
|
return tmquery.MustParse(fmt.Sprintf("%s='%s'", EventTypeKey, eventType))
|
|
}
|
|
|
|
type TxEventPublisher interface {
|
|
PublishEventTx(EventDataTx) error
|
|
}
|