-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added performed events scanner scanning for work ids in DedupKeyAdded events * refactor upkeep states store * tests * lint * lint in logprovider test * comments and fix scanner close * fix scanner tests * test errors
- Loading branch information
Showing
7 changed files
with
649 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
core/services/ocr2/plugins/ocr2keeper/evm21/upkeep_state_store.go
This file was deleted.
Oops, something went wrong.
137 changes: 0 additions & 137 deletions
137
core/services/ocr2/plugins/ocr2keeper/evm21/upkeep_state_store_test.go
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
core/services/ocr2/plugins/ocr2keeper/evm21/upkeepstate/scanner.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package upkeepstate | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" | ||
iregistry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_keeper_registry_master_wrapper_2_1" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/pg" | ||
) | ||
|
||
type PerformedLogsScanner interface { | ||
WorkIDsInRange(ctx context.Context, start, end int64) ([]string, error) | ||
} | ||
|
||
type performedEventsScanner struct { | ||
lggr logger.Logger | ||
poller logpoller.LogPoller | ||
registryAddress common.Address | ||
} | ||
|
||
func NewPerformedEventsScanner( | ||
lggr logger.Logger, | ||
poller logpoller.LogPoller, | ||
registryAddress common.Address, | ||
) *performedEventsScanner { | ||
return &performedEventsScanner{ | ||
lggr: lggr, | ||
poller: poller, | ||
registryAddress: registryAddress, | ||
} | ||
} | ||
|
||
func (s *performedEventsScanner) Start(_ context.Context) error { | ||
return s.poller.RegisterFilter(logpoller.Filter{ | ||
Name: dedupFilterName(s.registryAddress), | ||
EventSigs: []common.Hash{ | ||
// listening to dedup key added event | ||
iregistry21.IKeeperRegistryMasterDedupKeyAdded{}.Topic(), | ||
}, | ||
Addresses: []common.Address{s.registryAddress}, | ||
}) | ||
} | ||
|
||
// implements io.Closer, does nothing upon close | ||
func (s *performedEventsScanner) Close() error { | ||
return nil | ||
} | ||
|
||
func (s *performedEventsScanner) WorkIDsInRange(ctx context.Context, start, end int64) ([]string, error) { | ||
logs, err := s.poller.LogsWithSigs( | ||
start, | ||
end, | ||
[]common.Hash{ | ||
iregistry21.IKeeperRegistryMasterDedupKeyAdded{}.Topic(), | ||
}, | ||
s.registryAddress, | ||
pg.WithParentCtx(ctx), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("error fetching logs: %w", err) | ||
} | ||
|
||
return s.logsToWorkIDs(logs), nil | ||
} | ||
|
||
func (s *performedEventsScanner) logsToWorkIDs(logs []logpoller.Log) []string { | ||
workIDs := make([]string, 0) | ||
for _, log := range logs { | ||
topics := log.GetTopics() | ||
if len(topics) < 2 { | ||
s.lggr.Debugw("unexpected log topics", "topics", topics) | ||
continue | ||
} | ||
workIDs = append(workIDs, hexutil.Encode(topics[1].Bytes())) | ||
} | ||
return workIDs | ||
} | ||
|
||
func dedupFilterName(addr common.Address) string { | ||
return logpoller.FilterName("KeepersRegistry UpkeepStates Deduped", addr) | ||
} |
Oops, something went wrong.