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

BCF - 3139 Chain Reader Log Poller filters in config and some code cleanup #13356

Merged
merged 28 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aec73ec
Inital commit for log poller filters in config
ilija42 May 17, 2024
816ef3c
Merge remote-tracking branch 'origin/develop' into BCF-3139-chreader-…
ilija42 May 29, 2024
58c637d
Change Chain Reader Lp filters from per event binding to per contract
ilija42 May 29, 2024
e559f27
Merge remote-tracking branch 'origin/develop' into BCF-3139-chreader-…
ilija42 May 30, 2024
53a7dfb
Fix lint
ilija42 May 30, 2024
0055f69
Add ChReader contract log poller filter init
ilija42 May 30, 2024
a1cdcf9
Add per event polling filter override for Chain Reader
ilija42 May 31, 2024
474097a
Fix event definitions and filters handling in CR
ilija42 Jun 4, 2024
46e211d
Add changeset and lint
ilija42 Jun 4, 2024
ed7fbc3
Update variable naming in chain reader bindings.go
ilija42 Jun 4, 2024
1bd0753
Merge remote-tracking branch 'origin/develop' into BCF-3139-chreader-…
ilija42 Jun 4, 2024
23b7a8d
Change write target test
ilija42 Jun 4, 2024
09b7c37
Fix filter handling
ilija42 Jun 5, 2024
4e23914
Change contractBinding to not manage readBinding lp filters and lint
ilija42 Jun 6, 2024
affbb79
Move contractBinding to a separate file
ilija42 Jun 6, 2024
883d971
Improve event and contract bind handling and lint
ilija42 Jun 6, 2024
4cf0ec7
Handle concurrency edge cases in reader bindings
ilija42 Jun 6, 2024
c8c8739
Minor lint
ilija42 Jun 6, 2024
ebf32cb
Merge branch 'develop' into BCF-3139-chreader-lp-filter-config
ilija42 Jun 7, 2024
a9aa2f0
Add event validation test and some comments to chain reader
ilija42 Jun 10, 2024
0cfc95a
Add Chain Reader config json marshall test
ilija42 Jun 10, 2024
4a272d0
Use require instead of assert for Test_ChainReaderConfig
ilija42 Jun 11, 2024
d3f8ae0
Add comments to AddReadBinding
ilija42 Jun 11, 2024
81d9b9d
Rename CR verifyEventInputsUsed to verifyEventIndexedInputsUsed
ilija42 Jun 13, 2024
963d162
Merge remote-tracking branch 'origin/develop' into BCF-3139-chreader-…
ilija42 Jun 13, 2024
3acb2c4
Resolve merge issues in chain_reader_interface_tester.go
ilija42 Jun 13, 2024
1404497
Merge branch 'develop' into BCF-3139-chreader-lp-filter-config
reductionista Jun 13, 2024
1b51a25
Merge branch 'develop' into BCF-3139-chreader-lp-filter-config
ilija42 Jun 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/eleven-buckets-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#internal Add Log Poller support to Chain Reader through setting them in config. All filters should be part of the contract wide filter unless an event needs specific polling configuration, which can be set on a per event basis..
1 change: 1 addition & 0 deletions core/chains/evm/logpoller/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ func (o *DSORM) SelectIndexedLogsWithSigsExcluding(ctx context.Context, sigA, si
return logs, nil
}

// TODO flaky BCF-3258
func (o *DSORM) FilteredLogs(ctx context.Context, filter query.KeyFilter, limitAndSort query.LimitAndSort, _ string) ([]Log, error) {
qs, args, err := (&pgDSLParser{}).buildQuery(o.chainID, filter.Expressions, limitAndSort)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions core/internal/features/ocr2/features_ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ fromBlock = %d
if test.chainReaderAndCodec {
chainReaderSpec = `
[relayConfig.chainReader.contracts.median]
contractPollingFilter.genericEventNames = ["LatestRoundRequested"]

contractABI = '''
[
{
Expand Down
4 changes: 2 additions & 2 deletions core/services/relay/evm/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

type readBinding interface {
GetLatestValue(ctx context.Context, params, returnVal any) error
QueryKey(ctx context.Context, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error)
Bind(ctx context.Context, binding commontypes.BoundContract) error
SetCodec(codec commontypes.RemoteCodec)
Register(ctx context.Context) error
Unregister(ctx context.Context) error
GetLatestValue(ctx context.Context, params, returnVal any) error
QueryKey(ctx context.Context, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error)
}
64 changes: 36 additions & 28 deletions core/services/relay/evm/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,65 @@ import (
"fmt"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
)

// key is contract name
type contractBindings map[string]readBindings
// bindings manage all contract bindings, key is contract name.
type bindings map[string]*contractBinding
ilija42 marked this conversation as resolved.
Show resolved Hide resolved

// key is read name
type readBindings map[string]readBinding

func (b contractBindings) GetReadBinding(contractName, readName string) (readBinding, error) {
rb, rbExists := b[contractName]
if !rbExists {
func (b bindings) GetReadBinding(contractName, readName string) (readBinding, error) {
// GetReadBindings should only be called after Chain Reader init.
cb, cbExists := b[contractName]
if !cbExists {
return nil, fmt.Errorf("%w: no contract named %s", commontypes.ErrInvalidType, contractName)
}

reader, readerExists := rb[readName]
if !readerExists {
rb, rbExists := cb.readBindings[readName]
if !rbExists {
return nil, fmt.Errorf("%w: no readName named %s in contract %s", commontypes.ErrInvalidType, readName, contractName)
}
return reader, nil
return rb, nil
}

func (b contractBindings) AddReadBinding(contractName, readName string, reader readBinding) {
rbs, rbsExists := b[contractName]
if !rbsExists {
rbs = readBindings{}
b[contractName] = rbs
// AddReadBinding adds read bindings. Calling this outside of Chain Reader init is not thread safe.
func (b bindings) AddReadBinding(contractName, readName string, rb readBinding) {
cb, cbExists := b[contractName]
if !cbExists {
cb = &contractBinding{
name: contractName,
readBindings: make(map[string]readBinding),
}
b[contractName] = cb
}
rbs[readName] = reader
cb.readBindings[readName] = rb
}

func (b contractBindings) Bind(ctx context.Context, boundContracts []commontypes.BoundContract) error {
// Bind binds contract addresses to contract bindings and read bindings.
// Bind also registers the common contract polling filter and eventBindings polling filters.
func (b bindings) Bind(ctx context.Context, lp logpoller.LogPoller, boundContracts []commontypes.BoundContract) error {
for _, bc := range boundContracts {
rbs, rbsExist := b[bc.Name]
if !rbsExist {
cb, cbExists := b[bc.Name]
if !cbExists {
return fmt.Errorf("%w: no contract named %s", commontypes.ErrInvalidConfig, bc.Name)
}
for _, r := range rbs {
if err := r.Bind(ctx, bc); err != nil {

if err := cb.Bind(ctx, lp, bc); err != nil {
return err
}

for _, rb := range cb.readBindings {
if err := rb.Bind(ctx, bc); err != nil {
return err
}
}
}
return nil
}

func (b contractBindings) ForEach(ctx context.Context, fn func(readBinding, context.Context) error) error {
for _, rbs := range b {
for _, rb := range rbs {
if err := fn(rb, ctx); err != nil {
return err
}
func (b bindings) ForEach(ctx context.Context, fn func(context.Context, *contractBinding) error) error {
for _, cb := range b {
if err := fn(ctx, cb); err != nil {
return err
}
}
return nil
Expand Down
Loading
Loading