Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra committed Oct 8, 2024
2 parents b33f7ec + c654322 commit 99965a4
Show file tree
Hide file tree
Showing 30 changed files with 757 additions and 243 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-swans-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#internal Add support for data word detail manual input in Contract Reader for searching through EVM log event data with Contract Reader QueryKey ValueComparators.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# To be deprecated in Chainlink V3
/core/services/fluxmonitorv2 @smartcontractkit/foundations
/core/services/job @smartcontractkit/ccip
/core/services/job @smartcontractkit/foundations
/core/services/keystore @smartcontractkit/foundations
/core/services/ocr* @smartcontractkit/foundations
/core/services/periodicbackup @smartcontractkit/foundations
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ race.*
golangci-lint-output.txt
/golangci-lint/
.covdata
core/services/job/testdata/wasm/testmodule.wasm
core/services/job/testdata/wasm/testmodule.br

# DB state
./db/
Expand Down
5 changes: 5 additions & 0 deletions contracts/.changeset/funny-meals-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': minor
---

#internal Modify Contract Reader tester helper BCFR-912
28 changes: 18 additions & 10 deletions contracts/src/v0.8/automation/testhelpers/LogUpkeepCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ contract LogUpkeepCounter is ILogAutomation {
uint256 public previousPerformBlock;
uint256 public initialBlock;
uint256 public counter;
bool public autoExecution;

constructor(uint256 _testRange) {
testRange = _testRange;
previousPerformBlock = 0;
lastBlock = block.number;
initialBlock = 0;
counter = 0;
autoExecution = true;
}

function start() public {
Expand Down Expand Up @@ -65,16 +67,18 @@ contract LogUpkeepCounter is ILogAutomation {
counter = counter + 1;
previousPerformBlock = lastBlock;
Log memory log = abi.decode(performData, (Log));
if (log.topics[0] == sig1) {
emit Trigger();
} else if (log.topics[0] == sig2) {
emit Trigger(1);
} else if (log.topics[0] == sig3) {
emit Trigger(1, 2);
} else if (log.topics[0] == sig4) {
emit Trigger(1, 2, 3);
} else {
revert("could not find matching sig");
if (autoExecution) {
if (log.topics[0] == sig1) {
emit Trigger();
} else if (log.topics[0] == sig2) {
emit Trigger(1);
} else if (log.topics[0] == sig3) {
emit Trigger(1, 2);
} else if (log.topics[0] == sig4) {
emit Trigger(1, 2, 3);
} else {
revert("could not find matching sig");
}
}
emit PerformingUpkeep(tx.origin, initialBlock, lastBlock, previousPerformBlock, counter);
}
Expand All @@ -92,4 +96,8 @@ contract LogUpkeepCounter is ILogAutomation {
initialBlock = 0;
counter = 0;
}

function setAuto(bool _auto) external {
autoExecution = _auto;
}
}
18 changes: 18 additions & 0 deletions contracts/src/v0.8/shared/test/helpers/ChainReaderTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ contract ChainReaderTester {
// first topic is event hash, second and third topics get hashed before getting stored
event TriggeredWithFourTopicsWithHashed(string indexed field1, uint8[32] indexed field2, bytes32 indexed field3);

// emits dynamic bytes which encode data in the same way every time.
event StaticBytes(bytes message);

TestStruct[] private s_seen;
uint64[] private s_arr;
uint64 private s_value;
Expand Down Expand Up @@ -181,4 +184,19 @@ contract ChainReaderTester {
function triggerWithFourTopicsWithHashed(string memory field1, uint8[32] memory field2, bytes32 field3) public {
emit TriggeredWithFourTopicsWithHashed(field1, field2, field3);
}

// emulate CCTP message event.
function triggerStaticBytes(
uint32 val1,
uint32 val2,
uint32 val3,
uint64 val4,
bytes32 val5,
bytes32 val6,
bytes32 val7,
bytes memory raw
) public {
bytes memory _message = abi.encodePacked(val1, val2, val3, val4, val5, val6, val7, raw);
emit StaticBytes(_message);
}
}
1 change: 1 addition & 0 deletions core/capabilities/triggers/logevent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
Network string `json:"network"`
LookbackBlocks uint64 `json:"lookbakBlocks"`
PollPeriod uint32 `json:"pollPeriod"`
QueryCount uint64 `json:"queryCount"`
}

func (config Config) Version(capabilityVersion string) string {
Expand Down
7 changes: 6 additions & 1 deletion core/capabilities/triggers/logevent/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func newLogEventTrigger(ctx context.Context,
callbackCh := make(chan capabilities.TriggerResponse, defaultSendChannelBufferSize)
ticker := time.NewTicker(time.Duration(logEventConfig.PollPeriod) * time.Millisecond)

if logEventConfig.QueryCount == 0 {
logEventConfig.QueryCount = 20
}

// Initialise a Log Event Trigger
l := &logEventTrigger{
ch: callbackCh,
Expand Down Expand Up @@ -120,6 +124,7 @@ func (l *logEventTrigger) listen() {
cursor := ""
limitAndSort := query.LimitAndSort{
SortBy: []query.SortBy{query.NewSortByTimestamp(query.Asc)},
Limit: query.Limit{Count: l.logEventConfig.QueryCount},
}
for {
select {
Expand All @@ -134,7 +139,7 @@ func (l *logEventTrigger) listen() {
"startBlockNum", l.startBlockNum,
"cursor", cursor)
if cursor != "" {
limitAndSort.Limit = query.Limit{Cursor: cursor}
limitAndSort.Limit = query.CursorLimit(cursor, query.CursorFollowing, l.logEventConfig.QueryCount)
}
logs, err = l.contractReader.QueryKey(
ctx,
Expand Down
147 changes: 145 additions & 2 deletions core/gethwrappers/generated/chain_reader_tester/chain_reader_tester.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ batch_vrf_coordinator_v2: ../../contracts/solc/v0.8.6/BatchVRFCoordinatorV2/Batc
batch_vrf_coordinator_v2plus: ../../contracts/solc/v0.8.19/BatchVRFCoordinatorV2Plus/BatchVRFCoordinatorV2Plus.abi ../../contracts/solc/v0.8.19/BatchVRFCoordinatorV2Plus/BatchVRFCoordinatorV2Plus.bin f13715b38b5b9084b08bffa571fb1c8ef686001535902e1255052f074b31ad4e
blockhash_store: ../../contracts/solc/v0.8.19/BlockhashStore/BlockhashStore.abi ../../contracts/solc/v0.8.19/BlockhashStore/BlockhashStore.bin 31b118f9577240c8834c35f8b5a1440e82a6ca8aea702970de2601824b6ab0e1
chain_module_base: ../../contracts/solc/v0.8.19/ChainModuleBase/ChainModuleBase.abi ../../contracts/solc/v0.8.19/ChainModuleBase/ChainModuleBase.bin 7a82cc28014761090185c2650239ad01a0901181f1b2b899b42ca293bcda3741
chain_reader_tester: ../../contracts/solc/v0.8.19/ChainReaderTester/ChainReaderTester.abi ../../contracts/solc/v0.8.19/ChainReaderTester/ChainReaderTester.bin b9a488fc786f584a617764d8dc1722acdb30defb6b8f638e0ae03442795eaf3e
chain_reader_tester: ../../contracts/solc/v0.8.19/ChainReaderTester/ChainReaderTester.abi ../../contracts/solc/v0.8.19/ChainReaderTester/ChainReaderTester.bin 21fcc5fae2a95ce11590bcfc9ea2bde5ad9158f8dcb4efce7264492f8ad2b0a6
chain_specific_util_helper: ../../contracts/solc/v0.8.6/ChainSpecificUtilHelper/ChainSpecificUtilHelper.abi ../../contracts/solc/v0.8.6/ChainSpecificUtilHelper/ChainSpecificUtilHelper.bin 66eb30b0717fefe05672df5ec863c0b9a5a654623c4757307a2726d8f31e26b1
counter: ../../contracts/solc/v0.8.6/Counter/Counter.abi ../../contracts/solc/v0.8.6/Counter/Counter.bin 6ca06e000e8423573ffa0bdfda749d88236ab3da2a4cbb4a868c706da90488c9
cron_upkeep_factory_wrapper: ../../contracts/solc/v0.8.6/CronUpkeepFactory/CronUpkeepFactory.abi - dacb0f8cdf54ae9d2781c5e720fc314b32ed5e58eddccff512c75d6067292cd7
Expand Down Expand Up @@ -54,7 +54,7 @@ keeper_registry_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistry2_1/Keep
keepers_vrf_consumer: ../../contracts/solc/v0.8.6/KeepersVRFConsumer/KeepersVRFConsumer.abi ../../contracts/solc/v0.8.6/KeepersVRFConsumer/KeepersVRFConsumer.bin fa75572e689c9e84705c63e8dbe1b7b8aa1a8fe82d66356c4873d024bb9166e8
log_emitter: ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.abi ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.bin 4b129ab93432c95ff9143f0631323e189887668889e0b36ccccf18a571e41ccf
log_triggered_streams_lookup_wrapper: ../../contracts/solc/v0.8.16/LogTriggeredStreamsLookup/LogTriggeredStreamsLookup.abi ../../contracts/solc/v0.8.16/LogTriggeredStreamsLookup/LogTriggeredStreamsLookup.bin 920fff3b662909f12ed11b47d168036ffa74ad52070a94e2fa26cdad5e428b4e
log_upkeep_counter_wrapper: ../../contracts/solc/v0.8.6/LogUpkeepCounter/LogUpkeepCounter.abi ../../contracts/solc/v0.8.6/LogUpkeepCounter/LogUpkeepCounter.bin 42426bbb83f96dfbe55fc576d6c65020eaeed690e2289cf99b0c4aa810a5f4ec
log_upkeep_counter_wrapper: ../../contracts/solc/v0.8.6/LogUpkeepCounter/LogUpkeepCounter.abi ../../contracts/solc/v0.8.6/LogUpkeepCounter/LogUpkeepCounter.bin 5482033d55eddb653bf580de0cc950db89a329091e085ac4122583df4a9777cd
mock_aggregator_proxy: ../../contracts/solc/v0.8.6/MockAggregatorProxy/MockAggregatorProxy.abi ../../contracts/solc/v0.8.6/MockAggregatorProxy/MockAggregatorProxy.bin b16c108f3dd384c342ddff5e94da7c0a8d39d1be5e3d8f2cf61ecc7f0e50ff42
mock_ethusd_aggregator_wrapper: ../../contracts/solc/v0.8.19/MockETHUSDAggregator/MockETHUSDAggregator.abi ../../contracts/solc/v0.8.19/MockETHUSDAggregator/MockETHUSDAggregator.bin b9b361f502d2aad32311c60ca86b071de93a024ac488bcfa19725d368cd05d61
offchain_aggregator_wrapper: OffchainAggregator/OffchainAggregator.abi - 5c8d6562e94166d4790f1ee6e4321d359d9f7262e6c5452a712b1f1c896f45cf
Expand Down
25 changes: 15 additions & 10 deletions core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/types"
pkgworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows"

"github.com/smartcontractkit/chainlink/v2/core/services/relay"

Expand Down Expand Up @@ -865,7 +864,8 @@ type WorkflowSpecType string

const (
YamlSpec WorkflowSpecType = "yaml"
DefaultSpecType = YamlSpec
WASMFile WorkflowSpecType = "wasm_file"
DefaultSpecType = ""
)

type WorkflowSpec struct {
Expand All @@ -879,7 +879,7 @@ type WorkflowSpec struct {
WorkflowName string `toml:"-" db:"workflow_name"` // Derived. Do not modify. the name of the workflow.
CreatedAt time.Time `toml:"-"`
UpdatedAt time.Time `toml:"-"`
SpecType WorkflowSpecType `db:"spec_type"`
SpecType WorkflowSpecType `toml:"spec_type" db:"spec_type"`
sdkWorkflow *sdk.WorkflowSpec
rawSpec []byte
}
Expand All @@ -895,12 +895,8 @@ const (

// Validate checks the workflow spec for correctness
func (w *WorkflowSpec) Validate(ctx context.Context) error {
s, err := pkgworkflows.ParseWorkflowSpecYaml(w.Workflow)
s, err := w.SDKSpec(ctx)
if err != nil {
return fmt.Errorf("%w: failed to parse workflow spec %s: %w", ErrInvalidWorkflowYAMLSpec, w.Workflow, err)
}

if _, err = w.SDKSpec(ctx); err != nil {
return err
}

Expand All @@ -919,7 +915,11 @@ func (w *WorkflowSpec) SDKSpec(ctx context.Context) (sdk.WorkflowSpec, error) {
return *w.sdkWorkflow, nil
}

spec, rawSpec, cid, err := workflowSpecFactory.Spec(ctx, w.Workflow, []byte(w.Config), w.SpecType)
workflowSpecFactory, ok := workflowSpecFactories[w.SpecType]
if !ok {
return sdk.WorkflowSpec{}, fmt.Errorf("unknown spec type %s", w.SpecType)
}
spec, rawSpec, cid, err := workflowSpecFactory.Spec(ctx, w.Workflow, []byte(w.Config))
if err != nil {
return sdk.WorkflowSpec{}, err
}
Expand All @@ -934,7 +934,12 @@ func (w *WorkflowSpec) RawSpec(ctx context.Context) ([]byte, error) {
return w.rawSpec, nil
}

rs, err := workflowSpecFactory.RawSpec(ctx, w.Workflow, w.SpecType)
workflowSpecFactory, ok := workflowSpecFactories[w.SpecType]
if !ok {
return nil, fmt.Errorf("unknown spec type %s", w.SpecType)
}

rs, err := workflowSpecFactory.RawSpec(ctx, w.Workflow, []byte(w.Config))
if err != nil {
return nil, err
}
Expand Down
37 changes: 30 additions & 7 deletions core/services/job/models_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package job
package job_test

import (
_ "embed"
"encoding/json"
"reflect"
"testing"
"time"
Expand All @@ -11,8 +12,10 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
pkgworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk"

"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"

"github.com/stretchr/testify/assert"
Expand All @@ -27,7 +30,7 @@ func TestOCR2OracleSpec_RelayIdentifier(t *testing.T) {
type fields struct {
Relay string
ChainID string
RelayConfig JSONConfig
RelayConfig job.JSONConfig
}
tests := []struct {
name string
Expand Down Expand Up @@ -71,7 +74,7 @@ func TestOCR2OracleSpec_RelayIdentifier(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

s := &OCR2OracleSpec{
s := &job.OCR2OracleSpec{
Relay: tt.fields.Relay,
ChainID: tt.fields.ChainID,
RelayConfig: tt.fields.RelayConfig,
Expand All @@ -96,7 +99,7 @@ var (
)

func TestOCR2OracleSpec(t *testing.T) {
val := OCR2OracleSpec{
val := job.OCR2OracleSpec{
Relay: relay.NetworkEVM,
PluginType: types.Median,
ContractID: "foo",
Expand Down Expand Up @@ -259,13 +262,13 @@ func TestOCR2OracleSpec(t *testing.T) {
})

t.Run("round-trip", func(t *testing.T) {
var gotVal OCR2OracleSpec
var gotVal job.OCR2OracleSpec
require.NoError(t, toml.Unmarshal([]byte(compact), &gotVal))
gotB, err := toml.Marshal(gotVal)
require.NoError(t, err)
require.Equal(t, compact, string(gotB))
t.Run("pretty", func(t *testing.T) {
var gotVal OCR2OracleSpec
var gotVal job.OCR2OracleSpec
require.NoError(t, toml.Unmarshal([]byte(pretty), &gotVal))
gotB, err := toml.Marshal(gotVal)
require.NoError(t, err)
Expand Down Expand Up @@ -321,7 +324,7 @@ func TestWorkflowSpec_Validate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &WorkflowSpec{
w := &job.WorkflowSpec{
Workflow: tt.fields.Workflow,
}
err := w.Validate(testutils.Context(t))
Expand All @@ -333,4 +336,24 @@ func TestWorkflowSpec_Validate(t *testing.T) {
}
})
}

t.Run("WASM can validate", func(t *testing.T) {
config, err := json.Marshal(sdk.NewWorkflowParams{
Owner: "owner",
Name: "name",
})
require.NoError(t, err)

w := &job.WorkflowSpec{
Workflow: createTestBinary(t),
SpecType: job.WASMFile,
Config: string(config),
}

err = w.Validate(testutils.Context(t))
require.NoError(t, err)
assert.Equal(t, "owner", w.WorkflowOwner)
assert.Equal(t, "name", w.WorkflowName)
require.NotEmpty(t, w.WorkflowID)
})
}
33 changes: 33 additions & 0 deletions core/services/job/testdata/wasm/test_workflow_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build wasip1

package main

import (
"encoding/json"
"log"

"github.com/smartcontractkit/chainlink-common/pkg/workflows/wasm"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities/cli/cmd/testdata/fixtures/capabilities/basictrigger"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk"
)

func BuildWorkflow(config []byte) *sdk.WorkflowSpecFactory {
params := sdk.NewWorkflowParams{}
if err := json.Unmarshal(config, &params); err != nil {
log.Fatal(err)
}

workflow := sdk.NewWorkflowSpecFactory(params)

triggerCfg := basictrigger.TriggerConfig{Name: "trigger", Number: 100}
_ = triggerCfg.New(workflow)

return workflow
}

func main() {
runner := wasm.NewRunner()
workflow := BuildWorkflow(runner.Config())
runner.Run(workflow)
}
Loading

0 comments on commit 99965a4

Please sign in to comment.