From 058867669e661c50519ca56cdcd283b59497f32f Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Wed, 16 May 2018 16:30:51 +0200 Subject: [PATCH] Pass validator set to ExecCommitBlock, update testcases --- consensus/replay.go | 3 ++- state/execution.go | 4 ++-- state/execution_test.go | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/consensus/replay.go b/consensus/replay.go index 265ab5388..a066c8733 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -365,7 +365,8 @@ func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBl for i := appBlockHeight + 1; i <= finalBlock; i++ { h.logger.Info("Applying block", "height", i) block := h.store.LoadBlock(i) - appHash, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger) + appHash, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger, new(types.ValidatorSet)) + // TODO: Temporary, see above comment. if err != nil { return nil, err } diff --git a/state/execution.go b/state/execution.go index 3fe35e2fa..61544354f 100644 --- a/state/execution.go +++ b/state/execution.go @@ -359,8 +359,8 @@ func fireEvents(logger log.Logger, eventBus types.BlockEventPublisher, block *ty // ExecCommitBlock executes and commits a block on the proxyApp without validating or mutating the state. // It returns the application root hash (result of abci.Commit). -func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block, logger log.Logger) ([]byte, error) { - _, err := execBlockOnProxyApp(logger, appConnConsensus, block) +func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block, logger log.Logger, vs *types.ValidatorSet) ([]byte, error) { + _, err := execBlockOnProxyApp(logger, appConnConsensus, block, vs) if err != nil { logger.Error("Error executing block on proxy app", "height", block.Height, "err", err) return nil, err diff --git a/state/execution_test.go b/state/execution_test.go index 09c40b5a0..0462b0fed 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -66,16 +66,16 @@ func TestBeginBlockAbsentValidators(t *testing.T) { lastCommitPrecommits []*types.Vote expectedAbsentValidators []int32 }{ - {"none absent", []*types.Vote{{ValidatorIndex: 0, Timestamp: now, Type: types.VoteTypePrecommit}, {ValidatorIndex: 1, Timestamp: now}}, []int32{}}, - {"one absent", []*types.Vote{{ValidatorIndex: 0, Timestamp: now, Type: types.VoteTypePrecommit}, nil}, []int32{1}}, - {"multiple absent", []*types.Vote{nil, nil}, []int32{0, 1}}, + {"none absent", []*types.Vote{{ValidatorIndex: 0, Timestamp: now, Type: types.VoteTypePrecommit}, {ValidatorIndex: 1, Timestamp: now}}, [][]byte{}}, + {"one absent", []*types.Vote{{ValidatorIndex: 0, Timestamp: now, Type: types.VoteTypePrecommit}, nil}, [][]byte{privKey2.PubKey().Bytes()}}, + {"multiple absent", []*types.Vote{nil, nil}, [][]byte{privKey.PubKey().Bytes(), privKey2.PubKey().Bytes()}}, } for _, tc := range testCases { lastCommit := &types.Commit{BlockID: prevBlockID, Precommits: tc.lastCommitPrecommits} block, _ := state.MakeBlock(2, makeTxs(2), lastCommit) - _, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger()) + _, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), state.Validators) require.Nil(t, err, tc.desc) // -> app must receive an index of the absent validator @@ -120,7 +120,7 @@ func TestBeginBlockByzantineValidators(t *testing.T) { block, _ := state.MakeBlock(10, makeTxs(2), lastCommit) block.Evidence.Evidence = tc.evidence - _, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger()) + _, err = ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), state.Validators) require.Nil(t, err, tc.desc) // -> app must receive an index of the byzantine validator