Browse Source

fixes from Frey's review

pull/954/head
Anton Kaliaev 7 years ago
parent
commit
7f649ccf23
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 27 additions and 23 deletions
  1. +4
    -12
      state/execution.go
  2. +23
    -11
      state/execution_test.go

+ 4
- 12
state/execution.go View File

@ -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 {
found := false
for _, voteB := range block.LastCommit.Precommits {
valB := voteB.ValidatorIndex
if valA == valB {
found = true
break
}
}
if !found {
absentVals = append(absentVals, int32(valA))
for valI, vote := range block.LastCommit.Precommits {
if vote == nil {
absentVals = append(absentVals, int32(valI))
} }
} }


+ 23
- 11
state/execution_test.go View File

@ -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},
}}
valHash := state.Validators.Hash()
block, _ := types.MakeBlock(2, chainID, makeTxs(2), lastCommit,
prevBlockID, valHash, state.AppHash, testPartSize)
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}},
}
_, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), lastValidators)
require.Nil(t, err)
for _, tc := range testCases {
lastCommit := &types.Commit{BlockID: prevBlockID, Precommits: tc.lastCommitPrecommits}
// -> app must receive an index of the absent validator
assert.Equal(t, []int32{1}, app.AbsentValidators)
valHash := state.Validators.Hash()
block, _ := types.MakeBlock(2, chainID, makeTxs(2), state.LastBlockTotalTx, lastCommit,
prevBlockID, valHash, state.AppHash, testPartSize)
_, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), lastValidators)
require.Nil(t, err, tc.desc)
// -> app must receive an index of the absent validator
assert.Equal(t, tc.expectedAbsentValidators, app.AbsentValidators, tc.desc)
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------


Loading…
Cancel
Save