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

Seed order to manage logs overflow #10485

Merged
merged 24 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lint
  • Loading branch information
amirylm committed Sep 5, 2023
commit ddf86e80f4cebdf6bc2e14ff659ff0bfbc248265
27 changes: 14 additions & 13 deletions core/services/ocr2/plugins/ocr2keeper/evm21/logprovider/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"sync"
"sync/atomic"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/ocr2keepers/pkg/v3/random"
ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/v3/types"
infiloop2 marked this conversation as resolved.
Show resolved Hide resolved

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

var (
Expand All @@ -36,37 +37,37 @@ type fetchedBlock struct {
visited []fetchedLog
}

func (currentBlock *fetchedBlock) Append(lggr logger.Logger, fl fetchedLog, maxBlockLogs, maxUpkeepLogs int) (fetchedLog, bool) {
has, upkeepLogs := currentBlock.has(fl.upkeepID, fl.log)
func (b *fetchedBlock) Append(lggr logger.Logger, fl fetchedLog, maxBlockLogs, maxUpkeepLogs int) (fetchedLog, bool) {
has, upkeepLogs := b.has(fl.upkeepID, fl.log)
if has {
// Skipping known logs
return fetchedLog{}, false
}
// lggr.Debugw("Adding log", "i", i, "blockBlock", currentBlock.blockNumber, "logBlock", log.BlockNumber, "id", id)
currentBlock.logs = append(currentBlock.logs, fl)
b.logs = append(b.logs, fl)

// drop logs if we reached limits.
if upkeepLogs+1 > maxUpkeepLogs {
// in case we have logs overflow for a particular upkeep, we drop a log of that upkeep,
// based on shared, random (per block) order of the logs in the block.
currentBlock.Sort()
b.Sort()
var dropped fetchedLog
currentLogs := make([]fetchedLog, 0, len(currentBlock.logs)-1)
for _, l := range currentBlock.logs {
currentLogs := make([]fetchedLog, 0, len(b.logs)-1)
for _, l := range b.logs {
if dropped.upkeepID == nil && l.upkeepID.Cmp(fl.upkeepID) == 0 {
dropped = l
continue
}
currentLogs = append(currentLogs, l)
}
currentBlock.logs = currentLogs
b.logs = currentLogs
return dropped, true
} else if len(currentBlock.logs)+len(currentBlock.visited) > maxBlockLogs {
} else if len(b.logs)+len(b.visited) > maxBlockLogs {
// in case we have logs overflow in the buffer level, we drop a log based on
// shared, random (per block) order of the logs in the block.
currentBlock.Sort()
dropped := currentBlock.logs[0]
currentBlock.logs = currentBlock.logs[1:]
b.Sort()
dropped := b.logs[0]
b.logs = b.logs[1:]
return dropped, true
}

Expand Down
1 change: 1 addition & 0 deletions core/services/ocr2/plugins/ocr2keeper/evm21/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func (r *EvmRegistry) refreshActiveUpkeeps() error {
switch core.GetUpkeepType(*uid) {
case ocr2keepers.LogTrigger:
logTriggerIDs = append(logTriggerIDs, id)
default:
infiloop2 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down