Skip to content

Commit

Permalink
chore: add validator params to validatorSet
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Feb 11, 2025
1 parent a9cc0c5 commit dbf7d95
Show file tree
Hide file tree
Showing 28 changed files with 331 additions and 93 deletions.
1 change: 1 addition & 0 deletions internal/consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
14 changes: 13 additions & 1 deletion internal/consensus/replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = &params
}
state.Validators = types.NewValidatorSet(nil, nil, quorumType, nil, false, valParams)
}

// we only update state when we are in initial state
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions internal/evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/evidence/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -550,6 +550,7 @@ func TestEvidenceListSerialization(t *testing.T) {
btcjson.LLMQType_5_60,
crypto.RandQuorumHash(),
true,
nil,
)

dupl, err := types.NewDuplicateVoteEvidence(
Expand Down
2 changes: 1 addition & 1 deletion internal/evidence/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/state/current_round_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
}
} else {
// validators not changed, but we might have a new quorum hash or threshold public key
Expand All @@ -342,5 +342,5 @@ func valsetUpdate(
}
}

return nValSet, nil
return nValSet, nValSet.ValidateBasic()
}
9 changes: 7 additions & 2 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
}

Expand Down
6 changes: 4 additions & 2 deletions internal/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/test/factory/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions light/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (pkz privKeys) ToValidators(thresholdPublicKey crypto.PubKey) *types.Valida
btcjson.LLMQType_5_60,
crypto.Checksum(thresholdPublicKey.Bytes()),
true,
nil,
)
}

Expand Down
2 changes: 1 addition & 1 deletion light/provider/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down
Loading

0 comments on commit dbf7d95

Please sign in to comment.