Skip to content

Commit

Permalink
add LLR votes for right epoch only
Browse files Browse the repository at this point in the history
  • Loading branch information
rus-alex authored and uprendis committed Sep 12, 2023
1 parent 85695db commit ad3e9b2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
27 changes: 22 additions & 5 deletions gossip/emitter/emitter_llr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ func (em *Emitter) addLlrBlockVotes(e *inter.MutableEventPayload) {
if prevInFile != nil && start < *prevInFile+1 {
start = *prevInFile + 1
}
records := make([]hash.Hash, 0, 16)
records := make([]hash.Hash, 0, basiccheck.MaxBlockVotesPerEvent)
epochEnd := false
var epoch idx.Epoch
for b := start; len(records) < basiccheck.MaxBlockVotesPerEvent; b++ {
record := em.world.GetBlockRecordHash(b)
if record == nil {
break
}
blockEpoch := em.world.GetBlockEpoch(b)
if epoch == 0 {
if !em.isEpochValidator(blockEpoch) {
continue
}
epoch = blockEpoch
start = b
}
if epoch != blockEpoch || blockEpoch == 0 {
epochEnd = true
break
}
record := em.world.GetBlockRecordHash(b)
if record == nil {
break
}
records = append(records, *record)
}

Expand Down Expand Up @@ -73,6 +77,9 @@ func (em *Emitter) addLlrEpochVote(e *inter.MutableEventPayload) {
if prevInFile != nil && target < *prevInFile+1 {
target = *prevInFile + 1
}
if !em.isEpochValidator(target) {
return
}
vote := em.world.GetEpochRecordHash(target)
if vote == nil {
return
Expand Down Expand Up @@ -106,3 +113,13 @@ func (em *Emitter) skipLlrEpochVote() bool {
// otherwise, poor validators have a small chance to vote
return rand.Intn(30) != 0
}

func (em *Emitter) isEpochValidator(epoch idx.Epoch) bool {
es := em.world.GetHistoryEpochState(epoch)
if es == nil {
return false
}

_, ok := es.ValidatorProfiles[em.config.Validator.ID]
return ok
}
15 changes: 15 additions & 0 deletions gossip/emitter/mock/world.go

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

2 changes: 2 additions & 0 deletions gossip/emitter/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"

"github.com/Fantom-foundation/go-opera/inter"
"github.com/Fantom-foundation/go-opera/inter/iblockproc"
"github.com/Fantom-foundation/go-opera/opera"
"github.com/Fantom-foundation/go-opera/valkeystore"
"github.com/Fantom-foundation/go-opera/vecmt"
Expand Down Expand Up @@ -69,6 +70,7 @@ type Reader interface {
LlrReader
GetLatestBlockIndex() idx.Block
GetEpochValidators() (*pos.Validators, idx.Epoch)
GetHistoryEpochState(epoch idx.Epoch) *iblockproc.EpochState
GetEvent(hash.Event) *inter.Event
GetEventPayload(hash.Event) *inter.EventPayload
GetLastEvent(epoch idx.Epoch, from idx.ValidatorID) *hash.Event
Expand Down

0 comments on commit ad3e9b2

Please sign in to comment.