mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-26 07:12:16 +00:00
fixes from Frey's review
This commit is contained in:
parent
808b830942
commit
7f649ccf23
@ -76,19 +76,11 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
|
|||||||
}
|
}
|
||||||
proxyAppConn.SetResponseCallback(proxyCb)
|
proxyAppConn.SetResponseCallback(proxyCb)
|
||||||
|
|
||||||
// determine validators who did not sign last block
|
// determine which validators did not sign last block
|
||||||
absentVals := make([]int32, 0)
|
absentVals := make([]int32, 0)
|
||||||
for valA, _ := range lastValidators.Validators {
|
for valI, vote := range block.LastCommit.Precommits {
|
||||||
found := false
|
if vote == nil {
|
||||||
for _, voteB := range block.LastCommit.Precommits {
|
absentVals = append(absentVals, int32(valI))
|
||||||
valB := voteB.ValidatorIndex
|
|
||||||
if valA == valB {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
absentVals = append(absentVals, int32(valA))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package state
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -60,23 +61,34 @@ func TestBeginBlockAbsentValidators(t *testing.T) {
|
|||||||
types.NewValidator(val2PrivKey.PubKey(), 5),
|
types.NewValidator(val2PrivKey.PubKey(), 5),
|
||||||
})
|
})
|
||||||
|
|
||||||
// but last commit contains only the first validator
|
|
||||||
prevHash := state.LastBlockID.Hash
|
prevHash := state.LastBlockID.Hash
|
||||||
prevParts := types.PartSetHeader{}
|
prevParts := types.PartSetHeader{}
|
||||||
prevBlockID := types.BlockID{prevHash, prevParts}
|
prevBlockID := types.BlockID{prevHash, prevParts}
|
||||||
lastCommit := &types.Commit{BlockID: prevBlockID, Precommits: []*types.Vote{
|
|
||||||
{ValidatorIndex: 0},
|
now := time.Now().UTC()
|
||||||
}}
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
lastCommitPrecommits []*types.Vote
|
||||||
|
expectedAbsentValidators []int32
|
||||||
|
}{
|
||||||
|
{"none absent", []*types.Vote{{ValidatorIndex: 0, Timestamp: now}, {ValidatorIndex: 1, Timestamp: now}}, []int32{}},
|
||||||
|
{"one absent", []*types.Vote{{ValidatorIndex: 0, Timestamp: now}, nil}, []int32{1}},
|
||||||
|
{"multiple absent", []*types.Vote{nil, nil}, []int32{0, 1}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
lastCommit := &types.Commit{BlockID: prevBlockID, Precommits: tc.lastCommitPrecommits}
|
||||||
|
|
||||||
valHash := state.Validators.Hash()
|
valHash := state.Validators.Hash()
|
||||||
block, _ := types.MakeBlock(2, chainID, makeTxs(2), lastCommit,
|
block, _ := types.MakeBlock(2, chainID, makeTxs(2), state.LastBlockTotalTx, lastCommit,
|
||||||
prevBlockID, valHash, state.AppHash, testPartSize)
|
prevBlockID, valHash, state.AppHash, testPartSize)
|
||||||
|
|
||||||
_, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), lastValidators)
|
_, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), lastValidators)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err, tc.desc)
|
||||||
|
|
||||||
// -> app must receive an index of the absent validator
|
// -> app must receive an index of the absent validator
|
||||||
assert.Equal(t, []int32{1}, app.AbsentValidators)
|
assert.Equal(t, tc.expectedAbsentValidators, app.AbsentValidators, tc.desc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user