mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-11 04:11:21 +00:00
fix consensus tests
This commit is contained in:
@ -203,6 +203,18 @@ func waitFor(t *testing.T, cs *ConsensusState, height int, round int, step Round
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func incrementHeight(vss ...*validatorStub) {
|
||||||
|
for _, vs := range vss {
|
||||||
|
vs.Height += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func incrementRound(vss ...*validatorStub) {
|
||||||
|
for _, vs := range vss {
|
||||||
|
vs.Round += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *validatorStub, blockHash []byte) {
|
func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *validatorStub, blockHash []byte) {
|
||||||
prevotes := cs.Votes.Prevotes(round)
|
prevotes := cs.Votes.Prevotes(round)
|
||||||
var vote *types.Vote
|
var vote *types.Vote
|
||||||
@ -220,15 +232,14 @@ func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *valid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func incrementHeight(vss ...*validatorStub) {
|
func validateLastPrecommit(t *testing.T, cs *ConsensusState, privVal *validatorStub, blockHash []byte) {
|
||||||
for _, vs := range vss {
|
votes := cs.LastCommit
|
||||||
vs.Height += 1
|
var vote *types.Vote
|
||||||
|
if vote = votes.GetByAddress(privVal.Address); vote == nil {
|
||||||
|
panic("Failed to find precommit from validator")
|
||||||
}
|
}
|
||||||
}
|
if !bytes.Equal(vote.BlockHash, blockHash) {
|
||||||
|
panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockHash))
|
||||||
func incrementRound(vss ...*validatorStub) {
|
|
||||||
for _, vs := range vss {
|
|
||||||
vs.Round += 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +343,23 @@ func subscribeToEvent(cs *ConsensusState, eventID string) chan interface{} {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func subscribeToVoter(cs *ConsensusState, addr []byte) chan interface{} {
|
||||||
|
|
||||||
|
voteCh0 := subscribeToEvent(cs, types.EventStringVote())
|
||||||
|
voteCh := make(chan interface{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
v := <-voteCh0
|
||||||
|
vote := v.(*types.EventDataVote)
|
||||||
|
// we only fire for our own votes
|
||||||
|
if bytes.Equal(addr, vote.Address) {
|
||||||
|
voteCh <- v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return voteCh
|
||||||
|
}
|
||||||
|
|
||||||
func randGenesisState(numValidators int, randPower bool, minPower int64) (*sm.State, []*types.PrivValidator) {
|
func randGenesisState(numValidators int, randPower bool, minPower int64) (*sm.State, []*types.PrivValidator) {
|
||||||
db := dbm.NewMemDB()
|
db := dbm.NewMemDB()
|
||||||
genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
|
genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
|
||||||
|
@ -332,7 +332,7 @@ func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *t
|
|||||||
cs.SetProposal(proposal, peerKey)
|
cs.SetProposal(proposal, peerKey)
|
||||||
for i := 0; i < parts.Total(); i++ {
|
for i := 0; i < parts.Total(); i++ {
|
||||||
part := parts.GetPart(i)
|
part := parts.GetPart(i)
|
||||||
cs.AddProposalBlockPart(cs.Height, cs.Round, part, peerKey)
|
cs.AddProposalBlockPart(proposal.Height, proposal.Round, part, peerKey)
|
||||||
}
|
}
|
||||||
return nil // TODO errors
|
return nil // TODO errors
|
||||||
}
|
}
|
||||||
@ -1219,7 +1219,7 @@ func (cs *ConsensusState) addProposalBlockPart(height int, part *types.Part) (ad
|
|||||||
var n int
|
var n int
|
||||||
var err error
|
var err error
|
||||||
cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(), types.MaxBlockSize, &n, &err).(*types.Block)
|
cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(), types.MaxBlockSize, &n, &err).(*types.Block)
|
||||||
log.Info("Received complete proposal", "hash", cs.ProposalBlock.Hash())
|
log.Info("Received complete proposal", "hash", cs.ProposalBlock.Hash(), "round", cs.Proposal.Round)
|
||||||
if cs.Step == RoundStepPropose && cs.isProposalComplete() {
|
if cs.Step == RoundStepPropose && cs.isProposalComplete() {
|
||||||
// Move onto the next step
|
// Move onto the next step
|
||||||
cs.EnterPrevote(height, cs.Round)
|
cs.EnterPrevote(height, cs.Round)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -62,8 +62,12 @@ func (b *Block) ValidateBasic(chainID string, lastBlockHeight int, lastBlockHash
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) FillHeader() {
|
func (b *Block) FillHeader() {
|
||||||
b.LastValidationHash = b.LastValidation.Hash()
|
if b.LastValidationHash == nil {
|
||||||
b.DataHash = b.Data.Hash()
|
b.LastValidationHash = b.LastValidation.Hash()
|
||||||
|
}
|
||||||
|
if b.DataHash == nil {
|
||||||
|
b.DataHash = b.Data.Hash()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Computes and returns the block hash.
|
// Computes and returns the block hash.
|
||||||
|
Reference in New Issue
Block a user