mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-11 10:36:18 +00:00
Refactor so building and linting works
This is the first step towards implementing vote extensions: generating the relevant proto stubs and getting the build and linter to pass. Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
@@ -120,14 +120,16 @@ func (vs *validatorStub) signVote(
|
||||
}
|
||||
|
||||
vote := &types.Vote{
|
||||
ValidatorIndex: vs.Index,
|
||||
ValidatorAddress: pubKey.Address(),
|
||||
Height: vs.Height,
|
||||
Round: vs.Round,
|
||||
Timestamp: vs.clock.Now(),
|
||||
Type: voteType,
|
||||
BlockID: blockID,
|
||||
VoteExtension: types.VoteExtensionFromProto(kvstore.ConstructVoteExtension(pubKey.Address())),
|
||||
Type: voteType,
|
||||
Height: vs.Height,
|
||||
Round: vs.Round,
|
||||
BlockID: blockID,
|
||||
Timestamp: vs.clock.Now(),
|
||||
ValidatorAddress: pubKey.Address(),
|
||||
ValidatorIndex: vs.Index,
|
||||
Signature: []byte{},
|
||||
Extension: []byte{},
|
||||
ExtensionSignature: []byte{},
|
||||
}
|
||||
v := vote.ToProto()
|
||||
if err := vs.PrivValidator.SignVote(ctx, chainID, v); err != nil {
|
||||
@@ -158,10 +160,6 @@ func signVote(
|
||||
v, err := vs.signVote(ctx, voteType, chainID, blockID)
|
||||
require.NoError(t, err, "failed to sign vote")
|
||||
|
||||
// TODO: remove hardcoded vote extension.
|
||||
// currently set for abci/examples/kvstore/persistent_kvstore.go
|
||||
v.VoteExtension = types.VoteExtensionFromProto(kvstore.ConstructVoteExtension(v.ValidatorAddress))
|
||||
|
||||
vs.lastVote = v
|
||||
|
||||
return v
|
||||
|
||||
@@ -357,11 +357,6 @@ func TestConsMsgsVectors(t *testing.T) {
|
||||
}
|
||||
pbProposal := proposal.ToProto()
|
||||
|
||||
ext := types.VoteExtension{
|
||||
AppDataToSign: []byte("signed"),
|
||||
AppDataSelfAuthenticating: []byte("auth"),
|
||||
}
|
||||
|
||||
v := &types.Vote{
|
||||
ValidatorAddress: []byte("add_more_exclamation"),
|
||||
ValidatorIndex: 1,
|
||||
@@ -370,7 +365,7 @@ func TestConsMsgsVectors(t *testing.T) {
|
||||
Timestamp: date,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: bi,
|
||||
VoteExtension: ext,
|
||||
Extension: []byte("signed"),
|
||||
}
|
||||
vpb := v.ToProto()
|
||||
|
||||
|
||||
@@ -2466,7 +2466,7 @@ func (cs *State) signVote(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vote.VoteExtension = ext
|
||||
vote.Extension = ext
|
||||
case tmproto.PrevoteType:
|
||||
timeout = cs.config.TimeoutPrevote
|
||||
default:
|
||||
|
||||
@@ -1990,7 +1990,7 @@ func TestFinalizeBlockCalled(t *testing.T) {
|
||||
m := abcimocks.NewBaseMock()
|
||||
m.On("ProcessProposal", mock.Anything).Return(abcitypes.ResponseProcessProposal{Accept: true})
|
||||
m.On("VerifyVoteExtension", mock.Anything).Return(abcitypes.ResponseVerifyVoteExtension{
|
||||
Result: abcitypes.ResponseVerifyVoteExtension_ACCEPT,
|
||||
Accept: true,
|
||||
})
|
||||
m.On("FinalizeBlock", mock.Anything).Return(abcitypes.ResponseFinalizeBlock{}).Maybe()
|
||||
cs1, vss := makeState(ctx, t, makeStateArgs{config: config, application: m})
|
||||
|
||||
@@ -310,21 +310,25 @@ func (blockExec *BlockExecutor) ApplyBlock(
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func (blockExec *BlockExecutor) ExtendVote(ctx context.Context, vote *types.Vote) (types.VoteExtension, error) {
|
||||
func (blockExec *BlockExecutor) ExtendVote(ctx context.Context, vote *types.Vote) ([]byte, error) {
|
||||
req := abci.RequestExtendVote{
|
||||
Vote: vote.ToProto(),
|
||||
Hash: vote.BlockID.Hash,
|
||||
Height: vote.Height,
|
||||
}
|
||||
|
||||
resp, err := blockExec.appClient.ExtendVote(ctx, req)
|
||||
if err != nil {
|
||||
return types.VoteExtension{}, err
|
||||
return nil, err
|
||||
}
|
||||
return types.VoteExtensionFromProto(resp.VoteExtension), nil
|
||||
return resp.VoteExtension, nil
|
||||
}
|
||||
|
||||
func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *types.Vote) error {
|
||||
req := abci.RequestVerifyVoteExtension{
|
||||
Vote: vote.ToProto(),
|
||||
Hash: []byte{},
|
||||
ValidatorAddress: []byte{},
|
||||
Height: 0,
|
||||
VoteExtension: []byte{},
|
||||
}
|
||||
|
||||
resp, err := blockExec.appClient.VerifyVoteExtension(ctx, req)
|
||||
@@ -332,7 +336,7 @@ func (blockExec *BlockExecutor) VerifyVoteExtension(ctx context.Context, vote *t
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.IsErr() {
|
||||
if !resp.Accept {
|
||||
return types.ErrVoteInvalidExtension
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user