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

agreement: update AttachReceivedAt to handle compound (PP) messages #5142

Merged
merged 4 commits into from
Mar 10, 2023
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
2 changes: 1 addition & 1 deletion agreement/demux.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (d *demux) next(s *Service, deadline time.Duration, fastDeadline time.Durat
switch e.t() {
case payloadVerified:
e = e.(messageEvent).AttachValidatedAt(s.Clock.Since())
case payloadPresent:
case payloadPresent, votePresent:
e = e.(messageEvent).AttachReceivedAt(s.Clock.Since())
}
}()
Expand Down
17 changes: 16 additions & 1 deletion agreement/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,22 @@ func (e messageEvent) AttachValidatedAt(d time.Duration) messageEvent {
return e
}

// AttachReceivedAt looks for an unauthenticatedProposal inside a
// payloadPresent or votePresent messageEvent, and attaches the given
// time to the proposal's receivedAt field.
func (e messageEvent) AttachReceivedAt(d time.Duration) messageEvent {
e.Input.UnauthenticatedProposal.receivedAt = d
if e.T == payloadPresent {
e.Input.UnauthenticatedProposal.receivedAt = d
} else if e.T == votePresent {
// Check for non-nil Tail, indicating this votePresent event
// contains a synthetic payloadPresent event that was attached
// to it by setupCompoundMessage.
if e.Tail != nil && e.Tail.T == payloadPresent {
// The tail event is payloadPresent, serialized together
// with the proposal vote as a single CompoundMessage
// using a protocol.ProposalPayloadTag network message.
e.Tail.Input.UnauthenticatedProposal.receivedAt = d
}
}
return e
}
58 changes: 29 additions & 29 deletions agreement/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 47 additions & 7 deletions agreement/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3244,30 +3244,70 @@ func TestPlayerRetainsReceivedValidatedAt(t *testing.T) {
pWhite, pM, helper := setupP(t, r-1, p, soft)
pP, pV := helper.MakeRandomProposalPayload(t, r-1)

// send a payload
// store an arbitrary proposal/payload
// send voteVerified message
vVote := helper.MakeVerifiedVote(t, 0, r-1, p, propose, *pV)
inMsg := messageEvent{T: voteVerified, Input: message{Vote: vVote, UnauthenticatedVote: vVote.u()}}
err, panicErr := pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

// payloadPresent
// send payloadPresent message
m := message{UnauthenticatedProposal: pP.u()}
inMsg = messageEvent{T: payloadPresent, Input: m}
inMsg = inMsg.AttachReceivedAt(time.Second)
err, panicErr = pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

assertCorrectReceivedAtSet(t, pWhite, pM, helper, r, p, pP, pV, m)
}

// test that ReceivedAt and ValidateAt timing information are retained in proposalStore
// when the payloadPresent (as part of the CompoundMessage encoding used by PP messages)
// and payloadVerified events are processed, and that both timings
// are available when the ensureAction is called for the block.
func TestPlayerRetainsReceivedValidatedAtPP(t *testing.T) {
partitiontest.PartitionTest(t)

const r = round(20239)
const p = period(1001)
pWhite, pM, helper := setupP(t, r-1, p, soft)
pP, pV := helper.MakeRandomProposalPayload(t, r-1)

// create a PP message for an arbitrary proposal/payload similar to setupCompoundMessage
vVote := helper.MakeVerifiedVote(t, 0, r-1, p, propose, *pV)
voteMsg := message{Vote: vVote, UnauthenticatedVote: vVote.u()}
proposalMsg := message{UnauthenticatedProposal: pP.u()}
compoundMsg := messageEvent{T: votePresent, Input: voteMsg,
Tail: &messageEvent{T: payloadPresent, Input: proposalMsg}}
inMsg := compoundMsg.AttachReceivedAt(time.Second) // call AttachReceivedAt like demux would
err, panicErr := pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

// make sure vote verify requests
verifyEvent := ev(cryptoAction{T: verifyVote, M: voteMsg, Round: r - 1, Period: p, Step: propose, TaskIndex: 1})
require.Truef(t, pM.getTrace().Contains(verifyEvent), "Player should verify vote")

// send voteVerified
inMsg = messageEvent{T: voteVerified, Input: voteMsg, TaskIndex: 1}
err, panicErr = pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

assertCorrectReceivedAtSet(t, pWhite, pM, helper, r, p, pP, pV, proposalMsg)
}

func assertCorrectReceivedAtSet(t *testing.T, pWhite *player, pM ioAutomata, helper *voteMakerHelper,
r round, p period, pP *proposal, pV *proposalValue, m message) {
// make sure payload verify request
verifyEvent := ev(cryptoAction{T: verifyPayload, M: m, TaskIndex: 0})
verifyEvent := ev(cryptoAction{T: verifyPayload, M: m, Round: r - 1, Period: p, Step: propose, TaskIndex: 0})
require.Truef(t, pM.getTrace().Contains(verifyEvent), "Player should verify payload")

// payloadVerified
inMsg = messageEvent{T: payloadVerified, Input: message{Proposal: *pP}, Proto: ConsensusVersionView{Version: protocol.ConsensusCurrentVersion}}
inMsg = inMsg.AttachValidatedAt(2 * time.Second)
err, panicErr = pM.transition(inMsg)
inMsg := messageEvent{T: payloadVerified, Input: message{Proposal: *pP}, Proto: ConsensusVersionView{Version: protocol.ConsensusCurrentVersion}}
inMsg = inMsg.AttachValidatedAt(2 * time.Second) // call AttachValidatedAt like demux would
err, panicErr := pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

Expand Down
5 changes: 0 additions & 5 deletions agreement/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ type proposal struct {
// validated (and thus was ready to be delivered to the state
// machine), relative to the zero of that round.
validatedAt time.Duration

// receivedAt indicates the time at which this proposal was
// delivered to the agreement package (as a messageEvent),
// relative to the zero of that round.
receivedAt time.Duration
}

func makeProposal(ve ValidatedBlock, pf crypto.VrfProof, origPer period, origProp basics.Address) proposal {
Expand Down