Skip to content

Commit

Permalink
Varibility in the order of relaying information to subs
Browse files Browse the repository at this point in the history
  • Loading branch information
kiltsonfire authored and gameofpointers committed Aug 22, 2023
1 parent df8814c commit 8be6829
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math/big"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -296,14 +297,24 @@ func (sl *Slice) relayPh(block *types.Block, appendTime *time.Duration, reorg bo
return
}
} else if !domOrigin {
for i := range sl.subClients {
for _, i := range sl.randomRelayArray() {
if sl.subClients[i] != nil {
sl.subClients[i].SubRelayPendingHeader(context.Background(), pendingHeaderWithTermini, location)
}
}
}
}

func (sl *Slice) randomRelayArray() [3]int {
rand.Seed(time.Now().UnixNano())
nums := [3]int{0, 1, 2}
for i := len(nums) - 1; i > 0; i-- {
j := rand.Intn(i + 1)
nums[i], nums[j] = nums[j], nums[i]
}
return nums
}

// asyncPendingHeaderLoop waits for the pendingheader updates from the worker and updates the phCache
func (sl *Slice) asyncPendingHeaderLoop() {

Expand Down Expand Up @@ -514,7 +525,8 @@ func (sl *Slice) SubRelayPendingHeader(pendingHeader types.PendingHeader, locati
return
}
}
for i := range sl.subClients {

for _, i := range sl.randomRelayArray() {
if sl.subClients[i] != nil {
if ph, exists := sl.readPhCache(pendingHeader.Termini().SubTerminiAtIndex(common.NodeLocation.Region())); exists {
sl.subClients[i].SubRelayPendingHeader(context.Background(), ph, location)
Expand Down

0 comments on commit 8be6829

Please sign in to comment.