Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ferglor committed Jun 7, 2024
1 parent 2aae7a7 commit 214b0c6
Show file tree
Hide file tree
Showing 2 changed files with 1,163 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type logEventProvider struct {
func newDequeueCoordinator() *dequeueCoordinator {
return &dequeueCoordinator{
dequeuedMinimum: map[int64]bool{},
notReady: map[int64]bool{},
remainingLogs: map[int64]int{},
dequeuedLogs: map[int64]int{},
completeWindows: map[int64]bool{},
Expand All @@ -134,6 +135,7 @@ func newDequeueCoordinator() *dequeueCoordinator {

type dequeueCoordinator struct {
dequeuedMinimum map[int64]bool
notReady map[int64]bool
remainingLogs map[int64]int
dequeuedLogs map[int64]int
completeWindows map[int64]bool
Expand All @@ -142,10 +144,12 @@ type dequeueCoordinator struct {

func (c *dequeueCoordinator) dequeueBlockWindow(start int64, latestBlock int64, blockRate int) (int64, int64, bool) {
// check if minimum logs have been dequeued
for i := start; i < latestBlock; i += int64(blockRate) {
startWindow, end := getBlockWindow(start, blockRate)
for i := start; i <= latestBlock; i += int64(blockRate) {
startWindow, end := getBlockWindow(i, blockRate)
if latestBlock >= end {
c.completeWindows[startWindow] = true
} else if c.notReady[startWindow] { // the window is incomplete and has no logs to provide as of yet
return 0, 0, false
}

if hasDequeued, ok := c.dequeuedMinimum[startWindow]; ok {

Check failure on line 155 in core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/logprovider/provider.go

View workflow job for this annotation

GitHub Actions / lint

early-return: if c { ... } else { ... return } can be simplified to if !c { ... return } ... (move short variable declaration to its own line if necessary) (revive)
Expand All @@ -159,7 +163,7 @@ func (c *dequeueCoordinator) dequeueBlockWindow(start int64, latestBlock int64,

// check best effort dequeue
for i := start; i < latestBlock; i += int64(blockRate) {
startWindow, end := getBlockWindow(start, blockRate)
startWindow, end := getBlockWindow(i, blockRate)

if remainingLogs, ok := c.remainingLogs[startWindow]; ok {
if remainingLogs > 0 {
Expand Down Expand Up @@ -220,6 +224,8 @@ func (c *dequeueCoordinator) updateBlockWindow(startWindow int64, logs, remainin
}
} else if c.dequeuedLogs[startWindow] >= numberOfUpkeeps*logLimitLow { // this assumes we don't dequeue the same upkeeps more than logLimitLow in min commitment
c.dequeuedMinimum[startWindow] = true
} else if logs == 0 && remaining == 0 {
c.notReady[startWindow] = true
}
}

Expand Down
Loading

0 comments on commit 214b0c6

Please sign in to comment.