mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-10 03:51:20 +00:00
fix consensus tests
This commit is contained in:
parent
07a96a703e
commit
9dea9539b4
@ -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) {
|
||||
prevotes := cs.Votes.Prevotes(round)
|
||||
var vote *types.Vote
|
||||
@ -220,15 +232,14 @@ func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *valid
|
||||
}
|
||||
}
|
||||
|
||||
func incrementHeight(vss ...*validatorStub) {
|
||||
for _, vs := range vss {
|
||||
vs.Height += 1
|
||||
func validateLastPrecommit(t *testing.T, cs *ConsensusState, privVal *validatorStub, blockHash []byte) {
|
||||
votes := cs.LastCommit
|
||||
var vote *types.Vote
|
||||
if vote = votes.GetByAddress(privVal.Address); vote == nil {
|
||||
panic("Failed to find precommit from validator")
|
||||
}
|
||||
}
|
||||
|
||||
func incrementRound(vss ...*validatorStub) {
|
||||
for _, vs := range vss {
|
||||
vs.Round += 1
|
||||
if !bytes.Equal(vote.BlockHash, blockHash) {
|
||||
panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockHash))
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,6 +343,23 @@ func subscribeToEvent(cs *ConsensusState, eventID string) chan interface{} {
|
||||
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) {
|
||||
db := dbm.NewMemDB()
|
||||
genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
|
||||
|
@ -332,7 +332,7 @@ func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *t
|
||||
cs.SetProposal(proposal, peerKey)
|
||||
for i := 0; i < parts.Total(); 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
|
||||
}
|
||||
@ -1219,7 +1219,7 @@ func (cs *ConsensusState) addProposalBlockPart(height int, part *types.Part) (ad
|
||||
var n int
|
||||
var err error
|
||||
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() {
|
||||
// Move onto the next step
|
||||
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() {
|
||||
b.LastValidationHash = b.LastValidation.Hash()
|
||||
b.DataHash = b.Data.Hash()
|
||||
if b.LastValidationHash == nil {
|
||||
b.LastValidationHash = b.LastValidation.Hash()
|
||||
}
|
||||
if b.DataHash == nil {
|
||||
b.DataHash = b.Data.Hash()
|
||||
}
|
||||
}
|
||||
|
||||
// Computes and returns the block hash.
|
||||
|
Loading…
x
Reference in New Issue
Block a user