implement vote extensions

This commit is contained in:
Callum Waters
2022-10-13 10:15:55 +02:00
parent 1e9f0afbe6
commit f809a0f1a2
46 changed files with 3397 additions and 1060 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ func MakeHeader(t *testing.T, h *types.Header) *types.Header {
if h.Height == 0 {
h.Height = 1
}
if h.LastBlockID.IsZero() {
if h.LastBlockID.IsNil() {
h.LastBlockID = MakeBlockID()
}
if h.ChainID == "" {
+11 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/types"
)
func MakeCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.Commit, error) {
func MakeExtendedCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.ExtendedCommit, error) {
// all sign
for i := 0; i < len(validators); i++ {
pubKey, err := validators[i].GetPubKey()
@@ -32,12 +32,21 @@ func MakeCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, valida
return nil, err
}
vote.Signature = v.Signature
vote.ExtensionSignature = v.ExtensionSignature
if _, err := voteSet.AddVote(vote); err != nil {
return nil, err
}
}
return voteSet.MakeCommit(), nil
return voteSet.MakeExtendedCommit(), nil
}
func MakeCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.Commit, error) {
extCommit, err := MakeExtendedCommitFromVoteSet(blockID, voteSet, validators, now)
if err != nil {
return nil, err
}
return extCommit.ToCommit(), nil
}
func MakeVoteSet(lastState sm.State, round int32) *types.VoteSet {
+12 -3
View File
@@ -3,16 +3,25 @@ package test
import (
"time"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types"
)
func ConsensusParams() *types.ConsensusParams {
c := types.DefaultConsensusParams()
// enable vote extensions
c.ABCI.VoteExtensionsEnableHeight = 1
return c
}
func GenesisDoc(
config *cfg.Config,
chainID string,
time time.Time,
validators []*types.Validator,
consensusParams *types.ConsensusParams,
) *types.GenesisDoc {
if chainID == "" {
chainID = DefaultTestChainID
}
genesisValidators := make([]types.GenesisValidator, len(validators))
@@ -26,7 +35,7 @@ func GenesisDoc(
return &types.GenesisDoc{
GenesisTime: time,
InitialHeight: 1,
ChainID: config.ChainID(),
ChainID: chainID,
Validators: genesisValidators,
ConsensusParams: consensusParams,
}
+3 -4
View File
@@ -1,7 +1,6 @@
package test
import (
"context"
"sort"
"testing"
@@ -10,7 +9,7 @@ import (
"github.com/tendermint/tendermint/types"
)
func Validator(ctx context.Context, votingPower int64) (*types.Validator, types.PrivValidator, error) {
func Validator(votingPower int64) (*types.Validator, types.PrivValidator, error) {
privVal := types.NewMockPV()
pubKey, err := privVal.GetPubKey()
if err != nil {
@@ -21,7 +20,7 @@ func Validator(ctx context.Context, votingPower int64) (*types.Validator, types.
return val, privVal, nil
}
func ValidatorSet(ctx context.Context, t *testing.T, numValidators int, votingPower int64) (*types.ValidatorSet, []types.PrivValidator) {
func ValidatorSet(t *testing.T, numValidators int, votingPower int64) (*types.ValidatorSet, []types.PrivValidator) {
var (
valz = make([]*types.Validator, numValidators)
privValidators = make([]types.PrivValidator, numValidators)
@@ -29,7 +28,7 @@ func ValidatorSet(ctx context.Context, t *testing.T, numValidators int, votingPo
t.Helper()
for i := 0; i < numValidators; i++ {
val, privValidator, err := Validator(ctx, votingPower)
val, privValidator, err := Validator(votingPower)
require.NoError(t, err)
valz[i] = val
privValidators[i] = privValidator