Skip to content

Commit

Permalink
WIP: removed score from validator - tests still red
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Sep 16, 2024
1 parent 5227cc7 commit 68a03d6
Show file tree
Hide file tree
Showing 26 changed files with 385 additions and 1,069 deletions.
2 changes: 1 addition & 1 deletion dash/quorum/validator_conn_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func makeState(nVals int, height int64) (sm.State, dbm.DB) {
}

func makeBlock(ctx context.Context, t *testing.T, blockExec *sm.BlockExecutor, state sm.State, _height int64, commit *types.Commit) *types.Block {
block, crs, err := blockExec.CreateProposalBlock(ctx, 1, 0, state, commit, state.Validators.Proposer.ProTxHash, 1)
block, crs, err := blockExec.CreateProposalBlock(ctx, 1, 0, state, commit, state.Validators.Proposer().ProTxHash, 1)
require.NoError(t, err)

err = crs.UpdateBlock(block)
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestMsgToProto(t *testing.T) {
vote, err := factory.MakeVote(
ctx,
pv,
&types.ValidatorSet{Proposer: val, Validators: []*types.Validator{val}, QuorumHash: quorumHash, ThresholdPublicKey: pk},
&types.ValidatorSet{Validators: []*types.Validator{val}, QuorumHash: quorumHash, ThresholdPublicKey: pk},
"chainID",
0,
1,
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/state_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type StateDataStore struct {
emitter *eventemitter.EventEmitter
replayMode bool
version int64
validatorScoring validatorscoring.ValidatorScoringStrategy
validatorScoring validatorscoring.ProposerProvider
}

// NewStateDataStore creates and returns a new state-data store
Expand Down
72 changes: 45 additions & 27 deletions internal/consensus/state_proposaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ProposalerTestSuite struct {
suite.Suite

proposer *Proposaler
proposerSelector validatorscoring.ProposerProvider
mockBlockExec *mocks.Executor
mockPrivVals []types.PrivValidator
mockValSet *types.ValidatorSet
Expand Down Expand Up @@ -88,19 +89,19 @@ func (suite *ProposalerTestSuite) SetupTest() {
blockExec: blockExec,
committedState: suite.committedState,
}

vs, err := validatorscoring.NewProposerStrategy(
var err error
suite.proposerSelector, err = validatorscoring.NewProposerStrategy(
suite.committedState.ConsensusParams,
suite.committedState.Validators.Copy(),
suite.committedState.LastBlockHeight,
suite.committedState.LastBlockRound,
valSet,
0,
0,
nil,
)
if err != nil {
panic(fmt.Errorf("failed to create validator scoring strategy: %w", err))
}

suite.proposerProTxHash = vs.MustGetProposer(100, 0).ProTxHash
suite.proposerProTxHash = suite.proposerSelector.MustGetProposer(100, 0).ProTxHash
suite.blockH100R0 = suite.committedState.MakeBlock(100, []types.Tx{}, &suite.commitH99R0, nil, suite.proposerProTxHash, 0)
}

Expand Down Expand Up @@ -158,7 +159,11 @@ func (suite *ProposalerTestSuite) TestSet() {
wantErr: ErrInvalidProposalPOLRound.Error(),
},
{
rs: cstypes.RoundState{Height: 100, Round: 0, Validators: suite.mockValSet},
rs: cstypes.RoundState{Height: 100,
Round: 0,
Validators: suite.mockValSet,
ProposerSelector: suite.proposerSelector,
},
proposal: *proposalH100R0,
receivedAt: receivedAt,
wantProposal: proposalH100R0,
Expand All @@ -183,6 +188,8 @@ func (suite *ProposalerTestSuite) TestDecide() {
state := suite.committedState
proposalH100R0 := types.NewProposal(100, state.LastCoreChainLockedBlockHeight, 0, 0, blockID, suite.blockH100R0.Header.Time)
suite.signProposal(ctx, proposalH100R0)
vs, err := validatorscoring.NewProposerStrategy(types.ConsensusParams{}, suite.mockValSet, 100, 0, nil)
suite.Require().NoError(err)
testCases := []struct {
height int64
round int32
Expand All @@ -195,12 +202,13 @@ func (suite *ProposalerTestSuite) TestDecide() {
height: 100,
round: 0,
rs: cstypes.RoundState{
Height: 100,
Round: 0,
Validators: suite.mockValSet,
ValidBlock: nil,
LastCommit: &suite.commitH99R0,
ValidRound: 0,
Height: 100,
Round: 0,
Validators: suite.mockValSet,
ValidBlock: nil,
LastCommit: &suite.commitH99R0,
ValidRound: 0,
ProposerSelector: vs,
},
mockFn: func(rs cstypes.RoundState) {
suite.mockBlockExec.
Expand Down Expand Up @@ -229,6 +237,7 @@ func (suite *ProposalerTestSuite) TestDecide() {
ValidBlockRecvTime: suite.blockH100R0.Time.Add(100 * time.Millisecond),
LastCommit: &suite.commitH99R0,
ValidRound: 0,
ProposerSelector: vs,
},
wantProposal: proposalH100R0,
},
Expand Down Expand Up @@ -266,9 +275,11 @@ func (suite *ProposalerTestSuite) TestVerifyProposal() {
proposalH100R0wrongSig := *proposalH100R0
proposalH100R0wrongSig.Signature = make([]byte, 96)
valSet := *suite.mockValSet
proposer := valSet.Proposer.Copy()
proposer := valSet.Proposer()
proposer.PubKey = nil
valSet.Proposer = proposer
idx, _ := valSet.GetByProTxHash(proposer.ProTxHash)
valSet.Validators[int(idx)] = proposer

testCases := []struct {
proposal *types.Proposal
rs cstypes.RoundState
Expand All @@ -277,53 +288,60 @@ func (suite *ProposalerTestSuite) TestVerifyProposal() {
{
proposal: proposalH100R0,
rs: cstypes.RoundState{
Validators: suite.mockValSet,
Validators: suite.mockValSet,
ProposerSelector: suite.proposerSelector,
},
},
{
proposal: &proposalH100R0wrongSig,
rs: cstypes.RoundState{
Validators: suite.mockValSet,
Validators: suite.mockValSet,
ProposerSelector: suite.proposerSelector,
},
wantErr: ErrInvalidProposalSignature.Error(),
},
{
proposal: proposalH100R0,
rs: cstypes.RoundState{
Commit: nil,
Validators: &valSet,
Commit: nil,
Validators: &valSet,
ProposerSelector: suite.proposerSelector,
},
wantErr: ErrUnableToVerifyProposal.Error(),
},
{
proposal: proposalH100R0,
rs: cstypes.RoundState{
Commit: &types.Commit{Height: 99},
Validators: &valSet,
Commit: &types.Commit{Height: 99},
Validators: &valSet,
ProposerSelector: suite.proposerSelector,
},
wantErr: ErrUnableToVerifyProposal.Error(),
},
{
proposal: proposalH100R0,
rs: cstypes.RoundState{
Commit: &types.Commit{Height: 100, Round: 1},
Validators: &valSet,
Commit: &types.Commit{Height: 100, Round: 1},
Validators: &valSet,
ProposerSelector: suite.proposerSelector,
},
wantErr: ErrUnableToVerifyProposal.Error(),
},
{
proposal: proposalH100R0,
rs: cstypes.RoundState{
Commit: &types.Commit{Height: 100, Round: 0, BlockID: types.BlockID{Hash: nil}},
Validators: &valSet,
Commit: &types.Commit{Height: 100, Round: 0, BlockID: types.BlockID{Hash: nil}},
Validators: &valSet,
ProposerSelector: suite.proposerSelector,
},
wantErr: ErrInvalidProposalForCommit.Error(),
},
{
proposal: proposalH100R0,
rs: cstypes.RoundState{
Commit: &types.Commit{Height: 100, Round: 0, BlockID: proposalH100R0.BlockID},
Validators: &valSet,
Commit: &types.Commit{Height: 100, Round: 0, BlockID: proposalH100R0.BlockID},
Validators: &valSet,
ProposerSelector: suite.proposerSelector,
},
},
}
Expand Down
13 changes: 7 additions & 6 deletions internal/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestStateProposerSelection2(t *testing.T) {
// everyone just votes nil. we get a new proposer each round
for i := int32(0); int(i) < len(vss); i++ {
prop := stateData.ProposerSelector.MustGetProposer(height, round)
proTxHash, err := vss[int(i+round)%len(vss)].GetProTxHash(ctx)
proTxHash, err := vss[int(int32(height-1)+round)%len(vss)].GetProTxHash(ctx)
require.NoError(t, err)
correctProposer := proTxHash
require.True(t, bytes.Equal(prop.ProTxHash, correctProposer),
Expand Down Expand Up @@ -263,10 +263,11 @@ func TestStateProposerSelectionBetweenRoundsAndHeights(t *testing.T) {
}

// ensure correct order of voting
for i, p := range proposers {
expectedProTx := expectedValidatorSet.Validators[(i)%len(expectedValidatorSet.Validators)].ProTxHash
assert.Equal(t, expectedProTx, p.proposer.ProTxHash)
t.Logf("height %d, round %d, proposer %x", p.height, p.round, p.proposer.ProTxHash[:6])

for _, p := range proposers {
expectedProTx := expectedValidatorSet.Validators[(int(p.height-1)+int(p.round))%expectedValidatorSet.Size()].ProTxHash
assert.Equal(t, expectedProTx, p.proposer.ProTxHash,
"height %d, round %d, proposer %x, vset %v", p.height, p.round, p.proposer.ProTxHash[:6], expectedValidatorSet)
}

}
Expand Down Expand Up @@ -3373,7 +3374,7 @@ func TestStateTryAddCommitCallsProcessProposal(t *testing.T) {
parts, err := block.MakePartSet(999999999)
require.NoError(t, err)

peerID := css0StateData.Validators.Proposer.NodeAddress.NodeID
peerID := css0StateData.Validators.Proposer().NodeAddress.NodeID
css1StateData.Proposal = proposal
css1StateData.ProposalBlock = block
css1StateData.ProposalBlockParts = parts
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/types/round_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type RoundState struct {
// Subjective time when +2/3 precommits for Block at Round were found
CommitTime time.Time `json:"commit_time"`
Validators *types.ValidatorSet `json:"validators"`
ProposerSelector validatorscoring.ValidatorScoringStrategy
ProposerSelector validatorscoring.ProposerProvider
Proposal *types.Proposal `json:"proposal"`
ProposalReceiveTime time.Time `json:"proposal_receive_time"`
ProposalBlock *types.Block `json:"proposal_block"`
Expand Down
1 change: 0 additions & 1 deletion internal/evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ func initializeValidatorState(
// create validator set and state
valSet := &types.ValidatorSet{
Validators: []*types.Validator{validator},
Proposer: validator,
ThresholdPublicKey: validator.PubKey,
QuorumType: quorumType,
QuorumHash: quorumHash,
Expand Down
Loading

0 comments on commit 68a03d6

Please sign in to comment.