@ -18,6 +18,7 @@ import (
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/merkle"
sm "github.com/tendermint/tendermint/internal/state"
sm "github.com/tendermint/tendermint/internal/state"
statefactory "github.com/tendermint/tendermint/internal/state/test/factory"
statefactory "github.com/tendermint/tendermint/internal/state/test/factory"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
@ -103,8 +104,7 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
state . LastBlockHeight ++
state . LastBlockHeight ++
// Build mock responses.
// Build mock responses.
block , err := statefactory . MakeBlock ( state , 2 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( state , 2 , new ( types . Commit ) )
abciResponses := new ( tmstate . ABCIResponses )
abciResponses := new ( tmstate . ABCIResponses )
dtxs := make ( [ ] * abci . ExecTxResult , 2 )
dtxs := make ( [ ] * abci . ExecTxResult , 2 )
@ -205,14 +205,13 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
res , err := stateStore . LoadABCIResponses ( h )
res , err := stateStore . LoadABCIResponses ( h )
if assert . NoError ( t , err , "%d" , i ) {
if assert . NoError ( t , err , "%d" , i ) {
t . Log ( res )
t . Log ( res )
responses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
TxResults : tc . expected ,
} ,
}
sm . ABCIResponsesResultsHash ( res )
sm . ABCIResponsesResultsHash ( responses )
assert . Equal ( t , sm . ABCIResponsesResultsHash ( responses ) , sm . ABCIResponsesResultsHash ( res ) , "%d" , i )
e , err := abci . MarshalTxResults ( tc . expected )
require . NoError ( t , err )
he := merkle . HashFromByteSlices ( e )
rs , err := abci . MarshalTxResults ( res . FinalizeBlock . TxResults )
hrs := merkle . HashFromByteSlices ( rs )
require . NoError ( t , err )
assert . Equal ( t , he , hrs , "%d" , i )
}
}
}
}
}
}
@ -278,9 +277,12 @@ func TestOneValidatorChangesSaveLoad(t *testing.T) {
header , blockID , responses := makeHeaderPartsResponsesValPowerChange ( t , state , power )
header , blockID , responses := makeHeaderPartsResponsesValPowerChange ( t , state , power )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( responses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( responses . FinalizeBlock . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
state , err = state . Update ( blockID , & header , sm . ABCIResponsesResultsHash ( responses ) , responses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( responses . FinalizeBlock . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
state , err = state . Update ( blockID , & header , h , responses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
err := stateStore . Save ( state )
err = stateStore . Save ( state )
require . NoError ( t , err )
require . NoError ( t , err )
}
}
@ -451,19 +453,19 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) {
// NewValidatorSet calls IncrementProposerPriority but uses on a copy of val1
// NewValidatorSet calls IncrementProposerPriority but uses on a copy of val1
assert . EqualValues ( t , 0 , val1 . ProposerPriority )
assert . EqualValues ( t , 0 , val1 . ProposerPriority )
block , err := statefactory . MakeBlock ( state , state . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( state , state . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
require . NoError ( t , err )
updatedState , err := state . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
h := merkle . HashFromByteSlices ( rs )
updatedState , err := state . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
curTotal := val1VotingPower
curTotal := val1VotingPower
// one increment step and one validator: 0 + power - total_power == 0
// one increment step and one validator: 0 + power - total_power == 0
@ -478,7 +480,10 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) {
updateAddVal := abci . ValidatorUpdate { PubKey : fvp , Power : val2VotingPower }
updateAddVal := abci . ValidatorUpdate { PubKey : fvp , Power : val2VotingPower }
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { updateAddVal } )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { updateAddVal } )
assert . NoError ( t , err )
assert . NoError ( t , err )
updatedState2 , err := updatedState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err = abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h = merkle . HashFromByteSlices ( rs )
updatedState2 , err := updatedState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
require . Equal ( t , len ( updatedState2 . NextValidators . Validators ) , 2 )
require . Equal ( t , len ( updatedState2 . NextValidators . Validators ) , 2 )
@ -517,7 +522,10 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) {
// this will cause the diff of priorities (77)
// this will cause the diff of priorities (77)
// to be larger than threshold == 2*totalVotingPower (22):
// to be larger than threshold == 2*totalVotingPower (22):
updatedState3 , err := updatedState2 . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err = abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h = merkle . HashFromByteSlices ( rs )
updatedState3 , err := updatedState2 . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
require . Equal ( t , len ( updatedState3 . NextValidators . Validators ) , 2 )
require . Equal ( t , len ( updatedState3 . NextValidators . Validators ) , 2 )
@ -569,21 +577,21 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
// we only have one validator:
// we only have one validator:
assert . Equal ( t , val1PubKey . Address ( ) , state . Validators . Proposer . Address )
assert . Equal ( t , val1PubKey . Address ( ) , state . Validators . Proposer . Address )
block , err := statefactory . MakeBlock ( state , state . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( state , state . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
// no updates:
// no updates:
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
updatedState , err := state . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
updatedState , err := state . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
// 0 + 10 (initial prio) - 10 (avg) - 10 (mostest - total) = -10
// 0 + 10 (initial prio) - 10 (avg) - 10 (mostest - total) = -10
@ -600,7 +608,10 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { updateAddVal } )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { updateAddVal } )
assert . NoError ( t , err )
assert . NoError ( t , err )
updatedState2 , err := updatedState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err = abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h = merkle . HashFromByteSlices ( rs )
updatedState2 , err := updatedState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
require . Equal ( t , len ( updatedState2 . NextValidators . Validators ) , 2 )
require . Equal ( t , len ( updatedState2 . NextValidators . Validators ) , 2 )
@ -640,10 +651,13 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
updatedVal2 ,
updatedVal2 ,
)
)
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
updatedState3 , err := updatedState2 . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err = abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h = merkle . HashFromByteSlices ( rs )
updatedState3 , err := updatedState2 . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
assert . Equal ( t , updatedState3 . Validators . Proposer . Address , updatedState3 . NextValidators . Proposer . Address )
assert . Equal ( t , updatedState3 . Validators . Proposer . Address , updatedState3 . NextValidators . Proposer . Address )
@ -679,15 +693,16 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
// no changes in voting power and both validators have same voting power
// no changes in voting power and both validators have same voting power
// -> proposers should alternate:
// -> proposers should alternate:
oldState := updatedState3
oldState := updatedState3
abciResponses = & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb = & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
oldState , err = oldState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err = abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h = merkle . HashFromByteSlices ( rs )
oldState , err = oldState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
expectedVal1Prio2 = 1
expectedVal1Prio2 = 1
expectedVal2Prio2 = - 1
expectedVal2Prio2 = - 1
@ -696,15 +711,16 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
for i := 0 ; i < 1000 ; i ++ {
for i := 0 ; i < 1000 ; i ++ {
// no validator updates:
// no validator updates:
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
updatedState , err := oldState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
updatedState , err := oldState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
assert . NoError ( t , err )
assert . NoError ( t , err )
// alternate (and cyclic priorities):
// alternate (and cyclic priorities):
assert . NotEqual (
assert . NotEqual (
@ -755,21 +771,21 @@ func TestLargeGenesisValidator(t *testing.T) {
oldState := state
oldState := state
for i := 0 ; i < 10 ; i ++ {
for i := 0 ; i < 10 ; i ++ {
// no updates:
// no updates:
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
block , err := statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
updatedState , err := oldState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
updatedState , err := oldState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
// no changes in voting power (ProposerPrio += VotingPower == Voting in 1st round; than shiftByAvg == 0,
// no changes in voting power (ProposerPrio += VotingPower == Voting in 1st round; than shiftByAvg == 0,
// than -Total == -Voting)
// than -Total == -Voting)
@ -791,41 +807,41 @@ func TestLargeGenesisValidator(t *testing.T) {
firstAddedVal := abci . ValidatorUpdate { PubKey : fvp , Power : firstAddedValVotingPower }
firstAddedVal := abci . ValidatorUpdate { PubKey : fvp , Power : firstAddedValVotingPower }
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { firstAddedVal } )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { firstAddedVal } )
assert . NoError ( t , err )
assert . NoError ( t , err )
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : [ ] abci . ValidatorUpdate { firstAddedVal } ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : [ ] abci . ValidatorUpdate { firstAddedVal } ,
}
}
block , err := statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
updatedState , err := oldState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
updatedState , err := oldState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
lastState := updatedState
lastState := updatedState
for i := 0 ; i < 200 ; i ++ {
for i := 0 ; i < 200 ; i ++ {
// no updates:
// no updates:
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
block , err := statefactory . MakeBlock ( lastState , lastState . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( lastState , lastState . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err = block . MakePartSet ( testPartSize )
bps , err = block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
updatedStateInner , err := lastState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
updatedStateInner , err := lastState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
lastState = updatedStateInner
lastState = updatedStateInner
}
}
@ -851,18 +867,18 @@ func TestLargeGenesisValidator(t *testing.T) {
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { addedVal } )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( [ ] abci . ValidatorUpdate { addedVal } )
assert . NoError ( t , err )
assert . NoError ( t , err )
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : [ ] abci . ValidatorUpdate { addedVal } ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : [ ] abci . ValidatorUpdate { addedVal } ,
}
}
block , err := statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
state , err = state . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
state , err = state . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
}
}
require . Equal ( t , 10 + 2 , len ( state . NextValidators . Validators ) )
require . Equal ( t , 10 + 2 , len ( state . NextValidators . Validators ) )
@ -871,22 +887,23 @@ func TestLargeGenesisValidator(t *testing.T) {
gp , err := encoding . PubKeyToProto ( genesisPubKey )
gp , err := encoding . PubKeyToProto ( genesisPubKey )
require . NoError ( t , err )
require . NoError ( t , err )
removeGenesisVal := abci . ValidatorUpdate { PubKey : gp , Power : 0 }
removeGenesisVal := abci . ValidatorUpdate { PubKey : gp , Power : 0 }
abciResponses = & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : [ ] abci . ValidatorUpdate { removeGenesisVal } ,
} ,
fb = & abci . ResponseFinalizeBlock {
ValidatorUpdates : [ ] abci . ValidatorUpdate { removeGenesisVal } ,
}
}
block , err = statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
block = statefactory . MakeBlock ( oldState , oldState . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
require . NoError ( t , err )
bps , err = block . MakePartSet ( testPartSize )
bps , err = block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID = types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID = types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
updatedState , err = state . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err = abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h = merkle . HashFromByteSlices ( rs )
updatedState , err = state . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
// only the first added val (not the genesis val) should be left
// only the first added val (not the genesis val) should be left
assert . Equal ( t , 11 , len ( updatedState . NextValidators . Validators ) )
assert . Equal ( t , 11 , len ( updatedState . NextValidators . Validators ) )
@ -897,21 +914,21 @@ func TestLargeGenesisValidator(t *testing.T) {
count := 0
count := 0
isProposerUnchanged := true
isProposerUnchanged := true
for isProposerUnchanged {
for isProposerUnchanged {
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb = & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
require . NoError ( t , err )
block , err = statefactory . MakeBlock ( curState , curState . LastBlockHeight + 1 , new ( types . Commit ) )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
block = statefactory . MakeBlock ( curState , curState . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID = types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID = types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
curState , err = curState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
curState , err = curState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
if ! bytes . Equal ( curState . Validators . Proposer . Address , curState . NextValidators . Proposer . Address ) {
if ! bytes . Equal ( curState . Validators . Proposer . Address , curState . NextValidators . Proposer . Address ) {
isProposerUnchanged = false
isProposerUnchanged = false
@ -927,23 +944,23 @@ func TestLargeGenesisValidator(t *testing.T) {
proposers := make ( [ ] * types . Validator , numVals )
proposers := make ( [ ] * types . Validator , numVals )
for i := 0 ; i < 100 ; i ++ {
for i := 0 ; i < 100 ; i ++ {
// no updates:
// no updates:
abciResponses := & tmstate . ABCIResponses {
FinalizeBlock : & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
} ,
fb := & abci . ResponseFinalizeBlock {
ValidatorUpdates : nil ,
}
}
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( abciResponses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err := types . PB2TM . ValidatorUpdates ( fb . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
block , err := statefactory . MakeBlock ( updatedState , updatedState . LastBlockHeight + 1 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( updatedState , updatedState . LastBlockHeight + 1 , new ( types . Commit ) )
bps , err := block . MakePartSet ( testPartSize )
bps , err := block . MakePartSet ( testPartSize )
require . NoError ( t , err )
require . NoError ( t , err )
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
blockID := types . BlockID { Hash : block . Hash ( ) , PartSetHeader : bps . Header ( ) }
updatedState , err = updatedState . Update ( blockID , & block . Header , sm . ABCIResponsesResultsHash ( abciResponses ) , abciResponses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( fb . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
updatedState , err = updatedState . Update ( blockID , & block . Header , h , fb . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
if i > numVals { // expect proposers to cycle through after the first iteration (of numVals blocks):
if i > numVals { // expect proposers to cycle through after the first iteration (of numVals blocks):
if proposers [ i % numVals ] == nil {
if proposers [ i % numVals ] == nil {
@ -1002,7 +1019,10 @@ func TestManyValidatorChangesSaveLoad(t *testing.T) {
var validatorUpdates [ ] * types . Validator
var validatorUpdates [ ] * types . Validator
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( responses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( responses . FinalizeBlock . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
state , err = state . Update ( blockID , & header , sm . ABCIResponsesResultsHash ( responses ) , responses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( responses . FinalizeBlock . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
state , err = state . Update ( blockID , & header , h , responses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
nextHeight := state . LastBlockHeight + 1
nextHeight := state . LastBlockHeight + 1
err = stateStore . Save ( state )
err = stateStore . Save ( state )
@ -1035,8 +1055,7 @@ func TestStateMakeBlock(t *testing.T) {
proposerAddress := state . Validators . GetProposer ( ) . Address
proposerAddress := state . Validators . GetProposer ( ) . Address
stateVersion := state . Version . Consensus
stateVersion := state . Version . Consensus
block , err := statefactory . MakeBlock ( state , 2 , new ( types . Commit ) )
require . NoError ( t , err )
block := statefactory . MakeBlock ( state , 2 , new ( types . Commit ) )
// test we set some fields
// test we set some fields
assert . Equal ( t , stateVersion , block . Version )
assert . Equal ( t , stateVersion , block . Version )
@ -1080,10 +1099,13 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
header , blockID , responses := makeHeaderPartsResponsesParams ( t , state , & cp )
header , blockID , responses := makeHeaderPartsResponsesParams ( t , state , & cp )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( responses . FinalizeBlock . ValidatorUpdates )
validatorUpdates , err = types . PB2TM . ValidatorUpdates ( responses . FinalizeBlock . ValidatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
state , err = state . Update ( blockID , & header , sm . ABCIResponsesResultsHash ( responses ) , responses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
rs , err := abci . MarshalTxResults ( responses . FinalizeBlock . TxResults )
require . NoError ( t , err )
h := merkle . HashFromByteSlices ( rs )
state , err = state . Update ( blockID , & header , h , responses . FinalizeBlock . ConsensusParamUpdates , validatorUpdates )
require . NoError ( t , err )
require . NoError ( t , err )
err := stateStore . Save ( state )
err = stateStore . Save ( state )
require . NoError ( t , err )
require . NoError ( t , err )
}
}