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
6 changes: 3 additions & 3 deletions kaiax/vrank/impl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func (v *VRankModule) HandleVRankCandidate(msg *vrank.VRankCandidate) error {
if err != nil {
return err
}
if v.collector.HasCandMsg(vk, sender) {
return nil
}
blsNum := big.NewInt(0).Add(v.Chain.CurrentHeader().Number, big.NewInt(1)) // head + 1
blsPub, err := v.Randao.GetBlsPubkey(sender, blsNum)
if err != nil {
Expand All @@ -182,9 +185,6 @@ func (v *VRankModule) HandleVRankCandidate(msg *vrank.VRankCandidate) error {
if err != nil || !ok {
return vrank.ErrInvalidCandidateBlsSig
}
if v.collector.HasCandMsg(vk, sender) {
return nil
}
v.collector.AddCandMsg(vk, sender, receivedAt, msg)
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions kaiax/vrank/impl/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,13 @@ func TestHandleVRankCandidate(t *testing.T) {
assert.Equal(t, receivedAt, cm.ReceivedAt, "ReceivedAt should not change on duplicate")
}
}

// This replay carries a BLS signature from the wrong key. Dropping it without an error
// means the duplicate check ran before the verification.
_, wrongBlsSig := signVRankCandidate(t, val.VRankModule, val.Key, val.BlsKey, msg.BlockNumber, msg.Round, msg.BlockHash)
replay := msg
replay.BlsSig = wrongBlsSig
assert.NoError(t, val.VRankModule.HandleVRankCandidate(&replay))
})

t.Run("stale messages should be discarded", func(t *testing.T) {
Expand Down
Loading