From dbf7d953f2354f6d87103f566de06eacb1a30d35 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Tue, 11 Feb 2025 17:46:09 +0100 Subject: [PATCH] chore: add validator params to validatorSet --- internal/consensus/replay_test.go | 1 + internal/consensus/replayer.go | 14 +- .../selectproposer/height_proposer_test.go | 2 +- internal/evidence/pool_test.go | 4 +- internal/evidence/reactor_test.go | 5 +- internal/evidence/verify_test.go | 2 +- internal/state/current_round_state.go | 4 +- internal/state/state.go | 9 +- internal/state/state_test.go | 6 +- internal/test/factory/validator_set.go | 2 +- light/helpers_test.go | 1 + light/provider/http/http.go | 2 +- proto/tendermint/types/params.pb.go | 228 ++++++++++++++---- proto/tendermint/types/params.proto | 12 + rpc/client/evidence_test.go | 2 +- test/e2e/runner/evidence.go | 2 +- test/e2e/tests/validator_test.go | 4 +- types/evidence.go | 6 +- types/evidence_test.go | 3 +- types/generator.go | 2 +- types/params.go | 43 +++- types/params_test.go | 3 +- types/protobuf.go | 9 +- types/protobuf_test.go | 2 +- types/validation_test.go | 2 +- types/validator_set.go | 34 ++- types/validator_set_test.go | 18 +- types/vote_set_test.go | 2 +- 28 files changed, 331 insertions(+), 93 deletions(-) diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index 4f12f9d8c..eba868d17 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -1282,6 +1282,7 @@ func TestHandshakeUpdatesValidators(t *testing.T) { btcjson.LLMQType_5_60, randQuorumHash, true, + nil, ) abciValidatorSetUpdates := types.TM2PB.ValidatorUpdates(vals) app := &initChainApp{vals: &abciValidatorSetUpdates} diff --git a/internal/consensus/replayer.go b/internal/consensus/replayer.go index d950de4b2..4fd5e8645 100644 --- a/internal/consensus/replayer.go +++ b/internal/consensus/replayer.go @@ -344,7 +344,12 @@ func (r *BlockReplayer) execInitChain(ctx context.Context, rs *replayState, stat if len(res.ValidatorSetUpdate.ValidatorUpdates) != 0 { // we replace existing validator with the one from InitChain instead of applying it as a diff - state.Validators = types.NewValidatorSet(nil, nil, quorumType, nil, false) + var valParams *types.ValidatorParams + if res.ConsensusParams != nil && res.ConsensusParams.Validator != nil { + params := types.ValidatorParamsFromProto(res.ConsensusParams.Validator) + valParams = ¶ms + } + state.Validators = types.NewValidatorSet(nil, nil, quorumType, nil, false, valParams) } // we only update state when we are in initial state @@ -401,11 +406,18 @@ func validatorSetUpdateFromGenesis(genDoc *types.GenesisDoc) (*abci.ValidatorSet return nil, fmt.Errorf("blockReplayer blocks error when validating validator: %s", err) } } + + var validatorParams types.ValidatorParams + if genDoc.ConsensusParams != nil { + validatorParams = genDoc.ConsensusParams.Validator + } + validatorSet := types.NewValidatorSetCheckPublicKeys( validators, genDoc.ThresholdPublicKey, genDoc.QuorumType, genDoc.QuorumHash, + &validatorParams, ) err := validatorSet.ValidateBasic() if err != nil { diff --git a/internal/consensus/versioned/selectproposer/height_proposer_test.go b/internal/consensus/versioned/selectproposer/height_proposer_test.go index 9e370078e..248b651da 100644 --- a/internal/consensus/versioned/selectproposer/height_proposer_test.go +++ b/internal/consensus/versioned/selectproposer/height_proposer_test.go @@ -28,7 +28,7 @@ func TestProposerSelection1(t *testing.T) { types.NewTestValidatorGeneratedFromProTxHash(fooProTxHash), types.NewTestValidatorGeneratedFromProTxHash(barProTxHash), types.NewTestValidatorGeneratedFromProTxHash(bazProTxHash), - }, bls12381.GenPrivKey().PubKey(), btcjson.LLMQType_5_60, crypto.RandQuorumHash(), true) + }, bls12381.GenPrivKey().PubKey(), btcjson.LLMQType_5_60, crypto.RandQuorumHash(), true, nil) var proposers []string vs, err := selectproposer.NewProposerSelector(types.ConsensusParams{}, vset, 0, 0, nil, log.NewTestingLogger(t)) diff --git a/internal/evidence/pool_test.go b/internal/evidence/pool_test.go index 34b7aed6d..92b08ade4 100644 --- a/internal/evidence/pool_test.go +++ b/internal/evidence/pool_test.go @@ -130,7 +130,7 @@ func TestAddExpiredEvidence(t *testing.T) { quorumHash = crypto.RandQuorumHash() privval = types.NewMockPVForQuorum(quorumHash) val = privval.ExtractIntoValidator(ctx, quorumHash) - valSet = types.NewValidatorSet([]*types.Validator{val}, val.PubKey, btcjson.LLMQType_5_60, quorumHash, true) + valSet = types.NewValidatorSet([]*types.Validator{val}, val.PubKey, btcjson.LLMQType_5_60, quorumHash, true, nil) height = int64(30) stateStore = initializeValidatorState(ctx, t, privval, height, btcjson.LLMQType_5_60, quorumHash) evidenceDB = dbm.NewMemDB() @@ -221,7 +221,7 @@ func TestReportConflictingVotes(t *testing.T) { state.LastBlockHeight++ state.LastBlockTime = ev.Time() state.LastValidators = types.NewValidatorSet([]*types.Validator{val}, val.PubKey, btcjson.LLMQType_5_60, - quorumHash, true) + quorumHash, true, nil) pool.Update(ctx, state, []types.Evidence{}) // should be able to retrieve evidence from pool diff --git a/internal/evidence/reactor_test.go b/internal/evidence/reactor_test.go index cec9c185a..088232cec 100644 --- a/internal/evidence/reactor_test.go +++ b/internal/evidence/reactor_test.go @@ -99,14 +99,14 @@ func setup(ctx context.Context, t *testing.T, stateStores []sm.Store) *reactorTe rts.network.Nodes[nodeID].PeerManager.Register(ctx, pu) rts.nodes = append(rts.nodes, rts.network.Nodes[nodeID]) - chCreator := func(ctx context.Context, chdesc *p2p.ChannelDescriptor) (p2p.Channel, error) { + chCreator := func(_ctx context.Context, chdesc *p2p.ChannelDescriptor) (p2p.Channel, error) { return rts.evidenceChannels[nodeID], nil } rts.reactors[nodeID] = evidence.NewReactor( logger, chCreator, - func(ctx context.Context, _ string) *p2p.PeerUpdates { return pu }, + func(_ctx context.Context, _ string) *p2p.PeerUpdates { return pu }, rts.pools[nodeID]) require.NoError(t, rts.reactors[nodeID].Start(ctx)) @@ -550,6 +550,7 @@ func TestEvidenceListSerialization(t *testing.T) { btcjson.LLMQType_5_60, crypto.RandQuorumHash(), true, + nil, ) dupl, err := types.NewDuplicateVoteEvidence( diff --git a/internal/evidence/verify_test.go b/internal/evidence/verify_test.go index fde060ad3..df06a8f95 100644 --- a/internal/evidence/verify_test.go +++ b/internal/evidence/verify_test.go @@ -39,7 +39,7 @@ func TestVerifyDuplicateVoteEvidence(t *testing.T) { val := types.NewMockPVForQuorum(quorumHash) val2 := types.NewMockPVForQuorum(quorumHash) validator1 := val.ExtractIntoValidator(context.Background(), quorumHash) - valSet := types.NewValidatorSet([]*types.Validator{validator1}, validator1.PubKey, quorumType, quorumHash, true) + valSet := types.NewValidatorSet([]*types.Validator{validator1}, validator1.PubKey, quorumType, quorumHash, true, nil) stateID := types.RandStateID() blockID := makeBlockID([]byte("blockhash"), 1000, []byte("partshash"), stateID) blockID2 := makeBlockID([]byte("blockhash2"), 1000, []byte("partshash"), stateID) diff --git a/internal/state/current_round_state.go b/internal/state/current_round_state.go index a6848ccea..3842de27a 100644 --- a/internal/state/current_round_state.go +++ b/internal/state/current_round_state.go @@ -329,7 +329,7 @@ func valsetUpdate( } else { // if we don't have proTxHash, NewValidatorSetWithLocalNodeProTxHash behaves like NewValidatorSet nValSet = types.NewValidatorSetCheckPublicKeys(validatorUpdates, thresholdPubKey, - currentVals.QuorumType, quorumHash) + currentVals.QuorumType, quorumHash, ¶ms) } } else { // validators not changed, but we might have a new quorum hash or threshold public key @@ -342,5 +342,5 @@ func valsetUpdate( } } - return nValSet, nil + return nValSet, nValSet.ValidateBasic() } diff --git a/internal/state/state.go b/internal/state/state.go index cbffe452e..d18b02555 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -382,8 +382,13 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) { } var validatorSet *types.ValidatorSet + var valParams *types.ValidatorParams + if genDoc.ConsensusParams != nil { + valParams = &genDoc.ConsensusParams.Validator + } + if len(genDoc.Validators) == 0 { - validatorSet = types.NewValidatorSet(nil, nil, genDoc.QuorumType, nil, false) + validatorSet = types.NewValidatorSet(nil, nil, genDoc.QuorumType, nil, false, valParams) } else { validators := make([]*types.Validator, len(genDoc.Validators)) hasAllPublicKeys := true @@ -394,7 +399,7 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) { } } validatorSet = types.NewValidatorSet( - validators, genDoc.ThresholdPublicKey, genDoc.QuorumType, genDoc.QuorumHash, hasAllPublicKeys, + validators, genDoc.ThresholdPublicKey, genDoc.QuorumType, genDoc.QuorumHash, hasAllPublicKeys, valParams, ) } diff --git a/internal/state/state_test.go b/internal/state/state_test.go index 6d297bec0..31d95ca93 100644 --- a/internal/state/state_test.go +++ b/internal/state/state_test.go @@ -354,12 +354,14 @@ func TestEmptyValidatorUpdates(t *testing.T) { tearDown, _, state := setupTestCase(t) defer tearDown(t) + originalValidatorSet, _ := types.RandValidatorSet(2) + state.Validators = originalValidatorSet + firstNode := state.Validators.GetByIndex(0) require.NotZero(t, firstNode.ProTxHash) ctx := dash.ContextWithProTxHash(context.Background(), firstNode.ProTxHash) - newPrivKey := bls12381.GenPrivKeyFromSecret([]byte("test")) - newPubKey := newPrivKey.PubKey() + newPubKey := originalValidatorSet.ThresholdPublicKey newQuorumHash := crypto.RandQuorumHash() expectValidators := types.ValidatorListString(state.Validators.Validators) diff --git a/internal/test/factory/validator_set.go b/internal/test/factory/validator_set.go index 45ccddcd6..624c2f5fc 100644 --- a/internal/test/factory/validator_set.go +++ b/internal/test/factory/validator_set.go @@ -44,5 +44,5 @@ func MockValidatorSet() (*types.ValidatorSet, []types.PrivValidator) { false, ) } - return types.NewValidatorSet(valz, thPubKey, btcjson.LLMQType_5_60, quorumHash, true), privVals + return types.NewValidatorSet(valz, thPubKey, btcjson.LLMQType_5_60, quorumHash, true, nil), privVals } diff --git a/light/helpers_test.go b/light/helpers_test.go index 9ff02e0ca..d9c0766fb 100644 --- a/light/helpers_test.go +++ b/light/helpers_test.go @@ -51,6 +51,7 @@ func (pkz privKeys) ToValidators(thresholdPublicKey crypto.PubKey) *types.Valida btcjson.LLMQType_5_60, crypto.Checksum(thresholdPublicKey.Bytes()), true, + nil, ) } diff --git a/light/provider/http/http.go b/light/provider/http/http.go index 73451e6b4..2fdc7550b 100644 --- a/light/provider/http/http.go +++ b/light/provider/http/http.go @@ -238,7 +238,7 @@ func (p *http) validatorSet(ctx context.Context, height *int64, proposer types.P break } } - valSet := types.NewValidatorSet(vals, thresholdPubKey, quorumType, quorumHash, false) + valSet := types.NewValidatorSet(vals, thresholdPubKey, quorumType, quorumHash, false, nil) if valSet == nil || valSet.IsNilOrEmpty() { return nil, provider.ErrBadLightBlock{Reason: fmt.Errorf("retrieved nil or empty validator set")} diff --git a/proto/tendermint/types/params.pb.go b/proto/tendermint/types/params.pb.go index 9f0460c1a..65f620145 100644 --- a/proto/tendermint/types/params.pb.go +++ b/proto/tendermint/types/params.pb.go @@ -284,6 +284,9 @@ func (m *EvidenceParams) GetMaxBytes() int64 { // NOTE: uses ABCI pubkey naming, not Amino names. type ValidatorParams struct { PubKeyTypes []string `protobuf:"bytes,1,rep,name=pub_key_types,json=pubKeyTypes,proto3" json:"pub_key_types,omitempty"` + // Types that are valid to be assigned to XVotingPowerThreshold: + // *ValidatorParams_VotingPowerThreshold + XVotingPowerThreshold isValidatorParams_XVotingPowerThreshold `protobuf_oneof:"_voting_power_threshold"` } func (m *ValidatorParams) Reset() { *m = ValidatorParams{} } @@ -319,6 +322,26 @@ func (m *ValidatorParams) XXX_DiscardUnknown() { var xxx_messageInfo_ValidatorParams proto.InternalMessageInfo +type isValidatorParams_XVotingPowerThreshold interface { + isValidatorParams_XVotingPowerThreshold() + Equal(interface{}) bool + MarshalTo([]byte) (int, error) + Size() int +} + +type ValidatorParams_VotingPowerThreshold struct { + VotingPowerThreshold uint64 `protobuf:"varint,2,opt,name=voting_power_threshold,json=votingPowerThreshold,proto3,oneof" json:"voting_power_threshold,omitempty"` +} + +func (*ValidatorParams_VotingPowerThreshold) isValidatorParams_XVotingPowerThreshold() {} + +func (m *ValidatorParams) GetXVotingPowerThreshold() isValidatorParams_XVotingPowerThreshold { + if m != nil { + return m.XVotingPowerThreshold + } + return nil +} + func (m *ValidatorParams) GetPubKeyTypes() []string { if m != nil { return m.PubKeyTypes @@ -326,6 +349,20 @@ func (m *ValidatorParams) GetPubKeyTypes() []string { return nil } +func (m *ValidatorParams) GetVotingPowerThreshold() uint64 { + if x, ok := m.GetXVotingPowerThreshold().(*ValidatorParams_VotingPowerThreshold); ok { + return x.VotingPowerThreshold + } + return 0 +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*ValidatorParams) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*ValidatorParams_VotingPowerThreshold)(nil), + } +} + // VersionParams contains the ABCI application version. type VersionParams struct { AppVersion uint64 `protobuf:"varint,1,opt,name=app_version,json=appVersion,proto3" json:"app_version,omitempty"` @@ -659,57 +696,60 @@ func init() { func init() { proto.RegisterFile("tendermint/types/params.proto", fileDescriptor_e12598271a686f57) } var fileDescriptor_e12598271a686f57 = []byte{ - // 801 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x4f, 0x8f, 0xdb, 0x44, - 0x14, 0x8f, 0x1b, 0x6f, 0x36, 0x79, 0xd9, 0x6c, 0xcc, 0x00, 0xaa, 0x29, 0xac, 0xb3, 0xf8, 0x80, - 0x2a, 0x55, 0xb2, 0x97, 0x2e, 0x1c, 0x90, 0xf8, 0xa3, 0x26, 0x59, 0x95, 0x16, 0x35, 0x45, 0xce, - 0xd2, 0x03, 0x12, 0xb2, 0xc6, 0xce, 0xe0, 0x58, 0x1b, 0x7b, 0x2c, 0x8f, 0x1d, 0xc5, 0x9f, 0x80, - 0x2b, 0x27, 0xc4, 0x47, 0x80, 0x0b, 0xe2, 0x63, 0xf4, 0xd8, 0x0b, 0x12, 0x27, 0x40, 0xd9, 0x2f, - 0x82, 0x66, 0x3c, 0x4e, 0x48, 0x36, 0x65, 0x73, 0xb2, 0xe7, 0xbd, 0xdf, 0x6f, 0x7e, 0x7e, 0xf3, - 0x7e, 0x6f, 0x0c, 0x27, 0x19, 0x89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, 0x91, 0x64, 0x0d, 0x39, 0x09, 0x9d, 0x83, 0x3a, - 0xa7, 0x19, 0x91, 0x57, 0xdb, 0xad, 0x64, 0x01, 0x46, 0x9f, 0x03, 0xf0, 0xa7, 0xd4, 0x55, 0xf7, - 0x3c, 0x07, 0x4e, 0x11, 0xa2, 0x4f, 0xd5, 0xe6, 0x81, 0xd6, 0x78, 0xaa, 0x36, 0x1b, 0xda, 0xa1, - 0xd3, 0xf0, 0x69, 0x14, 0x85, 0x99, 0xf3, 0xb6, 0x57, 0x24, 0x98, 0x31, 0xb7, 0x5c, 0xba, 0xf2, - 0x1e, 0x32, 0x1f, 0x00, 0xac, 0x6f, 0x1a, 0x74, 0x02, 0x90, 0x12, 0x7f, 0x4a, 0xfc, 0x2b, 0x37, - 0x5b, 0x88, 0x13, 0x6b, 0x3a, 0x2d, 0x19, 0xb9, 0x5c, 0xf4, 0x9d, 0x5f, 0x96, 0x86, 0xf2, 0x72, - 0x69, 0x28, 0xaf, 0x96, 0x86, 0xf2, 0xcf, 0xd2, 0x50, 0x7e, 0xbc, 0x36, 0x6a, 0xaf, 0xae, 0x8d, - 0xda, 0x9f, 0xd7, 0x46, 0xed, 0xdb, 0x8f, 0x82, 0x30, 0x9b, 0xe6, 0x9e, 0xe5, 0xd3, 0xc8, 0x9e, - 0x60, 0x36, 0x4d, 0x70, 0x61, 0x97, 0xc3, 0xc3, 0x57, 0xe5, 0x8f, 0xc8, 0xde, 0xfe, 0xb9, 0x79, - 0x0d, 0x11, 0x3f, 0xff, 0x37, 0x00, 0x00, 0xff, 0xff, 0xe5, 0x7d, 0x36, 0x05, 0xf7, 0x06, 0x00, + // 849 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x95, 0x4d, 0x6f, 0x1b, 0x45, + 0x18, 0xc7, 0x3d, 0xf5, 0xc6, 0xb1, 0x1f, 0xc7, 0xb1, 0x19, 0x0a, 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 0xdf, 0x05, 0x58, 0x3c, 0x60, 0x78, 0x17, 0x20, 0xa3, 0xc1, 0x84, 0x06, 0x67, 0x9e, 0x98, 0xab, + 0x1b, 0xab, 0xbb, 0x0d, 0x3d, 0x73, 0x3a, 0x1f, 0xb8, 0xbf, 0x9c, 0xf7, 0xd0, 0xcb, 0xf3, 0x1e, + 0x7a, 0x75, 0xde, 0x43, 0xff, 0x9c, 0xf7, 0xd0, 0x8f, 0x17, 0xbd, 0xca, 0xab, 0x8b, 0x5e, 0xe5, + 0xcf, 0x8b, 0x5e, 0xe5, 0xab, 0x8f, 0xc3, 0x48, 0x4c, 0x72, 0xdf, 0x09, 0x58, 0xdc, 0x1f, 0x13, + 0x3e, 0x49, 0x49, 0xd1, 0x2f, 0x9b, 0x47, 0x8e, 0xca, 0xef, 0x5b, 0x7f, 0xf5, 0x9b, 0xe9, 0xd7, + 0xd4, 0xfc, 0xe1, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb2, 0xb1, 0x36, 0x07, 0x4e, 0x07, 0x00, 0x00, } @@ -839,6 +879,39 @@ func (this *ValidatorParams) Equal(that interface{}) bool { return false } } + if that1.XVotingPowerThreshold == nil { + if this.XVotingPowerThreshold != nil { + return false + } + } else if this.XVotingPowerThreshold == nil { + return false + } else if !this.XVotingPowerThreshold.Equal(that1.XVotingPowerThreshold) { + return false + } + return true +} +func (this *ValidatorParams_VotingPowerThreshold) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorParams_VotingPowerThreshold) + if !ok { + that2, ok := that.(ValidatorParams_VotingPowerThreshold) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.VotingPowerThreshold != that1.VotingPowerThreshold { + return false + } return true } func (this *VersionParams) Equal(that interface{}) bool { @@ -1219,6 +1292,15 @@ func (m *ValidatorParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.XVotingPowerThreshold != nil { + { + size := m.XVotingPowerThreshold.Size() + i -= size + if _, err := m.XVotingPowerThreshold.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } if len(m.PubKeyTypes) > 0 { for iNdEx := len(m.PubKeyTypes) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.PubKeyTypes[iNdEx]) @@ -1231,6 +1313,18 @@ func (m *ValidatorParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ValidatorParams_VotingPowerThreshold) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorParams_VotingPowerThreshold) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + i = encodeVarintParams(dAtA, i, uint64(m.VotingPowerThreshold)) + i-- + dAtA[i] = 0x10 + return len(dAtA) - i, nil +} func (m *VersionParams) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1533,9 +1627,21 @@ func (m *ValidatorParams) Size() (n int) { n += 1 + l + sovParams(uint64(l)) } } + if m.XVotingPowerThreshold != nil { + n += m.XVotingPowerThreshold.Size() + } return n } +func (m *ValidatorParams_VotingPowerThreshold) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + n += 1 + sovParams(uint64(m.VotingPowerThreshold)) + return n +} func (m *VersionParams) Size() (n int) { if m == nil { return 0 @@ -2201,6 +2307,26 @@ func (m *ValidatorParams) Unmarshal(dAtA []byte) error { } m.PubKeyTypes = append(m.PubKeyTypes, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VotingPowerThreshold", wireType) + } + var v uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.XVotingPowerThreshold = &ValidatorParams_VotingPowerThreshold{v} default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/proto/tendermint/types/params.proto b/proto/tendermint/types/params.proto index 3c4a7feec..5cc6ab2e6 100644 --- a/proto/tendermint/types/params.proto +++ b/proto/tendermint/types/params.proto @@ -58,6 +58,18 @@ message EvidenceParams { // NOTE: uses ABCI pubkey naming, not Amino names. message ValidatorParams { repeated string pub_key_types = 1; + // Threshold defines the minimum voting power of validators that must vote for a proposal + // to be considered signed and added to the block. + // + // For Dash Platform, the voting power can be calculated by multiply of the number of validators + // and const `DefaultDashVotingPower == 100`. + // + // For validator sets containing more than 3 validators, the threshold MUST be + // greater than 2/3 of the total voting power of all validators. + // + // If set to 0 or absent, default value is determined based on LLMQ quorum type defined for the network, + // with a fall back to 2/3 + 1 of the total voting power. + optional uint64 voting_power_threshold = 2; } // VersionParams contains the ABCI application version. diff --git a/rpc/client/evidence_test.go b/rpc/client/evidence_test.go index 5789e6a64..f15430df6 100644 --- a/rpc/client/evidence_test.go +++ b/rpc/client/evidence_test.go @@ -39,7 +39,7 @@ func newEvidence(t *testing.T, val *privval.FilePV, require.NoError(t, err) validator := types.NewValidator(privKey.PubKey(), types.DefaultDashVotingPower, val.Key.ProTxHash, "") - valSet := types.NewValidatorSet([]*types.Validator{validator}, validator.PubKey, quorumType, quorumHash, true) + valSet := types.NewValidatorSet([]*types.Validator{validator}, validator.PubKey, quorumType, quorumHash, true, nil) ev, err := types.NewDuplicateVoteEvidence(vote, vote2, timestamp, valSet) require.NoError(t, err) diff --git a/test/e2e/runner/evidence.go b/test/e2e/runner/evidence.go index 090199019..80d98ba35 100644 --- a/test/e2e/runner/evidence.go +++ b/test/e2e/runner/evidence.go @@ -71,7 +71,7 @@ func InjectEvidence(ctx context.Context, logger log.Logger, r *rand.Rand, testne valSet := types.NewValidatorSet(valRes.Validators, *valRes.ThresholdPublicKey, valRes.QuorumType, *valRes.QuorumHash, - false) + false, nil) if valSet == nil { return fmt.Errorf("could not create validator set from response") } diff --git a/test/e2e/tests/validator_test.go b/test/e2e/tests/validator_test.go index 837980060..db46577af 100644 --- a/test/e2e/tests/validator_test.go +++ b/test/e2e/tests/validator_test.go @@ -186,7 +186,7 @@ func newValidatorSchedule(testnet e2e.Testnet) *validatorSchedule { } } - vs := types.NewValidatorSet(makeVals(valMap), thresholdPublicKey, quorumType, quorumHash, true) + vs := types.NewValidatorSet(makeVals(valMap), thresholdPublicKey, quorumType, quorumHash, true, nil) ps, err := selectproposer.NewProposerSelector(*types.DefaultConsensusParams(), vs, testnet.InitialHeight, 0, nil, nil) if err != nil { panic(err) @@ -257,7 +257,7 @@ func (s *validatorSchedule) Increment(heights int64) error { } } else { vs := types.NewValidatorSet(makeVals(update), thresholdPublicKeyUpdate, btcjson.LLMQType_5_60, - quorumHashUpdate, true) + quorumHashUpdate, true, &cp.Validator) ps, err := selectproposer.NewProposerSelector(cp, vs, s.height, 0, nil, nil) if err != nil { diff --git a/types/evidence.go b/types/evidence.go index 86e3f0863..42d058de2 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "strings" + "testing" "time" "github.com/dashpay/dashd-go/btcjson" @@ -490,6 +491,9 @@ func NewMockDuplicateVoteEvidenceWithValidator( quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash, ) (*DuplicateVoteEvidence, error) { + if !testing.Testing() { + panic("NewMockDuplicateVoteEvidenceWithValidator should only be used in tests") + } pubKey, err := pv.GetPubKey(ctx, quorumHash) if err != nil { panic(err) @@ -510,7 +514,7 @@ func NewMockDuplicateVoteEvidenceWithValidator( voteA, voteB, time, - NewValidatorSet([]*Validator{val}, val.PubKey, quorumType, quorumHash, true), + NewValidatorSet([]*Validator{val}, val.PubKey, quorumType, quorumHash, true, nil), ) } diff --git a/types/evidence_test.go b/types/evidence_test.go index 19df99c4f..e7ed069c9 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -165,7 +165,8 @@ func TestDuplicateVoteEvidenceValidation(t *testing.T) { thresholdPublicKey, err := val.GetThresholdPublicKey(context.Background(), quorumHash) assert.NoError(t, err) valSet := NewValidatorSet( - []*Validator{val.ExtractIntoValidator(context.Background(), quorumHash)}, thresholdPublicKey, quorumType, quorumHash, true) + []*Validator{val.ExtractIntoValidator(context.Background(), quorumHash)}, + thresholdPublicKey, quorumType, quorumHash, true, nil) ev, err := NewDuplicateVoteEvidence(vote1, vote2, defaultVoteTime, valSet) require.NoError(t, err) tc.malleateEvidence(ev) diff --git a/types/generator.go b/types/generator.go index 75c8f034f..115d1cac0 100644 --- a/types/generator.go +++ b/types/generator.go @@ -83,7 +83,7 @@ func GenerateValidatorSet(valParams []ValSetParam, opts ...ValSetOptionFunc) (*V valz = append(valz, NewValidator(qks.PubKey, opt.VotingPower, proTxHash, "")) } sort.Sort(PrivValidatorsByProTxHash(privValidators)) - return NewValidatorSet(valz, ld.ThresholdPubKey, crypto.SmallQuorumType(), quorumHash, true), privValidators + return NewValidatorSet(valz, ld.ThresholdPubKey, crypto.SmallQuorumType(), quorumHash, true, nil), privValidators } // MakeGenesisValsFromValidatorSet converts ValidatorSet data into a list of GenesisValidator diff --git a/types/params.go b/types/params.go index fa7243825..ce2065eab 100644 --- a/types/params.go +++ b/types/params.go @@ -69,7 +69,8 @@ type EvidenceParams struct { // ValidatorParams restrict the public key types validators can use. // NOTE: uses ABCI pubkey naming, not Amino names. type ValidatorParams struct { - PubKeyTypes []string `json:"pub_key_types"` + PubKeyTypes []string `json:"pub_key_types"` + VotingPowerThreshold uint64 `json:"threshold"` } type VersionParams struct { @@ -141,7 +142,8 @@ func DefaultEvidenceParams() EvidenceParams { // only bls12381 pubkeys. func DefaultValidatorParams() ValidatorParams { return ValidatorParams{ - PubKeyTypes: []string{ABCIPubKeyTypeBLS12381}, + PubKeyTypes: []string{ABCIPubKeyTypeBLS12381}, + VotingPowerThreshold: 0, } } @@ -239,6 +241,33 @@ func (val *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool { return false } +func ValidatorParamsFromProto(pbValParams *tmproto.ValidatorParams) ValidatorParams { + if pbValParams != nil { + return ValidatorParams{ + // Copy Validator.PubkeyTypes, and set result's value to the copy. + // This avoids having to initialize the slice to 0 values, and then write to it again. + PubKeyTypes: append([]string{}, pbValParams.PubKeyTypes...), + VotingPowerThreshold: pbValParams.GetVotingPowerThreshold(), + } + } + + return ValidatorParams{ + PubKeyTypes: []string{}, + VotingPowerThreshold: 0, + } +} + +// GetVotingPowerThreshold returns the voting power threshold for the validator set. +// For nil ValidatorParams, it returns 0. +// +// Value of 0 means that the threshold is not set. +func (val *ValidatorParams) GetVotingPowerThreshold() uint64 { + if val != nil { + return val.VotingPowerThreshold + } + return 0 +} + func (params *ConsensusParams) Complete() { if params.Synchrony == (SynchronyParams{}) { params.Synchrony = DefaultSynchronyParams() @@ -392,9 +421,7 @@ func (params ConsensusParams) UpdateConsensusParams(params2 *tmproto.ConsensusPa res.Evidence.MaxBytes = params2.Evidence.MaxBytes } if params2.Validator != nil { - // Copy params2.Validator.PubkeyTypes, and set result's value to the copy. - // This avoids having to initialize the slice to 0 values, and then write to it again. - res.Validator.PubKeyTypes = append([]string{}, params2.Validator.PubKeyTypes...) + res.Validator = ValidatorParamsFromProto(params2.Validator) } if params2.Version != nil { res.Version.AppVersion = params2.Version.AppVersion @@ -441,6 +468,9 @@ func (params *ConsensusParams) ToProto() tmproto.ConsensusParams { }, Validator: &tmproto.ValidatorParams{ PubKeyTypes: params.Validator.PubKeyTypes, + XVotingPowerThreshold: &tmproto.ValidatorParams_VotingPowerThreshold{ + VotingPowerThreshold: params.Validator.VotingPowerThreshold, + }, }, Version: &tmproto.VersionParams{ AppVersion: params.Version.AppVersion, @@ -483,7 +513,8 @@ func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams if pbParams.Validator != nil { c.Validator = ValidatorParams{ - PubKeyTypes: pbParams.Validator.PubKeyTypes, + PubKeyTypes: pbParams.Validator.PubKeyTypes, + VotingPowerThreshold: pbParams.Validator.GetVotingPowerThreshold(), } } diff --git a/types/params_test.go b/types/params_test.go index ccd18e8e7..241181233 100644 --- a/types/params_test.go +++ b/types/params_test.go @@ -218,7 +218,8 @@ func makeParams(args makeParamsArgs) ConsensusParams { MaxBytes: args.maxEvidenceBytes, }, Validator: ValidatorParams{ - PubKeyTypes: args.pubkeyTypes, + PubKeyTypes: args.pubkeyTypes, + VotingPowerThreshold: 0, }, Synchrony: SynchronyParams{ Precision: args.precision, diff --git a/types/protobuf.go b/types/protobuf.go index 671e21321..979ac2fe4 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "testing" "github.com/dashpay/dashd-go/btcjson" @@ -159,10 +160,16 @@ func (pb2tm) ValidatorUpdatesFromValidatorSet(valSetUpdate *abci.ValidatorSetUpd return tmVals, pub, valSetUpdate.QuorumHash, nil } +// ValidatorSetFromProtoUpdate creates validator set from validator update. +// +// Only use in tests. func (pb2tm) ValidatorSetFromProtoUpdate( quorumType btcjson.LLMQType, valSetUpdate *abci.ValidatorSetUpdate, ) (*ValidatorSet, error) { + if !testing.Testing() { + panic("ValidatorSetFromProtoUpdate should only be used in tests") + } hasPublicKeys := true for i, v := range valSetUpdate.ValidatorUpdates { if v.PubKey == nil { @@ -183,7 +190,7 @@ func (pb2tm) ValidatorSetFromProtoUpdate( if err != nil { return nil, err } - return NewValidatorSet(tmVals, pub, quorumType, quorumHash, hasPublicKeys), nil + return NewValidatorSet(tmVals, pub, quorumType, quorumHash, hasPublicKeys, nil), nil } func (pb2tm) ThresholdPublicKeyUpdate(thresholdPublicKey crypto2.PublicKey) (crypto.PubKey, error) { diff --git a/types/protobuf_test.go b/types/protobuf_test.go index d1530e134..4774d40eb 100644 --- a/types/protobuf_test.go +++ b/types/protobuf_test.go @@ -43,7 +43,7 @@ func TestABCIValidators(t *testing.T) { assert.NoError(t, err) assert.Equal(t, tmValExpected, tmVals[0]) - abciVals := TM2PB.ValidatorUpdates(NewValidatorSet(tmVals, tmVal.PubKey, btcjson.LLMQType_5_60, quorumHash, true)) + abciVals := TM2PB.ValidatorUpdates(NewValidatorSet(tmVals, tmVal.PubKey, btcjson.LLMQType_5_60, quorumHash, true, nil)) assert.Equal(t, abci.ValidatorSetUpdate{ ValidatorUpdates: []abci.ValidatorUpdate{abciVal}, ThresholdPublicKey: *abciVal.PubKey, diff --git a/types/validation_test.go b/types/validation_test.go index f518d1f7e..59568dafb 100644 --- a/types/validation_test.go +++ b/types/validation_test.go @@ -23,7 +23,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) { pubKey = privKey.PubKey() v1 = NewValidatorDefaultVotingPower(pubKey, proTxHash) quorumHash = crypto.RandQuorumHash() - vset = NewValidatorSet([]*Validator{v1}, v1.PubKey, btcjson.LLMQType_5_60, quorumHash, true) + vset = NewValidatorSet([]*Validator{v1}, v1.PubKey, btcjson.LLMQType_5_60, quorumHash, true, nil) chainID = "Lalande21185" ) diff --git a/types/validator_set.go b/types/validator_set.go index 37aff76e3..2cdc0052c 100644 --- a/types/validator_set.go +++ b/types/validator_set.go @@ -64,6 +64,7 @@ type ValidatorSet struct { ThresholdPublicKey crypto.PubKey `json:"threshold_public_key"` QuorumHash crypto.QuorumHash `json:"quorum_hash"` QuorumType btcjson.LLMQType `json:"quorum_type"` + Params ValidatorParams `json:"validator_consensus_params"` HasPublicKeys bool `json:"has_public_keys"` } @@ -78,12 +79,15 @@ type ValidatorSet struct { // MaxVotesCount - commits by a validator set larger than this will fail // validation. func NewValidatorSet(valz []*Validator, newThresholdPublicKey crypto.PubKey, quorumType btcjson.LLMQType, - quorumHash crypto.QuorumHash, hasPublicKeys bool) *ValidatorSet { + quorumHash crypto.QuorumHash, hasPublicKeys bool, validatorParams *ValidatorParams) *ValidatorSet { vals := &ValidatorSet{ QuorumHash: quorumHash, QuorumType: quorumType, HasPublicKeys: hasPublicKeys, } + if validatorParams != nil { + vals.Params = *validatorParams + } err := vals.updateWithChangeSet(valz, false, newThresholdPublicKey, quorumHash) if err != nil { panic(fmt.Sprintf("Cannot create validator set: %v", err)) @@ -99,6 +103,7 @@ func NewValidatorSetCheckPublicKeys( newThresholdPublicKey crypto.PubKey, quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash, + params *ValidatorParams, ) *ValidatorSet { hasPublicKeys := true for _, val := range valz { @@ -106,12 +111,12 @@ func NewValidatorSetCheckPublicKeys( hasPublicKeys = false } } - return NewValidatorSet(valz, newThresholdPublicKey, quorumType, quorumHash, hasPublicKeys) + return NewValidatorSet(valz, newThresholdPublicKey, quorumType, quorumHash, hasPublicKeys, params) } // NewEmptyValidatorSet initializes a ValidatorSet with no validators func NewEmptyValidatorSet() *ValidatorSet { - return NewValidatorSet(nil, nil, 0, nil, false) + return NewValidatorSet(nil, nil, 0, nil, false, nil) } func (vals *ValidatorSet) ValidateBasic() error { @@ -152,6 +157,29 @@ func (vals *ValidatorSet) ValidateBasic() error { return fmt.Errorf("proposer failed validate basic, error: %w", err) } + if len(vals.Params.PubKeyTypes) != 0 { + for _, validator := range vals.Validators { + if !vals.Params.IsValidPubkeyType(validator.PubKey.Type()) { + return fmt.Errorf( + "validator %s is using pubkey %s, which is unsupported for consensus - expected %v", + validator.String(), + validator.PubKey.Type(), + vals.Params.PubKeyTypes, + ) + } + } + } + + if vals.Params.VotingPowerThreshold > 0 && vals.QuorumTypeMemberCount() > 3 { + power := vals.QuorumVotingPower() + if power < 0 { + return fmt.Errorf("quorum voting power %d is negative", power) + } + if uint64(power) < vals.Params.VotingPowerThreshold*2/3+1 { + return fmt.Errorf("quorum voting power %d is less than threshold %d", power, vals.Params.VotingPowerThreshold) + } + } + return nil } diff --git a/types/validator_set_test.go b/types/validator_set_test.go index c423ff771..ee0b38fc2 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -24,7 +24,7 @@ import ( func TestValidatorSetBasic(t *testing.T) { // empty or nil validator lists are allowed, - vset := NewValidatorSet([]*Validator{}, nil, btcjson.LLMQType_5_60, nil, true) + vset := NewValidatorSet([]*Validator{}, nil, btcjson.LLMQType_5_60, nil, true, nil) assert.EqualValues(t, vset, vset.Copy()) assert.False(t, vset.HasProTxHash([]byte("some val"))) @@ -233,7 +233,7 @@ func TestCopy(t *testing.T) { func BenchmarkValidatorSetCopy(b *testing.B) { b.StopTimer() - vset := NewValidatorSet([]*Validator{}, nil, btcjson.LLMQType_5_60, nil, true) + vset := NewValidatorSet([]*Validator{}, nil, btcjson.LLMQType_5_60, nil, true, nil) for i := 0; i < 1000; i++ { privKey := bls12381.GenPrivKey() pubKey := privKey.PubKey() @@ -279,7 +279,7 @@ func randValidatorInQuorum(ctx context.Context, t *testing.T, quorumHash crypto. func TestEmptySet(t *testing.T) { var valList []*Validator - valSet := NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true) + valSet := NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true, nil) // Add to empty set proTxHashes := []crypto.ProTxHash{crypto.Checksum([]byte("v1")), crypto.Checksum([]byte("v2"))} @@ -310,14 +310,18 @@ func TestUpdatesForNewValidatorSet(t *testing.T) { v112 := NewTestValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v1"))) v113 := NewTestValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v1"))) valList := []*Validator{v111, v112, v113} - assert.Panics(t, func() { NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true) }) + assert.Panics(t, func() { + NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true, nil) + }) // Verify set including validator with voting power 0 cannot be created v1 := NewTestRemoveValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v1"))) v2 := NewTestValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v2"))) v3 := NewTestValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v3"))) valList = []*Validator{v1, v2, v3} - assert.Panics(t, func() { NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true) }) + assert.Panics(t, func() { + NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true, nil) + }) // Verify set including validator with negative voting power cannot be created v1 = NewTestValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v1"))) @@ -327,7 +331,9 @@ func TestUpdatesForNewValidatorSet(t *testing.T) { } v3 = NewTestValidatorGeneratedFromProTxHash(crypto.Checksum([]byte("v3"))) valList = []*Validator{v1, v2, v3} - assert.Panics(t, func() { NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true) }) + assert.Panics(t, func() { + NewValidatorSet(valList, bls12381.PubKey{}, btcjson.LLMQType_5_60, crypto.QuorumHash{}, true, nil) + }) } diff --git a/types/vote_set_test.go b/types/vote_set_test.go index f3a47aaa5..2ce386e54 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -640,7 +640,7 @@ func randVoteSetWithLLMQType( sort.Sort(PrivValidatorsByProTxHash(privValidators)) - valSet := NewValidatorSet(valz, ld.ThresholdPubKey, llmqType, quorumHash, true) + valSet := NewValidatorSet(valz, ld.ThresholdPubKey, llmqType, quorumHash, true, nil) voteSet := NewVoteSet("test_chain_id", height, round, signedMsgType, valSet) return voteSet, valSet, privValidators