@ -91,11 +91,11 @@ func stopConsensusNet(logger log.Logger, reactors []*ConsensusReactor, eventBuse
func TestReactorBasic ( t * testing . T ) {
N := 4
css := randConsensusNet ( N , "consensus_reactor_test" , newMockTickerFunc ( true ) , newCounter )
reactors , event Subs, eventBuses := startConsensusNet ( t , css , N )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , N )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N , func ( j int ) {
<- event Subs[ j ] . Out ( )
<- blocks Subs[ j ] . Out ( )
} , css )
}
@ -167,19 +167,19 @@ func TestReactorWithEvidence(t *testing.T) {
css [ i ] = cs
}
reactors , event Subs, eventBuses := startConsensusNet ( t , css , nValidators )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , nValidators )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block with no evidence
timeoutWaitGroup ( t , nValidators , func ( j int ) {
msg := <- event Subs[ j ] . Out ( )
msg := <- blocks Subs[ j ] . Out ( )
block := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
assert . True ( t , len ( block . Evidence . Evidence ) == 0 )
} , css )
// second block should have evidence
timeoutWaitGroup ( t , nValidators , func ( j int ) {
msg := <- event Subs[ j ] . Out ( )
msg := <- blocks Subs[ j ] . Out ( )
block := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
assert . True ( t , len ( block . Evidence . Evidence ) > 0 )
} , css )
@ -225,7 +225,7 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
func ( c * cfg . Config ) {
c . Consensus . CreateEmptyBlocks = false
} )
reactors , event Subs, eventBuses := startConsensusNet ( t , css , N )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , N )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// send a tx
@ -235,7 +235,7 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N , func ( j int ) {
<- event Subs[ j ] . Out ( )
<- blocks Subs[ j ] . Out ( )
} , css )
}
@ -243,12 +243,12 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
func TestReactorRecordsVotesAndBlockParts ( t * testing . T ) {
N := 4
css := randConsensusNet ( N , "consensus_reactor_test" , newMockTickerFunc ( true ) , newCounter )
reactors , event Subs, eventBuses := startConsensusNet ( t , css , N )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , N )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N , func ( j int ) {
<- event Subs[ j ] . Out ( )
<- blocks Subs[ j ] . Out ( )
} , css )
// Get peer
@ -267,7 +267,7 @@ func TestReactorVotingPowerChange(t *testing.T) {
nVals := 4
logger := log . TestingLogger ( )
css := randConsensusNet ( nVals , "consensus_voting_power_changes_test" , newMockTickerFunc ( true ) , newPersistentKVStore )
reactors , event Subs, eventBuses := startConsensusNet ( t , css , nVals )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , nVals )
defer stopConsensusNet ( logger , reactors , eventBuses )
// map of active validators
@ -279,7 +279,7 @@ func TestReactorVotingPowerChange(t *testing.T) {
// wait till everyone makes block 1
timeoutWaitGroup ( t , nVals , func ( j int ) {
<- event Subs[ j ] . Out ( )
<- blocks Subs[ j ] . Out ( )
} , css )
//---------------------------------------------------------------------------
@ -290,10 +290,10 @@ func TestReactorVotingPowerChange(t *testing.T) {
updateValidatorTx := kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 25 )
previousTotalVotingPower := css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , event Subs, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , blocks Subs, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css )
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -302,10 +302,10 @@ func TestReactorVotingPowerChange(t *testing.T) {
updateValidatorTx = kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 2 )
previousTotalVotingPower = css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , event Subs, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , blocks Subs, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css )
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -314,10 +314,10 @@ func TestReactorVotingPowerChange(t *testing.T) {
updateValidatorTx = kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 26 )
previousTotalVotingPower = css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , event Subs, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , blocks Subs, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocks Subs, css )
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -331,7 +331,7 @@ func TestReactorValidatorSetChanges(t *testing.T) {
logger := log . TestingLogger ( )
reactors , event Subs, eventBuses := startConsensusNet ( t , css , nPeers )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , nPeers )
defer stopConsensusNet ( logger , reactors , eventBuses )
// map of active validators
@ -343,7 +343,7 @@ func TestReactorValidatorSetChanges(t *testing.T) {
// wait till everyone makes block 1
timeoutWaitGroup ( t , nPeers , func ( j int ) {
<- event Subs[ j ] . Out ( )
<- blocks Subs[ j ] . Out ( )
} , css )
//---------------------------------------------------------------------------
@ -356,22 +356,22 @@ func TestReactorValidatorSetChanges(t *testing.T) {
// wait till everyone makes block 2
// ensure the commit includes all validators
// send newValTx to change vals in block 3
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css , newValidatorTx1 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css , newValidatorTx1 )
// wait till everyone makes block 3.
// it includes the commit for block 2, which is by the original validator set
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , event Subs, css , newValidatorTx1 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocks Subs, css , newValidatorTx1 )
// wait till everyone makes block 4.
// it includes the commit for block 3, which is by the original validator set
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css )
// the commits for block 4 should be with the updated validator set
activeVals [ string ( newValidatorPubKey1 . Address ( ) ) ] = struct { } { }
// wait till everyone makes block 5
// it includes the commit for block 4, which should have the updated validator set
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , event Subs, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocks Subs, css )
//---------------------------------------------------------------------------
logger . Info ( "---------------------------- Testing changing the voting power of one validator" )
@ -381,10 +381,10 @@ func TestReactorValidatorSetChanges(t *testing.T) {
updateValidatorTx1 := kvstore . MakeValSetChangeTx ( updatePubKey1ABCI , 25 )
previousTotalVotingPower := css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css , updateValidatorTx1 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , event Subs, css , updateValidatorTx1 )
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css , updateValidatorTx1 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocks Subs, css , updateValidatorTx1 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocks Subs, css )
if css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Errorf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -401,12 +401,12 @@ func TestReactorValidatorSetChanges(t *testing.T) {
newVal3ABCI := types . TM2PB . PubKey ( newValidatorPubKey3 )
newValidatorTx3 := kvstore . MakeValSetChangeTx ( newVal3ABCI , testMinPower )
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , event Subs, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocks Subs, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css )
activeVals [ string ( newValidatorPubKey2 . Address ( ) ) ] = struct { } { }
activeVals [ string ( newValidatorPubKey3 . Address ( ) ) ] = struct { } { }
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , event Subs, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocks Subs, css )
//---------------------------------------------------------------------------
logger . Info ( "---------------------------- Testing removing two validators at once" )
@ -414,12 +414,12 @@ func TestReactorValidatorSetChanges(t *testing.T) {
removeValidatorTx2 := kvstore . MakeValSetChangeTx ( newVal2ABCI , 0 )
removeValidatorTx3 := kvstore . MakeValSetChangeTx ( newVal3ABCI , 0 )
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , event Subs, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , event Subs, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocks Subs, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocks Subs, css )
delete ( activeVals , string ( newValidatorPubKey2 . Address ( ) ) )
delete ( activeVals , string ( newValidatorPubKey3 . Address ( ) ) )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , event Subs, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocks Subs, css )
}
// Check we can make blocks with skip_timeout_commit=false
@ -431,12 +431,12 @@ func TestReactorWithTimeoutCommit(t *testing.T) {
css [ i ] . config . SkipTimeoutCommit = false
}
reactors , event Subs, eventBuses := startConsensusNet ( t , css , N - 1 )
reactors , blocks Subs, eventBuses := startConsensusNet ( t , css , N - 1 )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N - 1 , func ( j int ) {
<- event Subs[ j ] . Out ( )
<- blocks Subs[ j ] . Out ( )
} , css )
}
@ -444,13 +444,13 @@ func waitForAndValidateBlock(
t * testing . T ,
n int ,
activeVals map [ string ] struct { } ,
event Subs [ ] types . Subscription ,
blocks Subs [ ] types . Subscription ,
css [ ] * ConsensusState ,
txs ... [ ] byte ,
) {
timeoutWaitGroup ( t , n , func ( j int ) {
css [ j ] . Logger . Debug ( "waitForAndValidateBlock" )
msg := <- event Subs[ j ] . Out ( )
msg := <- blocks Subs[ j ] . Out ( )
newBlock := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
css [ j ] . Logger . Debug ( "waitForAndValidateBlock: Got block" , "height" , newBlock . Height )
err := validateBlock ( newBlock , activeVals )
@ -466,7 +466,7 @@ func waitForAndValidateBlockWithTx(
t * testing . T ,
n int ,
activeVals map [ string ] struct { } ,
event Subs [ ] types . Subscription ,
blocks Subs [ ] types . Subscription ,
css [ ] * ConsensusState ,
txs ... [ ] byte ,
) {
@ -475,7 +475,7 @@ func waitForAndValidateBlockWithTx(
BLOCK_TX_LOOP :
for {
css [ j ] . Logger . Debug ( "waitForAndValidateBlockWithTx" , "ntxs" , ntxs )
msg := <- event Subs[ j ] . Out ( )
msg := <- blocks Subs[ j ] . Out ( )
newBlock := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
css [ j ] . Logger . Debug ( "waitForAndValidateBlockWithTx: Got block" , "height" , newBlock . Height )
err := validateBlock ( newBlock , activeVals )
@ -501,7 +501,7 @@ func waitForBlockWithUpdatedValsAndValidateIt(
t * testing . T ,
n int ,
updatedVals map [ string ] struct { } ,
event Subs [ ] types . Subscription ,
blocks Subs [ ] types . Subscription ,
css [ ] * ConsensusState ,
) {
timeoutWaitGroup ( t , n , func ( j int ) {
@ -510,7 +510,7 @@ func waitForBlockWithUpdatedValsAndValidateIt(
LOOP :
for {
css [ j ] . Logger . Debug ( "waitForBlockWithUpdatedValsAndValidateIt" )
msg := <- event Subs[ j ] . Out ( )
msg := <- blocks Subs[ j ] . Out ( )
newBlock = msg . Data ( ) . ( types . EventDataNewBlock ) . Block
if newBlock . LastCommit . Size ( ) == len ( updatedVals ) {
css [ j ] . Logger . Debug ( "waitForBlockWithUpdatedValsAndValidateIt: Got block" , "height" , newBlock . Height )