Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix filter for next round period 0 votes #62

Merged
merged 5 commits into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions agreement/voteAggregator.go
Expand Up @@ -248,8 +248,12 @@ func voteFresh(proto protocol.ConsensusVersion, freshData freshnessData, vote un
return fmt.Errorf("filtered vote from bad round: player.Round=%v; vote.Round=%v", freshData.PlayerRound, vote.R.Round)
}

if freshData.PlayerRound+1 == vote.R.Round && (vote.R.Period > 0 || vote.R.Step > next) {
return fmt.Errorf("filtered future vote from bad period or step: player.Round=%v; vote.(Round,Period,Step)=(%v,%v,%v)", freshData.PlayerRound, vote.R.Round, vote.R.Period, vote.R.Step)
if freshData.PlayerRound+1 == vote.R.Round {
if (vote.R.Period > 0 || vote.R.Step > next) {
return fmt.Errorf("filtered future vote from bad period or step: player.Round=%v; vote.(Round,Period,Step)=(%v,%v,%v)", freshData.PlayerRound, vote.R.Round, vote.R.Period, vote.R.Step)
}
// pipeline votes from next round period 0
return nil
Vervious marked this conversation as resolved.
Show resolved Hide resolved
}

switch vote.R.Period {
Expand Down
62 changes: 62 additions & 0 deletions agreement/voteAggregator_test.go
Expand Up @@ -777,3 +777,65 @@ func TestVoteAggregatorFiltersVotePresentPeriod(t *testing.T) {
require.NoError(t, err)
require.NoErrorf(t, res, "VotePresent not correctly filtered")
}

func TestVoteAggregatorFiltersVoteNextRound(t *testing.T) {
// Set up a composed test machine
rRouter := new(rootRouter)
rRouter.update(player{}, 0, false)
voteM := &ioAutomataConcrete{
listener: rRouter.voteRoot,
routerCtx: rRouter,
}
helper := voteMakerHelper{}
helper.Setup()
b := testCaseBuilder{}

// define a current player state for freshness testing
lastConcludingStep := next
msgTemplate := filterableMessageEvent{
FreshnessData: freshnessData{
PlayerRound: round(10),
PlayerPeriod: period(10),
PlayerStep: next + 5,
PlayerLastConcluding: lastConcludingStep,
},
}
// generate old next vote in next round, period 0, step 1; make sure it is accepted
pV := helper.MakeRandomProposalValue()
uv := helper.MakeUnauthenticatedVote(t, 0, round(11), period(0), soft, *pV)
Vervious marked this conversation as resolved.
Show resolved Hide resolved
inMsg := msgTemplate // copy
inMsg.messageEvent = messageEvent{
T: votePresent,
Input: message{
UnauthenticatedVote: uv,
},
}
b.AddInOutPair(inMsg, emptyEvent{})

// next round, period 0, step > next should be rejected
uv = helper.MakeUnauthenticatedVote(t, 1, round(11), period(0), next+1, *pV)
inMsg = msgTemplate // copy
inMsg.messageEvent = messageEvent{
T: votePresent,
Input: message{
UnauthenticatedVote: uv,
},
}
b.AddInOutPair(inMsg, filteredEvent{T: voteFiltered})

// next round, period 1 should be rejected
uv = helper.MakeUnauthenticatedVote(t, 1, round(11), period(1), soft, *pV)
inMsg = msgTemplate // copy
inMsg.messageEvent = messageEvent{
T: votePresent,
Input: message{
UnauthenticatedVote: uv,
},
}
b.AddInOutPair(inMsg, filteredEvent{T: voteFiltered})

// finalize
res, err := b.Build().Validate(voteM)
require.NoError(t, err)
require.NoErrorf(t, res, "Votes from next round not correctly filtered")
}