@ -30,9 +30,13 @@ import (
//----------------------------------------------
//----------------------------------------------
// in-process testnets
// in-process testnets
func startConsensusNet ( t * testing . T , css [ ] * ConsensusState , N int ) ( [ ] * ConsensusReactor , [ ] chan interface { } , [ ] * types . EventBus ) {
func startConsensusNet ( t * testing . T , css [ ] * ConsensusState , N int ) (
[ ] * ConsensusReactor ,
[ ] types . Subscription ,
[ ] * types . EventBus ,
) {
reactors := make ( [ ] * ConsensusReactor , N )
reactors := make ( [ ] * ConsensusReactor , N )
eventChans := make ( [ ] chan interface { } , N )
blocksSub s := make ( [ ] types . Subscription , 0 )
eventBuses := make ( [ ] * types . EventBus , N )
eventBuses := make ( [ ] * types . EventBus , N )
for i := 0 ; i < N ; i ++ {
for i := 0 ; i < N ; i ++ {
/ * logger , err := tmflags . ParseLogLevel ( "consensus:info,*:error" , logger , "info" )
/ * logger , err := tmflags . ParseLogLevel ( "consensus:info,*:error" , logger , "info" )
@ -44,9 +48,9 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int) ([]*Consensus
eventBuses [ i ] = css [ i ] . eventBus
eventBuses [ i ] = css [ i ] . eventBus
reactors [ i ] . SetEventBus ( eventBuses [ i ] )
reactors [ i ] . SetEventBus ( eventBuses [ i ] )
eventChans [ i ] = make ( chan interface { } , 1 )
err := eventBuses [ i ] . Subscribe ( context . Background ( ) , testSubscriber , types . EventQueryNewBlock , eventChans [ i ] )
blocksSub , err := eventBuses [ i ] . Subscribe ( context . Background ( ) , testSubscriber , types . EventQueryNewBlock )
require . NoError ( t , err )
require . NoError ( t , err )
blocksSubs = append ( blocksSubs , blocksSub )
}
}
// make connected switches and start all reactors
// make connected switches and start all reactors
p2p . MakeConnectedSwitches ( config . P2P , N , func ( i int , s * p2p . Switch ) * p2p . Switch {
p2p . MakeConnectedSwitches ( config . P2P , N , func ( i int , s * p2p . Switch ) * p2p . Switch {
@ -63,7 +67,7 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int) ([]*Consensus
s := reactors [ i ] . conS . GetState ( )
s := reactors [ i ] . conS . GetState ( )
reactors [ i ] . SwitchToConsensus ( s , 0 )
reactors [ i ] . SwitchToConsensus ( s , 0 )
}
}
return reactors , eventChan s, eventBuses
return reactors , blocksSub s, eventBuses
}
}
func stopConsensusNet ( logger log . Logger , reactors [ ] * ConsensusReactor , eventBuses [ ] * types . EventBus ) {
func stopConsensusNet ( logger log . Logger , reactors [ ] * ConsensusReactor , eventBuses [ ] * types . EventBus ) {
@ -84,11 +88,11 @@ func TestReactorBasic(t *testing.T) {
N := 4
N := 4
css , cleanup := randConsensusNet ( N , "consensus_reactor_test" , newMockTickerFunc ( true ) , newCounter )
css , cleanup := randConsensusNet ( N , "consensus_reactor_test" , newMockTickerFunc ( true ) , newCounter )
defer cleanup ( )
defer cleanup ( )
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , N )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , N )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N , func ( j int ) {
timeoutWaitGroup ( t , N , func ( j int ) {
<- eventChan s[ j ]
<- blocksSub s[ j ] . Out ( )
} , css )
} , css )
}
}
@ -161,20 +165,20 @@ func TestReactorWithEvidence(t *testing.T) {
css [ i ] = cs
css [ i ] = cs
}
}
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , nValidators )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , nValidators )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block with no evidence
// wait till everyone makes the first new block with no evidence
timeoutWaitGroup ( t , nValidators , func ( j int ) {
timeoutWaitGroup ( t , nValidators , func ( j int ) {
blockI := <- eventChan s[ j ]
block := blockI . ( types . EventDataNewBlock ) . Block
msg := <- blocksSub s[ j ] . Out ( )
block := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
assert . True ( t , len ( block . Evidence . Evidence ) == 0 )
assert . True ( t , len ( block . Evidence . Evidence ) == 0 )
} , css )
} , css )
// second block should have evidence
// second block should have evidence
timeoutWaitGroup ( t , nValidators , func ( j int ) {
timeoutWaitGroup ( t , nValidators , func ( j int ) {
blockI := <- eventChan s[ j ]
block := blockI . ( types . EventDataNewBlock ) . Block
msg := <- blocksSub s[ j ] . Out ( )
block := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
assert . True ( t , len ( block . Evidence . Evidence ) > 0 )
assert . True ( t , len ( block . Evidence . Evidence ) > 0 )
} , css )
} , css )
}
}
@ -221,7 +225,7 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
c . Consensus . CreateEmptyBlocks = false
c . Consensus . CreateEmptyBlocks = false
} )
} )
defer cleanup ( )
defer cleanup ( )
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , N )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , N )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// send a tx
// send a tx
@ -231,7 +235,7 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
// wait till everyone makes the first new block
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N , func ( j int ) {
timeoutWaitGroup ( t , N , func ( j int ) {
<- eventChan s[ j ]
<- blocksSub s[ j ] . Out ( )
} , css )
} , css )
}
}
@ -240,12 +244,12 @@ func TestReactorRecordsVotesAndBlockParts(t *testing.T) {
N := 4
N := 4
css , cleanup := randConsensusNet ( N , "consensus_reactor_test" , newMockTickerFunc ( true ) , newCounter )
css , cleanup := randConsensusNet ( N , "consensus_reactor_test" , newMockTickerFunc ( true ) , newCounter )
defer cleanup ( )
defer cleanup ( )
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , N )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , N )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N , func ( j int ) {
timeoutWaitGroup ( t , N , func ( j int ) {
<- eventChan s[ j ]
<- blocksSub s[ j ] . Out ( )
} , css )
} , css )
// Get peer
// Get peer
@ -265,7 +269,7 @@ func TestReactorVotingPowerChange(t *testing.T) {
logger := log . TestingLogger ( )
logger := log . TestingLogger ( )
css , cleanup := randConsensusNet ( nVals , "consensus_voting_power_changes_test" , newMockTickerFunc ( true ) , newPersistentKVStore )
css , cleanup := randConsensusNet ( nVals , "consensus_voting_power_changes_test" , newMockTickerFunc ( true ) , newPersistentKVStore )
defer cleanup ( )
defer cleanup ( )
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , nVals )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , nVals )
defer stopConsensusNet ( logger , reactors , eventBuses )
defer stopConsensusNet ( logger , reactors , eventBuses )
// map of active validators
// map of active validators
@ -277,7 +281,7 @@ func TestReactorVotingPowerChange(t *testing.T) {
// wait till everyone makes block 1
// wait till everyone makes block 1
timeoutWaitGroup ( t , nVals , func ( j int ) {
timeoutWaitGroup ( t , nVals , func ( j int ) {
<- eventChan s[ j ]
<- blocksSub s[ j ] . Out ( )
} , css )
} , css )
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
@ -288,10 +292,10 @@ func TestReactorVotingPowerChange(t *testing.T) {
updateValidatorTx := kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 25 )
updateValidatorTx := kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 25 )
previousTotalVotingPower := css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
previousTotalVotingPower := css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , eventChan s, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , blocksSub s, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css )
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -300,10 +304,10 @@ func TestReactorVotingPowerChange(t *testing.T) {
updateValidatorTx = kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 2 )
updateValidatorTx = kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 2 )
previousTotalVotingPower = css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
previousTotalVotingPower = css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , eventChan s, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , blocksSub s, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css )
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -312,10 +316,10 @@ func TestReactorVotingPowerChange(t *testing.T) {
updateValidatorTx = kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 26 )
updateValidatorTx = kvstore . MakeValSetChangeTx ( val1PubKeyABCI , 26 )
previousTotalVotingPower = css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
previousTotalVotingPower = css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , eventChan s, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nVals , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css , updateValidatorTx )
waitForAndValidateBlockWithTx ( t , nVals , activeVals , blocksSub s, css , updateValidatorTx )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css )
waitForAndValidateBlock ( t , nVals , activeVals , blocksSub s, css )
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
if css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
t . Fatalf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ 0 ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -329,7 +333,7 @@ func TestReactorValidatorSetChanges(t *testing.T) {
defer cleanup ( )
defer cleanup ( )
logger := log . TestingLogger ( )
logger := log . TestingLogger ( )
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , nPeers )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , nPeers )
defer stopConsensusNet ( logger , reactors , eventBuses )
defer stopConsensusNet ( logger , reactors , eventBuses )
// map of active validators
// map of active validators
@ -341,7 +345,7 @@ func TestReactorValidatorSetChanges(t *testing.T) {
// wait till everyone makes block 1
// wait till everyone makes block 1
timeoutWaitGroup ( t , nPeers , func ( j int ) {
timeoutWaitGroup ( t , nPeers , func ( j int ) {
<- eventChan s[ j ]
<- blocksSub s[ j ] . Out ( )
} , css )
} , css )
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
@ -354,22 +358,22 @@ func TestReactorValidatorSetChanges(t *testing.T) {
// wait till everyone makes block 2
// wait till everyone makes block 2
// ensure the commit includes all validators
// ensure the commit includes all validators
// send newValTx to change vals in block 3
// send newValTx to change vals in block 3
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css , newValidatorTx1 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css , newValidatorTx1 )
// wait till everyone makes block 3.
// wait till everyone makes block 3.
// it includes the commit for block 2, which is by the original validator set
// it includes the commit for block 2, which is by the original validator set
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , eventChan s, css , newValidatorTx1 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocksSub s, css , newValidatorTx1 )
// wait till everyone makes block 4.
// wait till everyone makes block 4.
// it includes the commit for block 3, which is by the original validator set
// it includes the commit for block 3, which is by the original validator set
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css )
// the commits for block 4 should be with the updated validator set
// the commits for block 4 should be with the updated validator set
activeVals [ string ( newValidatorPubKey1 . Address ( ) ) ] = struct { } { }
activeVals [ string ( newValidatorPubKey1 . Address ( ) ) ] = struct { } { }
// wait till everyone makes block 5
// wait till everyone makes block 5
// it includes the commit for block 4, which should have the updated validator set
// it includes the commit for block 4, which should have the updated validator set
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , eventChan s, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocksSub s, css )
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
logger . Info ( "---------------------------- Testing changing the voting power of one validator" )
logger . Info ( "---------------------------- Testing changing the voting power of one validator" )
@ -379,10 +383,10 @@ func TestReactorValidatorSetChanges(t *testing.T) {
updateValidatorTx1 := kvstore . MakeValSetChangeTx ( updatePubKey1ABCI , 25 )
updateValidatorTx1 := kvstore . MakeValSetChangeTx ( updatePubKey1ABCI , 25 )
previousTotalVotingPower := css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
previousTotalVotingPower := css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( )
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css , updateValidatorTx1 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , eventChan s, css , updateValidatorTx1 )
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css , updateValidatorTx1 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocksSub s, css , updateValidatorTx1 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocksSub s, css )
if css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
if css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) == previousTotalVotingPower {
t . Errorf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
t . Errorf ( "expected voting power to change (before: %d, after: %d)" , previousTotalVotingPower , css [ nVals ] . GetRoundState ( ) . LastValidators . TotalVotingPower ( ) )
@ -399,12 +403,12 @@ func TestReactorValidatorSetChanges(t *testing.T) {
newVal3ABCI := types . TM2PB . PubKey ( newValidatorPubKey3 )
newVal3ABCI := types . TM2PB . PubKey ( newValidatorPubKey3 )
newValidatorTx3 := kvstore . MakeValSetChangeTx ( newVal3ABCI , testMinPower )
newValidatorTx3 := kvstore . MakeValSetChangeTx ( newVal3ABCI , testMinPower )
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , eventChan s, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocksSub s, css , newValidatorTx2 , newValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css )
activeVals [ string ( newValidatorPubKey2 . Address ( ) ) ] = struct { } { }
activeVals [ string ( newValidatorPubKey2 . Address ( ) ) ] = struct { } { }
activeVals [ string ( newValidatorPubKey3 . Address ( ) ) ] = struct { } { }
activeVals [ string ( newValidatorPubKey3 . Address ( ) ) ] = struct { } { }
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , eventChan s, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocksSub s, css )
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
logger . Info ( "---------------------------- Testing removing two validators at once" )
logger . Info ( "---------------------------- Testing removing two validators at once" )
@ -412,12 +416,12 @@ func TestReactorValidatorSetChanges(t *testing.T) {
removeValidatorTx2 := kvstore . MakeValSetChangeTx ( newVal2ABCI , 0 )
removeValidatorTx2 := kvstore . MakeValSetChangeTx ( newVal2ABCI , 0 )
removeValidatorTx3 := kvstore . MakeValSetChangeTx ( newVal3ABCI , 0 )
removeValidatorTx3 := kvstore . MakeValSetChangeTx ( newVal3ABCI , 0 )
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , eventChan s, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , eventChan s, css )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlockWithTx ( t , nPeers , activeVals , blocksSub s, css , removeValidatorTx2 , removeValidatorTx3 )
waitForAndValidateBlock ( t , nPeers , activeVals , blocksSub s, css )
delete ( activeVals , string ( newValidatorPubKey2 . Address ( ) ) )
delete ( activeVals , string ( newValidatorPubKey2 . Address ( ) ) )
delete ( activeVals , string ( newValidatorPubKey3 . Address ( ) ) )
delete ( activeVals , string ( newValidatorPubKey3 . Address ( ) ) )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , eventChan s, css )
waitForBlockWithUpdatedValsAndValidateIt ( t , nPeers , activeVals , blocksSub s, css )
}
}
// Check we can make blocks with skip_timeout_commit=false
// Check we can make blocks with skip_timeout_commit=false
@ -430,23 +434,27 @@ func TestReactorWithTimeoutCommit(t *testing.T) {
css [ i ] . config . SkipTimeoutCommit = false
css [ i ] . config . SkipTimeoutCommit = false
}
}
reactors , eventChan s, eventBuses := startConsensusNet ( t , css , N - 1 )
reactors , blocksSub s, eventBuses := startConsensusNet ( t , css , N - 1 )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
defer stopConsensusNet ( log . TestingLogger ( ) , reactors , eventBuses )
// wait till everyone makes the first new block
// wait till everyone makes the first new block
timeoutWaitGroup ( t , N - 1 , func ( j int ) {
timeoutWaitGroup ( t , N - 1 , func ( j int ) {
<- eventChan s[ j ]
<- blocksSub s[ j ] . Out ( )
} , css )
} , css )
}
}
func waitForAndValidateBlock ( t * testing . T , n int , activeVals map [ string ] struct { } , eventChans [ ] chan interface { } , css [ ] * ConsensusState , txs ... [ ] byte ) {
func waitForAndValidateBlock (
t * testing . T ,
n int ,
activeVals map [ string ] struct { } ,
blocksSubs [ ] types . Subscription ,
css [ ] * ConsensusState ,
txs ... [ ] byte ,
) {
timeoutWaitGroup ( t , n , func ( j int ) {
timeoutWaitGroup ( t , n , func ( j int ) {
css [ j ] . Logger . Debug ( "waitForAndValidateBlock" )
css [ j ] . Logger . Debug ( "waitForAndValidateBlock" )
newBlockI , ok := <- eventChans [ j ]
if ! ok {
return
}
newBlock := newBlockI . ( types . EventDataNewBlock ) . Block
msg := <- blocksSubs [ j ] . Out ( )
newBlock := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
css [ j ] . Logger . Debug ( "waitForAndValidateBlock: Got block" , "height" , newBlock . Height )
css [ j ] . Logger . Debug ( "waitForAndValidateBlock: Got block" , "height" , newBlock . Height )
err := validateBlock ( newBlock , activeVals )
err := validateBlock ( newBlock , activeVals )
assert . Nil ( t , err )
assert . Nil ( t , err )
@ -457,17 +465,21 @@ func waitForAndValidateBlock(t *testing.T, n int, activeVals map[string]struct{}
} , css )
} , css )
}
}
func waitForAndValidateBlockWithTx ( t * testing . T , n int , activeVals map [ string ] struct { } , eventChans [ ] chan interface { } , css [ ] * ConsensusState , txs ... [ ] byte ) {
func waitForAndValidateBlockWithTx (
t * testing . T ,
n int ,
activeVals map [ string ] struct { } ,
blocksSubs [ ] types . Subscription ,
css [ ] * ConsensusState ,
txs ... [ ] byte ,
) {
timeoutWaitGroup ( t , n , func ( j int ) {
timeoutWaitGroup ( t , n , func ( j int ) {
ntxs := 0
ntxs := 0
BLOCK_TX_LOOP :
BLOCK_TX_LOOP :
for {
for {
css [ j ] . Logger . Debug ( "waitForAndValidateBlockWithTx" , "ntxs" , ntxs )
css [ j ] . Logger . Debug ( "waitForAndValidateBlockWithTx" , "ntxs" , ntxs )
newBlockI , ok := <- eventChans [ j ]
if ! ok {
return
}
newBlock := newBlockI . ( types . EventDataNewBlock ) . Block
msg := <- blocksSubs [ j ] . Out ( )
newBlock := msg . Data ( ) . ( types . EventDataNewBlock ) . Block
css [ j ] . Logger . Debug ( "waitForAndValidateBlockWithTx: Got block" , "height" , newBlock . Height )
css [ j ] . Logger . Debug ( "waitForAndValidateBlockWithTx: Got block" , "height" , newBlock . Height )
err := validateBlock ( newBlock , activeVals )
err := validateBlock ( newBlock , activeVals )
assert . Nil ( t , err )
assert . Nil ( t , err )
@ -488,18 +500,21 @@ func waitForAndValidateBlockWithTx(t *testing.T, n int, activeVals map[string]st
} , css )
} , css )
}
}
func waitForBlockWithUpdatedValsAndValidateIt ( t * testing . T , n int , updatedVals map [ string ] struct { } , eventChans [ ] chan interface { } , css [ ] * ConsensusState ) {
func waitForBlockWithUpdatedValsAndValidateIt (
t * testing . T ,
n int ,
updatedVals map [ string ] struct { } ,
blocksSubs [ ] types . Subscription ,
css [ ] * ConsensusState ,
) {
timeoutWaitGroup ( t , n , func ( j int ) {
timeoutWaitGroup ( t , n , func ( j int ) {
var newBlock * types . Block
var newBlock * types . Block
LOOP :
LOOP :
for {
for {
css [ j ] . Logger . Debug ( "waitForBlockWithUpdatedValsAndValidateIt" )
css [ j ] . Logger . Debug ( "waitForBlockWithUpdatedValsAndValidateIt" )
newBlockI , ok := <- eventChans [ j ]
if ! ok {
return
}
newBlock = newBlockI . ( types . EventDataNewBlock ) . Block
msg := <- blocksSubs [ j ] . Out ( )
newBlock = msg . Data ( ) . ( types . EventDataNewBlock ) . Block
if newBlock . LastCommit . Size ( ) == len ( updatedVals ) {
if newBlock . LastCommit . Size ( ) == len ( updatedVals ) {
css [ j ] . Logger . Debug ( "waitForBlockWithUpdatedValsAndValidateIt: Got block" , "height" , newBlock . Height )
css [ j ] . Logger . Debug ( "waitForBlockWithUpdatedValsAndValidateIt: Got block" , "height" , newBlock . Height )
break LOOP
break LOOP