Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions agreement/voteAggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func (agg *voteAggregator) filterBundle(ub unauthenticatedBundle, freshData fres

// voteStepFresh is a helper function for vote relay rules. Votes from steps
// [soft, next] are always propagated, as are votes from [s-1, s+1] where s is
// the current/last concluding step.
// the current/last concluding step. Set mine to 0 to effectively disable allowing
// votes adjacent to the current/last concluding step.
func voteStepFresh(descr string, proto protocol.ConsensusVersion, mine, vote step) error {
if vote <= next {
// always propagate first recovery vote to ensure synchronous block of periods after partition
Expand All @@ -248,8 +249,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) {
return fmt.Errorf("filtered future vote from bad period: 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 voteStepFresh("from next round", proto, 0, vote.R.Step)
}

switch vote.R.Period {
Expand Down
62 changes: 62 additions & 0 deletions agreement/voteAggregator_test.go
Original file line number Diff line number Diff line change
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)
Comment thread
Vervious marked this conversation as 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")
}