-
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.
evm implementation of query keys api
- Loading branch information
Showing
14 changed files
with
266 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ require ( | |
github.com/prometheus/client_golang v1.20.5 | ||
github.com/shopspring/decimal v1.4.0 | ||
github.com/smartcontractkit/chainlink-automation v0.8.1 | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241204184525-29871ced7b4d | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206101351-7a8b9d81635c | ||
Check failure on line 29 in core/scripts/go.mod GitHub Actions / Validate go.mod dependencies
|
||
github.com/smartcontractkit/chainlink/deployment v0.0.0-00010101000000-000000000000 | ||
github.com/smartcontractkit/chainlink/v2 v2.14.0-mercury-20240807.0.20241106193309-5560cd76211a | ||
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12 | ||
|
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
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
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
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
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,156 @@ | ||
package read | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"iter" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
||
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" | ||
"github.com/smartcontractkit/chainlink-common/pkg/types/query" | ||
"github.com/smartcontractkit/chainlink-common/pkg/values" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" | ||
) | ||
|
||
type EventQuery struct { | ||
Filter query.KeyFilter | ||
EventBinding *EventBinding | ||
SequenceDataType any | ||
IsValuePtr bool | ||
Address common.Address | ||
} | ||
|
||
func MultiEventTypeQuery(ctx context.Context, lp logpoller.LogPoller, eventQueries []EventQuery, limitAndSort query.LimitAndSort) (sequences iter.Seq2[string, commontypes.Sequence], err error) { | ||
defer func() { | ||
if err != nil { | ||
if len(eventQueries) > 0 { | ||
var calls []Call | ||
for _, eq := range eventQueries { | ||
calls = append(calls, Call{ | ||
ContractAddress: eq.Address, | ||
ContractName: eq.EventBinding.contractName, | ||
ReadName: eq.EventBinding.eventName, | ||
ReturnVal: eq.SequenceDataType, | ||
}) | ||
} | ||
|
||
err = newErrorFromCalls(err, calls, "", eventReadType) | ||
} else { | ||
err = fmt.Errorf("no event queries provided: %w", err) | ||
} | ||
} | ||
}() | ||
|
||
for _, eq := range eventQueries { | ||
if err = eq.EventBinding.validateBound(eq.Address); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
allFilterExpressions := make([]query.Expression, 0, len(eventQueries)) | ||
for _, eq := range eventQueries { | ||
var expressions []query.Expression | ||
|
||
defaultExpressions := []query.Expression{ | ||
logpoller.NewAddressFilter(eq.Address), | ||
logpoller.NewEventSigFilter(eq.EventBinding.hash), | ||
} | ||
expressions = append(expressions, defaultExpressions...) | ||
|
||
remapped, remapErr := eq.EventBinding.remap(eq.Filter) | ||
if remapErr != nil { | ||
return nil, fmt.Errorf("error remapping filter: %w", err) | ||
} | ||
expressions = append(expressions, remapped.Expressions...) | ||
|
||
filterExpression := query.And(expressions...) | ||
|
||
allFilterExpressions = append(allFilterExpressions, filterExpression) | ||
} | ||
|
||
eventQuery := query.Or(allFilterExpressions...) | ||
|
||
queryName := "" | ||
for _, eq := range eventQueries { | ||
queryName += eq.EventBinding.contractName + "-" + eq.Address.String() + "-" + eq.EventBinding.eventName + "-" | ||
} | ||
queryName = strings.TrimSuffix(queryName, "-") | ||
|
||
logs, err := lp.FilteredLogs(ctx, []query.Expression{eventQuery}, limitAndSort, queryName) | ||
if err != nil { | ||
return nil, wrapInternalErr(err) | ||
} | ||
|
||
return decodeMultiEventTypeLogsIntoSequences(ctx, logs, eventQueries) | ||
} | ||
|
||
func decodeMultiEventTypeLogsIntoSequences(ctx context.Context, logs []logpoller.Log, eventQueries []EventQuery) (iter.Seq2[string, commontypes.Sequence], error) { | ||
type sequenceWithKey struct { | ||
Key string | ||
Sequence commontypes.Sequence | ||
} | ||
sequenceWithKeys := make([]sequenceWithKey, 0, len(logs)) | ||
eventSigToEventQuery := map[common.Hash]EventQuery{} | ||
for _, eq := range eventQueries { | ||
eventSigToEventQuery[eq.EventBinding.hash] = eq | ||
} | ||
|
||
for _, logEntry := range logs { | ||
eventSignatureHash := logEntry.EventSig | ||
|
||
eq, exists := eventSigToEventQuery[eventSignatureHash] | ||
if !exists { | ||
return nil, fmt.Errorf("no event query found for log with event signature %s", eventSignatureHash) | ||
} | ||
|
||
seqWithKey := sequenceWithKey{ | ||
Key: eq.Filter.Key, | ||
Sequence: commontypes.Sequence{ | ||
Cursor: logpoller.FormatContractReaderCursor(logEntry), | ||
Head: commontypes.Head{ | ||
Height: strconv.FormatInt(logEntry.BlockNumber, 10), | ||
Hash: logEntry.BlockHash.Bytes(), | ||
Timestamp: uint64(logEntry.BlockTimestamp.Unix()), //nolint:gosec // G115 false positive | ||
}, | ||
}, | ||
} | ||
|
||
var typeVal reflect.Value | ||
|
||
typeInto := reflect.TypeOf(eq.SequenceDataType) | ||
if typeInto.Kind() == reflect.Pointer { | ||
typeVal = reflect.New(typeInto.Elem()) | ||
} else { | ||
typeVal = reflect.Indirect(reflect.New(typeInto)) | ||
} | ||
|
||
// create a new value of the same type as 'into' for the data to be extracted to | ||
seqWithKey.Sequence.Data = typeVal.Interface() | ||
|
||
if err := eq.EventBinding.decodeLog(ctx, &logEntry, seqWithKey.Sequence.Data); err != nil { | ||
return nil, err | ||
} | ||
|
||
if eq.IsValuePtr { | ||
wrappedValue, err := values.Wrap(seqWithKey.Sequence.Data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
seqWithKey.Sequence.Data = &wrappedValue | ||
} | ||
|
||
sequenceWithKeys = append(sequenceWithKeys, seqWithKey) | ||
} | ||
|
||
return func(yield func(string, commontypes.Sequence) bool) { | ||
for _, s := range sequenceWithKeys { | ||
if !yield(s.Key, s.Sequence) { | ||
return | ||
} | ||
} | ||
}, nil | ||
} |
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ require ( | |
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240926212305-a6deabdfce86 | ||
github.com/smartcontractkit/chain-selectors v1.0.31 | ||
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241204015713-8956bb614e9e | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241204184525-29871ced7b4d | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206101351-7a8b9d81635c | ||
Check failure on line 28 in deployment/go.mod GitHub Actions / Validate go.mod dependencies
|
||
github.com/smartcontractkit/chainlink-protos/job-distributor v0.6.0 | ||
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.13 | ||
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 | ||
|
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
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 |
---|---|---|
|
@@ -79,7 +79,7 @@ require ( | |
github.com/smartcontractkit/chain-selectors v1.0.31 | ||
github.com/smartcontractkit/chainlink-automation v0.8.1 | ||
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241204015713-8956bb614e9e | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241204184525-29871ced7b4d | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206101351-7a8b9d81635c | ||
Check failure on line 82 in go.mod GitHub Actions / Validate go.mod dependencies
|
||
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241202195413-82468150ac1e | ||
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241202141438-a90db35252db | ||
github.com/smartcontractkit/chainlink-feeds v0.1.1 | ||
|
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
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 |
---|---|---|
|
@@ -41,7 +41,7 @@ require ( | |
github.com/smartcontractkit/chain-selectors v1.0.31 | ||
github.com/smartcontractkit/chainlink-automation v0.8.1 | ||
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241204015713-8956bb614e9e | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241204184525-29871ced7b4d | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206101351-7a8b9d81635c | ||
Check failure on line 44 in integration-tests/go.mod GitHub Actions / Validate go.mod dependencies
|
||
github.com/smartcontractkit/chainlink-protos/job-distributor v0.6.0 | ||
github.com/smartcontractkit/chainlink-testing-framework/havoc v1.50.2 | ||
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.18 | ||
|
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
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ require ( | |
github.com/pkg/errors v0.9.1 | ||
github.com/rs/zerolog v1.33.0 | ||
github.com/slack-go/slack v0.15.0 | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241204184525-29871ced7b4d | ||
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206101351-7a8b9d81635c | ||
Check failure on line 22 in integration-tests/load/go.mod GitHub Actions / Validate go.mod dependencies
|
||
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.18 | ||
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.9 | ||
github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.2 | ||
|
Oops, something went wrong.