2015-12-01 20:12:01 -08:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
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
|
|
|
"context"
|
2015-12-01 20:12:01 -08:00
|
|
|
"fmt"
|
2016-11-23 18:20:46 -05:00
|
|
|
"io/ioutil"
|
2017-01-12 14:44:42 -05:00
|
|
|
"os"
|
2017-01-12 12:37:24 -05:00
|
|
|
"path"
|
2015-12-01 20:12:01 -08:00
|
|
|
"sort"
|
2016-01-06 17:14:20 -08:00
|
|
|
"sync"
|
2015-12-01 20:12:01 -08:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-06-22 06:59:02 +02:00
|
|
|
abcicli "github.com/tendermint/tendermint/abci/client"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2015-12-01 20:12:01 -08:00
|
|
|
bc "github.com/tendermint/tendermint/blockchain"
|
2017-05-02 00:43:49 -04:00
|
|
|
cfg "github.com/tendermint/tendermint/config"
|
2017-10-10 12:39:21 +04:00
|
|
|
cstypes "github.com/tendermint/tendermint/consensus/types"
|
2015-12-01 20:12:01 -08:00
|
|
|
mempl "github.com/tendermint/tendermint/mempool"
|
2017-04-08 22:04:06 -04:00
|
|
|
"github.com/tendermint/tendermint/p2p"
|
2018-06-01 19:17:37 +02:00
|
|
|
"github.com/tendermint/tendermint/privval"
|
2015-12-01 20:12:01 -08:00
|
|
|
sm "github.com/tendermint/tendermint/state"
|
|
|
|
"github.com/tendermint/tendermint/types"
|
2018-07-01 22:36:49 -04:00
|
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
|
|
dbm "github.com/tendermint/tendermint/libs/db"
|
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2018-06-22 06:59:02 +02:00
|
|
|
"github.com/tendermint/tendermint/abci/example/counter"
|
|
|
|
"github.com/tendermint/tendermint/abci/example/kvstore"
|
2017-05-14 21:44:01 +02:00
|
|
|
|
|
|
|
"github.com/go-kit/kit/log/term"
|
2015-12-01 20:12:01 -08: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
|
|
|
const (
|
|
|
|
testSubscriber = "test-client"
|
|
|
|
)
|
|
|
|
|
2017-05-01 20:09:29 -04:00
|
|
|
// genesis, chain_id, priv_val
|
2018-01-19 00:14:35 -05:00
|
|
|
var config *cfg.Config // NOTE: must be reset for each _test.go file
|
|
|
|
var ensureTimeout = time.Second * 1 // must be in seconds because CreateEmptyBlocksInterval is
|
2015-12-10 11:41:18 -05:00
|
|
|
|
2017-01-12 14:44:42 -05:00
|
|
|
func ensureDir(dir string, mode os.FileMode) {
|
2017-10-04 16:40:45 -04:00
|
|
|
if err := cmn.EnsureDir(dir, mode); err != nil {
|
2017-01-12 14:44:42 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 22:33:08 -04:00
|
|
|
func ResetConfig(name string) *cfg.Config {
|
|
|
|
return cfg.ResetTestRoot(name)
|
2017-05-02 00:43:49 -04:00
|
|
|
}
|
|
|
|
|
2017-01-12 12:37:24 -05:00
|
|
|
//-------------------------------------------------------------------------------
|
2018-02-27 14:01:10 +00:00
|
|
|
// validator stub (a kvstore consensus peer we control)
|
2017-01-12 12:37:24 -05:00
|
|
|
|
2015-12-01 20:12:01 -08:00
|
|
|
type validatorStub struct {
|
2016-07-01 17:47:31 -04:00
|
|
|
Index int // Validator index. NOTE: we don't assume validator set changes.
|
2017-12-01 19:04:53 -06:00
|
|
|
Height int64
|
2015-12-01 20:12:01 -08:00
|
|
|
Round int
|
2017-09-18 23:16:14 -04:00
|
|
|
types.PrivValidator
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
|
2017-12-02 01:47:55 -05:00
|
|
|
var testMinPower int64 = 10
|
2016-11-23 18:20:46 -05:00
|
|
|
|
2017-09-18 23:16:14 -04:00
|
|
|
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
|
2015-12-01 20:12:01 -08:00
|
|
|
return &validatorStub{
|
2016-07-01 17:47:31 -04:00
|
|
|
Index: valIndex,
|
2015-12-01 20:12:01 -08:00
|
|
|
PrivValidator: privValidator,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *validatorStub) signVote(voteType byte, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
|
|
|
|
vote := &types.Vote{
|
2016-07-01 17:47:31 -04:00
|
|
|
ValidatorIndex: vs.Index,
|
2017-09-21 16:32:02 -04:00
|
|
|
ValidatorAddress: vs.PrivValidator.GetAddress(),
|
2015-12-01 20:12:01 -08:00
|
|
|
Height: vs.Height,
|
|
|
|
Round: vs.Round,
|
2017-12-11 18:42:58 +01:00
|
|
|
Timestamp: time.Now().UTC(),
|
2015-12-01 20:12:01 -08:00
|
|
|
Type: voteType,
|
2016-08-16 14:59:19 -07:00
|
|
|
BlockID: types.BlockID{hash, header},
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
2017-12-10 20:43:58 -05:00
|
|
|
err := vs.PrivValidator.SignVote(config.ChainID(), vote)
|
2015-12-01 20:12:01 -08:00
|
|
|
return vote, err
|
|
|
|
}
|
|
|
|
|
2016-07-01 17:47:31 -04:00
|
|
|
// Sign vote for type/hash/header
|
2015-12-01 20:12:01 -08:00
|
|
|
func signVote(vs *validatorStub, voteType byte, hash []byte, header types.PartSetHeader) *types.Vote {
|
|
|
|
v, err := vs.signVote(voteType, hash, header)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("failed to sign vote: %v", err))
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2017-01-12 12:37:24 -05:00
|
|
|
func signVotes(voteType byte, hash []byte, header types.PartSetHeader, vss ...*validatorStub) []*types.Vote {
|
|
|
|
votes := make([]*types.Vote, len(vss))
|
|
|
|
for i, vs := range vss {
|
|
|
|
votes[i] = signVote(vs, voteType, hash, header)
|
|
|
|
}
|
|
|
|
return votes
|
|
|
|
}
|
|
|
|
|
|
|
|
func incrementHeight(vss ...*validatorStub) {
|
|
|
|
for _, vs := range vss {
|
2018-04-02 10:21:17 +02:00
|
|
|
vs.Height++
|
2017-01-12 12:37:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func incrementRound(vss ...*validatorStub) {
|
|
|
|
for _, vs := range vss {
|
2018-04-02 10:21:17 +02:00
|
|
|
vs.Round++
|
2017-01-12 12:37:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// Functions for transitioning the consensus state
|
|
|
|
|
2017-12-01 19:04:53 -06:00
|
|
|
func startTestRound(cs *ConsensusState, height int64, round int) {
|
2017-01-12 12:37:24 -05:00
|
|
|
cs.enterNewRound(height, round)
|
|
|
|
cs.startRoutines(0)
|
|
|
|
}
|
|
|
|
|
2016-07-01 17:47:31 -04:00
|
|
|
// Create proposal block from cs1 but sign it with vs
|
2017-12-01 19:04:53 -06:00
|
|
|
func decideProposal(cs1 *ConsensusState, vs *validatorStub, height int64, round int) (proposal *types.Proposal, block *types.Block) {
|
2015-12-01 20:12:01 -08:00
|
|
|
block, blockParts := cs1.createProposalBlock()
|
|
|
|
if block == nil { // on error
|
|
|
|
panic("error creating proposal block")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make proposal
|
2016-08-20 15:08:26 -07:00
|
|
|
polRound, polBlockID := cs1.Votes.POLInfo()
|
|
|
|
proposal = types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
|
2017-12-10 20:43:58 -05:00
|
|
|
if err := vs.SignProposal(cs1.state.ChainID, proposal); err != nil {
|
2015-12-01 20:12:01 -08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-07-01 17:47:31 -04:00
|
|
|
func addVotes(to *ConsensusState, votes ...*types.Vote) {
|
|
|
|
for _, vote := range votes {
|
|
|
|
to.peerMsgQueue <- msgInfo{Msg: &VoteMessage{vote}}
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-01 17:47:31 -04:00
|
|
|
func signAddVotes(to *ConsensusState, voteType byte, hash []byte, header types.PartSetHeader, vss ...*validatorStub) {
|
|
|
|
votes := signVotes(voteType, hash, header, vss...)
|
|
|
|
addVotes(to, votes...)
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *validatorStub, blockHash []byte) {
|
|
|
|
prevotes := cs.Votes.Prevotes(round)
|
|
|
|
var vote *types.Vote
|
2017-09-21 16:32:02 -04:00
|
|
|
if vote = prevotes.GetByAddress(privVal.GetAddress()); vote == nil {
|
2015-12-01 20:12:01 -08:00
|
|
|
panic("Failed to find prevote from validator")
|
|
|
|
}
|
|
|
|
if blockHash == nil {
|
2016-08-16 14:59:19 -07:00
|
|
|
if vote.BlockID.Hash != nil {
|
|
|
|
panic(fmt.Sprintf("Expected prevote to be for nil, got %X", vote.BlockID.Hash))
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
} else {
|
2016-08-16 14:59:19 -07:00
|
|
|
if !bytes.Equal(vote.BlockID.Hash, blockHash) {
|
|
|
|
panic(fmt.Sprintf("Expected prevote to be for %X, got %X", blockHash, vote.BlockID.Hash))
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-13 14:56:05 -05:00
|
|
|
func validateLastPrecommit(t *testing.T, cs *ConsensusState, privVal *validatorStub, blockHash []byte) {
|
|
|
|
votes := cs.LastCommit
|
|
|
|
var vote *types.Vote
|
2017-09-21 16:32:02 -04:00
|
|
|
if vote = votes.GetByAddress(privVal.GetAddress()); vote == nil {
|
2015-12-13 14:56:05 -05:00
|
|
|
panic("Failed to find precommit from validator")
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
2016-08-16 14:59:19 -07:00
|
|
|
if !bytes.Equal(vote.BlockID.Hash, blockHash) {
|
|
|
|
panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash))
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func validatePrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
|
|
|
|
precommits := cs.Votes.Precommits(thisRound)
|
|
|
|
var vote *types.Vote
|
2017-09-21 16:32:02 -04:00
|
|
|
if vote = precommits.GetByAddress(privVal.GetAddress()); vote == nil {
|
2015-12-01 20:12:01 -08:00
|
|
|
panic("Failed to find precommit from validator")
|
|
|
|
}
|
|
|
|
|
|
|
|
if votedBlockHash == nil {
|
2016-08-16 14:59:19 -07:00
|
|
|
if vote.BlockID.Hash != nil {
|
2015-12-01 20:12:01 -08:00
|
|
|
panic("Expected precommit to be for nil")
|
|
|
|
}
|
|
|
|
} else {
|
2016-08-16 14:59:19 -07:00
|
|
|
if !bytes.Equal(vote.BlockID.Hash, votedBlockHash) {
|
2015-12-01 20:12:01 -08:00
|
|
|
panic("Expected precommit to be for proposal block")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if lockedBlockHash == nil {
|
|
|
|
if cs.LockedRound != lockRound || cs.LockedBlock != nil {
|
|
|
|
panic(fmt.Sprintf("Expected to be locked on nil at round %d. Got locked at round %d with block %v", lockRound, cs.LockedRound, cs.LockedBlock))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if cs.LockedRound != lockRound || !bytes.Equal(cs.LockedBlock.Hash(), lockedBlockHash) {
|
|
|
|
panic(fmt.Sprintf("Expected block to be locked on round %d, got %d. Got locked block %X, expected %X", lockRound, cs.LockedRound, cs.LockedBlock.Hash(), lockedBlockHash))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func validatePrevoteAndPrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
|
|
|
|
// verify the prevote
|
|
|
|
validatePrevote(t, cs, thisRound, privVal, votedBlockHash)
|
|
|
|
// verify precommit
|
|
|
|
cs.mtx.Lock()
|
|
|
|
validatePrecommit(t, cs, thisRound, lockRound, privVal, votedBlockHash, lockedBlockHash)
|
|
|
|
cs.mtx.Unlock()
|
|
|
|
}
|
|
|
|
|
2017-01-12 12:37:24 -05:00
|
|
|
// genesis
|
|
|
|
func subscribeToVoter(cs *ConsensusState, addr []byte) chan interface{} {
|
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
|
|
|
voteCh0 := make(chan interface{})
|
|
|
|
err := cs.eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryVote, voteCh0)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, types.EventQueryVote))
|
|
|
|
}
|
2017-01-12 12:37:24 -05:00
|
|
|
voteCh := make(chan interface{})
|
|
|
|
go func() {
|
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
|
|
|
for v := range voteCh0 {
|
2018-04-05 08:17:10 -07:00
|
|
|
vote := v.(types.EventDataVote)
|
2017-01-12 12:37:24 -05:00
|
|
|
// we only fire for our own votes
|
|
|
|
if bytes.Equal(addr, vote.Vote.ValidatorAddress) {
|
|
|
|
voteCh <- v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return voteCh
|
2016-01-18 15:57:57 -05:00
|
|
|
}
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2017-01-12 12:37:24 -05:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// consensus states
|
|
|
|
|
2017-12-27 22:09:48 -05:00
|
|
|
func newConsensusState(state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
|
2017-01-12 12:37:24 -05:00
|
|
|
return newConsensusStateWithConfig(config, state, pv, app)
|
2016-10-11 12:51:48 -04:00
|
|
|
}
|
|
|
|
|
2017-12-27 22:09:48 -05:00
|
|
|
func newConsensusStateWithConfig(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
|
2015-12-01 20:12:01 -08:00
|
|
|
blockDB := dbm.NewMemDB()
|
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
|
|
|
return newConsensusStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB)
|
|
|
|
}
|
|
|
|
|
2017-12-27 22:09:48 -05:00
|
|
|
func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application, blockDB dbm.DB) *ConsensusState {
|
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
|
|
|
// Get BlockStore
|
2015-12-01 20:12:01 -08:00
|
|
|
blockStore := bc.NewBlockStore(blockDB)
|
|
|
|
|
|
|
|
// one for mempool, one for consensus
|
2016-04-11 18:08:28 -04:00
|
|
|
mtx := new(sync.Mutex)
|
2017-01-12 15:53:32 -05:00
|
|
|
proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
|
|
|
|
proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
|
2015-12-01 20:12:01 -08:00
|
|
|
|
|
|
|
// Make Mempool
|
2017-07-25 13:57:11 -04:00
|
|
|
mempool := mempl.NewMempool(thisConfig.Mempool, proxyAppConnMem, 0)
|
2017-05-02 11:53:32 +04:00
|
|
|
mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
|
2017-08-04 21:46:17 -04:00
|
|
|
if thisConfig.Consensus.WaitForTxs() {
|
2017-07-25 13:57:11 -04:00
|
|
|
mempool.EnableTxsAvailable()
|
|
|
|
}
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2017-11-19 02:02:58 +00:00
|
|
|
// mock the evidence pool
|
2018-06-04 13:46:34 -07:00
|
|
|
evpool := sm.MockEvidencePool{}
|
2017-11-19 02:02:58 +00:00
|
|
|
|
2018-05-15 14:32:06 +04:00
|
|
|
// Make ConsensusState
|
2017-12-28 18:58:05 -05:00
|
|
|
stateDB := dbm.NewMemDB()
|
2017-12-28 18:26:13 -05:00
|
|
|
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
|
2017-12-27 22:09:48 -05:00
|
|
|
cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
|
2018-01-24 23:34:57 -05:00
|
|
|
cs.SetLogger(log.TestingLogger().With("module", "consensus"))
|
2016-01-18 15:57:57 -05:00
|
|
|
cs.SetPrivValidator(pv)
|
2015-12-01 20:12:01 -08: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(log.TestingLogger().With("module", "events"))
|
|
|
|
eventBus.Start()
|
|
|
|
cs.SetEventBus(eventBus)
|
2016-01-18 15:57:57 -05:00
|
|
|
return cs
|
|
|
|
}
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2018-06-01 19:17:37 +02:00
|
|
|
func loadPrivValidator(config *cfg.Config) *privval.FilePV {
|
2017-05-04 22:33:08 -04:00
|
|
|
privValidatorFile := config.PrivValidatorFile()
|
2017-01-12 14:44:42 -05:00
|
|
|
ensureDir(path.Dir(privValidatorFile), 0700)
|
2018-06-01 19:17:37 +02:00
|
|
|
privValidator := privval.LoadOrGenFilePV(privValidatorFile)
|
2017-01-12 12:37:24 -05:00
|
|
|
privValidator.Reset()
|
|
|
|
return privValidator
|
|
|
|
}
|
|
|
|
|
2016-01-18 15:57:57 -05:00
|
|
|
func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
|
|
|
|
// Get State
|
|
|
|
state, privVals := randGenesisState(nValidators, false, 10)
|
|
|
|
|
|
|
|
vss := make([]*validatorStub, nValidators)
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2016-04-11 18:08:28 -04:00
|
|
|
cs := newConsensusState(state, privVals[0], counter.NewCounterApplication(true))
|
2015-12-08 16:00:59 -05:00
|
|
|
|
2015-12-01 20:12:01 -08:00
|
|
|
for i := 0; i < nValidators; i++ {
|
2016-07-01 17:47:31 -04:00
|
|
|
vss[i] = NewValidatorStub(privVals[i], i)
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
// since cs1 starts at 1
|
|
|
|
incrementHeight(vss[1:]...)
|
|
|
|
|
|
|
|
return cs, vss
|
|
|
|
}
|
|
|
|
|
2017-01-12 12:37:24 -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
|
|
|
func ensureNoNewStep(stepCh <-chan interface{}) {
|
2017-08-08 16:35:25 -04:00
|
|
|
timer := time.NewTimer(ensureTimeout)
|
2017-01-12 12:37:24 -05:00
|
|
|
select {
|
2017-07-13 15:03:19 -04:00
|
|
|
case <-timer.C:
|
2017-01-12 12:37:24 -05:00
|
|
|
break
|
|
|
|
case <-stepCh:
|
2017-07-13 15:03:19 -04:00
|
|
|
panic("We should be stuck waiting, not moving to the next step")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func ensureNewStep(stepCh <-chan interface{}) {
|
2017-08-08 16:35:25 -04:00
|
|
|
timer := time.NewTimer(ensureTimeout)
|
2017-07-13 15:03:19 -04:00
|
|
|
select {
|
|
|
|
case <-timer.C:
|
|
|
|
panic("We shouldnt be stuck waiting")
|
|
|
|
case <-stepCh:
|
|
|
|
break
|
2017-01-12 12:37:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// consensus nets
|
|
|
|
|
2017-05-14 21:44:01 +02:00
|
|
|
// consensusLogger is a TestingLogger which uses a different
|
|
|
|
// color for each validator ("validator" key must exist).
|
|
|
|
func consensusLogger() log.Logger {
|
|
|
|
return log.TestingLoggerWithColorFn(func(keyvals ...interface{}) term.FgBgColor {
|
|
|
|
for i := 0; i < len(keyvals)-1; i += 2 {
|
|
|
|
if keyvals[i] == "validator" {
|
|
|
|
return term.FgBgColor{Fg: term.Color(uint8(keyvals[i+1].(int) + 1))}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return term.FgBgColor{}
|
2018-01-24 23:34:57 -05:00
|
|
|
}).With("module", "consensus")
|
2017-05-14 21:44:01 +02:00
|
|
|
}
|
|
|
|
|
2017-08-10 01:09:04 -04:00
|
|
|
func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application, configOpts ...func(*cfg.Config)) []*ConsensusState {
|
2017-12-25 14:07:45 -06:00
|
|
|
genDoc, privVals := randGenesisDoc(nValidators, false, 30)
|
2016-06-26 00:40:53 -04:00
|
|
|
css := make([]*ConsensusState, nValidators)
|
2017-05-14 21:44:01 +02:00
|
|
|
logger := consensusLogger()
|
2016-06-26 00:40:53 -04:00
|
|
|
for i := 0; i < nValidators; i++ {
|
2017-12-27 22:09:48 -05:00
|
|
|
stateDB := dbm.NewMemDB() // each state needs its own db
|
2017-12-28 18:26:13 -05:00
|
|
|
state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
2017-10-04 16:40:45 -04:00
|
|
|
thisConfig := ResetConfig(cmn.Fmt("%s_%d", testName, i))
|
2017-08-10 01:09:04 -04:00
|
|
|
for _, opt := range configOpts {
|
|
|
|
opt(thisConfig)
|
|
|
|
}
|
2017-05-04 22:33:08 -04:00
|
|
|
ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
|
2017-10-23 10:03:54 -04:00
|
|
|
app := appFunc()
|
|
|
|
vals := types.TM2PB.Validators(state.Validators)
|
|
|
|
app.InitChain(abci.RequestInitChain{Validators: vals})
|
|
|
|
|
|
|
|
css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
|
2016-12-19 10:44:25 -05:00
|
|
|
css[i].SetTimeoutTicker(tickerFunc())
|
2018-01-24 23:34:57 -05:00
|
|
|
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
|
2016-06-26 00:40:53 -04:00
|
|
|
}
|
|
|
|
return css
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:20:46 -05:00
|
|
|
// nPeers = nValidators + nNotValidator
|
2017-01-12 15:53:32 -05:00
|
|
|
func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
|
2017-12-02 01:47:55 -05:00
|
|
|
genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower)
|
2016-11-23 18:20:46 -05:00
|
|
|
css := make([]*ConsensusState, nPeers)
|
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
|
|
|
logger := consensusLogger()
|
2016-11-23 18:20:46 -05:00
|
|
|
for i := 0; i < nPeers; i++ {
|
2017-12-27 22:09:48 -05:00
|
|
|
stateDB := dbm.NewMemDB() // each state needs its own db
|
2017-12-28 18:26:13 -05:00
|
|
|
state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
2017-10-04 16:40:45 -04:00
|
|
|
thisConfig := ResetConfig(cmn.Fmt("%s_%d", testName, i))
|
2017-05-04 22:33:08 -04:00
|
|
|
ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
|
2017-09-18 23:16:14 -04:00
|
|
|
var privVal types.PrivValidator
|
2016-11-23 18:20:46 -05:00
|
|
|
if i < nValidators {
|
|
|
|
privVal = privVals[i]
|
|
|
|
} else {
|
2017-10-04 16:40:45 -04:00
|
|
|
_, tempFilePath := cmn.Tempfile("priv_validator_")
|
2018-06-01 19:17:37 +02:00
|
|
|
privVal = privval.GenFilePV(tempFilePath)
|
2016-11-23 18:20:46 -05:00
|
|
|
}
|
|
|
|
|
2017-10-23 10:03:54 -04:00
|
|
|
app := appFunc()
|
|
|
|
vals := types.TM2PB.Validators(state.Validators)
|
|
|
|
app.InitChain(abci.RequestInitChain{Validators: vals})
|
|
|
|
|
|
|
|
css[i] = newConsensusStateWithConfig(thisConfig, state, privVal, app)
|
2016-12-19 10:44:25 -05:00
|
|
|
css[i].SetTimeoutTicker(tickerFunc())
|
2018-01-24 23:34:57 -05:00
|
|
|
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
|
2016-11-23 18:20:46 -05:00
|
|
|
}
|
|
|
|
return css
|
|
|
|
}
|
|
|
|
|
2017-09-12 20:49:22 -04:00
|
|
|
func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int {
|
2017-01-12 12:37:24 -05:00
|
|
|
for i, s := range switches {
|
2018-04-11 11:11:11 +03:00
|
|
|
if peer.NodeInfo().ID == s.NodeInfo().ID {
|
2017-01-12 12:37:24 -05:00
|
|
|
return i
|
2016-07-11 20:40:48 -04:00
|
|
|
}
|
2017-01-12 12:37:24 -05:00
|
|
|
}
|
|
|
|
panic("didnt find peer in switches")
|
|
|
|
return -1
|
2016-07-11 20:40:48 -04:00
|
|
|
}
|
|
|
|
|
2017-01-12 12:37:24 -05:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// genesis
|
2015-12-01 20:12:01 -08:00
|
|
|
|
2018-04-03 07:03:08 -07:00
|
|
|
func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.GenesisDoc, []types.PrivValidator) {
|
2015-12-01 20:12:01 -08:00
|
|
|
validators := make([]types.GenesisValidator, numValidators)
|
2018-04-03 07:03:08 -07:00
|
|
|
privValidators := make([]types.PrivValidator, numValidators)
|
2015-12-01 20:12:01 -08:00
|
|
|
for i := 0; i < numValidators; i++ {
|
|
|
|
val, privVal := types.RandValidator(randPower, minPower)
|
|
|
|
validators[i] = types.GenesisValidator{
|
|
|
|
PubKey: val.PubKey,
|
2017-09-21 14:37:34 -04:00
|
|
|
Power: val.VotingPower,
|
2015-12-01 20:12:01 -08:00
|
|
|
}
|
|
|
|
privValidators[i] = privVal
|
|
|
|
}
|
|
|
|
sort.Sort(types.PrivValidatorsByAddress(privValidators))
|
2017-12-10 20:43:58 -05:00
|
|
|
|
2015-12-01 20:12:01 -08:00
|
|
|
return &types.GenesisDoc{
|
|
|
|
GenesisTime: time.Now(),
|
2017-12-10 20:43:58 -05:00
|
|
|
ChainID: config.ChainID(),
|
2015-12-01 20:12:01 -08:00
|
|
|
Validators: validators,
|
|
|
|
}, privValidators
|
2015-12-12 01:28:53 -05:00
|
|
|
}
|
2016-11-23 18:20:46 -05:00
|
|
|
|
2018-04-03 07:03:08 -07:00
|
|
|
func randGenesisState(numValidators int, randPower bool, minPower int64) (sm.State, []types.PrivValidator) {
|
2017-01-12 12:37:24 -05:00
|
|
|
genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
|
2017-12-27 22:09:48 -05:00
|
|
|
s0, _ := sm.MakeGenesisState(genDoc)
|
2017-01-12 12:37:24 -05:00
|
|
|
db := dbm.NewMemDB()
|
2017-12-27 22:09:48 -05:00
|
|
|
sm.SaveState(db, s0)
|
2017-01-12 12:37:24 -05:00
|
|
|
return s0, privValidators
|
2016-11-23 18:20:46 -05:00
|
|
|
}
|
2016-12-06 19:54:10 -05:00
|
|
|
|
2016-12-19 10:44:25 -05:00
|
|
|
//------------------------------------
|
2017-01-12 12:37:24 -05:00
|
|
|
// mock ticker
|
2016-12-19 10:44:25 -05:00
|
|
|
|
|
|
|
func newMockTickerFunc(onlyOnce bool) func() TimeoutTicker {
|
|
|
|
return func() TimeoutTicker {
|
|
|
|
return &mockTicker{
|
2016-12-19 22:29:32 -05:00
|
|
|
c: make(chan timeoutInfo, 10),
|
2016-12-19 10:44:25 -05:00
|
|
|
onlyOnce: onlyOnce,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:51:58 -05:00
|
|
|
// mock ticker only fires on RoundStepNewHeight
|
2016-12-19 10:44:25 -05:00
|
|
|
// and only once if onlyOnce=true
|
|
|
|
type mockTicker struct {
|
2016-12-19 22:29:32 -05:00
|
|
|
c chan timeoutInfo
|
2016-12-19 10:44:25 -05:00
|
|
|
|
2016-12-19 22:29:32 -05:00
|
|
|
mtx sync.Mutex
|
2016-12-19 10:44:25 -05:00
|
|
|
onlyOnce bool
|
|
|
|
fired bool
|
|
|
|
}
|
|
|
|
|
2017-11-06 13:20:39 -05:00
|
|
|
func (m *mockTicker) Start() error {
|
|
|
|
return nil
|
2016-12-19 10:44:25 -05:00
|
|
|
}
|
|
|
|
|
2017-11-06 13:20:39 -05:00
|
|
|
func (m *mockTicker) Stop() error {
|
|
|
|
return nil
|
2016-12-19 22:29:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockTicker) ScheduleTimeout(ti timeoutInfo) {
|
|
|
|
m.mtx.Lock()
|
|
|
|
defer m.mtx.Unlock()
|
2016-12-19 10:44:25 -05:00
|
|
|
if m.onlyOnce && m.fired {
|
|
|
|
return
|
|
|
|
}
|
2017-10-10 12:39:21 +04:00
|
|
|
if ti.Step == cstypes.RoundStepNewHeight {
|
2016-12-19 22:29:32 -05:00
|
|
|
m.c <- ti
|
2016-12-19 10:44:25 -05:00
|
|
|
m.fired = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 22:29:32 -05:00
|
|
|
func (m *mockTicker) Chan() <-chan timeoutInfo {
|
2016-12-19 10:44:25 -05:00
|
|
|
return m.c
|
|
|
|
}
|
|
|
|
|
2017-05-12 23:07:53 +02:00
|
|
|
func (mockTicker) SetLogger(log.Logger) {
|
|
|
|
}
|
|
|
|
|
2016-12-19 10:44:25 -05:00
|
|
|
//------------------------------------
|
2017-01-11 15:32:03 -05:00
|
|
|
|
2017-01-12 15:53:32 -05:00
|
|
|
func newCounter() abci.Application {
|
2017-01-11 15:32:03 -05:00
|
|
|
return counter.NewCounterApplication(true)
|
|
|
|
}
|
|
|
|
|
2018-02-27 14:01:10 +00:00
|
|
|
func newPersistentKVStore() abci.Application {
|
|
|
|
dir, _ := ioutil.TempDir("/tmp", "persistent-kvstore")
|
|
|
|
return kvstore.NewPersistentKVStoreApplication(dir)
|
2017-01-11 15:32:03 -05:00
|
|
|
}
|